// Constants for kernels 1 -- 5 #define TS 32 // The square-root of the 2D tile-size (== work-group dims) // Constants for kernels 3, 5 #define WPT 8 // The amount of work-per-thread, i.e. the thread-coarsening factor #define RTS (TS/WPT) // The reduced tile-size in one dimension // Increased the amount of work-per-thread by a factor WPT __kernel void sgemm(const __global float* A, const __global float* B, __global float* C, const int M, const int N, const int K) { // Thread identifiers const int row = get_local_id(0); // Local row ID (max: TS) const int col = get_local_id(1); // Local col ID (max: TS/WPT == RTS) const int globalRow = TS*get_group_id(0) + row; // Row ID of C (0..M) const int globalCol = TS*get_group_id(1) + col; // Col ID of C (0..N) // Local memory to fit a tile of TS*TS elements of A and B __local float Asub[TS][TS]; __local float Bsub[TS][TS]; // Initialise the accumulation registers float acc[WPT]; for (int w=0; w= M || tiledCol >= K) { Asub[row + w*RTS][col] = 0.0f; } else { Asub[row + w*RTS][col] = A[(globalRow + w*RTS)*K + tiledCol]; } if(globalCol >= N || tiledRow + w*RTS >= K) { Bsub[row + w*RTS][col] = 0.0f; } else { Bsub[row + w*RTS][col] = B[(tiledRow + w*RTS)*N + globalCol]; } } // Synchronise to make sure the tile is loaded barrier(CLK_LOCAL_MEM_FENCE); // Perform the computation for a single tile for (int k=0; k= M || globalCol >= N) { continue; } else { C[(globalRow + w*RTS)*N + globalCol] = acc[w]; } } }