From d1d6c448c9cb531950e9cf7e2df894cf948059a0 Mon Sep 17 00:00:00 2001 From: Sourabh Betigeri Date: Thu, 15 Aug 2024 12:14:41 -0700 Subject: [PATCH] SWDEV-462192 SWDEV-459056 - Fixes corruption SPT is destroyed with hipDeviceReset(). If a stream is created right after reset, the same object id could be reused. Later SPT destructor incorrectly verifies that the stream is valid referring to the reused object id causing the corruption. Change-Id: I3b1f7ffdf8bab874dca7b8fde22318162997b8f6 [ROCm/clr commit: f6a68b3c2e09d3266bb76a12f8c772151a1621c7] --- projects/clr/hipamd/src/hip_device.cpp | 1 + projects/clr/hipamd/src/hip_internal.hpp | 1 + projects/clr/hipamd/src/hip_stream.cpp | 4 ++++ 3 files changed, 6 insertions(+) diff --git a/projects/clr/hipamd/src/hip_device.cpp b/projects/clr/hipamd/src/hip_device.cpp index 802a94177e..27f1ef4c1f 100644 --- a/projects/clr/hipamd/src/hip_device.cpp +++ b/projects/clr/hipamd/src/hip_device.cpp @@ -249,6 +249,7 @@ void Device::destroyAllStreams() { for (auto& it : toBeDeleted) { hip::Stream::Destroy(it); } + hip::tls.stream_per_thread_obj_.clear_spt(); } // ================================================================================================ diff --git a/projects/clr/hipamd/src/hip_internal.hpp b/projects/clr/hipamd/src/hip_internal.hpp index a53affd19a..d9f26e4679 100644 --- a/projects/clr/hipamd/src/hip_internal.hpp +++ b/projects/clr/hipamd/src/hip_internal.hpp @@ -269,6 +269,7 @@ public: void operator=(const stream_per_thread& ) = delete; ~stream_per_thread(); hipStream_t get(); + void clear_spt(); }; class Device; diff --git a/projects/clr/hipamd/src/hip_stream.cpp b/projects/clr/hipamd/src/hip_stream.cpp index 9ea50d4023..72af505a41 100644 --- a/projects/clr/hipamd/src/hip_stream.cpp +++ b/projects/clr/hipamd/src/hip_stream.cpp @@ -236,6 +236,10 @@ hipStream_t stream_per_thread::get() { return m_streams[currDev]; } +void stream_per_thread::clear_spt() { + m_streams[getCurrentDevice()->deviceId()] = nullptr; +} + // ================================================================================================ void getStreamPerThread(hipStream_t& stream) {