adding tensor regression test.

This commit is contained in:
Blaise Tine
2023-11-14 05:37:46 -08:00
parent ecf546bc4a
commit 4e7a536918
22 changed files with 474 additions and 133 deletions

View File

@@ -5,35 +5,37 @@ __kernel void matmul(__global float *A,
__local float *localA,
__local float *localB)
{
int row = get_global_id(1);
int col = get_global_id(0);
int globalRow = get_global_id(1);
int globalCol = get_global_id(0);
int localRow = get_local_id(1);
int localCol = get_local_id(0);
int localSize = get_local_size(0); // assuming square local size
float sum = 0.0f;
// Loop over all blocks of both matrices
for (int k = 0; k < N; k += localSize) {
// Load block of matrix A to local memory
localA[localRow * localSize + localCol] = A[row * N + k + localCol];
// Load initial blocks of A and B into local memory
int k = 0;
localA[localRow * localSize + localCol] = A[globalRow * N + k + localCol];
localB[localRow * localSize + localCol] = B[(k + localRow) * N + globalCol];
// Load block of matrix B to local memory, adjusting for column-major access
localB[localRow * localSize + localCol] = B[(k + localRow) * N + col];
// Synchronize to make sure the tiles are loaded
// Iterate over blocks
for (k = 0; k < N; k += 16) {
// Ensure the initial block is loaded
barrier(CLK_LOCAL_MEM_FENCE);
// Multiply the two matrix blocks and accumulate result
for (int j = 0; j < localSize; j++) {
// Compute multiplication for this block
for (int j = 0; j < 16; j++) {
sum += localA[localRow * localSize + j] * localB[j * localSize + localCol];
}
// Synchronize before loading the next block
barrier(CLK_LOCAL_MEM_FENCE);
// Load the next block of matrix A into local memory
if (k + 16 < N) {
localA[localRow * localSize + localCol] = A[globalRow * N + k + 16 + localCol];
localB[localRow * localSize + localCol] = B[(k + 16 + localRow) * N + globalCol];
}
}
C[row * N + col] = sum;
C[globalRow * N + globalCol] = sum;
}
/*__kernel void matmul(__global float *A, __global float *B, __global float *C, const unsigned int N)
@@ -49,15 +51,14 @@ __kernel void matmul(__global float *A,
float sum = 0.0f;
// Load initial blocks of A and B into local memory
int k = 0;
localA[localRow][localCol] = A[globalRow * N + k + localCol];
localB[localRow][localCol] = B[(k + localRow) * N + globalCol];
// Iterate over blocks
for (int k = 0; k < N; k += 16) {
// Load a block of matrix A into local memory
localA[localRow][localCol] = A[globalRow * N + k + localCol];
// Load a block of matrix B into local memory
localB[localRow][localCol] = B[(k + localRow) * N + globalCol];
// Ensure the entire block is loaded
for (k = 0; k < N; k += 16) {
// Ensure the initial block is loaded
barrier(CLK_LOCAL_MEM_FENCE);
// Compute multiplication for this block
@@ -65,8 +66,11 @@ __kernel void matmul(__global float *A,
sum += localA[localRow][j] * localB[j][localCol];
}
// Wait until all threads have computed before loading the next block
barrier(CLK_LOCAL_MEM_FENCE);
// Load the next block of matrix A into local memory
if (k + 16 < N) {
localA[localRow][localCol] = A[globalRow * N + k + 16 + localCol];
localB[localRow][localCol] = B[(k + 16 + localRow) * N + globalCol];
}
}
C[globalRow * N + globalCol] = sum;