Skip to content

Instantly share code, notes, and snippets.

@tugrul512bit
Created June 10, 2017 12:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tugrul512bit/39bc5b2d938ad8cd9d6ea2ba35103f90 to your computer and use it in GitHub Desktop.
Save tugrul512bit/39bc5b2d938ad8cd9d6ea2ba35103f90 to your computer and use it in GitHub Desktop.
class OpenClCommandQueue
{
private:
int counter;
std::mutex m;
public:
cl::CommandQueue commandQueue;
OpenClCommandQueue(cl::Context context, cl::Device device, int async)
{
counter = 0;
cl_int err;
if (async != 0)
commandQueue = cl::CommandQueue(context, device, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, &err);
else
commandQueue = cl::CommandQueue(context, device,0Ui64,&err);
handleError(err);
}
// increments a counter whenever an observed marker calls its callback
static void CL_CALLBACK markerCallbackCounter(cl_event evt, cl_int cint, void * vp)
{
((OpenClCommandQueue *)vp)->incrementMarkerCounter();
}
void incrementMarkerCounter()
{
m.lock();
counter++;
m.unlock();
}
// adds a marker to command queue to know when it has been reached(by a callback)
void addMarkerForCountingWithCallback()
{
cl::Event evt;
commandQueue.enqueueMarkerWithWaitList(NULL, &evt);
evt.setCallback(CL_COMPLETE, &markerCallbackCounter, this);
}
void resetMarkerCallbackCounter()
{
m.lock();
counter = 0;
m.unlock();
}
int getCount()
{
int result = 0;
m.lock();
result = counter;
m.unlock();
return result;
}
~OpenClCommandQueue()
{
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment