diff options
Diffstat (limited to 'get_global_id_2d.c')
-rw-r--r-- | get_global_id_2d.c | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/get_global_id_2d.c b/get_global_id_2d.c new file mode 100644 index 0000000..ae940e7 --- /dev/null +++ b/get_global_id_2d.c @@ -0,0 +1,60 @@ +#include <assert.h> +#include <stdio.h> + +#include <CL/cl.h> + +#include "util.h" + + +int main (int argc, char ** argv) +{ + unsigned i,j; + cl_int error; + + cl_mem out_buffer; + int out_data[10][10]; + size_t global_work_size[2] = {10, 10}; + + struct clu_context context; + + cluSimpleInit(&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 (!cluKernelSetArg(context.kernel, 0, sizeof(cl_mem), &out_buffer)) { + return EXIT_FAILURE; + } + + error = clEnqueueNDRangeKernel(context.command_queue, + context.kernel, + 2, /* dimensions */ + NULL, + global_work_size, + global_work_size, + 0, NULL, NULL); + + assert(error == CL_SUCCESS); + + 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 < 10; i++) { + for (j = 0; j < 10; j++) { + fprintf(stderr, "%2u ", out_data[i][j]); + } + fprintf(stderr, "\n"); + } +} |