From f320acb79745f76d84c70a48b40d8c0c6dc8e529 Mon Sep 17 00:00:00 2001 From: Saleel Kudchadker Date: Fri, 1 Apr 2022 15:16:13 -0700 Subject: [PATCH] SWDEV-276210 - Honor scopes for hipEventRecord Honor hipEventReleaseToDevice and hipEventReleaseToSystem flags. hipEventRecord would flush caches if no release flags are provided. To change this behavior set ROC_EVENT_NO_FLUSH=1 Change-Id: I03e41b515b1d0cf963b0c2d5b9901b09e71a0e59 --- hipamd/src/hip_event.cpp | 21 +++++++++++++++++---- hipamd/src/hip_event.hpp | 7 ++++--- hipamd/src/hip_event_ipc.cpp | 2 +- hipamd/src/hip_stream.cpp | 2 +- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/hipamd/src/hip_event.cpp b/hipamd/src/hip_event.cpp index 51e462d1f7..f879c348ab 100644 --- a/hipamd/src/hip_event.cpp +++ b/hipamd/src/hip_event.cpp @@ -71,7 +71,11 @@ hipError_t Event::synchronize() { // Check HW status of the ROCcrl event. Note: not all ROCclr modes support HW status static constexpr bool kWaitCompletion = true; if (!g_devices[deviceId()]->devices()[0]->IsHwEventReady(*event_, kWaitCompletion)) { - event_->awaitCompletion(); + amd::Command* command = nullptr; + hipError_t status = recordCommand(command, event_->command().queue(), flags); + command->enqueue(); + g_devices[deviceId()]->devices()[0]->IsHwEventReady(command->event(), kWaitCompletion); + command->release(); } return hipSuccess; @@ -202,11 +206,20 @@ hipError_t Event::streamWait(hipStream_t stream, uint flags) { return hipSuccess; } -hipError_t Event::recordCommand(amd::Command*& command, amd::HostQueue* queue) { +hipError_t Event::recordCommand(amd::Command*& command, amd::HostQueue* queue, + uint32_t ext_flags ) { if (command == nullptr) { - static constexpr bool kRecordExplicitGpuTs = true; + uint32_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 { + releaseFlags = amd::Device::kCacheStateIgnore; + } // Always submit a EventMarker. - command = new hip::EventMarker(*queue, !kMarkerDisableFlush, kRecordExplicitGpuTs); + command = new hip::EventMarker(*queue, !kMarkerDisableFlush, releaseFlags); } return hipSuccess; } diff --git a/hipamd/src/hip_event.hpp b/hipamd/src/hip_event.hpp index 89095b5c73..97ba296ad0 100644 --- a/hipamd/src/hip_event.hpp +++ b/hipamd/src/hip_event.hpp @@ -53,7 +53,7 @@ typedef struct ihipIpcEventShmem_s { class EventMarker : public amd::Marker { public: - EventMarker(amd::HostQueue& queue, bool disableFlush, bool markerTs = false) + EventMarker(amd::HostQueue& queue, bool disableFlush, uint32_t markerTs = 0) : amd::Marker(queue, disableFlush) { profilingInfo_.enabled_ = true; profilingInfo_.callback_ = nullptr; @@ -93,7 +93,8 @@ class Event { virtual hipError_t enqueueStreamWaitCommand(hipStream_t stream, amd::Command* command); virtual hipError_t streamWait(hipStream_t stream, uint flags); - virtual hipError_t recordCommand(amd::Command*& command, amd::HostQueue* queue); + virtual hipError_t recordCommand(amd::Command*& command, amd::HostQueue* queue, + uint32_t flags = 0); virtual hipError_t enqueueRecordCommand(hipStream_t stream, amd::Command* command, bool record); hipError_t addMarker(hipStream_t stream, amd::Command* command, bool record); @@ -199,7 +200,7 @@ class IPCEvent : public Event { hipError_t enqueueStreamWaitCommand(hipStream_t stream, amd::Command* command); hipError_t streamWait(hipStream_t stream, uint flags); - hipError_t recordCommand(amd::Command*& command, amd::HostQueue* queue); + hipError_t recordCommand(amd::Command*& command, amd::HostQueue* queue, uint32_t flags = 0); hipError_t enqueueRecordCommand(hipStream_t stream, amd::Command* command, bool record); }; diff --git a/hipamd/src/hip_event_ipc.cpp b/hipamd/src/hip_event_ipc.cpp index 4dedb4e506..24807ebbf2 100644 --- a/hipamd/src/hip_event_ipc.cpp +++ b/hipamd/src/hip_event_ipc.cpp @@ -130,7 +130,7 @@ hipError_t IPCEvent::streamWait(hipStream_t stream, uint flags) { return hipSuccess; } -hipError_t IPCEvent::recordCommand(amd::Command*& command, amd::HostQueue* queue) { +hipError_t IPCEvent::recordCommand(amd::Command*& command, amd::HostQueue* queue, uint32_t flags) { bool recorded = isRecorded(); if (!recorded) { command = new amd::Marker(*queue, kMarkerDisableFlush); diff --git a/hipamd/src/hip_stream.cpp b/hipamd/src/hip_stream.cpp index 065395e98d..946785bb59 100644 --- a/hipamd/src/hip_stream.cpp +++ b/hipamd/src/hip_stream.cpp @@ -208,7 +208,7 @@ void Stream::destroyAllStreams(int deviceId) { // ================================================================================================ void iHipWaitActiveStreams(amd::HostQueue* blocking_queue, bool wait_null_stream) { - amd::Command::EventWaitList eventWaitList; + amd::Command::EventWaitList eventWaitList(0); { amd::ScopedLock lock(streamSetLock);