From 28852a587dc40a54ce32a63ec1a134e4ca4a57b8 Mon Sep 17 00:00:00 2001 From: Tom Stellard Date: Thu, 15 Mar 2012 11:58:43 -0400 Subject: Turn get-global-id into a test --- get_global_id.c | 48 +++++++++++++++++++++++++++++++++++++----------- run_tests.sh | 16 ++++++++++++++++ 2 files changed, 53 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; } diff --git a/run_tests.sh b/run_tests.sh index b26b9c4..5f2e461 100644 --- a/run_tests.sh +++ b/run_tests.sh @@ -102,4 +102,20 @@ run_test "./math-int mod_four 20 4 0" #Constant power of two divisor, modulo is non-zero run_test "./math-int mod_four 5 4 1" +############################################################################### +#get_global_id() # +############################################################################### + +#One work group +run_test "./get-global-id 100 100" +#One work item per work group +run_test "./get-global-id 250 1" +#Large number of threads in one work group +run_test "./get-global-id 1000000 1000000" +#Large number of work groups, one work item per group +run_test "./get-global-id 2000000 1" +#Large number of threads +run_test "./get-global-id 5000000 1000" + + echo "$PASS passes, $FAIL fails" -- cgit v1.2.3