[llvm] [Offload] Re-allocate overlapping memory (PR #159567)

Joseph Huber via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 18 06:59:36 PDT 2025


================
@@ -615,18 +621,58 @@ TargetAllocTy convertOlToPluginAllocTy(ol_alloc_type_t Type) {
 
 Error olMemAlloc_impl(ol_device_handle_t Device, ol_alloc_type_t Type,
                       size_t Size, void **AllocationOut) {
-  auto Alloc =
-      Device->Device->dataAlloc(Size, nullptr, convertOlToPluginAllocTy(Type));
-  if (!Alloc)
-    return Alloc.takeError();
+  void *OldAlloc = nullptr;
+
+  // Repeat the allocation up to a certain amount of times. If it happens to
+  // already be allocated (e.g. by a device from another vendor) throw it away
+  // and try again.
+  for (size_t Count = 0; Count < 10; Count++) {
----------------
jhuber6 wrote:

I figured something like this
```c
SmallVector<void *> Stack;
for (;;) {
  try_do_alloc();
  Stack.push_back(ptr);
  if (success)
    break;
}
for (void *p : Stack)
  free(p);
```

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


More information about the llvm-commits mailing list