#include #include #include #include #include "cl_simple.h" #include "cl_util.h" #define GLOBAL_DIM_X 10 #define GLOBAL_DIM_Y 10 int main (int argc, char ** argv) { unsigned i,j; cl_int error; cl_mem out_buffer; int out_data[GLOBAL_DIM_X * GLOBAL_DIM_Y]; size_t global_work_size[2] = {GLOBAL_DIM_X, GLOBAL_DIM_Y}; size_t local_work_size[2] = {5, 5}; struct cl_simple_context context; clSimpleSimpleInit(&context, "global_id2d"); /* XXX: Delete this to see a missing error path */ out_buffer = clCreateBuffer(context.cl_ctx, CL_MEM_WRITE_ONLY, sizeof(out_data), NULL, &error); assert(error == CL_SUCCESS); if (!clSimpleKernelSetArg(context.kernel, 0, sizeof(cl_mem), &out_buffer)) { return EXIT_FAILURE; } if (!clSimpleEnqueueNDRangeKernel(context.command_queue, context.kernel, 2, global_work_size, local_work_size)) { return EXIT_FAILURE; } error = clEnqueueReadBuffer(context.command_queue, out_buffer, CL_TRUE, 0, sizeof(out_data), out_data, 0, NULL, NULL); assert(error == CL_SUCCESS); for (i = 0; i < GLOBAL_DIM_X; i++) { for (j = 0; j < GLOBAL_DIM_Y; j++) { fprintf(stderr, "%2u ", out_data[i * GLOBAL_DIM_Y + j]); } fprintf(stderr, "\n"); } }