0

I'm struggling saving/loading binary-kernels: If i build from source, the program runs fine. But if i write and load the kernel to binary. I get CL_INVALID_COMMAND_QUEUE calling m_prog.getCommandQueues()[iDevice].enqueueNDRangeKernel. My Platform is in both cases (from binary, from source) Intel and my device is in both cases my CPU.

Maybe helpful additional information:

  1. No exceptions are thrown before CL_INVALID_COMMAND_QUEUE ( with __CL_ENABLE_EXCEPTIONS defined)

  2. program ref count 1

  3. program num devs 1

  4. program num devs 1

  5. program build status for device CL_BUILD_SUCCES

  6. program build log

    • Device build started

    • Device build done

    • Reload Program Binary Object.

.

/// write binaries to file
std::ofstream bfile(filenameGenerator(m_platform, fileName), std::ios::binary);
if (!bfile) return IT_CL_FILE_NOT_FOUND;

std::vector<size_t> sizes = m_prog.getInfo<CL_PROGRAM_BINARY_SIZES>();
std::vector<char*>  binaries = m_prog.getInfo<CL_PROGRAM_BINARIES>();

bfile.write((char*)&sizes[0], sizeof(size_t));
bfile.write(binaries[0], sizes[0]);
delete[] binaries[0];

/// ... somewhere else ...

///read binaries from file
ifstream bfile(filenameGenerator(platform, fileName), std::ios::binary);
size_t n;
std::vector<char> buf;

bfile.read((char*)&n, sizeof(size_t));
buf.resize(n);
bfile.read(buf.data(), n);

m_prog = cl::Program(context, devs, cl::Program::Binaries(
    1, std::make_pair(static_cast<const void*>(buf.data()), n)));
m_prog.build(devs);

/// later ...
m_prog.getCommandQueues()[iDevice].enqueueNDRangeKernel ///throws

EDIT: added the last two lines of code, to clearify the calling order

2 Answers 2

1

A program should only have an associated command queue when it has been built for a specific device.

A program loaded from a binary data has not been built, and it is unclear if it has a command queue.

Calling m_prog.getCommandQueues()[device] is not recommended, since you cannot be sure a queue will be returned. You should create your own queue outside, and queue the program there.

Sign up to request clarification or add additional context in comments.

3 Comments

but i called m_prog.build(devs) first(see Edit), why shouldnt be there no command queues (i'm openCL novice). It would be kind to show some source code to explain what i've to do.
"Build" didn't build anything, since you loaded the binaries already. That is the only explanation I have for the behavior you are experiencing vs the normal code build approach.
Thank you your answer gave me a deeper insight.
0

I found the solution myself, i was able to succed in not initializing the vector<cl::CommandQueue> and only resizes the vector.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.