#include "mat_mul.h" #include #include #define MAX_DEV 4 #define CHECK_ERROR(err) \ if (err != CL_SUCCESS) { \ printf("[%s:%d] OpenCL error %d\n", __FILE__, __LINE__, err); \ exit(EXIT_FAILURE); \ } static cl_int err; static cl_platform_id platform; static cl_device_id device[MAX_DEV]; static cl_context context; static cl_command_queue queue[MAX_DEV]; static cl_program program[MAX_DEV]; static cl_kernel kernel[MAX_DEV]; static cl_mem a_d[MAX_DEV], b_d[MAX_DEV], c_d[MAX_DEV]; static float *A, *B, *C; static int M, N, K; static int ndev; // Constants for kernels 3, 5 #define TS 32 #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 void mat_mul(float *_A, float *_B, float *_C, int _M, int _N, int _K) { A = _A, B = _B, C = _C; M = _M, N = _N, K = _K; int size; for(int i=0;i a_d (gpu), B (cpu) -> b_d (gpu) err = clEnqueueWriteBuffer(queue[i], a_d[i], CL_FALSE, 0, size * K * sizeof(float), &A[M/ndev*K*i], 0, NULL, NULL); CHECK_ERROR(err); err = clEnqueueWriteBuffer(queue[i], b_d[i], CL_FALSE, 0, K * N * sizeof(float), B, 0, NULL, NULL); CHECK_ERROR(err); } // DO NOT REMOVE; NEEDED FOR TIME MEASURE for(int i=0;i C (cpu) for(int i=0;i