AnsweredAssumed Answered

Save binary using C++ wrapper

Question asked by thesmith on Aug 22, 2013

Hi everyone,


I have a small question which should be simple enough for you. I am trying to save a binary to disk in order to load if later on. I am able to do it using C, but using the C++ wrapper, I can't seem to get it to work. Here is the relevant code, originally taken from here :


// Allocate some memory for all the kernel binary data
const std::vector<unsigned long> binSizes = program.getInfo<CL_PROGRAM_BINARY_SIZES>();
std::vector<char> binData (std::accumulate(binSizes.begin(),binSizes.end(),0));
char* binChunk = &binData[0] ;

//A list of pointers to the binary data
std::vector<char*> binaries;
for(unsigned int i = 0; i<binSizes.size(); ++i) {
     binaries.push_back(binChunk) ;
     binChunk += binSizes[i] ;

program.getInfo(CL_PROGRAM_BINARIES , &binaries[0] ) ;
std::ofstream binaryfile("kernel.bin", std::ios::binary);
for (unsigned int i = 0; i < binaries.size(); ++i)
     binaryfile << binaries[i];


The only thing I get in my "kernel.bin" file is the word "ELF", surrounded by some other bytes that aren't caracters. There are 7 bytes in all. So what's wrong here? It seems to fail at the last step, getting the actual binary, because I do get a binary size (28496 for my particular kernel).


Edit: I forgot to say that I'm using AMDAPP 2.8.1, and the OpenCL device is a CPU, an Intel i7-2600.


Thanks for the help,