Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exposing hapiAddCallback to Charm4py #3852

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion src/arch/cuda/hybridAPI/hapi_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1367,6 +1367,7 @@ void hapiPollEvents(void* param) {
std::queue<hapiEvent>& queue = CpvAccess(hapi_event_queue);
while (!queue.empty()) {
hapiEvent hev = queue.front();
queue.pop(); // TODO: investigate possible race condition with charm4py futures - temporarily resolved by popping here
if (cudaEventQuery(hev.event) == cudaSuccess) {
// invoke Charm++ callback if one was given
hev.cb.send(hev.cb_msg);
Expand All @@ -1376,7 +1377,6 @@ void hapiPollEvents(void* param) {
hapiWorkRequestCleanup(hev.wr);
}
cudaEventDestroy(hev.event);
queue.pop();
CpvAccess(n_hapi_events)--;

// inform QD that an event was processed
Expand Down
5 changes: 5 additions & 0 deletions src/ck-core/charm.h
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,11 @@ extern int CkDisableTracing(int epIdx);
extern void CkEnableTracing(int epIdx);
extern void CkCallWhenIdle(int epIdx, void* obj);


#if CMK_CHARM4PY && CMK_CUDA
extern void CkHapiAddCallback(long stream, void (*cb)(void*, void*), int fid);
#endif

#ifdef __cplusplus
}
#endif
Expand Down
12 changes: 12 additions & 0 deletions src/ck-core/ck.C
Original file line number Diff line number Diff line change
Expand Up @@ -2637,6 +2637,18 @@ void CkArrayExtSend_multi(int aid, int *idx, int ndims, int epIdx, int num_bufs,
}
}


#if CMK_CUDA
#include "hapi.h"
void CkHapiAddCallback(long stream, void (*cb)(void*, void*), int fid)
{
cudaStream_t stream_ptr = (cudaStream_t)stream;
CkCallback callback(cb, (void *) fid);

hapiAddCallback(stream_ptr, callback, NULL);
}
#endif // CMK_CUDA

#endif

//------------------- Message Watcher (record/replay) ----------------
Expand Down
Loading