Skip to content

Commit

Permalink
Merge pull request #32 from LLNL/events-hack
Browse files Browse the repository at this point in the history
FastEvent uses CUDA events
  • Loading branch information
ndryden authored Jan 22, 2019
2 parents 073b717 + ee5d926 commit 288a3d0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,44 +109,56 @@ bool stream_memory_operations_supported() {
}

FastEvent::FastEvent() {
#if 0
if (stream_memory_operations_supported()) {
sync_event = get_pinned_memory<int32_t>(1);
// Initialize to completed to match CUDA event semantics.
__atomic_store_n(sync_event, 1, __ATOMIC_SEQ_CST);
AL_CHECK_CUDA_DRV(cuMemHostGetDevicePointer(
&sync_event_dev_ptr, sync_event, 0));
}
else {
else
#endif
{
plain_event = get_cuda_event();
}
}

FastEvent::~FastEvent() {
#if 0
if (stream_memory_operations_supported()) {
release_pinned_memory(sync_event);
}
else {
else
#endif
{
release_cuda_event(plain_event);
}
}

void FastEvent::record(cudaStream_t stream) {
#if 0
if (stream_memory_operations_supported()) {
// We cannot use std::atomic because we need the actual address of the memory.
__atomic_store_n(sync_event, 0, __ATOMIC_SEQ_CST);
AL_CHECK_CUDA_DRV(cuStreamWriteValue32(
stream, sync_event_dev_ptr, 1,
CU_STREAM_WRITE_VALUE_DEFAULT));
}
else {
else
#endif
{
AL_CHECK_CUDA(cudaEventRecord(plain_event, stream));
}
}

bool FastEvent::query() {
#if 0
if (stream_memory_operations_supported())
return __atomic_load_n(sync_event, __ATOMIC_SEQ_CST);
else {
else
#endif
{
cudaError_t r = cudaEventQuery(plain_event);
if (r == cudaSuccess)
return true;
Expand Down
4 changes: 4 additions & 0 deletions src/cuda.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ bool stream_memory_operations_supported();
* using the stream memory write operation.
* This falls back to the usual CUDA events when stream memory operations are
* not available.
* @note This is currently always falling back on CUDA events to work around a
* hang, the underlying cause of which has not been diagnosed.
*/
class FastEvent {
public:
Expand All @@ -153,8 +155,10 @@ class FastEvent {
/** Return true if the event has completed. */
bool query();
private:
#if 0
int32_t* sync_event __attribute__((aligned(64)));
CUdeviceptr sync_event_dev_ptr;
#endif
cudaEvent_t plain_event;
};

Expand Down

0 comments on commit 288a3d0

Please sign in to comment.