cancel
Showing results for
Did you mean:

# Archives Discussions Journeyman III

## MatrixMultiplication sample question?

I agree. row-major order is equivalent to: matrixA[ i*SIZE + j ] but in the example they're multiplying pos.y by SIZE (or widthA/4), which is equivalent to matrixA[ i + j*SIZE ]. Journeyman III

## MatrixMultiplication sample question?

 Originally posted by: jski I agree. row-major order is equivalent to: matrixA[ i*SIZE + j ] but in the example they're multiplying pos.y by SIZE (or widthA/4), which is equivalent to matrixA[ i + j*SIZE ].

Just not, row-major is matrixA[i + j *WIDTH].

EDIT: see wiki: http://en.wikipedia.org/wiki/Row_major Journeyman III

## MatrixMultiplication sample question?

I do believe we've arrive at the crux (according to Wikipedia):

Row major: offset = row*NUMCOLS + column (or offset = i*SIZE + j)

Column major:  offset = row + column*NUMROWS (or offset = i + j*SIZE),

which is what I believe I've been saying.

But you're saying (whatever we call it) that the OpenCL code in the example is using: offset = i + j*SIZE ???

---John Journeyman III

## MatrixMultiplication sample question?

I have to sorry for making a bit mess here. I have just verified, that I have swapped the meaning of the letters i and j. (I didn't remember it from school and I meant that i,j is similar to x,y where x is vertical coordinate, but it is the opposite )
So you were right that row-major is:
offset = i*SIZE + j
> But you're saying (whatever we call it) that the OpenCL code in the example is using: offset = i + j*SIZE ???
I'd better not use i and j In sample it is therefore:
offset = row_index * width + column_index (supposing that i == row index, j == column index)
So row-major.
In the sample is pos.y equivalent to the letter i.
Again, sorry for making a mess  Journeyman III

## MatrixMultiplication sample question?

Pulec, first THANKS!

So we've arrive at the conclusion: in this example, AMD has inverted the usual interpretation of get_global_id(0) and get_global_id(1).   Here, get_global_id(0) corresponds to the Y-axis and get_global_id(1) corresponds to the X-axis ??? Journeyman III

## MatrixMultiplication sample question?

> So we've arrive at the conclusion
I am afraid we didn't.

The meaning of X,Y is usual, get_global_id(0) corresponds to the X-axis/j-matrix-coordinate/horizontal axis. get_global_id(1) is Y-axis or row matrix coordinate.
Or why do you mean it is inverted?

The sample is basically this (non-vectorized version):

int2 pos = (int2)(get_global_id(0), get_global_id(1));

matrixC[pos.x + pos.y * widthB] = 0;
for(int k = 0; k < widthA; ++k)
{
matrixC[pos.x + pos.y * widthB] += matrixA[k + pos.y * widthA] * matrixB[pos.x + k * widthB];
}
I think it is perfectly staightforward - for Cij we take a row from matA multiplied by column from matB (pos.x == j; pos.y == i). Journeyman III

## MatrixMultiplication sample question?

Thanks.

My misunderstanding was I had assumed the opposite of: pos.x == j; pos.y == i. ---John Journeyman III

## MatrixMultiplication sample question?

 Originally posted by: jskiThanks.My misunderstanding was: pos.x == j; pos.y == i.  I had assumed the opposite.  ---John

Yes, it's natural, I had also swapped the the mapping of those letters, as you has probably noticed  Journeyman III