diff --git a/hipamd/src/hip_context.cpp b/hipamd/src/hip_context.cpp index d28f9c350f..0f4c4ce2c3 100644 --- a/hipamd/src/hip_context.cpp +++ b/hipamd/src/hip_context.cpp @@ -349,7 +349,7 @@ hipError_t hipDevicePrimaryCtxGetState(hipDevice_t dev, unsigned int* flags, int } if (active != nullptr) { - *active = (g_devices[dev] == hip::getCurrentDevice())? 1 : 0; + *active = g_devices[dev]->GetActiveStatus() ? 1 : 0; } HIP_RETURN(hipSuccess); diff --git a/hipamd/src/hip_internal.hpp b/hipamd/src/hip_internal.hpp index 629e2e6868..a711052e81 100644 --- a/hipamd/src/hip_internal.hpp +++ b/hipamd/src/hip_internal.hpp @@ -325,9 +325,17 @@ namespace hip { /// Maintain list of user enabled peers std::list userEnabledPeers; + /// True if this device is active + bool isActive_; + + std::vector queues_; + public: - Device(amd::Context* ctx, int devId): - context_(ctx), deviceId_(devId), null_stream_(this, Stream::Priority::Normal, 0, true), flags_(hipDeviceScheduleSpin) + Device(amd::Context* ctx, int devId): context_(ctx), + deviceId_(devId), + null_stream_(this, Stream::Priority::Normal, 0, true), + flags_(hipDeviceScheduleSpin), + isActive_(false) { assert(ctx != nullptr); } ~Device() {} @@ -358,6 +366,23 @@ namespace hip { unsigned int getFlags() const { return flags_; } void setFlags(unsigned int flags) { flags_ = flags; } amd::HostQueue* NullStream(bool skip_alloc = false); + + void SaveQueue(amd::HostQueue* queue) { + amd::ScopedLock lock(lock_); + queues_.push_back(queue); + } + + bool GetActiveStatus() { + amd::ScopedLock lock(lock_); + if (isActive_) return true; + for (int i = 0; i < queues_.size(); i++) { + if (queues_[i]->GetQueueStatus()) { + isActive_ = true; + return true; + } + } + return false; + } }; /// Current thread's device diff --git a/hipamd/src/hip_stream.cpp b/hipamd/src/hip_stream.cpp index 4a9356c4c1..f74b4c0999 100644 --- a/hipamd/src/hip_stream.cpp +++ b/hipamd/src/hip_stream.cpp @@ -107,6 +107,7 @@ bool Stream::Create() { streamSet.insert(this); queue_ = queue; queue->vdev()->profilerAttach(isProfilerAttached); + device_->SaveQueue(queue); } else if (queue != nullptr) { queue->release(); }