From 83f44eaf94939d126d6c4daf866c40a2778d561b Mon Sep 17 00:00:00 2001 From: Tom Stellard Date: Wed, 14 Mar 2012 14:58:09 -0400 Subject: add clTestReadOutput --- get_global_id.c | 28 +--------------------------- util.c | 22 ++++++++++++++++++++++ util.h | 2 ++ 3 files changed, 25 insertions(+), 27 deletions(-) diff --git a/get_global_id.c b/get_global_id.c index 0f64192..84e6fb9 100644 --- a/get_global_id.c +++ b/get_global_id.c @@ -23,37 +23,11 @@ int main(int argc, char ** argv) context.kernel, 1, &global_work_size, &global_work_size); - error = clEnqueueReadBuffer(context.command_queue, - context.out_buffer, - CL_TRUE, /* TRUE means it is a blocking read. */ - 0, /* Buffer offset to read from. */ - sizeof(out_data), /* Bytes to read */ - out_data, /* Pointer to store the data */ - 0, /* Events in wait list */ - NULL, /* Wait list */ - NULL); /* Event object */ - - - if (error != CL_SUCCESS) { - fprintf(stderr, "clEnqueueReadBuffer() failed: %s\n", - clTestErrorString(error)); - return EXIT_FAILURE; - } + clTestReadOutput(&context, out_data, sizeof(out_data)); - fprintf(stderr, "clEnqueueReadBuffer() suceeded.\n"); for (i = 0; i < 10; i++) { fprintf(stderr, "id %u = %u\n", i, out_data[i]); } -/* - - if (out_value == expected) { - fprintf(stderr, "Pass\n"); - return EXIT_SUCCESS; - } else { - fprintf(stderr, "Expected %d, but got %d\n", expected, out_value); - return EXIT_FAILURE; - } -*/ } diff --git a/util.c b/util.c index 766f1c4..1bfd975 100644 --- a/util.c +++ b/util.c @@ -317,3 +317,25 @@ unsigned clTestEnqueueNDRangeKernel(cl_command_queue command_queue, return 1; } + +unsigned clTestReadOutput(struct cltest_context * context, void * data, + size_t data_bytes) +{ + cl_int error = clEnqueueReadBuffer(context->command_queue, + context->out_buffer, + CL_TRUE, /* TRUE means it is a blocking read. */ + 0, /* Buffer offset to read from. */ + data_bytes, /* Bytes to read */ + data, /* Pointer to store the data */ + 0, /* Events in wait list */ + NULL, /* Wait list */ + NULL); /* Event object */ + + if (error != CL_SUCCESS) { + fprintf(stderr, "clEnqueueReadBuffer() failed: %s\n", + clTestErrorString(error)); + return 0; + } + + return 1; +} diff --git a/util.h b/util.h index ecaab60..4d30690 100644 --- a/util.h +++ b/util.h @@ -21,3 +21,5 @@ unsigned clTestKernelSetArg(cl_kernel kernel, cl_uint index, size_t size, unsigned clTestEnqueueNDRangeKernel(cl_command_queue command_queue, cl_kernel kernel, cl_uint work_dim, const size_t * global_work_size, const size_t * local_work_size); +unsigned clTestReadOutput(struct cltest_context * context, void * data, + size_t data_bytes); -- cgit v1.2.3