adding tensor regression test.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -184,8 +184,8 @@ int main (int argc, char **argv) {
|
||||
CL_CHECK(clSetKernelArg(kernel, 1, sizeof(cl_mem), (void *)&b_memobj));
|
||||
CL_CHECK(clSetKernelArg(kernel, 2, sizeof(cl_mem), (void *)&c_memobj));
|
||||
CL_CHECK(clSetKernelArg(kernel, 3, sizeof(uint32_t), &size));
|
||||
CL_CHECK(clSetKernelArg(kernel, 4, local_size[0]*local_size[1]*sizeof(float), NULL));
|
||||
CL_CHECK(clSetKernelArg(kernel, 5, local_size[0]*local_size[1]*sizeof(float), NULL));
|
||||
//CL_CHECK(clSetKernelArg(kernel, 4, local_size[0]*local_size[1]*sizeof(float), NULL));
|
||||
//CL_CHECK(clSetKernelArg(kernel, 5, local_size[0]*local_size[1]*sizeof(float), NULL));
|
||||
|
||||
// Allocate memories for input arrays and output arrays.
|
||||
std::vector<float> h_a(size * size);
|
||||
|
||||
Reference in New Issue
Block a user