summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--get_global_id.c48
-rw-r--r--run_tests.sh16
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"