OpenCL Matrix Multiplication - Getting wrong answer

Posted by Yash on Stack Overflow See other posts from Stack Overflow or by Yash
Published on 2012-10-21T16:57:19Z Indexed on 2012/10/21 17:00 UTC
Read the original article Hit count: 211

Filed under:
|

here's a simple OpenCL Matrix Multiplication kernel which is driving me crazy:

__kernel void matrixMul(  __global int* C,
                          __global int* A,
                          __global int* B,
                          int wA, int wB){

                int row = get_global_id(1); //2D Threas ID x
                int col = get_global_id(0); //2D Threas ID y

                //Perform dot-product accumulated into value
                int value;
                for ( int k = 0; k < wA; k++ ){
                    value += A[row*wA + k] * B[k*wB+col];
                }
                C[row*wA+col] = value; //Write to the device memory
            }

Where (inputs)

A = [72 45
     75 61]
B = [26 53 
     46 76]

Output I am getting:

C = [3942 7236
     3312 5472]

But the output should be:

C = [3943 7236
     4756 8611]

The problem I am facing here is that for any dimension array the elements of the first row of the resulting matrix is correct. The elements of all the other rows of the resulting matrix is wrong.

By the way I am using pyopencl.

I don't know what I mistake I am doing here. I have spent the entire day with no luck.

Please help me with this

© Stack Overflow or respective owner

Related posts about opencl

Related posts about pyopencl