From 9fdbbe53dcc6afee9e8fc8217fb26b9800530ac1 Mon Sep 17 00:00:00 2001 From: Saleel Kudchadker Date: Fri, 20 Jan 2023 15:35:25 -0800 Subject: [PATCH] SWDEV-364604 - Add support for hipEventDisableSystemFence Change-Id: I1a6451c873fb22729ac61e4e80f8531251e990f0 [ROCm/clr commit: 7fc5ae2226315c0ae3aab5f9a3da2e51f75529f8] --- projects/clr/hipamd/src/hip_event.cpp | 26 ++++++++++++++++---------- projects/clr/hipamd/src/hip_module.cpp | 11 +++++++++-- projects/clr/hipamd/src/hip_stream.cpp | 8 ++++++++ 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/projects/clr/hipamd/src/hip_event.cpp b/projects/clr/hipamd/src/hip_event.cpp index 83cbb9ef32..7ddac56089 100644 --- a/projects/clr/hipamd/src/hip_event.cpp +++ b/projects/clr/hipamd/src/hip_event.cpp @@ -222,13 +222,12 @@ hipError_t Event::recordCommand(amd::Command*& command, amd::HostQueue* stream, uint32_t ext_flags ) { if (command == nullptr) { int32_t releaseFlags = ((ext_flags == 0) ? flags : ext_flags) & - (hipEventReleaseToSystem | hipEventReleaseToDevice); - if (releaseFlags & hipEventReleaseToDevice) { - releaseFlags = amd::Device::kCacheStateAgent; - } else if (releaseFlags & hipEventReleaseToSystem) { - releaseFlags = amd::Device::kCacheStateSystem; - } else { + (hipEventReleaseToDevice | hipEventReleaseToSystem | + hipEventDisableSystemFence); + if (releaseFlags & hipEventDisableSystemFence) { releaseFlags = amd::Device::kCacheStateIgnore; + } else { + releaseFlags = amd::Device::kCacheStateInvalid; } // Always submit a EventMarker. command = new hip::EventMarker(*stream, !kMarkerDisableFlush, true, releaseFlags); @@ -279,14 +278,21 @@ bool isValid(hipEvent_t event) { // ================================================================================================ hipError_t ihipEventCreateWithFlags(hipEvent_t* event, unsigned flags) { unsigned supportedFlags = hipEventDefault | hipEventBlockingSync | hipEventDisableTiming | - hipEventReleaseToDevice | hipEventReleaseToSystem | hipEventInterprocess; + hipEventReleaseToDevice | hipEventReleaseToSystem | + hipEventInterprocess | hipEventDisableSystemFence; - const unsigned releaseFlags = (hipEventReleaseToDevice | hipEventReleaseToSystem); + const unsigned releaseFlags = (hipEventReleaseToDevice | hipEventReleaseToSystem | + hipEventDisableSystemFence); // can't set any unsupported flags. - // can't set both release flags + // can set only one of the release flags. // if hipEventInterprocess flag is set, then hipEventDisableTiming flag also must be set const bool illegalFlags = (flags & ~supportedFlags) || - ((flags & releaseFlags) == releaseFlags) || + ([](unsigned int num){ + unsigned int bitcount; + for (bitcount = 0; num; bitcount++) { + num &= num - 1; + } + return bitcount; } (flags & releaseFlags) > 1) || ((flags & hipEventInterprocess) && !(flags & hipEventDisableTiming)); if (!illegalFlags) { hip::Event* e = nullptr; diff --git a/projects/clr/hipamd/src/hip_module.cpp b/projects/clr/hipamd/src/hip_module.cpp index 98cc7fd599..a3fa4919e7 100644 --- a/projects/clr/hipamd/src/hip_module.cpp +++ b/projects/clr/hipamd/src/hip_module.cpp @@ -388,11 +388,18 @@ hipError_t ihipModuleLaunchKernel(hipFunction_t f, uint32_t globalWorkSizeX, } } - command->enqueue(); - if (stopEvent != nullptr) { hip::Event* eStop = reinterpret_cast(stopEvent); + if (eStop->flags & hipEventDisableSystemFence) { + command->setEventScope(amd::Device::kCacheStateIgnore); + } else { + command->setEventScope(amd::Device::kCacheStateSystem); + } + // Enqueue Dispatch and bind the stop event + command->enqueue(); eStop->BindCommand(*command, false); + } else { + command->enqueue(); } if (command->status() == CL_INVALID_OPERATION) { diff --git a/projects/clr/hipamd/src/hip_stream.cpp b/projects/clr/hipamd/src/hip_stream.cpp index e6c2839a5b..80ea30133b 100644 --- a/projects/clr/hipamd/src/hip_stream.cpp +++ b/projects/clr/hipamd/src/hip_stream.cpp @@ -225,6 +225,14 @@ void iHipWaitActiveStreams(hip::Stream* blocking_stream, bool wait_null_stream) command->enqueue(); command->release(); } + + //Reset the dirty flag for all streams now that the marker is submitted + for (const auto& stream : streamSet) { + amd::HostQueue* active_queue = stream->asHostQueue(); + if (active_queue->vdev()->isFenceDirty()) { + active_queue->vdev()->resetFenceDirty(); + } + } } // Release all active commands. It's safe after the marker was enqueued