Results 1 to 3 of 3

Thread: Kernel pre-compilation

  1. #1

    Kernel pre-compilation

    Hi all,

    I'm a bit confused about all what I read on the program pre-compilation.
    Everytime, there is just a part of the code but almost never all the example code.
    I've seen 3 examples, maybe not complete.

    Version 1
    a. Use clCreateProgramWithSource and clBuildProgram to compile a program for which the sources are contained into a char*.
    b. Use clGetProgramInfo with the option CL_PROGRAM_BINARY_SIZES to generate a string (char*) which contains the program compiled (binary).
    c. Keep the string as a variable.
    d. Later on, create and compile a new program from the binary (variable in c.) using clCreateProgramWithBinary and clBuildProgram.

    Version 2
    a. Use clCreateProgramWithSource and clBuildProgram to compile a program for which the sources are contained into a char*.
    b. Use clGetProgramInfo with the option CL_PROGRAM_BINARY_SIZES to generate a string (char*) which contains the program compiled (binary).
    c. Write the string in an output file.
    d. Later on, read the previously generated file and store it into a char*.
    e. Create and compile a new program from the binary (char*) using clCreateProgramWithBinary and clBuildProgram.

    Version 3
    a. Write the kernel into a .cl file.
    b. Use XCode to automatically compile the .cl file into a binary file.
    c. Later on, create and compile a new program from the binary file using clCreateProgramWithBinary and clBuildProgram.

    For the version 3, I guess what I miss is that the compile program is simply read from the binary file and stored into a char *, as for the version 2.

    Except their obvious differences, is there any better or worse solution?
    Are the versions 1 and 2 similar? It seems that yes and I don't understand why we should use an external file. I guess that the openCL programs could be compiled the first time the program (main program) is used, and then are never compiled again. But I can't be sure.

    Thanks for your reactions on the subject.

    Regards,

    Vincent

  2. #2
    Senior Member
    Join Date
    May 2010
    Location
    Toronto, Canada
    Posts
    845

    Re: Kernel pre-compilation

    With version 2 of the code (storing the program binary into a file) the application only needs to compile the sources once and after that the application can always use the program binary that was saved into the file. That can save a lot of time and it's the right way to go.
    Disclaimer: Employee of Qualcomm Canada. Any opinions expressed here are personal and do not necessarily reflect the views of my employer. LinkedIn profile.

  3. #3

    Re: Kernel pre-compilation

    It confirms what I thought.
    I my case, the OpenCL program compilation takes way less than 1 second.
    I can compile my OpenCL program at the beginning of the main program and store compiled OpenCL compiled programs in char * variables.
    I don't need then to read from the disk, which should be longer in my case.

    Many thanks,

    Vincent Garcia

Similar Threads

  1. Compilation of the Kernel is always at runtime?
    By luizdrumond in forum OpenCL
    Replies: 1
    Last Post: 07-19-2011, 04:36 PM
  2. Kernel compilation problem....
    By Craig in forum OpenCL
    Replies: 16
    Last Post: 11-06-2010, 03:05 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
  •