Commit cb283e98 authored by Ville Pietilä's avatar Ville Pietilä
Browse files

Small performance optimization.

parent 4c5ebf64
...@@ -320,11 +320,11 @@ namespace memory { ...@@ -320,11 +320,11 @@ namespace memory {
{ {
std::lock_guard<std::mutex> lock(mutex_); std::lock_guard<std::mutex> lock(mutex_);
std::vector<void*> keys; std::vector<void*> keys;
for (const auto& [p, _] : allocated_memory_) keys.reserve(allocated_memory_.size());
{ for (const auto& [p, _] : allocated_memory_) {
keys.push_back(p); keys.push_back(p);
} }
for (auto p : keys) for (const void* p : keys)
{ {
if (canDeallocate(p)) if (canDeallocate(p))
{ {
...@@ -358,6 +358,13 @@ namespace memory { ...@@ -358,6 +358,13 @@ namespace memory {
bool canDeallocate(void* p) bool canDeallocate(void* p)
{ {
const bool can_deallocate_on_host = host_destruct_events_[p];
if (!can_deallocate_on_host)
{
return false;
}
bool can_deallocate_on_device = false; bool can_deallocate_on_device = false;
hipError_t state = hipEventQuery(device_destruct_events_[p]); hipError_t state = hipEventQuery(device_destruct_events_[p]);
if (state == hipSuccess) if (state == hipSuccess)
...@@ -369,7 +376,6 @@ namespace memory { ...@@ -369,7 +376,6 @@ namespace memory {
throw std::runtime_error("Error querying event state: " + std::to_string(state)); throw std::runtime_error("Error querying event state: " + std::to_string(state));
} }
const bool can_deallocate_on_host = host_destruct_events_[p];
return can_deallocate_on_device && can_deallocate_on_host; return can_deallocate_on_device && can_deallocate_on_host;
} }
}; };
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment