[Openmp-commits] [PATCH] D143775: [Libomptarget] Implement the host memory allocator with coarse memory

Joseph Huber via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Fri Feb 10 12:40:10 PST 2023


jhuber6 created this revision.
jhuber6 added reviewers: jdoerfert, kevinsala, JonChesterfield, ye-luo, tianshilei1992.
Herald added subscribers: kosarev, kerbowa, jvesely.
Herald added a project: All.
jhuber6 requested review of this revision.
Herald added subscribers: openmp-commits, sstefan1.
Herald added a project: OpenMP.

This patch should enable the "Host" allocation using coarse-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 stuptiated 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 <https://reviews.llvm.org/D143771>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143775

Files:
  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


Index: openmp/libomptarget/test/api/omp_host_pinned_memory_alloc.c
===================================================================
--- openmp/libomptarget/test/api/omp_host_pinned_memory_alloc.c
+++ 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 @@
   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");
Index: openmp/libomptarget/test/api/omp_host_pinned_memory.c
===================================================================
--- openmp/libomptarget/test/api/omp_host_pinned_memory.c
+++ 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>
Index: openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp
===================================================================
--- openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp
+++ openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp
@@ -1485,6 +1485,12 @@
     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 @@
       MemoryPool = CoarseGrainedMemoryPools[0];
       break;
     case TARGET_ALLOC_HOST:
+      MemoryPool = &HostDevice.getCoarseGrainedMemoryPool();
       break;
     case TARGET_ALLOC_SHARED:
       MemoryPool = &HostDevice.getFineGrainedMemoryPool();
@@ -2623,6 +2630,7 @@
     MemoryPool = CoarseGrainedMemoryPools[0];
     break;
   case TARGET_ALLOC_HOST:
+    MemoryPool = &HostDevice.getCoarseGrainedMemoryPool();
     break;
   case TARGET_ALLOC_SHARED:
     MemoryPool = &HostDevice.getFineGrainedMemoryPool();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D143775.496583.patch
Type: text/x-patch
Size: 2285 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20230210/af56a50e/attachment.bin>


More information about the Openmp-commits mailing list