Created
June 9, 2017 15:11
-
-
Save tugrul512bit/640108e504d9ce3fa09164314cbae0a2 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; | |
evt.setCallback(CL_COMPLETE, &markerCallbackCounter, NULL); | |
commandQueue.enqueueMarkerWithWaitList(NULL, &evt); | |
} | |
void resetMarkerCallbackCounter() | |
{ | |
m.lock(); | |
counter = 0; | |
m.unlock(); | |
} | |
int getCount() | |
{ | |
int result = 0; | |
m.lock(); | |
result = counter; | |
m.unlock(); | |
return result; | |
} | |
~OpenClCommandQueue() | |
{ | |
} | |
}; |
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
test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment