Forums - OpenCL - How am I supposed to compile binaries for Adreno?

4 posts / 0 new
Last post
OpenCL - How am I supposed to compile binaries for Adreno?
asamarin
Join Date: 7 Dec 16
Posts: 4
Posted: Sat, 2017-02-11 05:46

Hi all,

[NOTE: I have already posted this question very verbosely on StackOverflow here [1], so please refer to it if you need further insights. Therefore, I'll spare the nitty-gritty details here and just summarize what my problem is]

I'm trying to fetch the resulting binaries after an OpenCL program compilation on an LG V20 phone (which has a Snapdragon 820 SoC) using clGetProgramBuildInfo with CL_PROGRAM_BINARIES. This is supported by the standard, and even Qualcomm recommends compiling CL binaries offline and loading them at application initialization ([2]):

Build kernel source code offline and load the binary at runtime to reduce latency when the application launches

However, no matter how hard I try but it seems that Qualcomm's libOpenCL.so implementation simply refuses to give me the resulting executable bytes after compiling my CL program (check SO post for details). So, my question is: How can I get a blob that I can later on reuse with clCreateProgramWithBinary then?

Any help appreciated.

[1] http://stackoverflow.com/questions/41965894/cant-get-compiled-opencl-binaries-with-clgetprograminfo-on-qualcomm-adreno-gpus
[2]  https://developer.qualcomm.com/download/adrenosdk/adreno-opencl-programming-guide.pdf

  • Up0
  • Down0
Rick Weyrauch
Join Date: 2 Dec 16
Posts: 13
Posted: Wed, 2017-02-22 13:26

I have been able to succesfully retrieve binaries from the Adreno on an 820 using the following code...

    cl_uint numDevices;
    clGetProgramInfo(program, CL_PROGRAM_NUM_DEVICES, sizeof(cl_uint), &numDevices, NULL);
 
     std::vector<cl_device_id> deviceIds(numDevices);
     clGetProgramInfo(program, CL_PROGRAM_DEVICES, sizeof(cl_device_id)*deviceIds.size(), deviceIds.data(), NULL);
 
      std::vector<size_t> binarySizes(numDevices, 0u);
      err = clGetProgramInfo(program, CL_PROGRAM_BINARY_SIZES, sizeof(size_t)*binarySizes.size(), binarySizes.data(), NULL);
 
       std::vector<unsigned char*> binaries(numDevices, 0u);
       for (size_t i = 0u; i < numDevices; i++)
       {
             binaries[i] = new unsigned char[binarySizes[i]];
       }
 
       clGetProgramInfo(program, CL_PROGRAM_BINARIES, sizeof(unsigned char*)*binaries.size(), binaries.data(), NULL);
 
       for (int i =0; i < numDevices; i++)
       {
             write(fp, binaries[i], binarySizes[i]);
       }
 
 
Hope this helps.
 
-rick
  • Up0
  • Down0
asamarin
Join Date: 7 Dec 16
Posts: 4
Posted: Tue, 2017-03-07 01:30

Hi Rick,

Thank you so much; it's working now! I'm not quite sure what was I doing wrong exactly, because my code was following a very similar reasoning as yours, but as I was initially using C++ bindings instead of pure C, my best bet so far is that maybe those bindings are not as polished as the C API as of today.

In any case, huge thanks again for your help.

  • Up0
  • Down0
niewei
Join Date: 18 Oct 16
Posts: 1
Posted: Mon, 2018-09-24 08:35

hi  asamarin:

I study opencl few days, i have a question about build offline

how could i do for cl file build offline, don't build online, becasue it would cost long time

thanks in advance!

 

  • Up0
  • Down0
or Register

Opinions expressed in the content posted here are the personal opinions of the original authors, and do not necessarily reflect those of Qualcomm Incorporated or its subsidiaries (“Qualcomm”). The content is provided for informational purposes only and is not meant to be an endorsement or representation by Qualcomm or any other party. This site may also provide links or references to non-Qualcomm sites and resources. Qualcomm makes no representations, warranties, or other commitments whatsoever about any non-Qualcomm sites or third-party resources that may be referenced, accessible from, or linked to this site.