18 Replies Latest reply on Nov 20, 2009 5:36 PM by david_aiken

    printf within kernel

    david_aiken

      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? 

        • printf within kernel
          nou

          yes printf work in kernel. i try it on gcc

            • printf within kernel
              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.

                • printf within kernel
                  nou

                  are you able use printf in normal code? maybe one printf in code will help

                  • printf within kernel
                    AndreasStahl

                     

                    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?

                      • printf within kernel
                        RyFo18

                        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.

                          • printf within kernel
                            david_aiken

                            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.

                              • printf within kernel
                                nou

                                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.

                                  • printf within kernel
                                    david_aiken

                                    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 within kernel
                                        omkaranathan

                                        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. 

                                          • printf within kernel
                                            nou

                                            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

                                              • printf within kernel
                                                david_aiken

                                                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.

                                                 

                                                  • printf within kernel
                                                    RyFo18

                                                    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);

                                                      • printf within kernel
                                                        david_aiken

                                                        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!

                                  • printf within kernel
                                    MicahVillmow
                                    Yes printf currently is only supported on the CPU device as there is no standard library in OpenCL that contains the printf function, so it is not valid on every device. This is stated in 6.8.f of the OpenCL 1.0 spec.