#include "mat_mul.h" #include #include #define TS 32 #define WPT 8 #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; 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; int ndev; int i, m; 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; m = (M+ndev-1)/ndev; // Setup kernel arguments for(i=0; i a_d (gpu), B (cpu) -> b_d (gpu) for(i=0; i C (cpu) int tmp = M%ndev; int offsetm = m; for(i=0; i