From 4d9c540f4fe57551dbfc3cb1b8bf85ee3c19f551 Mon Sep 17 00:00:00 2001 From: Christophe Paquot Date: Thu, 9 Apr 2020 12:44:21 -0700 Subject: [PATCH] Remove a map lookup whenever we were getting the default stream Change-Id: I64b6d1deea41d81e94a58a83de287e78923656b3 --- vdi/hip_context.cpp | 24 ++++-------------------- vdi/hip_device.cpp | 14 ++++++++++++++ vdi/hip_internal.hpp | 5 +++-- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/vdi/hip_context.cpp b/vdi/hip_context.cpp index 6151f68c6a..440c3f4b47 100644 --- a/vdi/hip_context.cpp +++ b/vdi/hip_context.cpp @@ -34,8 +34,6 @@ thread_local hipError_t g_lastError = hipSuccess; std::once_flag g_ihipInitialized; Device* host_device = nullptr; -std::map g_nullStreams; - void init() { if (!amd::Runtime::initialized()) { amd::IS_HIP = true; @@ -93,24 +91,10 @@ amd::HostQueue* getQueue(hipStream_t stream) { } } -amd::HostQueue* getNullStream(Device& dev) { - auto stream = g_nullStreams.find(&dev); - if (stream == g_nullStreams.end()) { - amd::Device* device = dev.devices()[0]; - cl_command_queue_properties properties = CL_QUEUE_PROFILING_ENABLE; - amd::HostQueue* queue = new amd::HostQueue(*dev.asContext(), *device, properties, - amd::CommandQueue::RealTimeDisabled, - amd::CommandQueue::Priority::Normal); - g_nullStreams[&dev] = queue; - return queue; - } - return stream->second; -} - amd::HostQueue* getNullStream(amd::Context& ctx) { - for (auto& it : g_nullStreams) { - if (it.first->asContext() == &ctx) { - return it.second; + for (auto& it : g_devices) { + if (it->asContext() == &ctx) { + return it->defaultStream(); } } return nullptr; @@ -118,7 +102,7 @@ amd::HostQueue* getNullStream(amd::Context& ctx) { amd::HostQueue* getNullStream() { Device* device = getCurrentDevice(); - return device ? getNullStream(*device) : nullptr; + return device ? device->defaultStream() : nullptr; } }; diff --git a/vdi/hip_device.cpp b/vdi/hip_device.cpp index 30b2292271..cc27fef05e 100644 --- a/vdi/hip_device.cpp +++ b/vdi/hip_device.cpp @@ -22,6 +22,20 @@ #include "hip_internal.hpp" +namespace hip { + +amd::HostQueue* Device::defaultStream() { + if (defaultStream_ == nullptr) { + const cl_command_queue_properties properties = CL_QUEUE_PROFILING_ENABLE; + defaultStream_ = new amd::HostQueue(*asContext(), *devices()[0], properties, + amd::CommandQueue::RealTimeDisabled, + amd::CommandQueue::Priority::Normal); + } + return defaultStream_; +} + +}; + hipError_t hipDeviceGet(hipDevice_t *device, int deviceId) { HIP_INIT_API(hipDeviceGet, device, deviceId); diff --git a/vdi/hip_internal.hpp b/vdi/hip_internal.hpp index a2851fd978..ed99d6911e 100755 --- a/vdi/hip_internal.hpp +++ b/vdi/hip_internal.hpp @@ -84,6 +84,8 @@ namespace hip { amd::Monitor lock_{"Device lock"}; /// VDI context amd::Context* context_; + /// VDI host queue for default streams + amd::HostQueue* defaultStream_; /// Device's ID /// Store it here so we don't have to loop through the device list every time int deviceId_; @@ -117,6 +119,7 @@ namespace hip { return hipErrorPeerAccessNotEnabled; } } + amd::HostQueue* defaultStream(); }; extern std::once_flag g_ihipInitialized; @@ -135,8 +138,6 @@ namespace hip { /// Note: This follows the CUDA spec to sync with default streams /// and Blocking streams extern amd::HostQueue* getQueue(hipStream_t s); - /// Get default stream of the device - extern amd::HostQueue* getNullStream(Device&); /// Get default stream associated with the VDI context extern amd::HostQueue* getNullStream(amd::Context&); /// Get default stream of the thread