Results 1 to 4 of 4

Thread: preprocessor macros to detect if compiled for CPU or GPU

  1. #1
    Junior Member
    Join Date
    Aug 2011
    Posts
    8

    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
    Code :
    #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

  2. #2
    Senior Member
    Join Date
    Mar 2011
    Location
    Seoul
    Posts
    118

    Re: preprocessor macros to detect if compiled for CPU or GPU

    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

  3. #3
    Senior Member
    Join Date
    Aug 2011
    Posts
    271

    Re: preprocessor macros to detect if compiled for CPU or GPU

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

  4. #4
    Junior Member
    Join Date
    Aug 2011
    Posts
    8

    Re: preprocessor macros to detect if compiled for CPU or GPU

    Quote Originally Posted by notzed
    Although the spec might not define them specific vendors do, so that should suffice for debugging purposes. AMD define __CPU__ and __GPU__ for example.
    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

Similar Threads

  1. The execution in GPU is not the same that CPU
    By luizdrumond in forum OpenCL
    Replies: 3
    Last Post: 09-02-2011, 03:00 PM
  2. if and while loops better on gpu or cpu
    By agmegharaj in forum OpenCL
    Replies: 1
    Last Post: 08-28-2011, 02:57 PM
  3. CPU vs GPU optimizations
    By akhal in forum OpenCL
    Replies: 6
    Last Post: 07-31-2011, 11:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •