[Openmp-commits] [openmp] 5d560b6 - [Libomptarget] Implement the host memory allocator with fine grained memory

Joseph Huber via Openmp-commits openmp-commits at lists.llvm.org
Mon Feb 20 06:44:25 PST 2023


Author: Joseph Huber
Date: 2023-02-20T08:44:09-06:00
New Revision: 5d560b6966b722e45085f010bb98d2b081c461c7

URL: https://github.com/llvm/llvm-project/commit/5d560b6966b722e45085f010bb98d2b081c461c7
DIFF: https://github.com/llvm/llvm-project/commit/5d560b6966b722e45085f010bb98d2b081c461c7.diff

LOG: [Libomptarget] Implement the host memory allocator with fine grained memory

This patch should enable the "Host" allocation using fine-grained
memory. As far as I understand, this is HSA managed memory that is
availible to the host, but can be accessed by the device as well.
The original patch that introduced these extensions just stipulated that
it's "non-migratable" memory, which is most likely true because it's
managed by the host but accessible by the device. This should work
sufficiently well for what we expect the "host" allocation to do.

Depends on D143771

Reviewed By: kevinsala

Differential Revision: https://reviews.llvm.org/D143775

Added: 
    

Modified: 
    openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp
    openmp/libomptarget/test/api/omp_host_pinned_memory.c
    openmp/libomptarget/test/api/omp_host_pinned_memory_alloc.c

Removed: 
    


################################################################################
diff  --git a/openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp b/openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp
index 5bb62f8924726..c28081c439345 100644
--- a/openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp
+++ b/openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp
@@ -1485,6 +1485,12 @@ struct AMDHostDeviceTy : public AMDGenericDeviceTy {
     return *FineGrainedMemoryPools[0];
   }
 
+  AMDGPUMemoryPoolTy &getCoarseGrainedMemoryPool() {
+    assert(!CoarseGrainedMemoryPools.empty() && "No coarse-grained mempool");
+    // Retrive any memory pool.
+    return *CoarseGrainedMemoryPools[0];
+  }
+
   /// Get a memory pool for kernel args allocations.
   AMDGPUMemoryPoolTy &getArgsMemoryPool() {
     assert(!ArgsMemoryPools.empty() && "No kernelargs mempool");
@@ -1762,6 +1768,7 @@ struct AMDGPUDeviceTy : public GenericDeviceTy, AMDGenericDeviceTy {
       MemoryPool = CoarseGrainedMemoryPools[0];
       break;
     case TARGET_ALLOC_HOST:
+      MemoryPool = &HostDevice.getFineGrainedMemoryPool();
       break;
     case TARGET_ALLOC_SHARED:
       MemoryPool = &HostDevice.getFineGrainedMemoryPool();
@@ -2623,6 +2630,7 @@ void *AMDGPUDeviceTy::allocate(size_t Size, void *, TargetAllocTy Kind) {
     MemoryPool = CoarseGrainedMemoryPools[0];
     break;
   case TARGET_ALLOC_HOST:
+    MemoryPool = &HostDevice.getFineGrainedMemoryPool();
     break;
   case TARGET_ALLOC_SHARED:
     MemoryPool = &HostDevice.getFineGrainedMemoryPool();

diff  --git a/openmp/libomptarget/test/api/omp_host_pinned_memory.c b/openmp/libomptarget/test/api/omp_host_pinned_memory.c
index d7238058481a0..7a6a00d489d5a 100644
--- a/openmp/libomptarget/test/api/omp_host_pinned_memory.c
+++ b/openmp/libomptarget/test/api/omp_host_pinned_memory.c
@@ -1,5 +1,4 @@
 // RUN: %libomptarget-compile-run-and-check-generic
-// UNSUPPORTED: amdgcn-amd-amdhsa
 
 #include <omp.h>
 #include <stdio.h>

diff  --git a/openmp/libomptarget/test/api/omp_host_pinned_memory_alloc.c b/openmp/libomptarget/test/api/omp_host_pinned_memory_alloc.c
index 03dc92af1794e..fa3e2455d3714 100644
--- a/openmp/libomptarget/test/api/omp_host_pinned_memory_alloc.c
+++ b/openmp/libomptarget/test/api/omp_host_pinned_memory_alloc.c
@@ -1,5 +1,4 @@
 // RUN: %libomptarget-compile-run-and-check-generic
-// UNSUPPORTED: amdgcn-amd-amdhsa
 
 #include <omp.h>
 #include <stdio.h>
@@ -20,7 +19,7 @@ int main() {
   for (int i = 0; i < N; ++i)
     sum += hst_ptr[i];
 
-  omp_free(hst_ptr, llvm_omp_target_shared_mem_alloc);
+  omp_free(hst_ptr, llvm_omp_target_host_mem_alloc);
   // CHECK: PASS
   if (sum == N)
     printf("PASS\n");


        


More information about the Openmp-commits mailing list