Remove a map lookup whenever we were getting the default stream

Change-Id: I64b6d1deea41d81e94a58a83de287e78923656b3
Этот коммит содержится в:
Christophe Paquot
2020-04-09 12:44:21 -07:00
родитель f03a1ef371
Коммит 4d9c540f4f
3 изменённых файлов: 21 добавлений и 22 удалений
+4 -20
Просмотреть файл
@@ -34,8 +34,6 @@ thread_local hipError_t g_lastError = hipSuccess;
std::once_flag g_ihipInitialized;
Device* host_device = nullptr;
std::map<Device*, amd::HostQueue*> 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;
}
};
+14
Просмотреть файл
@@ -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);
+3 -2
Просмотреть файл
@@ -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