-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
130 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,57 @@ | ||
__kernel void matrix_multiplication(...) | ||
#define TILE_SIZE 16 | ||
#define THREAD_WORK 16 | ||
|
||
__kernel void matrix_multiplication(const __global float* a, | ||
const __global float* b, | ||
__global float* c, | ||
unsigned int M, | ||
unsigned int K, | ||
unsigned int N) | ||
{ | ||
// TODO | ||
} | ||
int i = get_global_id(0); | ||
int j = get_global_id(1); | ||
|
||
float sum = 0.0f; | ||
for(int k = 0; k < K; ++k) | ||
{ | ||
sum += a[j * K + k]* b[k * N + i]; | ||
} | ||
c[j * N + i] = sum; | ||
} | ||
|
||
__kernel void matrix_multiplication_1(const __global float* a, | ||
const __global float* b, | ||
__global float* c, | ||
unsigned int M, | ||
unsigned int K, | ||
unsigned int N) | ||
{ | ||
int global_i = get_global_id(0); | ||
int global_j = get_global_id(1); | ||
int local_i = get_local_id(0); | ||
int local_j = get_local_id(1); | ||
|
||
if (global_i >= M || global_j > N || local_i > TILE_SIZE || local_j > TILE_SIZE) | ||
{ | ||
return; | ||
} | ||
|
||
__local float tileA[TILE_SIZE][TILE_SIZE + 1]; | ||
__local float tileB[TILE_SIZE][TILE_SIZE + 1]; | ||
|
||
float sum = 0.0f; | ||
for (int tileK = 0; tileK * TILE_SIZE < K; ++tileK) | ||
{ | ||
tileA[local_j][local_i] = a[global_j * K + TILE_SIZE * tileK + local_i]; | ||
tileB[local_j][local_i] = b[(TILE_SIZE * tileK + local_j) * N + global_i]; | ||
barrier(CLK_LOCAL_MEM_FENCE); | ||
|
||
for (int k = 0; k < TILE_SIZE; ++k) | ||
{ | ||
sum += tileA[local_j][k] * tileB[k][local_i]; | ||
} | ||
barrier(CLK_LOCAL_MEM_FENCE); | ||
} | ||
c[global_j * N + global_i] = sum; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,31 @@ | ||
__kernel void matrix_transpose(...) | ||
#define TILE_SIZE 32 | ||
|
||
__kernel void matrix_transpose(__global float* as, | ||
__global float* as_t, | ||
unsigned int m, | ||
unsigned int k) | ||
{ | ||
// TODO | ||
} | ||
int global_i = get_global_id(0); | ||
int global_j = get_global_id(1); | ||
|
||
if (global_j >= m || global_i >= k) | ||
{ | ||
return; | ||
} | ||
|
||
int local_i = get_local_id(0); | ||
int local_j = get_local_id(1); | ||
|
||
if ((local_i >= TILE_SIZE) || (local_j >= TILE_SIZE)) | ||
{ | ||
return; | ||
} | ||
|
||
__local float tile[TILE_SIZE][TILE_SIZE + 1]; | ||
tile[local_j][local_i] = as[global_j * k + global_i]; | ||
|
||
barrier(CLK_LOCAL_MEM_FENCE); | ||
|
||
as_t[global_i * m + global_j] = tile[local_j][local_i]; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters