# How does this code perform matrix-matrix multiplication?

Discussion created by gpgpu on Oct 26, 2008
Latest reply on Oct 27, 2008 by foxx1337

kernel void
simple_matmult(float Width, float A[][], float B[][], out float result<>
{
// vPos - Position of the output matrix i.e. (x,y)
float2 vPos = indexof(result).xy;

// index - coordinates of A & B from where the values are fetched
float4 index = float4(vPos.x, 0.0f, 0.0f, vPos.y);
// step - represents the step by which index is incremented
float4 step = float4(0.0f, 1.0f, 1.0f, 0.0f);

// accumulator - Accumulates the result of intermediate calculation
// between A & B
float accumulator = 0.0f;

// Running a  loop which starts from
// (0,vPos.y) in A and (vPos.x,0) in B
// and increments the 'y' value of A and the 'x' value of B
// which basically implies that we're fetching values from
// the 'vPos.y'th row of A and 'vPox.x'th column of B
float i0 = Width;
while(i0 > 0)
{
// A[k] * B[k][j]
accumulator += A[index.zw]*B[index.xy];
index += step;
i0 = i0 - 1.0f;
}

// Writing the result back to the buffer
result = accumulator;
}

accumulator += A[index.zw]*B[index.xy];
I am confused by this statement.

According to the aboving statement, it should be A's column * B's row.

I really don't understand this statement.

Thanks for explaination.