Advertisement
Guest User

Untitled

a guest
Nov 3rd, 2014
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.67 KB | None | 0 0
  1. // index of element in matrix
  2. uint index(uint row, uint column)
  3. {
  4.     return column*4 + row;
  5. }
  6.  
  7. const int N = 10000;
  8.  
  9. //~ // c = a*b
  10. __kernel void matrix_mul(__global float* a, __global float* b, __global float* c)
  11. {
  12.     const uint n = get_global_id(0)*N;
  13.  
  14.     for(int i=n; i<n+N; ++i)
  15.     {
  16.         c[i] = 0;
  17.  
  18.         uint m = i/16; // index of matrix
  19.         m*=16; // offset of matrix
  20.         uint row = i%4; // row of current element within the matrix
  21.         uint col = i/4 % 4; // column of current element within the matrix
  22.  
  23.         for(uint k=0; k<4; ++k)
  24.         {
  25.             c[i] += a[m + index(row, k)] * b[m + index(k, col)];
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement