[llvm] [offload] add context to olMemAlloc* (PR #222677)

Jan Trusiłło via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 11 04:19:43 PDT 2026


================
@@ -4295,6 +4318,56 @@ struct AMDGPUPluginTy final : public GenericPluginTy {
   AMDHostDeviceTy *HostDevice;
 };
 
+Expected<void *> AMDGPUPluginContextTy::allocate(GenericDeviceTy &Device,
+                                                 int64_t Size,
+                                                 TargetAllocTy Kind,
+                                                 size_t Alignment) {
+  auto PtrOrErr = PluginContextTy::allocate(Device, Size, Kind, Alignment);
+  if (!PtrOrErr || !*PtrOrErr)
+    return PtrOrErr;
+  std::lock_guard<std::mutex> Lock(AllocationsMutex);
+  Allocations[*PtrOrErr] = {Kind, &Device};
+  return PtrOrErr;
+}
+
+Error AMDGPUPluginContextTy::deallocate(GenericDeviceTy &Device, void *Ptr,
+                                        TargetAllocTy Kind) {
+  // Erase before base deallocate: once Ptr returns to the MM freelist a
+  // concurrent alloc could reuse it and re-populate Allocations. On failure
+  // Ptr is in an undetermined state (maybe freed, maybe not) so we don't
+  // re-add it either.
+  {
+    std::lock_guard<std::mutex> Lock(AllocationsMutex);
+    Allocations.erase(Ptr);
+  }
+  return PluginContextTy::deallocate(Device, Ptr, Kind);
+}
+
+Expected<PluginAllocInfoTy>
+AMDGPUPluginContextTy::getAllocInfo(const void *Ptr) {
+  AllocInfo Info;
+  {
+    std::lock_guard<std::mutex> Lock(AllocationsMutex);
+    auto It = Allocations.find(Ptr);
+    if (It == Allocations.end())
----------------
311Volt wrote:

Do we have a test case for interior pointers?

https://github.com/llvm/llvm-project/pull/222677


More information about the llvm-commits mailing list