diff options
Diffstat (limited to 'get_global_id.c')
-rw-r--r-- | get_global_id.c | 48 |
1 files changed, 37 insertions, 11 deletions
diff --git a/get_global_id.c b/get_global_id.c index f9a5170..e06349a 100644 --- a/get_global_id.c +++ b/get_global_id.c @@ -7,27 +7,53 @@ int main(int argc, char ** argv) { - cl_int error; - struct cl_simple_context context; unsigned i; - int out_data[10]; - size_t global_work_size = 10; + int * out; + unsigned out_size; + size_t global_work_size, local_work_size; + + global_work_size = atoi(argv[1]); + local_work_size = atoi(argv[2]); + + out_size = global_work_size * sizeof(int); + out = malloc(out_size); + + if (!out) { + return EXIT_FAILURE; + } - clSimpleSimpleInit(&context, "global_id"); + if (!clSimpleSimpleInit(&context, "global_id")) { + return EXIT_FAILURE; + } - clSimpleSetOutputBuffer(&context, sizeof(out_data)); + if (!clSimpleSetOutputBuffer(&context, out_size)) { + return EXIT_FAILURE; + } - clSimpleEnqueueNDRangeKernel(context.command_queue, + if(!clSimpleEnqueueNDRangeKernel(context.command_queue, context.kernel, - 1, &global_work_size, &global_work_size); + 1, &global_work_size, &global_work_size)) { + return EXIT_FAILURE; + } - clSimpleReadOutput(&context, out_data, sizeof(out_data)); + if (!clSimpleReadOutput(&context, out, out_size)) { + return EXIT_FAILURE; + } + /* Print the result */ + for (i = 0; i < global_work_size; i++) { + fprintf(stderr, "id %u = %u\n", i, out[i]); + } - for (i = 0; i < 10; i++) { - fprintf(stderr, "id %u = %u\n", i, out_data[i]); + /* Check the result */ + for (i = 0; i < global_work_size; i++) { + if (i != out[i]) { + fprintf(stderr, "Expected out[%u] = %u, actual: %u\n", i, i, out[i]); + return EXIT_FAILURE; + } } + return EXIT_SUCCESS; } |