Created
June 10, 2017 12:55
-
-
Save tugrul512bit/39bc5b2d938ad8cd9d6ea2ba35103f90 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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