clMathLibraries / clBLAS

a software library containing BLAS functions written in OpenCL
Apache License 2.0
839 stars 240 forks source link

Basic gemm application not computing correctly #79

Closed cdeterman closed 9 years ago

cdeterman commented 9 years ago

I am trying to adapt the example_sgemm.c file for a full matrix multiplication (not the 'lower-right submatrix'). However I can not figure out how to get the numbers to come out correctly.

If I take the exact matrices to another language like R. I get the output between the matrices simply with this:

A <- matrix(c(11, 12, 13, 14, 15,
              21, 22, 23, 24, 25,
              31, 32, 33, 34, 35,
              41, 42, 43, 44, 45 ), nrow=4)

B <- matrix(c( 11, 12, 13,
               21, 22, 23,
               31, 32, 33,
               41, 42, 43,
               51, 52, 53), nrow=5)

A %*% B
     [,1] [,2] [,3]
[1,] 2230 4297 6273
[2,] 2369 4612 6729
[3,] 2513 4932 7225
[4,] 2697 5257 7726

Now, I saw this previously closed issue #15 and tried adapt the statements to set the offsets to zero. I also set the alpha = 1 and beta=0. But the output returned is:

2115 2180 2245 
3665 3780 3895 
5215 5380 5545 
6765 6980 7195 

I have been trying for hours to just do what should be a relatively simple task but have come up short. Could someone please help me sort out what is causing the numbers to be different when the inputs are identical? Clearly I must have made some mistake in my arguments to clblasSgemm. I have provided my current file in a temporary repository here.

TimmyLiu commented 9 years ago

for the first element in C, 11 x 11 + 12x21 + 13x31 + 14x41 + 15 x 51 = 121+252+403+574+765=2115, which is the answer clBLAS gave. I am not familiar with the syntax in R. Are you sure it is doing the same matrix multiplication?

cdeterman commented 9 years ago

@TimmyLiu I seem to have a knack for embarrassing questions here. I spent last last few hours fighting with this and it was because I didn't have an argument in R byrow=TRUE. The matrices were conformable but didn't have the same elements in the two places. I am glad to confirm that the code is working correctly. The numbers match now. Thank you for your attention and sorry for another silly issue.