 I trying to multiplicate matrices this way:

``````//  A[m * k]     B[k  * n]      C        C
//  | 1 2 |    | 1 2 3 4|    | 1   2  3  4| |  2  4  6  8|
//  | 3 4 |  * | 5 6 7 8| =  | 12 18 21 24| | 20 24 28 32|
//  | 5 6 |    | 9 1 2 3| =  | 45  5 10 15| | 54  6 12 18|
``````

The problem is I cannot figure out how to make the index for A?

``````__global__ void HadamardProduct( const float* A, const float* B, float* C, const size_t width, const size_t height, const size_t length )
{
const size_t xIndex = blockIdx.x * blockDim.x + threadIdx.x;
const size_t yIndex = blockIdx.y * blockDim.y + threadIdx.y;

const size_t indexB  = yIndex * width + xIndex;

if( (xIndex < width) && (yIndex < height))
{
for( size_t n = 0; n < length; n++ )  // copy B to n-element of C
{
const size_t indexC  = width * height * n + indexB;
const size_t indexA  = height * n + yIndex;

C[ indexC ] = A[ yIndex ] /* [indexB]*/;
}
}
}
``````

if I comment out A[ yIndex ] I have copies of B in C which is correect, but with A

``````const size_t length = 2;   //length number of rows of matrix op(A) and C
const size_t height = 3;   //height number of columns of op(A) and rows of op(B).
const size_t width  = 4;   //width  number of columns of op(A) and rows of op(B).

float A[ length * height ] = { 1, 2, 3, 4, 5, 6 };

float B[ height * width ] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3 };

float C[ length * width * height ] = { 0 };

int rst = ::DoHadamardProduct( A, B, C, width, height, length );
``````

I wanna have:

``````float expected[ _countof(C) ] = { 1, 3, 5, 1, 3, 5, 1, 3, 5, 1, 3, 5, 2, 4, 6, 2, 4, 6, 2, 4, 6, 2, 4, 6 };
``````