[llvm] [Offload] Guard olMemAlloc/Free with a mutex (PR #153786)
Joseph Huber via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 15 06:22:01 PDT 2025
================
@@ -449,26 +450,33 @@ Error olMemAlloc_impl(ol_device_handle_t Device, ol_alloc_type_t Type,
return Alloc.takeError();
*AllocationOut = *Alloc;
- OffloadContext::get().AllocInfoMap.insert_or_assign(*Alloc,
- AllocInfo{Device, Type});
+ {
+ std::lock_guard<std::mutex> Lock(OffloadContext::get().AllocInfoMapMutex);
+ OffloadContext::get().AllocInfoMap.insert_or_assign(
+ *Alloc, AllocInfo{Device, Type});
+ }
return Error::success();
}
Error olMemFree_impl(void *Address) {
- if (!OffloadContext::get().AllocInfoMap.contains(Address))
- return createOffloadError(ErrorCode::INVALID_ARGUMENT,
- "address is not a known allocation");
-
- auto AllocInfo = OffloadContext::get().AllocInfoMap.at(Address);
- auto Device = AllocInfo.Device;
- auto Type = AllocInfo.Type;
+ ol_device_handle_t Device;
+ ol_alloc_type_t Type;
+ {
+ std::lock_guard<std::mutex> Lock(OffloadContext::get().AllocInfoMapMutex);
+ if (!OffloadContext::get().AllocInfoMap.contains(Address))
+ return createOffloadError(ErrorCode::INVALID_ARGUMENT,
+ "address is not a known allocation");
+
+ auto AllocInfo = OffloadContext::get().AllocInfoMap.at(Address);
+ Device = AllocInfo.Device;
+ Type = AllocInfo.Type;
+ OffloadContext::get().AllocInfoMap.erase(Address);
----------------
jhuber6 wrote:
Is this the only part we need to guard?
https://github.com/llvm/llvm-project/pull/153786
More information about the llvm-commits
mailing list