void* ClWrapper::getDeviceInfo(cl_device_info paramName) { size_t infoSize = 0; CL_SAFE_CALL( clGetDeviceInfo(_device_id, paramName, 0, NULL, &infoSize) ); char* info = (char*)malloc(infoSize); CL_SAFE_CALL( clGetDeviceInfo(_device_id, paramName, infoSize, info, NULL) ); return info; }
char* ClWrapper::getPlatformInfo(cl_platform_info paramName) { size_t infoSize = 0; CL_SAFE_CALL( clGetPlatformInfo(_platform, paramName, 0, NULL, &infoSize) ); char* info = (char*)malloc(infoSize); CL_SAFE_CALL( clGetPlatformInfo(_platform, paramName, infoSize, info, NULL) ); return info; }
/* XXX: same program_source with different kernel_name[], context or device * will retrieve the same key */ gegl_cl_run_data * gegl_cl_compile_and_build (const char *program_source, const char *kernel_name[]) { gint errcode; gegl_cl_run_data *cl_data = NULL; if ((cl_data = (gegl_cl_run_data *)g_hash_table_lookup(cl_program_hash, program_source)) == NULL) { size_t length = strlen(program_source); gint i; guint kernel_n = 0; while (kernel_name[++kernel_n] != NULL); cl_data = (gegl_cl_run_data *) g_malloc(sizeof(gegl_cl_run_data)+sizeof(cl_kernel)*kernel_n); CL_SAFE_CALL( cl_data->program = gegl_clCreateProgramWithSource(gegl_cl_get_context(), 1, &program_source, &length, &errcode) ); errcode = gegl_clBuildProgram(cl_data->program, 0, NULL, NULL, NULL, NULL); if (errcode != CL_SUCCESS) { char buffer[2000]; CL_SAFE_CALL( errcode = gegl_clGetProgramBuildInfo(cl_data->program, gegl_cl_get_device_id(), CL_PROGRAM_BUILD_LOG, sizeof(buffer), buffer, NULL) ); g_warning("OpenCL Build Error:%s\n%s", gegl_cl_errstring(errcode), buffer); return NULL; } else { g_printf("[OpenCL] Compiling successful\n"); } for (i=0; i<kernel_n; i++) CL_SAFE_CALL( cl_data->kernel[i] = gegl_clCreateKernel(cl_data->program, kernel_name[i], &errcode) ); g_hash_table_insert(cl_program_hash, g_strdup (program_source), (void*)cl_data); } return cl_data; }
static void motion_blur_cl (GeglBuffer *src, const GeglRectangle *src_rect, GeglBuffer *dst, const GeglRectangle *dst_rect, const int num_steps, const float offset_x, const float offset_y) { const Babl * in_format = babl_format("RaGaBaA float"); const Babl *out_format = babl_format("RaGaBaA float"); /* AreaFilter general processing flow. Loading data and making the necessary color space conversion. */ #include "gegl-cl-operation-area-filter-fw1.h" /////////////////////////////////////////////////////////////////////////// /* Algorithm specific processing flow. Build kernels, setting parameters, and running them. */ if (!cl_data) { const char *kernel_name[] = { "motion_blur_CL", NULL }; cl_data = gegl_cl_compile_and_build(kernel_source, kernel_name); } if (!cl_data) CL_ERROR; cl_int cl_src_width = src_rect->width; cl_int cl_src_height = src_rect->height; cl_int cl_src_x = src_rect->x; cl_int cl_src_y = src_rect->y; cl_int cl_dst_x = dst_rect->x; cl_int cl_dst_y = dst_rect->y; cl_int cl_num_steps = num_steps; cl_float cl_offset_x = offset_x; cl_float cl_offset_y = offset_y; CL_SAFE_CALL(errcode = gegl_clSetKernelArg( cl_data->kernel[0], 0, sizeof(cl_mem), (void*)&src_mem)); CL_SAFE_CALL(errcode = gegl_clSetKernelArg( cl_data->kernel[0], 1, sizeof(cl_int), (void*)&cl_src_width)); CL_SAFE_CALL(errcode = gegl_clSetKernelArg( cl_data->kernel[0], 2, sizeof(cl_int), (void*)&cl_src_height)); CL_SAFE_CALL(errcode = gegl_clSetKernelArg( cl_data->kernel[0], 3, sizeof(cl_int), (void*)&cl_src_x)); CL_SAFE_CALL(errcode = gegl_clSetKernelArg( cl_data->kernel[0], 4, sizeof(cl_int), (void*)&cl_src_y)); CL_SAFE_CALL(errcode = gegl_clSetKernelArg( cl_data->kernel[0], 5, sizeof(cl_mem), (void*)&dst_mem)); CL_SAFE_CALL(errcode = gegl_clSetKernelArg( cl_data->kernel[0], 6, sizeof(cl_int), (void*)&cl_dst_x)); CL_SAFE_CALL(errcode = gegl_clSetKernelArg( cl_data->kernel[0], 7, sizeof(cl_int), (void*)&cl_dst_y)); CL_SAFE_CALL(errcode = gegl_clSetKernelArg( cl_data->kernel[0], 8, sizeof(cl_int), (void*)&cl_num_steps)); CL_SAFE_CALL(errcode = gegl_clSetKernelArg( cl_data->kernel[0], 9, sizeof(cl_float), (void*)&cl_offset_x)); CL_SAFE_CALL(errcode = gegl_clSetKernelArg( cl_data->kernel[0], 10, sizeof(cl_float), (void*)&cl_offset_y)); CL_SAFE_CALL(errcode = gegl_clEnqueueNDRangeKernel( gegl_cl_get_command_queue(), cl_data->kernel[0], 2, NULL, gbl_size, NULL, 0, NULL, NULL)); errcode = gegl_clEnqueueBarrier(gegl_cl_get_command_queue()); if (CL_SUCCESS != errcode) CL_ERROR; /////////////////////////////////////////////////////////////////////////// /* AreaFilter general processing flow. Making the necessary color space conversion and Saving data. */ #include "gegl-cl-operation-area-filter-fw2.h" }
void ClWrapper::createDevice() { CL_SAFE_CALL( clGetDeviceIDs(_platform, _device_type, 1, &_device_id, NULL) ); }
void ClWrapper::createPlatform() { CL_SAFE_CALL(clGetPlatformIDs(1, &_platform, NULL)); }