Use printf in kernel function

Hi All

I need to use printf() in my kernel function for debugging purpose.
How can I do this in JOCL ?

This link helps only in pure OpenCL code.
http://devgurus.amd.com/thread/151246

How can we use this in JOCL ?

Regards
Rohit Sarewar

Hi

Admittedly, I have never used this (although it’s certainly very helpful for debugging - so thanks for this heads up :)), but I just tested it, by changing the Kernel from the JOCLSample.java to

    private static String programSource =
    	"#pragma OPENCL EXTENSION cl_amd_printf : enable"+"
"+
        "__kernel void "+
        "sampleKernel(__global const float *a,"+
        "             __global const float *b,"+
        "             __global float *c)"+
        "{"+
        "    int gid = get_global_id(0);"+
        "    printf(\"Test %d\
\", gid);"+
        "    c[gid] = a[gid] * b[gid];"+
        "}";

and it worked for me - that is, it printed out the “Test X” strings.

Of course, the pragma will only work on an AMD platform. For Intel, there is an analogous “cl_intel_printf” pragma. I did not find one for NVIDIA, though, and the attempt to use the given pragma resulted in an CL_INVALID_BINARY error.

Do you have an AMD card? If yes, which problems did you encounter when trying to use this pragma?

bye
Marco