#include "mat_mul.h" #include #include #define CHECK_ERROR(err) \ if (err != CL_SUCCESS) { \ printf("[%s:%d] OpenCL error %d\n", __FILE__, __LINE__, err); \ exit(EXIT_FAILURE); \ } #define MAX_DEV 4 #define TS 32 #define WPT 8 #define RTS TS/WPT static cl_int err; static cl_platform_id platform; //static cl_device_id device; static cl_device_id device[MAX_DEV]; static cl_context context; //static cl_command_queue queue; static cl_command_queue queue[MAX_DEV]; static cl_program program; //static cl_program program[MAX_DEV]; //static cl_kernel kernel; static cl_kernel kernel[MAX_DEV]; //static cl_mem a_d, b_d, c_d; static cl_mem a_d[MAX_DEV], b_d[MAX_DEV], c_d[MAX_DEV]; static int ndev; static float *A, *B, *C; static int M, N, K; 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; N = _N, K = _K; // Setup kernel arguments //err = clSetKernelArg(kernel, 0, sizeof(cl_mem), &a_d); //CHECK_ERROR(err); //err = clSetKernelArg(kernel, 1, sizeof(cl_mem), &b_d); //CHECK_ERROR(err); //err = clSetKernelArg(kernel, 2, sizeof(cl_mem), &c_d); //CHECK_ERROR(err); //err = clSetKernelArg(kernel, 3, sizeof(int), &M); //CHECK_ERROR(err); //err = clSetKernelArg(kernel, 4, sizeof(int), &N); //CHECK_ERROR(err); //err = clSetKernelArg(kernel, 5, sizeof(int), &K); //CHECK_ERROR(err); for (int i=0; i a_d (gpu), B (cpu) -> b_d (gpu) //err = clEnqueueWriteBuffer(queue, a_d, CL_TRUE, 0, M * K * sizeof(float), A, 0, NULL, NULL); //CHECK_ERROR(err); //err = clEnqueueWriteBuffer(queue, b_d, CL_TRUE, 0, K * N * sizeof(float), B, 0, NULL, NULL); //CHECK_ERROR(err); for (int i=0; i C (cpu) //err = clEnqueueReadBuffer(queue, c_d, CL_TRUE, 0, M * N * sizeof(float), C, 0, NULL, NULL); for (int i=0; i