Create a gist now

Instantly share code, notes, and snippets.

@krk /naive-matmul.c Secret
Created Jun 27, 2017

What would you like to do?
inline
float* h_loc(float* h_B, int width, int i, int j)
{
return h_B + i*width + j;
}
void hostMatrixMultiply(
float* h_C,
float* h_A,
float* h_B,
int m,
int n,
int r)
{
clock_t start = clock(), diff;
for(int i=0; i<m; i++)
{
for(int k=0; k<r; k++)
{
float sum = 0;
for(int j=0; j<n; j++)
{
sum += *h_loc(h_A, n, i, j) * *h_loc(h_B, r, j, k);
}
*h_loc(h_C, r, i, k) = sum;
}
}
diff = clock() - start;
int msec = diff * 1000 / CLOCKS_PER_SEC;
printf("hostMatrixMultiply: %i ms\n", msec);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment