diff options
-rw-r--r-- | hello_world.c | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/hello_world.c b/hello_world.c index 9a1d011..7cf6860 100644 --- a/hello_world.c +++ b/hello_world.c @@ -11,13 +11,20 @@ const char * err_string(cl_int error) CASE_ERR(CL_DEVICE_NOT_AVAILABLE); CASE_ERR(CL_DEVICE_NOT_FOUND); + CASE_ERR(CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST); CASE_ERR(CL_INVALID_ARG_INDEX); CASE_ERR(CL_INVALID_ARG_SIZE); CASE_ERR(CL_INVALID_ARG_VALUE); + CASE_ERR(CL_INVALID_COMMAND_QUEUE); CASE_ERR(CL_INVALID_CONTEXT); CASE_ERR(CL_INVALID_DEVICE); CASE_ERR(CL_INVALID_DEVICE_TYPE); + CASE_ERR(CL_INVALID_EVENT_WAIT_LIST); + CASE_ERR(CL_INVALID_GLOBAL_OFFSET); + CASE_ERR(CL_INVALID_GLOBAL_WORK_SIZE); + CASE_ERR(CL_INVALID_IMAGE_SIZE); CASE_ERR(CL_INVALID_KERNEL); + CASE_ERR(CL_INVALID_KERNEL_ARGS); CASE_ERR(CL_INVALID_KERNEL_DEFINITION); CASE_ERR(CL_INVALID_KERNEL_NAME); CASE_ERR(CL_INVALID_MEM_OBJECT); @@ -28,6 +35,11 @@ const char * err_string(cl_int error) CASE_ERR(CL_INVALID_PROPERTY); CASE_ERR(CL_INVALID_SAMPLER); CASE_ERR(CL_INVALID_VALUE); + CASE_ERR(CL_INVALID_WORK_DIMENSION); + CASE_ERR(CL_INVALID_WORK_GROUP_SIZE); + CASE_ERR(CL_INVALID_WORK_ITEM_SIZE); + CASE_ERR(CL_MEM_OBJECT_ALLOCATION_FAILURE); + CASE_ERR(CL_MISALIGNED_SUB_BUFFER_OFFSET); CASE_ERR(CL_OUT_OF_HOST_MEMORY); CASE_ERR(CL_OUT_OF_RESOURCES); CASE_ERR(CL_SUCCESS); @@ -63,6 +75,7 @@ int main(int argc, char ** argv) cl_mem out_buffer; float out_value = 0.0; + size_t global_work_size = 1; error = clGetPlatformIDs( 1, /* Max number of platform IDs to return */ @@ -192,7 +205,44 @@ int main(int argc, char ** argv) return EXIT_FAILURE; } - fprintf(stderr, "clSetKernelArg succeeded.\n"); + fprintf(stderr, "clSetKernelArg() succeeded.\n"); + + error = clEnqueueNDRangeKernel(command_queue, + kernel, + 1, /* Number of dimensions */ + NULL, /* Global work offset */ + &global_work_size, + &global_work_size, /* local work size */ + 0, /* Events in wait list */ + NULL, /* Wait list */ + NULL); /* Event object for this event */ + + if (error != CL_SUCCESS) { + fprintf(stderr, "clEnqueueNDRangeKernel() failed: %s\n", err_string(error)); + return EXIT_FAILURE; + } + + fprintf(stderr, "clEnqueueNDRangeKernel() suceeded.\n"); + + error = clEnqueueReadBuffer(command_queue, + out_buffer, + CL_TRUE, /* TRUE means it is a blocking read. */ + 0, /* Buffer offset to read from. */ + sizeof(float), /* Bytes to read */ + &out_value, /* 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", err_string(error)); + return EXIT_FAILURE; + } + + fprintf(stderr, "clEnqueueReadBuffer() suceeded.\n"); + + fprintf(stderr, "pi = %f\n", out_value); return EXIT_SUCCESS; } |