Probably a FAQ, but is it possible to use printf or some other mechanism (source level debugging within Visual Studio!) within a kernel to output data structures when using the CPU?
yes printf work in kernel. i try it on gcc
Regrettably i'm on 32-bit Vista. I tried simply placing a printf into the kernel, but there was a build error:
undefined reference to 'printf'
I tried including stdio.h, but it balked on that, too.
are you able use printf in normal code? maybe one printf in code will help
I find that I can only use printf in the kernel if I'm running the kernel on a cpu, and that it doesn't work when running it on the gpu.
I think that is what you would expect.
Anyway.. the SDK is, i think, still in beta and this would seem to be low-hanging fruit that would avoid significant drudgery for developers. Call it a feature request. Apple does support printf in the kernel as a standard debug strategy when using the CPU device.
Originally posted by: david_aiken Regrettably i'm on 32-bit Vista. I tried simply placing a printf into the kernel, but there was a build error:
undefined reference to 'printf'
I tried including stdio.h, but it balked on that, too.
I had a similar experience on win7 x64, beta 4, on an AMD CPU nonetheless . So I guess it does not work currently?
When you call clCreateProgramWithSource, try passing the header file into the strings argument. I'm not sure if this works, I saw this on another forum, but it sounds like it should.
I tried adding the path to the stdio.h, but the build fails with a bad log. Changing the include path might affect internals of the build in unusual ways.
If printf in the kernel is supported then an example of how to use it would be appreciated, or perhaps just an acknowledgement that it's broken and will/may be addressed in a future release.
for me it work on linux with gcc compiler and CPU device. i simple write printf("Hello world!") into kernel and it work. no include no special setting. i do not test other platform.
Which platform are you testing, Nou? Are you (or Micah.. or anyone else) doing anything special?
I just tried installed the 2.0 beta 4 SDK on Ubuntu 9.10 64-bit and built the samples. I do not have an ATI GPU installed. The RadixSort example works great. Then i insert
printf("test");
at the top of the histogram() kernel function in the RadixSort_Kernels.cl file and when i run it again get
Error: clBuildProgram failed. Error code : unknown error code
I realize Ubuntu 9.04 32/64-bit is the version currently supported.. has anyone been able to get it to work there?
printf in kernel code is not supported currently. Its great if it works for you under linux. You can expect it to be fully supported in one of the upcoming releases.
i work on ubuntu 9.04 x64 and i have radeon 3850 and AMD Athlon X2 5000+. i add printf("test"); into histogram kernel from RadixSort and run. and it work. i do not know why but for me it just work.
For test only: Expires on Sun Feb 28 00:00:00 2010 *** CAL version mismatch: This OpenCL build requires version 1.4.422, version 1.4.403 installed. Aborting. Unsupported GPU device; falling back to CPU ... testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest dSortedData
Thanks for your help Nou. i looked at your output and conspicuously missing in mine is the failure to find a GPU.
On Vista the NVidia GTX 275 driver is not considered a GPU device and the Intel Core 2 Quad is used successfully (for the RadixSort demo, among others) as the CPU device.
On Ubuntu 9.10 64-bit it's using the GTX 275 driver as a GPU device (which is a great example of interoperability). Unfortunately, when i explicitly ask to use the CPU device it fails with a CL_DEVICE_NOT_FOUND. I've opened up a separate topic for this.
Here is what I did to get printf to work within my kernels (I am using OpenSUSE though). I just put the stdio.h file in my working directory.
const char *header = "-I stdio.h\0"; err = clBuildProgram(program, 1, devices, header, NULL, NULL);
Thanks.. i've been able to get it to work without explicitly including stdio.h. The problem was, as Nou suggested on another thread, that Ubuntu was using the libOpenCL.so installed into /usr/lib by NVidia. I fixed this by prepending the ATI library path to the LD_LIBRARY_PATH (previously it was appended). Since i'm running both NVidia and AMD i use separate scripts to setup the environment for either.
Once this is done, an ldd shows the correct library is picked up and voila - the printf works in the kernel!
thanks to all for their help!
Is there a way to call printf() or some similar function from within a kernel on Vista when using the CPU device?