Getting Started with OpenCL on Linux: Errata Example code of this guide not compiling (Version Augus

Since I found this problem, but I could not find any help on the web… I post here the solution to help future beginners like me:

Inside this manual (August, 25 2009):

Getting Started OpenCL for NVIDIA GPUs

Installation and Verification on Linux

You can find a code sample to test your newly installed environment, but if you try to compile it, you’ll get this error:

error: ‘cpProgram’ was not declared in this scope

To solve it, you just need to change the code row causing the error with this one:

[codebox]clBuildProgram(OpenCLProgram, 0, NULL, NULL, NULL, NULL);[/codebox]

After this step the code will compile, but it won’t run correctly; the reason is that the runtime “kernel compiling” of the OpenCLSource code will fail since it can’t interpret correctly the “string” with the source code (you can realize that using the function clGetProgramBuildInfo):

[codebox]char logbuffer[2048];

clGetProgramBuildInfo(OpenCLProgram, *GPUDevices, CL_PROGRAM_BUILD_LOG, sizeof(logbuffer), logbuffer, NULL);[/codebox]

To solve also this issue, you have to add some “\n” inside the code in this way:

[codebox]const char* OpenCLSource = {

   "__kernel void VectorAdd(__global int* c, __global int* a, __global int* b) \n",

   "{ \n",

   "       // Index of the elements to add \n",

   "       int n = get_global_id(0); \n",

   "       // Sum the n’th element of vectors a and b and store in c \n",

   "       c[n] = a[n] + b[n]; \n",

   "} \n"

};[/codebox]

I hope this post may help to save some time to the beginners and may encourage someone to correct the code in the future releases of the manual.

cheers,

Enrico

Thank you. This helped me. It would be nice to have a sample output as well though. My output (confirmed the vector sum as correct via alternate implementation):

Hello CUDA World! Hello CUDA World! Hello CUDA World! Hello CUDA World! Hello CUDA World! Hello CUDA World! Hello CUDA World! Hello CUDA World! Hello CUDA World! Hello CUDA World! Hello CUDA World! Hello CUDA World! Hello CUDA World! Hello CUDA World! Hello CUDA World! Hello CUDA World! Hello CUDA World!