The following OpenCL program hangs on the evmk2h platform. The problem occurs when reading event profiling information from within an callback function. Disabling CL_QUEUE_PROFILING_ENABLE avoids stalling the application (but disallows profiling, obviously). The same program works fine on a Xeon Phi. Could you please fix this? BTW, I am very glad that OpenCL and OpenMP are (finally!) supported.
Thanks, John Romein
#define __CL_ENABLE_EXCEPTIONS
#include <CL/cl.hpp>
#include <iostream>
#include <string>
#include <vector>
const char *kernelSource = "kernel void foo() { printf(\"kernel running\\n\"); }";
void eventCompleteCallBack(cl_event ev, cl_int status, void *arg)
{
cl_ulong start, end;
std::cout << "before clGetEventProfilingInfo" << std::endl;
clGetEventProfilingInfo(ev, CL_PROFILING_COMMAND_START, sizeof start, &start, 0);
std::cout << "after clGetEventProfilingInfo" << std::endl;
clGetEventProfilingInfo(ev, CL_PROFILING_COMMAND_END, sizeof end, &end, 0);
std::cout << "time = " << (end - start) / 1e9 << std::endl;
}
int main(int argc, char *argv[])
{
try
{
cl::Context context(CL_DEVICE_TYPE_ACCELERATOR);
std::vector<cl::Device> devices(context.getInfo<CL_CONTEXT_DEVICES>());
cl::Program::Sources source(1, std::make_pair(kernelSource, strlen(kernelSource)));
cl::Program program(context, source);
program.build(devices);
cl::CommandQueue queue(context, devices[0], CL_QUEUE_PROFILING_ENABLE);
cl::Kernel kernel(program, "foo");
cl::Event event;
queue.enqueueTask(kernel, 0, &event);
event.setCallback(CL_COMPLETE, eventCompleteCallBack);
queue.finish(); // not strictly necessary
} catch (cl::Error &err) {
std::cerr <<"cl::Error(): " << err.what() << '(' << err.err() << ')' << std::endl;
}
return 0;
}