-
Notifications
You must be signed in to change notification settings - Fork 32
Naive Matrix
Portalez Régis edited this page Jul 24, 2017
·
7 revisions
We implement here the matrix multiplication algorithm. As all such projects, it performs badly compared to vendors library such as cublas. We use the Naive Matrix Class to materialize a matrix.
The implementation is naive, and no optimization effort is done:
[EntryPoint]
public static void ComputeRowsOfProduct(NaiveMatrix resultMatrix, NaiveMatrix matrixA, NaiveMatrix matrixB, int lineFrom, int lineTo)
{
int commonSize = matrixA.Width;
int bWidth = matrixB.Width;
for (int i = lineFrom + threadIdx.y + blockIdx.y * blockDim.y; i < lineTo; i += blockDim.y * gridDim.y)
{
for (int j = threadIdx.x + blockIdx.x * blockDim.x; j < bWidth; j += blockDim.x * gridDim.x)
{
resultMatrix[i * bWidth + j] = 0.0f;
for (int k = 0; k < commonSize; ++k)
{
resultMatrix[i * bWidth + j] += (matrixA[i * commonSize + k] * matrixB[k * bWidth + j]);
}
}
}
}
Purpose of this example is to serve as base example for Shared-Matrix example, which demonstrates usage of shared memory from C#.
Newton Fractal | Home | Shared Matrix |