================
@@ -4185,6 +4246,59 @@ struct AMDGPUPluginTy final : public GenericPluginTy {
return KernelAgents;
}
+ /// Enable SVM if the user, the driver and the runtime support it.
+ void initSVM(ArrayRef<hsa_agent_t> HostAgents) {
+ bool Supported = false;
+ if (!OMPX_UseSVM ||
+ hsa_system_get_info(HSA_AMD_SYSTEM_INFO_SVM_SUPPORTED, &Supported) !=
+ HSA_STATUS_SUCCESS ||
+ !Supported)
+ return;
+
+ // SVM is recognized through the registration of its addresses, which the
+ // runtime reports since version 1.13 of the AMD extension.
+ auto Version = hsa_utils::getAMDExtensionVersion();
+ if (!Version || *Version < llvm::VersionTuple(1, 13))
+ return;
+
+ // Accesses may incur a page fault and the migration of the memory to the
+ // accessing agent.
+ for (hsa_agent_t Agent :
+ llvm::concat<const hsa_agent_t>(HostAgents, KernelAgents))
+ SVMAttrs.push_back({HSA_AMD_SVM_ATTRIB_AGENT_ACCESSIBLE, Agent.handle});
+ }
+
+ /// Allocate shared virtual memory (SVM), which is accessible by all the
+ /// agents and which the driver migrates between them on demand. Returns null
+ /// if SVM is unsupported.
+ Expected<void *> allocateSVM(size_t Size, size_t Alignment) {
+ // The reserved addresses are page aligned.
+ if (SVMAttrs.empty() ||
+ Alignment > llvm::sys::Process::getPageSizeEstimate())
+ return nullptr;
+
+ // Reserve addresses that are not registered in the driver, so that the SVM
+ // attributes govern the memory backing them.
+ void *Ptr = nullptr;
+ hsa_status_t Status = hsa_amd_vmem_address_reserve(
+ &Ptr, Size, /*address=*/0, HSA_AMD_VMEM_ADDRESS_NO_REGISTER);
----------------
ro-i wrote:
thanks, done
https://github.com/llvm/llvm-project/pull/215801
_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits