From 0dadf681db8c42ccbcd70efd3caf607f00bb08cd Mon Sep 17 00:00:00 2001 From: Ben Sander Date: Mon, 26 Sep 2016 16:32:35 -0500 Subject: [PATCH] Fix signal resource issue. Remove memory leak with new hc::completion_future. Implement HIP_LAUNCH_BLOCKING with queue-level wait. Change-Id: I45975f81c4d239fdeed7776970988d28449865dc [ROCm/hip commit: 225e37fdc9eaec5ae4d33c5b10863786c1ff51f6] --- projects/hip/include/hcc_detail/hip_hcc.h | 2 +- projects/hip/src/hip_hcc.cpp | 15 ++++++++------- projects/hip/src/hip_memory.cpp | 5 +++-- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/projects/hip/include/hcc_detail/hip_hcc.h b/projects/hip/include/hcc_detail/hip_hcc.h index 6c061b01a9..9d4b70c73f 100644 --- a/projects/hip/include/hcc_detail/hip_hcc.h +++ b/projects/hip/include/hcc_detail/hip_hcc.h @@ -373,7 +373,7 @@ typedef uint64_t SeqNum_t ; //--- // Member functions that begin with locked_ are thread-safe accessors - these acquire / release the critical mutex. LockedAccessor_StreamCrit_t lockopen_preKernelCommand(); - void lockclose_postKernelCommand(hc::completion_future &kernel_future); + void lockclose_postKernelCommand(hc::accelerator_view *av); void locked_wait(bool assertQueueEmpty=false); diff --git a/projects/hip/src/hip_hcc.cpp b/projects/hip/src/hip_hcc.cpp index 1058d96412..fcbc553f83 100644 --- a/projects/hip/src/hip_hcc.cpp +++ b/projects/hip/src/hip_hcc.cpp @@ -253,11 +253,12 @@ LockedAccessor_StreamCrit_t ihipStream_t::lockopen_preKernelCommand() //--- // Must be called after kernel finishes, this releases the lock on the stream so other commands can submit. -void ihipStream_t::lockclose_postKernelCommand(hc::completion_future &kernelFuture) +void ihipStream_t::lockclose_postKernelCommand(hc::accelerator_view *av) { if (HIP_LAUNCH_BLOCKING) { - kernelFuture.wait(); + // TODO - fix this so it goes through proper stream::wait() call. + av->wait(); // direct wait OK since we know the stream is locked. tprintf(DB_SYNC, " %s LAUNCH_BLOCKING for kernel completion\n", ToString(this).c_str()); } @@ -1163,7 +1164,7 @@ hipStream_t ihipPreLaunchKernel(hipStream_t stream, dim3 grid, dim3 block, grid_ auto crit = stream->lockopen_preKernelCommand(); lp->av = &(crit->_av); - lp->cf = new hc::completion_future; + lp->cf = nullptr; ihipPrintKernelLaunch(kernelNameStr, lp, stream); return (stream); @@ -1185,7 +1186,7 @@ hipStream_t ihipPreLaunchKernel(hipStream_t stream, size_t grid, dim3 block, gri auto crit = stream->lockopen_preKernelCommand(); lp->av = &(crit->_av); - lp->cf = new hc::completion_future; + lp->cf = nullptr; ihipPrintKernelLaunch(kernelNameStr, lp, stream); return (stream); } @@ -1206,7 +1207,7 @@ hipStream_t ihipPreLaunchKernel(hipStream_t stream, dim3 grid, size_t block, gri auto crit = stream->lockopen_preKernelCommand(); lp->av = &(crit->_av); - lp->cf = new hc::completion_future; + lp->cf = nullptr; ihipPrintKernelLaunch(kernelNameStr, lp, stream); return (stream); } @@ -1227,7 +1228,7 @@ hipStream_t ihipPreLaunchKernel(hipStream_t stream, size_t grid, size_t block, g auto crit = stream->lockopen_preKernelCommand(); lp->av = &(crit->_av); - lp->cf = new hc::completion_future; // TODO, is this necessary? + lp->cf = nullptr; ihipPrintKernelLaunch(kernelNameStr, lp, stream); @@ -1240,7 +1241,7 @@ hipStream_t ihipPreLaunchKernel(hipStream_t stream, size_t grid, size_t block, g //This releases the lock on the stream. void ihipPostLaunchKernel(hipStream_t stream, grid_launch_parm &lp) { - stream->lockclose_postKernelCommand(*(lp.cf)); + stream->lockclose_postKernelCommand(lp.av); } diff --git a/projects/hip/src/hip_memory.cpp b/projects/hip/src/hip_memory.cpp index d2bb084fc5..08c4b4392f 100644 --- a/projects/hip/src/hip_memory.cpp +++ b/projects/hip/src/hip_memory.cpp @@ -772,7 +772,7 @@ hipError_t hipMemsetAsync(void* dst, int value, size_t sizeBytes, hipStream_t s } } - stream->lockclose_postKernelCommand(cf); + stream->lockclose_postKernelCommand(&crit->_av); if (HIP_LAUNCH_BLOCKING) { @@ -822,9 +822,10 @@ hipError_t hipMemset(void* dst, int value, size_t sizeBytes ) e = hipErrorInvalidValue; } } + // TODO - is hipMemset supposed to be async? cf.wait(); - stream->lockclose_postKernelCommand(cf); + stream->lockclose_postKernelCommand(&crit->_av); if (HIP_LAUNCH_BLOCKING) {