preprocessor macros to detect if compiled for CPU or GPU

Hi all,

I was wondering if there is some sort of define that is set whenever a kernel/program is compiled /built for a certain architecture type. I usually debug my kernels on the CPU using printfs, which result in an empty build error log when I try to compile for the GPU on Lion. I figured if I had a way to wrap my printfs like the following


#if defined(_CPU_)
#define PRINT(fmt, ...) printf(fmt, ...)
#else
#define PRINT(fmt, ...)
#endif

Then I would not need to uncomment my debug code whenever I do a quick switch to my GPU to see if the code runs.

Thank you
Herbert

Currently none of those macros are part of the OpenCL specification.

If you want them included you could support my post in the Suggestions for next release section - Predefined Macros: device type:
viewtopic.php?f=41&t=4380

Although the spec might not define them specific vendors do, so that should suffice for debugging purposes. AMD define CPU and GPU for example.

Another mechanism is to pass -DDEBUG=1 to the command line: this could potentially be done in one place depending on how you wrote your code, and AMD also allow you to set the environmental variable AMD_OCL_BUILD_OPTIONS_APPEND or AMD_OCL_BUILD_OPTIONS as well.

Also, varadic macros aren’t supported according to the spec.
I just use
#define d(x) x
And then
d(printf(“blah”));

Is this something I can find out by looking at the OpenCL headers, or is the only way to try out compiling a kernel that uses them? (I am on OSX Lion, CL 1.1)

Thank you
Herbert