@@ -101,7 +101,6 @@ ResourceManager& ResourceManager::getInstance()
101101
102102ResourceManager::ResourceManager ()
103103 : m_allocations(),
104- m_exact_allocations (),
105104 m_allocators (),
106105 m_shared_allocator_names(),
107106 m_allocators_by_id(),
@@ -112,8 +111,7 @@ ResourceManager::ResourceManager()
112111 m_zero_byte_pool(nullptr ),
113112 m_introspection_level{parse_introspection_level (std::getenv (s_introspection_level_env_name))},
114113 m_id (0 ),
115- m_mutex(),
116- m_exact_allocations_mutex()
114+ m_mutex()
117115{
118116 UMPIRE_LOG (Debug, " () entering" );
119117
@@ -133,7 +131,9 @@ ResourceManager::~ResourceManager()
133131 if (allocator->getCurrentSize () != 0 ) {
134132 std::stringstream ss;
135133
136- printTrackedAllocationRecords (allocator.get (), ss);
134+ if (getIntrospectionLevel () == IntrospectionLevel::On) {
135+ printTrackedAllocationRecords (allocator.get (), ss);
136+ }
137137
138138 UMPIRE_LOG (Error, allocator->getName ()
139139 << " Allocator still has " << allocator->getCurrentSize () << " bytes allocated" << std::endl
@@ -184,9 +184,16 @@ void ResourceManager::initialize()
184184
185185void ResourceManager::setIntrospectionLevel (IntrospectionLevel level)
186186{
187- if (m_allocations_exist) {
187+ const auto current_level = getIntrospectionLevel ();
188+
189+ // Only block lowering from On mode if tracked allocations exist in AllocationMap
190+ // (can't switch to Basic/Off if we have tracked allocations)
191+ if (current_level == IntrospectionLevel::On &&
192+ static_cast <int >(level) < static_cast <int >(current_level) &&
193+ m_allocations.size () > 0 ) {
188194 UMPIRE_ERROR (runtime_error,
189- " Cannot change introspection level after allocations have been made" );
195+ fmt::format (" Cannot lower introspection level from \" on\" to \" {}\" while tracked allocations exist" ,
196+ to_string (level)));
190197 }
191198 m_introspection_level.store (level, std::memory_order_relaxed);
192199}
@@ -554,8 +561,9 @@ Allocator ResourceManager::getAllocator(void* ptr)
554561{
555562 UMPIRE_LOG (Debug, " (ptr=" << ptr << " )" );
556563 const auto level = getIntrospectionLevel ();
557- if (!requires_full_introspection (level)) {
558- throw_requires_full_introspection (" ResourceManager::getAllocator(void*)" , level);
564+ if (level == IntrospectionLevel::Off) {
565+ UMPIRE_ERROR (runtime_error,
566+ " ResourceManager::getAllocator(void*) requires introspection to be enabled (basic or on mode)" );
559567 }
560568 return Allocator (findAllocatorForPointer (ptr));
561569}
@@ -621,8 +629,6 @@ void ResourceManager::registerAllocation(void* ptr, util::AllocationRecord recor
621629 UMPIRE_ERROR (runtime_error, " Cannot register nullptr!" );
622630 }
623631
624- m_allocations_exist = true ; // Mark that allocations exist
625-
626632 UMPIRE_LOG (Debug,
627633 " (ptr=" << ptr << " , size=" << record.size << " , strategy=" << record.strategy << " ) with " << this );
628634
@@ -1099,13 +1105,6 @@ void* ResourceManager::move(void* ptr, Allocator allocator)
10991105 throw_requires_full_introspection (" ResourceManager::move" , level);
11001106 }
11011107
1102- const auto level = getIntrospectionLevel ();
1103-
1104- if (level != IntrospectionLevel::On) {
1105- UMPIRE_ERROR (runtime_error,
1106- " move() requires IntrospectionLevel::On" );
1107- }
1108-
11091108 auto alloc_record = m_allocations.find (ptr);
11101109
11111110 // short-circuit if ptr was allocated by 'allocator'
@@ -1187,13 +1186,6 @@ camp::resources::EventProxy<camp::resources::Resource> ResourceManager::prefetch
11871186 throw_requires_full_introspection (" ResourceManager::prefetch" , level);
11881187 }
11891188
1190- const auto level = getIntrospectionLevel ();
1191-
1192- if (level != IntrospectionLevel::On) {
1193- UMPIRE_ERROR (runtime_error,
1194- " prefetch() requires IntrospectionLevel::On" );
1195- }
1196-
11971189 auto & op_registry = op::MemoryOperationRegistry::getInstance ();
11981190 auto alloc_record = m_allocations.find (ptr);
11991191
0 commit comments