Results 1 to 3 of 3

Thread: compiling kernels OpenCL using clBuildProgram

  1. #1
    Junior Member
    Join Date
    May 2012
    Posts
    13

    compiling kernels OpenCL using clBuildProgram

    Hello,

    I am porting some CPU code to OpenCL and I will have some 20 odd different kernels. My question is that should I compile all 20 kernels at the beginning of the program and maintain an array of cl_kernel objects and call them as necessary or is there a better way to do this. Also, it is enough to call clBuildProgram for each kernel just once during the lifetime of the program.

    Is it possible to build the kernels at compile time?

    Thanks,

    xarg

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

    Re: compiling kernels OpenCL using clBuildProgram

    Quote Originally Posted by xargon
    Hello,

    I am porting some CPU code to OpenCL and I will have some 20 odd different kernels. My question is that should I compile all 20 kernels at the beginning of the program and maintain an array of cl_kernel objects and call them as necessary or is there a better way to do this. Also, it is enough to call clBuildProgram for each kernel just once during the lifetime of the program.

    Is it possible to build the kernels at compile time?

    Thanks,

    xarg
    You can't build kernels at compile time unless you're only going to run it against the same vendor's hardware (same as the vendor sdk/driver you're talking to), and even then probably only with a limited range of hardware/limited range of driver revisions. Even if you could, it limits you to pre-written code, and run-time code-generation is a practical and worthwhile solution to some problems.

    But caching of the binaries works pretty well and amounts to much the same thing. Particularly with AMD's implementation who's binaries are the device-specific code so the load isn't much more than a manual dlopen. AFAICT nvidia already caches the binaries, and their binaries are a higher-level intermediate assembly language which takes longer to load even when cached (still faster then a full build tho). (and i recall seeing someone mention macos just returns the filename to the .o file for the 'binary'). You could possible pre-compile and cache at install time, but then you'd still need a fall-back at realisation time incase the driver rejects it/the user changes configuration so there doesn't seem much point doubling up on the code for no real benefit.

    In my limited experience adding all the compiles/loads at the start gives a user a more natural experience; i.e. they're used to long start-up times ever since computers existed. If you try load-on-demand it tends to throw up potentially long pauses in unexpected places. Assuming you're not otherwise memory constrained of course, or that this delay will be unacceptably long.

    And finally yes, you can just run clbuildprogram and lookup the kernel handles and keep them around for the life of the programme. Drivers may swap the code in/out of the device as necessary as well, but this will be transparent.

  3. #3
    Junior Member
    Join Date
    May 2012
    Posts
    13

    Re: compiling kernels OpenCL using clBuildProgram

    Thanks for the very detailed and illuminating reply!

    /x

Similar Threads

  1. OpenCL slow compiling on AMD card
    By Gopal_HC in forum OpenCL
    Replies: 4
    Last Post: 01-02-2013, 04:31 AM
  2. compiling and runing OpenCL code
    By college_guy in forum OpenCL
    Replies: 4
    Last Post: 04-07-2011, 05:07 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
  •