summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--hello_world.c68
-rw-r--r--util.c47
-rw-r--r--util.h2
4 files changed, 64 insertions, 55 deletions
diff --git a/Makefile b/Makefile
index d5fb6dc..02e399d 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
CFLAGS=-g
-hello_world: hello_world.o
+hello_world: hello_world.o util.o
gcc -o hello_world $^ -L/usr/local/lib/ -lOpenCL
diff --git a/hello_world.c b/hello_world.c
index 1ca145a..9853897 100644
--- a/hello_world.c
+++ b/hello_world.c
@@ -3,49 +3,6 @@
#include <CL/cl.h>
-#define CASE_ERR(ec) case ec: return #ec;
-
-const char * err_string(cl_int error)
-{
- switch(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);
- CASE_ERR(CL_INVALID_OPERATION);
- CASE_ERR(CL_INVALID_PLATFORM);
- CASE_ERR(CL_INVALID_PROGRAM);
- CASE_ERR(CL_INVALID_PROGRAM_EXECUTABLE);
- 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);
-
- }
-}
const char * program_src =
"#define __global __attribute__((address_space(1)))\n"
@@ -85,7 +42,7 @@ int main(int argc, char ** argv)
* found on the system */
if (error != CL_SUCCESS) {
- fprintf(stderr, "clGetPlatformIDs() failed: %s\n", err_string(error));
+ fprintf(stderr, "clGetPlatformIDs() failed: %s\n", cluErrorString(error));
return EXIT_FAILURE;
}
@@ -100,7 +57,7 @@ int main(int argc, char ** argv)
&total_gpu_devices);
if (error != CL_SUCCESS) {
- fprintf(stderr, "clGetDeviceIDs() failed: %s\n", err_string(error));
+ fprintf(stderr, "clGetDeviceIDs() failed: %s\n", cluErrorString(error));
return EXIT_FAILURE;
}
@@ -114,7 +71,7 @@ int main(int argc, char ** argv)
&error); /* Error code */
if (error != CL_SUCCESS) {
- fprintf(stderr, "clCreateContext() failed: %s\n", err_string(error));
+ fprintf(stderr, "clCreateContext() failed: %s\n", cluErrorString(error));
return EXIT_FAILURE;
}
@@ -126,7 +83,8 @@ int main(int argc, char ** argv)
&error); /* Error code */
if (error != CL_SUCCESS) {
- fprintf(stderr, "clCreateCommandQueue() failed: %s\n", err_string(error));
+ fprintf(stderr, "clCreateCommandQueue() failed: %s\n",
+ cluErrorString(error));
return EXIT_FAILURE;
}
@@ -141,7 +99,7 @@ int main(int argc, char ** argv)
if (error != CL_SUCCESS) {
fprintf(stderr, "clCreateProgramWithSource() failed: %s\n",
- err_string(error));
+ cluErrorString(error));
return EXIT_FAILURE;
}
@@ -165,7 +123,7 @@ int main(int argc, char ** argv)
NULL); /* Number of bytes written to the log */
if (error != CL_SUCCESS) {
fprintf(stderr, "clGetProgramBuildInfo() failed: %s\n",
- err_string(error));
+ cluErrorString(error));
} else {
fprintf(stderr, "Build Log: \n%s\n\n", build_str);
}
@@ -177,7 +135,7 @@ int main(int argc, char ** argv)
kernel = clCreateKernel(program, "hello world", &error);
if (error != CL_SUCCESS) {
- fprintf(stderr, "clCreateKernel() failed: %s\n", err_string(error));
+ fprintf(stderr, "clCreateKernel() failed: %s\n", cluErrorString(error));
return EXIT_FAILURE;
}
@@ -190,7 +148,7 @@ int main(int argc, char ** argv)
&error); /* error code */
if (error != CL_SUCCESS) {
- fprintf(stderr, "clCreateBuffer() failed: %s\n", err_string(error));
+ fprintf(stderr, "clCreateBuffer() failed: %s\n", cluErrorString(error));
return EXIT_FAILURE;
}
@@ -202,7 +160,7 @@ int main(int argc, char ** argv)
&out_buffer);
if (error != CL_SUCCESS) {
- fprintf(stderr, "clSetKernelArg failed: %s\n", err_string(error));
+ fprintf(stderr, "clSetKernelArg failed: %s\n", cluErrorString(error));
return EXIT_FAILURE;
}
@@ -220,7 +178,8 @@ int main(int argc, char ** argv)
NULL); /* Event object for this event */
if (error != CL_SUCCESS) {
- fprintf(stderr, "clEnqueueNDRangeKernel() failed: %s\n", err_string(error));
+ fprintf(stderr, "clEnqueueNDRangeKernel() failed: %s\n",
+ cluErrorString(error));
return EXIT_FAILURE;
}
@@ -238,7 +197,8 @@ int main(int argc, char ** argv)
if (error != CL_SUCCESS) {
- fprintf(stderr, "clEnqueueReadBuffer() failed: %s\n", err_string(error));
+ fprintf(stderr, "clEnqueueReadBuffer() failed: %s\n",
+ cluErrorString(error));
return EXIT_FAILURE;
}
diff --git a/util.c b/util.c
new file mode 100644
index 0000000..6b493af
--- /dev/null
+++ b/util.c
@@ -0,0 +1,47 @@
+#include <CL/cl.h>
+
+#include "util.h"
+
+#define CASE_ERR(ec) case ec: return #ec;
+
+const char * cluErrorString(cl_int error)
+{
+ switch(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);
+ CASE_ERR(CL_INVALID_OPERATION);
+ CASE_ERR(CL_INVALID_PLATFORM);
+ CASE_ERR(CL_INVALID_PROGRAM);
+ CASE_ERR(CL_INVALID_PROGRAM_EXECUTABLE);
+ 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);
+
+ }
+}
diff --git a/util.h b/util.h
new file mode 100644
index 0000000..5293d32
--- /dev/null
+++ b/util.h
@@ -0,0 +1,2 @@
+
+const char * cluErrorString(cl_int error);