I want to do nonsquare matrix multiplication using CUDA The input is two matrices: a and b
a = RandomReal[{0, 5}, {100, 4}];
b = RandomReal[{0, 5}, {4, 6}];
m = Dimensions[a][[1]];
nn = Dimensions[a][[2]];
k = Dimensions[b][[2]];
cc = ConstantArray[0, {m, k}]; (*output*)
for this case, the output matrix will have dimensions, 100 x 6
the CUDA code:
code = "
__global__ void squarematrixmult(double *a, double *b, double *c, \
mint m, mint nn, mint k)
{
int row = blockIdx.y * blockDim.y + threadIdx.y;
int col = blockIdx.x * blockDim.x + threadIdx.x;
float sum = 0;
if( col < k && row < m)
{
for(int i = 0; i < nn; i++)
{
sum += a[row * nn + i] * b[i * k + col];
}
c[row * k + col] = sum;
}
} ";
the computation:
cudaFun =
CUDAFunctionLoad[code,
"squarematrixmult", {{_Real, _, "Input"}, {_Real, _,
"Input"}, {_Real, _,
"Output"}, _Integer, _Integer, _Integer}, {32, 32}];
res = cudaFun[a, b, cc, m, nn, k];
However, since the defined block size is {32,32}, the given answer is only for 32 elements. elements after 32 are all zeros. for this case, the output is 100 x 6, but only 32 x 6 have values (correct values), but else are zeros.
So how can i fix the way to define threads/blocks/grids in CUDAFunctionLoad? thank you so much