diff options
author | Tom Stellard <thomas.stellard@amd.com> | 2012-02-13 11:54:51 -0500 |
---|---|---|
committer | Tom Stellard <thomas.stellard@amd.com> | 2012-02-13 11:54:51 -0500 |
commit | 192dd3f9f196fe5e07f9e026f790a355aee3b8a5 (patch) | |
tree | 1747f782670908965c47efa536486b4ad15fefe1 | |
parent | 63fd66aa1a490748c4f4d2a4bd43d5b228b1e2ac (diff) |
Add some more function calls
-rw-r--r-- | Makefile | 3 | ||||
-rw-r--r-- | hello_world.c | 86 |
2 files changed, 88 insertions, 1 deletions
@@ -1,3 +1,4 @@ +CFLAGS=-g hello_world: hello_world.o - gcc -o hello_world $^ -L/home/tstellar/mesa/lib -lOpenCL + gcc -o hello_world $^ -L/usr/local/lib/ -lOpenCL diff --git a/hello_world.c b/hello_world.c index 22ccea7..9a1d011 100644 --- a/hello_world.c +++ b/hello_world.c @@ -11,11 +11,22 @@ const char * err_string(cl_int error) CASE_ERR(CL_DEVICE_NOT_AVAILABLE); CASE_ERR(CL_DEVICE_NOT_FOUND); + CASE_ERR(CL_INVALID_ARG_INDEX); + CASE_ERR(CL_INVALID_ARG_SIZE); + CASE_ERR(CL_INVALID_ARG_VALUE); + CASE_ERR(CL_INVALID_CONTEXT); CASE_ERR(CL_INVALID_DEVICE); CASE_ERR(CL_INVALID_DEVICE_TYPE); + CASE_ERR(CL_INVALID_KERNEL); + 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_OUT_OF_HOST_MEMORY); CASE_ERR(CL_OUT_OF_RESOURCES); @@ -24,6 +35,14 @@ const char * err_string(cl_int error) } } +const char * program_src = +"__kernel\n" +"void pi(__global float * out) \n" +"{\n" +" out[0] = 3.14159f;\n" +"}\n"; + + int main(int argc, char ** argv) { cl_int error; @@ -38,6 +57,10 @@ int main(int argc, char ** argv) cl_command_queue command_queue; + cl_program program; + + cl_kernel kernel; + cl_mem out_buffer; float out_value = 0.0; @@ -95,6 +118,57 @@ int main(int argc, char ** argv) fprintf(stderr, "clCreateCommandQueue() succeeded.\n"); + program = clCreateProgramWithSource(context, + 1, /* Number of strings */ + &program_src, + NULL, /* String lengths, 0 means all the + * strings are NULL terminated. */ + &error); + + if (error != CL_SUCCESS) { + fprintf(stderr, "clCreateProgramWithSource() failed: %s\n", + err_string(error)); + return EXIT_FAILURE; + } + + fprintf(stderr, "clCreateProgramWithSource() suceeded.\n"); + + error = clBuildProgram(program, + 1, /* Number of devices */ + &device_id, + NULL, /* options */ + NULL, /* callback function when compile is complete */ + NULL); /* user data for callback */ + + + if (error != CL_SUCCESS) { + char build_str[10000]; + error = clGetProgramBuildInfo(program, + device_id, + CL_PROGRAM_BUILD_LOG, + 10000, /* Size of output string */ + build_str, /* pointer to write the log to */ + NULL); /* Number of bytes written to the log */ + if (error != CL_SUCCESS) { + fprintf(stderr, "clGetProgramBuildInfo() failed: %s\n", + err_string(error)); + } else { + fprintf(stderr, "Build Log: \n%s\n\n", build_str); + } + return EXIT_FAILURE; + } + + fprintf(stderr, "clBuildProgram() suceeded.\n"); + + kernel = clCreateKernel(program, "hello world", &error); + + if (error != CL_SUCCESS) { + fprintf(stderr, "clCreateKernel() failed: %s\n", err_string(error)); + return EXIT_FAILURE; + } + + fprintf(stderr, "clCreateKernel() suceeded.\n"); + out_buffer = clCreateBuffer(context, CL_MEM_WRITE_ONLY, /* Flags */ sizeof(float), /* Size of buffer */ @@ -108,5 +182,17 @@ int main(int argc, char ** argv) fprintf(stderr, "clCreateBuffer() succeeded.\n"); + error = clSetKernelArg(kernel, + 0, /* Arg index */ + sizeof(cl_mem), + &out_buffer); + + if (error != CL_SUCCESS) { + fprintf(stderr, "clSetKernelArg failed: %s\n", err_string(error)); + return EXIT_FAILURE; + } + + fprintf(stderr, "clSetKernelArg succeeded.\n"); + return EXIT_SUCCESS; } |