[clang] [OpenMP] Basic BumpAllocator for (AMD)GPUs (PR #69806)

Joseph Huber via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 20 19:39:17 PDT 2023


================
@@ -48,25 +48,17 @@ namespace {
 extern "C" {
 [[gnu::weak, gnu::leaf]] void *malloc(uint64_t Size);
 [[gnu::weak, gnu::leaf]] void free(void *Ptr);
-}
 
-///}
+void *llvm_device_malloc(uint64_t Size) { return allocator::alloc(Size); }
+void llvm_device_free(void *Ptr) { allocator::free(Ptr); }
 
-/// AMDGCN implementations of the shuffle sync idiom.
-///
-///{
 #pragma omp begin declare variant match(device = {arch(amdgcn)})
 
-extern "C" {
-void *malloc(uint64_t Size) {
-  // TODO: Use some preallocated space for dynamic malloc.
-  return nullptr;
-}
-
-void free(void *Ptr) {}
-}
+void *malloc(uint64_t Size) { return llvm_device_malloc(Size); }
----------------
jhuber6 wrote:

These need to be marked weak if we want them to defer to a stronger definition of `malloc` (e.g. one coming from `libc` if linked)

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


More information about the cfe-commits mailing list