From 13d6ac74de66dfb38c049f9a3dfb08e9f0c80751 Mon Sep 17 00:00:00 2001 From: cao lei Date: Wed, 31 May 2023 16:08:14 -0700 Subject: [PATCH] fix memory profile build (#16177) ### Description This PR is to fix the build break when onnxruntime_ENABLE_MEMORY_PROFILE is on ### Motivation and Context This PR is to fix the build break when onnxruntime_ENABLE_MEMORY_PROFILE is on. It fixes this issue https://github.com/microsoft/onnxruntime/issues/16124 Co-authored-by: Lei Cao --- onnxruntime/core/framework/execution_frame.cc | 8 ++++---- onnxruntime/core/framework/memory_info.cc | 20 +++++++++---------- onnxruntime/core/framework/memory_info.h | 4 ++-- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/onnxruntime/core/framework/execution_frame.cc b/onnxruntime/core/framework/execution_frame.cc index c21d67d2e9..d9c49dc6be 100644 --- a/onnxruntime/core/framework/execution_frame.cc +++ b/onnxruntime/core/framework/execution_frame.cc @@ -421,14 +421,14 @@ ExecutionFrame::ExecutionFrame(gsl::span feed_mlvalue_idxs, gsl::span // Planning of one memory type should only happen once. #if !defined(ORT_MINIMAL_BUILD) && defined(ORT_MEMORY_PROFILE) ORT_ENFORCE( - static_activation_memory_sizes_in_byte_.find(location.name) == + static_activation_memory_sizes_in_byte_.find(location.ToString()) == static_activation_memory_sizes_in_byte_.end(), "Memory type ", - location.name, + location.ToString(), " should only appear once."); // static_activation_memory_in_bytes_ is max virtual memory size the planner computes. // Memory dynamically allocated when executing kernels is not recorded using this field. - static_activation_memory_sizes_in_byte_[location.name] = peak_size; + static_activation_memory_sizes_in_byte_[location.ToString()] = peak_size; #endif // the memory pattern buffer will leave in the whole execution. #ifdef ORT_ENABLE_STREAM @@ -609,7 +609,7 @@ Status ExecutionFrame::AllocateMLValueTensorSelfOwnBufferHelper(OrtValue& ort_va // Dynamic activation size would be accessed by multiple threads // if parallel executor is used. std::unique_lock lock(mtx_); - dynamic_activation_memory_sizes_in_byte_[location.name] += size; + dynamic_activation_memory_sizes_in_byte_[location.ToString()] += size; session_state_.GetMemoryProfiler()->GetMemoryInfo().SetDynamicAllocation(ort_value_index); #endif } diff --git a/onnxruntime/core/framework/memory_info.cc b/onnxruntime/core/framework/memory_info.cc index 41c8191778..afb338f47f 100644 --- a/onnxruntime/core/framework/memory_info.cc +++ b/onnxruntime/core/framework/memory_info.cc @@ -130,7 +130,7 @@ void PrintInforPerTensor(const MemoryInfo::AllocInfoPerTensor& alloc_info, const std::cout << "Index: " << alloc_info.mlvalue_index << ", "; std::cout << "Reuse inplace: " << alloc_info.inplace_reuse << ", "; std::cout << "Alloc type: " << alloc_info.alloc_kind << ", "; - std::cout << "Location: " << alloc_info.location.name << ", "; + std::cout << "Location: " << alloc_info.location.ToString() << ", "; std::cout << "lifetime: (" << alloc_info.lifetime_interval.first << ", " << alloc_info.lifetime_interval.second << "), "; std::cout << "planned block: (" << mem_info.planned_block.offset_ << ", " << (mem_info.planned_block.offset_ + mem_info.planned_block.size_) << "), "; @@ -142,24 +142,24 @@ void PrintInforPerTensor(const MemoryInfo::AllocInfoPerTensor& alloc_info, const void MemoryInfo::PrintMemoryInfoForLocation(const OrtDevice::DeviceType location) { for (const auto& map : tensors_memory_info_map_) { - if (map.first.device.Type() != location) continue; - std::cout << "Initializer in " << map.first.name << "\n"; + if (map.first.Type() != location) continue; + std::cout << "Initializer in " << map.first.ToString() << "\n"; const auto& initailizer_map = map.second.at(MapType::Initializer); for (const auto& item : initailizer_map) { - if (AllocPlan(item.first)->location.device.Type() != location) continue; + if (AllocPlan(item.first)->location.Type() != location) continue; PrintInforPerTensor(*AllocPlan(item.first), item.second, initailizer_map.GetAllocAddress(item.first)); } - std::cout << "\nStatic Activation in " << map.first.name << "\n"; + std::cout << "\nStatic Activation in " << map.first.ToString() << "\n"; const auto& static_activation_map = map.second.at(MapType::StaticActivation); for (const auto& item : static_activation_map) { - if (AllocPlan(item.first)->location.device.Type() != location) continue; + if (AllocPlan(item.first)->location.Type() != location) continue; PrintInforPerTensor(*AllocPlan(item.first), item.second, static_activation_map.GetAllocAddress(item.first)); } - std::cout << "\nDynamic Activation in " << map.first.name << "\n"; + std::cout << "\nDynamic Activation in " << map.first.ToString() << "\n"; const auto& dynamic_activation_map = map.second.at(MapType::DynamicActivation); for (const auto& item : dynamic_activation_map) { - if (AllocPlan(item.first)->location.device.Type() != location) continue; + if (AllocPlan(item.first)->location.Type() != location) continue; PrintInforPerTensor(*AllocPlan(item.first), item.second, dynamic_activation_map.GetAllocAddress(item.first)); } } @@ -273,10 +273,10 @@ void MemoryProfiler::CreateEvents(const std::string& p_name, // Create Event for each tensor auto& time_step_trace = GetMemoryInfo().time_step_trace_; for (const auto& location_map : GetMemoryInfo().tensors_memory_info_map_) { - const OrtMemoryInfo& memory_info = location_map.first; + const OrtDevice& memory_info = location_map.first; const auto& maptype_to_map_mapping = location_map.second; - if (memory_info.device.Type() != device_type) continue; + if (memory_info.Type() != device_type) continue; // If there is no tensor of a map_type, we skip creating event for that map_type if (maptype_to_map_mapping.find(map_type) == maptype_to_map_mapping.end()) continue; diff --git a/onnxruntime/core/framework/memory_info.h b/onnxruntime/core/framework/memory_info.h index 4b11dcaf7a..e38ccb3d94 100644 --- a/onnxruntime/core/framework/memory_info.h +++ b/onnxruntime/core/framework/memory_info.h @@ -122,7 +122,7 @@ class MemoryInfo { bool inplace_reuse{false}; OrtValueIndex reused_buffer{0}; // The index of the reused tensor, if no reuse, it is its own tensor. AllocKind alloc_kind{AllocKind::kAllocate}; - OrtMemoryInfo location; + OrtDevice location; }; struct AllocationSummary { @@ -185,7 +185,7 @@ class MemoryInfo { } // Key: The map type. E.g., initializer, activation. Value: A map from the tensor index to its memory information - std::map > tensors_memory_info_map_; + std::map > tensors_memory_info_map_; // Key: The tensor index. Value: The Allocation information per tensor std::map tensor_alloc_info_map_;