Results 1 to 5 of 5

Thread: #include headers from memory, not from filesystem?

  1. #1
    Junior Member
    Join Date
    Aug 2009
    Posts
    9

    #include headers from memory, not from filesystem?

    Hi!

    In a commercial environment, we have the requirement that no OpenCL source code can be stored in the file system as plain text. Is it still possible under this restriction to use #include statements in OpenCL code, i.e., can I somehow tell the OpenCL compiler that "#include <something.h>" means to fetch "something.h" from a location in memory instead of the file system? Although #include statements can sometimes be avoided by passing headers as additional source strings to "clCreateProgramWithSource", there are still situations which should be left to the OpenCL preprocessor, such as code like this:

    #ifdef USE_SOME_FEATURE
    #include <use_some_feature.h>
    #endif

    where USE_SOME_FEATURE is dynamically specified as an OpenCL preprocessor option at application runtime. Do you have any ideas about this?

    Thanks & kind regards,
    Markus

  2. #2
    Senior Member
    Join Date
    Nov 2009
    Posts
    118

    Re: #include headers from memory, not from filesystem?

    You can preprocess your file (replacing include <...> with the real code) before sending it to opencl driver.

    But even if not present on the file system, sending sources to opencl driver (via createprogramwithsource), is not very safe.
    They can easily be watched, with a fake opencl driver.

  3. #3
    Junior Member
    Join Date
    Aug 2009
    Posts
    9

    Re: #include headers from memory, not from filesystem?

    Quote Originally Posted by matrem
    You can preprocess your file (replacing include <...> with the real code) before sending it to opencl driver.
    This could be a solution if I could tell the preprocessor to only process "#include" statements and not to touch the "#ifdef USE_SOME_FEATURE" in the above example. Do you know if this is possible?

    Quote Originally Posted by matrem
    But even if not present on the file system, sending sources to opencl driver (via createprogramwithsource), is not very safe.
    They can easily be watched, with a fake opencl driver.
    This is true, but if the environment changes (e.g., hardware upgrade, OpenCL or driver update), the source code has to be recompiled. According to the OpenCL documentation, the binaries may contain an intermediate representation, from which the actual binary code can be created, but this is not required, so I don't see a generic solution here.

    Thanks & kind regards,
    Markus

  4. #4
    Senior Member
    Join Date
    Nov 2009
    Posts
    118

    Re: #include headers from memory, not from filesystem?

    I don't see a generic solution here
    That's because there is no generic binary solution

    When I said "preprocess your file", I want to say process it yourself in your host program to replace the #include <...> line with the code in file "...".
    So everything is possible, it's up to you.

  5. #5

    Re: #include headers from memory, not from filesystem?

    Quote Originally Posted by grabner
    Although #include statements can sometimes be avoided by passing headers as additional source strings to "clCreateProgramWithSource", there are still situations which should be left to the OpenCL preprocessor, such as code like this:

    #ifdef USE_SOME_FEATURE
    #include <use_some_feature.h>
    #endif
    Why about using the inverse of a traditional header gaurd to turn the header file on and off? The trick is making sure to pass the files in the correct order to clCreateProgramWithSource. Something like the following:

    use_some_feature.h:
    Code :
    #ifdef USE_SOME_FEATURE 
    #ifndef USE_SOME_FEATURE_HEADER_GAURD
    #define USE_SOME_FEATURE_HEADER_GAURD
     
    #endif // USE_SOME_FEATURE_HEADER_GAURD
    #endif // USE_SOME_FEATURE

    mykernel.h:
    Code :
    #define USE_SOME_FEATURE
    __kernel void Foo()

    Then call clCreateProgramWithSource passing the source from mykernel.h first and then use_some_feature.h.

    Though I sympathize with your frustration of shipping binary OpenCL code, so much so I was compelled to start a blog: http://iheartcode.blogspot.com/2010/04/ ... n-gpu.html

Similar Threads

  1. include headers to OpenCL .cl file
    By yakovm in forum OpenCL
    Replies: 0
    Last Post: 01-24-2013, 07:09 AM
  2. include headers to .cl file
    By opencl_JEDI in forum OpenCL
    Replies: 1
    Last Post: 03-06-2010, 06:33 PM

Posting Permissions

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