[Openmp-commits] [openmp] [OpenMP][libomptarget] Enable parallel copies via multiple SDMA engines (PR #71801)

Jan Patrick Lehr via Openmp-commits openmp-commits at lists.llvm.org
Thu Nov 9 13:53:59 PST 2023

@@ -130,6 +130,38 @@ Error iterateAgentMemoryPools(hsa_agent_t Agent, CallbackTy Cb) {
                        "Error in hsa_amd_agent_iterate_memory_pools: %s");
+/// Dispatches an asynchronous memory copy
+/// Enables different SDMA engines for the dispatch in a round-robin fashion.
+Error asyncMemCopy(bool UseMultipleSdmaEngines, void *Dst, hsa_agent_t DstAgent,
+                   const void *Src, hsa_agent_t SrcAgent, size_t Size,
+                   uint32_t NumDepSignals, const hsa_signal_t *DepSignals,
+                   hsa_signal_t CompletionSignal) {
+  if (UseMultipleSdmaEngines) {
+    hsa_status_t S =
+        hsa_amd_memory_async_copy(Dst, DstAgent, Src, SrcAgent, Size,
+                                  NumDepSignals, DepSignals, CompletionSignal);
+    return Plugin::check(S, "Error in hsa_amd_memory_async_copy");
+  }
+// This solution is probably not the best
+#if !(HSA_AMD_INTERFACE_VERSION_MAJOR >= 1 &&                                  \
+  return Plugin::error("Async copy on selected SDMA requires ROCm 5.7");
+  static int SdmaEngine = 1;
+  // This call is only avail in ROCm >= 5.7
+  hsa_status_t S = hsa_amd_memory_async_copy_on_engine(
jplehr wrote:

I think if users are going to set the env var to `true` than we would crash. I can do a build against an older ROCm version to see what happens.
Remember, this is not default behavior, but has to be enabled explicitly.

Would it be acceptable to note that in the Documentation (that I still have to add)? Since we have limited capability to check for which HSA version we are running, this is indeed a bit of a pain point.


More information about the Openmp-commits mailing list