| | |
| | | |
| | | void check_error(cl_info info) |
| | | { |
| | | // clFinish(cl.queue); |
| | | clFinish(cl.queue); |
| | | if (info.error != CL_SUCCESS) { |
| | | printf("\n Error number %d", info.error); |
| | | abort(); |
| | |
| | | void cl_setup() |
| | | { |
| | | if(!cl.initialized){ |
| | | printf("initializing\n"); |
| | | fprintf(stderr, "Initializing OpenCL\n"); |
| | | cl = cl_init(gpu_index); |
| | | } |
| | | } |
| | |
| | | |
| | | void cl_read_array(cl_mem mem, float *x, int n) |
| | | { |
| | | if(gpu_index < 0) return; |
| | | cl.error = clEnqueueReadBuffer(cl.queue, mem, CL_TRUE, 0, sizeof(float)*n,x,0,0,0); |
| | | check_error(cl); |
| | | } |
| | |
| | | |
| | | void cl_write_array(cl_mem mem, float *x, int n) |
| | | { |
| | | if(gpu_index < 0) return; |
| | | cl.error = clEnqueueWriteBuffer(cl.queue, mem, CL_TRUE, 0,sizeof(float)*n,x,0,0,0); |
| | | check_error(cl); |
| | | } |
| | |
| | | |
| | | cl_mem cl_make_int_array(int *x, int n) |
| | | { |
| | | if(gpu_index < 0) return 0; |
| | | cl_mem mem = clCreateBuffer(cl.context, |
| | | CL_MEM_READ_WRITE|CL_MEM_COPY_HOST_PTR, |
| | | sizeof(int)*n, x, &cl.error); |