SWDEV-413997 - VMM IPC implementation for Linux.

Change-Id: Icfeb83ca51e96be35abb67a94d6e3e1a1ca5a934
This commit is contained in:
kjayapra-amd
2024-03-20 06:09:38 -04:00
parent 8179fa98a2
commit 56ebf5157a
5 changed files with 139 additions and 11 deletions
+23
View File
@@ -1859,6 +1859,29 @@ class Device : public RuntimeObject {
*/
virtual void virtualFree(void* addr) = 0;
/**
* Export Shareable VMM Handle to FD
*
* @param hsa_handle hsa_handle which has the phys_mem info.
* @param flags any flags to be passed
* @param shareableHandle exported handle, points to fdesc.
*/
virtual bool ExportShareableVMMHandle(uint64_t hsa_handle, int flags, void* shareableHandle) {
ShouldNotCallThis();
return false;
}
/**
* Import FD from Shareable VMM Handle
*
* @param osHandle os handle/fdesc
* @param hsa_handle_ptr hsa_handle which has the phys_mem info.
*/
virtual bool ImportShareableVMMHandle(void* osHandle, uint64_t* hsa_handle_ptr) const {
ShouldNotCallThis();
return false;
}
/**
* @return True if the device successfully applied the SVM attributes in HMM for device memory
*/
+45 -4
View File
@@ -2418,10 +2418,7 @@ void* Device::svmAlloc(amd::Context& context, size_t size, size_t alignment, cl_
}
// add the information to context so that we can use it later.
if (mem->getMemFlags() & ROCCLR_MEM_PHYMEM) {
mem->setSvmPtr(reinterpret_cast<void*>(mem->getUserData().hsa_handle));
amd::MemObjMap::AddMemObj(mem->getSvmPtr(), mem);
} else if (mem->getSvmPtr() != nullptr) {
if (mem->getSvmPtr() != nullptr) {
amd::MemObjMap::AddMemObj(mem->getSvmPtr(), mem);
}
svmPtr = mem->getSvmPtr();
@@ -2510,6 +2507,50 @@ bool Device::GetMemAccess(void* va_addr, VmmAccess* access_flags_ptr) {
return true;
}
// ================================================================================================
bool Device::ExportShareableVMMHandle(uint64_t hsa_handle, int flags, void* shareableHandle) {
hsa_status_t hsa_status = HSA_STATUS_SUCCESS;
hsa_amd_vmem_alloc_handle_t hsa_vmem_handle {};
if (hsa_handle == 0) {
LogError("HSA Handle is not valid");
return false;
}
int dmabuf_fd = 0;
hsa_vmem_handle.handle = hsa_handle;
if ((hsa_status = hsa_amd_vmem_export_shareable_handle(&dmabuf_fd,
hsa_vmem_handle, flags)) != HSA_STATUS_SUCCESS) {
LogPrintfError("Failed hsa_vmem_export_shareable_handle with status: %d \n", hsa_status);
return false;
}
*(reinterpret_cast<int*>(shareableHandle)) = dmabuf_fd;
return true;
}
// ================================================================================================
bool Device::ImportShareableVMMHandle(void* osHandle, uint64_t* hsa_handle_ptr) const {
hsa_status_t hsa_status = HSA_STATUS_SUCCESS;
hsa_amd_vmem_alloc_handle_t hsa_vmem_handle {};
if (hsa_handle_ptr == nullptr) {
LogError("HSA Handle ptr is null");
return false;
}
int dmabuf_fd = *(reinterpret_cast<int*>(osHandle));
if ((hsa_status = hsa_amd_vmem_import_shareable_handle(dmabuf_fd, &hsa_vmem_handle))
!= HSA_STATUS_SUCCESS) {
LogPrintfError("Failed hsa_amd_vmem_import_shareable_handle with status: %d \n", hsa_status);
return false;
}
*hsa_handle_ptr = hsa_vmem_handle.handle;
return true;
}
// ================================================================================================
bool Device::SetSvmAttributesInt(const void* dev_ptr, size_t count,
amd::MemoryAdvice advice, bool first_alloc, bool use_cpu) const {
+4
View File
@@ -473,6 +473,10 @@ class Device : public NullDevice {
virtual bool SetMemAccess(void* va_addr, size_t va_size, VmmAccess access_flags);
virtual bool GetMemAccess(void* va_addr, VmmAccess* access_flags_ptr);
virtual bool ExportShareableVMMHandle(uint64_t hsa_handle, int flags, void* shareableHandle);
virtual bool ImportShareableVMMHandle(void* osHandle, uint64_t* hsa_handle_ptr) const;
virtual bool SetClockMode(const cl_set_device_clock_mode_input_amd setClockModeInput,
cl_set_device_clock_mode_output_amd* pSetClockModeOutput);
+18 -2
View File
@@ -769,12 +769,28 @@ bool Buffer::create(bool alloc_local) {
cl_mem_flags memFlags = owner()->getMemFlags();
if (memFlags & ROCCLR_MEM_PHYMEM) {
// If this is physical memory request, then get an handle and store it in user data
owner()->getUserData().hsa_handle = dev().deviceVmemAlloc(owner()->getSize(), 0);
if (memFlags & ROCCLR_MEM_INTERPROCESS) {
int dmabuf_fd = *(reinterpret_cast<int*>(owner()->getSvmPtr()));
// if interprocess flag is set, then the memory is importable.
if (!dev().ImportShareableVMMHandle(owner()->getSvmPtr(),
&owner()->getUserData().hsa_handle)) {
LogPrintfError("Importing Shareable Memory failed with os_handle: 0x%x \n",
owner()->getSvmPtr());
return false;
}
} else {
// If this is physical memory request, then get an handle and store it in user data
owner()->getUserData().hsa_handle = dev().deviceVmemAlloc(owner()->getSize(), 0);
}
if (owner()->getUserData().hsa_handle == 0) {
LogError("HSA Opaque Handle returned was null");
return false;
}
owner()->setSvmPtr(reinterpret_cast<void*>(owner()->getUserData().hsa_handle));
amd::MemObjMap::AddMemObj(owner()->getSvmPtr(), owner());
return true;
}