From 5b731168cab5a6f335adce4f02e7c1b31ecee7dd Mon Sep 17 00:00:00 2001 From: Ajay Date: Fri, 17 May 2024 12:08:20 -0700 Subject: [PATCH] SWDEV-439581 - hip event flags clean up Change-Id: I2197762d912da41a8b53b32b3446f0a958c988a6 [ROCm/clr commit: 6ec5074d744825134f74434f3022c79ca6fe1131] --- projects/clr/hipamd/src/hip_event.cpp | 14 +++++++------- projects/clr/hipamd/src/hip_event.hpp | 6 +++--- projects/clr/hipamd/src/hip_module.cpp | 2 +- projects/clr/rocclr/device/device.hpp | 3 ++- projects/clr/rocclr/device/rocm/rocdevice.cpp | 5 ++++- projects/clr/rocclr/device/rocm/rocdevice.hpp | 4 ++-- 6 files changed, 19 insertions(+), 15 deletions(-) diff --git a/projects/clr/hipamd/src/hip_event.cpp b/projects/clr/hipamd/src/hip_event.cpp index b7f039399f..35c5ee120d 100644 --- a/projects/clr/hipamd/src/hip_event.cpp +++ b/projects/clr/hipamd/src/hip_event.cpp @@ -74,12 +74,12 @@ hipError_t Event::synchronize() { auto hip_device = g_devices[deviceId()]; // Check HW status of the ROCcrl event. Note: not all ROCclr modes support HW status static constexpr bool kWaitCompletion = true; - if (!hip_device->devices()[0]->IsHwEventReady(*event_, kWaitCompletion, flags)) { + if (!hip_device->devices()[0]->IsHwEventReady(*event_, kWaitCompletion, flags_)) { if (event_->HwEvent() != nullptr) { amd::Command* command = nullptr; - hipError_t status = recordCommand(command, event_->command().queue(), flags); + hipError_t status = recordCommand(command, event_->command().queue(), flags_); command->enqueue(); - hip_device->devices()[0]->IsHwEventReady(command->event(), kWaitCompletion, flags); + hip_device->devices()[0]->IsHwEventReady(command->event(), kWaitCompletion, flags_); command->release(); } else { event_->awaitCompletion(); @@ -93,7 +93,7 @@ bool Event::awaitEventCompletion() { } bool EventDD::awaitEventCompletion() { - return g_devices[deviceId()]->devices()[0]->IsHwEventReady(*event_, true, flags); + return g_devices[deviceId()]->devices()[0]->IsHwEventReady(*event_, true, flags_); } hipError_t Event::elapsedTime(Event& eStop, float& ms) { @@ -104,7 +104,7 @@ hipError_t Event::elapsedTime(Event& eStop, float& ms) { return hipErrorInvalidHandle; } - if (flags & hipEventDisableTiming) { + if (flags_ & hipEventDisableTiming) { return hipErrorInvalidHandle; } @@ -120,7 +120,7 @@ hipError_t Event::elapsedTime(Event& eStop, float& ms) { return hipErrorInvalidHandle; } - if ((flags | eStop.flags) & hipEventDisableTiming) { + if ((flags_ | eStop.flags_) & hipEventDisableTiming) { return hipErrorInvalidHandle; } @@ -224,7 +224,7 @@ hipError_t Event::streamWait(hipStream_t stream, uint flags) { 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) & + int32_t releaseFlags = ((ext_flags == 0) ? flags_ : ext_flags) & (hipEventReleaseToDevice | hipEventReleaseToSystem | hipEventDisableSystemFence); if (releaseFlags & hipEventDisableSystemFence) { diff --git a/projects/clr/hipamd/src/hip_event.hpp b/projects/clr/hipamd/src/hip_event.hpp index e97fa28c2a..5ff7da5dde 100644 --- a/projects/clr/hipamd/src/hip_event.hpp +++ b/projects/clr/hipamd/src/hip_event.hpp @@ -102,13 +102,13 @@ class Event { if (type == Query) { ready = g_devices[deviceId()]->devices()[0]->IsHwEventReadyForcedWait(*event_); } else { - ready = g_devices[deviceId()]->devices()[0]->IsHwEventReady(*event_, flags); + ready = g_devices[deviceId()]->devices()[0]->IsHwEventReady(*event_, false, flags_); } return ready; } public: - Event(unsigned int flags) : flags(flags), lock_("hipEvent_t", true), + Event(uint32_t flags) : flags_(flags), lock_("hipEvent_t", true), event_(nullptr), unrecorded_(false), stream_(nullptr) { // No need to init event_ here as addMarker does that device_id_ = hip::getCurrentDevice()->deviceId(); // Created in current device ctx @@ -119,7 +119,7 @@ class Event { event_->release(); } } - unsigned int flags; + uint32_t flags_; //!< flags associated with the event virtual hipError_t query(); virtual hipError_t synchronize(); diff --git a/projects/clr/hipamd/src/hip_module.cpp b/projects/clr/hipamd/src/hip_module.cpp index 8707486424..614fa02be4 100644 --- a/projects/clr/hipamd/src/hip_module.cpp +++ b/projects/clr/hipamd/src/hip_module.cpp @@ -405,7 +405,7 @@ hipError_t ihipModuleLaunchKernel(hipFunction_t f, uint32_t globalWorkSizeX, if (stopEvent != nullptr) { hip::Event* eStop = reinterpret_cast(stopEvent); - if (eStop->flags & hipEventDisableSystemFence) { + if (eStop->flags_ & hipEventDisableSystemFence) { command->setEventScope(amd::Device::kCacheStateIgnore); } else { command->setEventScope(amd::Device::kCacheStateSystem); diff --git a/projects/clr/rocclr/device/device.hpp b/projects/clr/rocclr/device/device.hpp index f246856d8e..e919ab052b 100644 --- a/projects/clr/rocclr/device/device.hpp +++ b/projects/clr/rocclr/device/device.hpp @@ -1930,7 +1930,8 @@ class Device : public RuntimeObject { virtual bool IsHwEventReady( const amd::Event& event, //!< AMD event for HW status validation bool wait = false, //!< If true then forces the event completion - int hip_event_flags = 0) const { + uint32_t hip_event_flags = 0 //!< flags associated with the event. 0 = hipEventDefault + ) const { return false; }; diff --git a/projects/clr/rocclr/device/rocm/rocdevice.cpp b/projects/clr/rocclr/device/rocm/rocdevice.cpp index 8384545bef..a5f5c4ab0b 100644 --- a/projects/clr/rocclr/device/rocm/rocdevice.cpp +++ b/projects/clr/rocclr/device/rocm/rocdevice.cpp @@ -2924,13 +2924,16 @@ bool Device::IsHwEventReadyForcedWait(const amd::Event& event) const { } // ================================================================================================ -bool Device::IsHwEventReady(const amd::Event& event, bool wait, int hip_event_flags) const { +bool Device::IsHwEventReady(const amd::Event& event, bool wait, uint32_t hip_event_flags) const { void* hw_event = (event.NotifyEvent() != nullptr) ? event.NotifyEvent()->HwEvent() : event.HwEvent(); if (hw_event == nullptr) { ClPrint(amd::LOG_INFO, amd::LOG_SIG, "No HW event"); return false; } else if (wait) { + // hipEventBlockingSync + // when set the CPU gives up host thread for other work + // when not set the CPU enters a busy-wait on the event to occur constexpr int kHipEventBlockingSync = 0x1; bool active_wait = !(hip_event_flags & kHipEventBlockingSync) && ActiveWait(); return WaitForSignal(reinterpret_cast(hw_event)->signal_, active_wait); diff --git a/projects/clr/rocclr/device/rocm/rocdevice.hpp b/projects/clr/rocclr/device/rocm/rocdevice.hpp index 8a18f896c9..7b04c5b084 100644 --- a/projects/clr/rocclr/device/rocm/rocdevice.hpp +++ b/projects/clr/rocclr/device/rocm/rocdevice.hpp @@ -288,7 +288,7 @@ class NullDevice : public amd::Device { } bool IsHwEventReady(const amd::Event& event, bool wait = false, - int hip_event_flags = 0) const override { + uint32_t hip_event_flags = 0) const override { return false; } @@ -488,7 +488,7 @@ class Device : public NullDevice { cl_set_device_clock_mode_output_amd* pSetClockModeOutput); virtual bool IsHwEventReady(const amd::Event& event, bool wait = false, - int hip_event_flags = 0) const; + uint32_t hip_event_flags = 0) const; virtual bool IsHwEventReadyForcedWait(const amd::Event& event) const; virtual void getHwEventTime(const amd::Event& event, uint64_t* start, uint64_t* end) const; virtual void ReleaseGlobalSignal(void* signal) const;