summaryrefslogtreecommitdiff
path: root/loop.c
diff options
context:
space:
mode:
authorTom Stellard <thomas.stellard@amd.com>2012-04-30 10:16:30 -0400
committerTom Stellard <thomas.stellard@amd.com>2012-04-30 10:16:30 -0400
commit59bc019bea96f7e7b69720cd796947798a710beb (patch)
treef57af3db1402c5ca7bdd6534d311b1281cd71c32 /loop.c
parent80e104ead1f8e463c6fd35ba3faf7bae0e65380f (diff)
Turn loop into a test and add some loop test cases to run_tests.sh
Diffstat (limited to 'loop.c')
-rw-r--r--loop.c77
1 files changed, 41 insertions, 36 deletions
diff --git a/loop.c b/loop.c
index 151dfde..9a806ef 100644
--- a/loop.c
+++ b/loop.c
@@ -15,61 +15,66 @@ int main (int argc, char ** argv)
cl_int error;
- cl_mem out_buffer;
- int * out_data;
- size_t global_work_size = 5;
+ unsigned pass = 1;
+ int * out;
+ char * kernel_name;
+ size_t global_work_size = 10;
int iterations;
- unsigned out_data_size;
+ unsigned out_size;
- if (argc != 2) {
- fprintf(stderr, "Usage: loop iterations\n");
+ if (argc != 3) {
+ fprintf(stderr, "Usage: loop kernel_name iterations\n");
return EXIT_FAILURE;
}
- iterations = atoi(argv[1]);
- out_data_size = global_work_size * iterations * sizeof(int);
- out_data = malloc(out_data_size);
+ kernel_name = argv[1];
+ iterations = atoi(argv[2]);
+ out_size = global_work_size * iterations * sizeof(int);
+ out = malloc(out_size);
- if (!clSimpleSimpleInit(&context, "loop")) {
+ if (!clSimpleSimpleInit(&context, kernel_name)) {
return EXIT_FAILURE;
}
- out_buffer = clCreateBuffer(context.cl_ctx,
- CL_MEM_WRITE_ONLY,
- out_data_size,
- NULL, &error);
-
- assert(error == CL_SUCCESS);
-
- if (!clSimpleKernelSetArg(context.kernel, 0, sizeof(cl_mem), &out_buffer)
- || !clSimpleKernelSetArg(context.kernel, 1, sizeof(int), &iterations)) {
+ if (!clSimpleSetOutputBuffer(&context, out_size)) {
return EXIT_FAILURE;
}
- error = clEnqueueNDRangeKernel(context.command_queue,
- context.kernel,
- 1,
- NULL,
- &global_work_size,
- &global_work_size,
- 0, NULL, NULL);
+ if (error != CL_SUCCESS) {
+ fprintf(stderr, "clCreateBuffer() failed\n");
+ return EXIT_FAILURE;
+ }
- assert(error == CL_SUCCESS);
+ if (!clSimpleKernelSetArg(context.kernel, 1, sizeof(int), &iterations)) {
+ return EXIT_FAILURE;
+ }
- error = clEnqueueReadBuffer(context.command_queue,
- out_buffer,
- CL_TRUE,
- 0,
- out_data_size,
- out_data,
- 0, NULL, NULL);
+ if( !clSimpleEnqueueNDRangeKernel(context.command_queue,
+ context.kernel,
+ 1, &global_work_size, &global_work_size)) {
+ return EXIT_FAILURE;
+ }
- assert(error == CL_SUCCESS);
+ if (!clSimpleReadOutput(&context, out, out_size)) {
+ return EXIT_FAILURE;
+ }
for (i = 0; i < global_work_size; i++) {
for (j = 0; j < iterations; j++) {
- fprintf(stderr, "%2u ", out_data[(i * iterations) + j]);
+ unsigned id = (i * iterations) + j;
+ if (out[id] != id) {
+ fprintf(stderr, "\n\nExpected %d, but got %d\n\n", id, out[id]);
+ pass = 0;
+ }
+ fprintf(stderr, "%2u ", out[id]);
}
fprintf(stderr, "\n");
}
+ if (pass) {
+ fprintf(stderr, "Pass\n");
+ return EXIT_SUCCESS;
+ } else {
+ fprintf(stderr, "Fail\n");
+ return EXIT_FAILURE;
+ }
}