Skip to content

Instantly share code, notes, and snippets.

@krk
Created June 27, 2017 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krk/0133d4fcce46c18edb3b8f656eb624e0 to your computer and use it in GitHub Desktop.
Save krk/0133d4fcce46c18edb3b8f656eb624e0 to your computer and use it in GitHub Desktop.
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