Add check/query for virtual memory API support

Checks whether version of libdrm library installed on current
system supports the amdgpu_device_get_fd API. This API is
required to support the virtual memory API functions. The
amdgpu_device_get_fd function was introduced in libdrm-2.4.109.
Using a runtime check test instead of static dependency to be
able to support previous APIs on older versions of libdrm.
Add query for virtual memory API support.

This is part of patch series for Virtual Memory API.

Change-Id: Iec831eb24b5d1689c392e50ae86f4d52d4870ac4
Этот коммит содержится в:
David Yat Sin
2022-12-19 00:29:17 +00:00
родитель 3ebe1fdff9
Коммит e65edb35fc
3 изменённых файлов: 50 добавлений и 1 удалений
+7
Просмотреть файл
@@ -415,6 +415,8 @@ class Runtime {
KfdVersion_t KfdVersion() const { return kfd_version; }
bool VirtualMemApiSupported() const { return virtual_mem_api_supported_; }
protected:
static void AsyncEventsLoop(void*);
@@ -662,6 +664,11 @@ class Runtime {
std::unique_ptr<AMD::SvmProfileControl> svm_profile_;
private:
void CheckVirtualMemApiSupport();
bool virtual_mem_api_supported_;
// Frees runtime memory when the runtime library is unloaded if safe to do so.
// Failure to release the runtime indicates an incorrect application but is
// common (example: calls library routines at process exit).
+37
Просмотреть файл
@@ -48,6 +48,7 @@
#include <string>
#include <vector>
#include <list>
#include <dlfcn.h>
#include "core/common/shared.h"
#include "core/inc/hsa_ext_interface.h"
@@ -702,6 +703,10 @@ hsa_status_t Runtime::GetSystemInfo(hsa_system_info_t attribute, void* value) {
*(reinterpret_cast<bool*>(value)) = false;
break;
}
case HSA_AMD_SYSTEM_INFO_VIRTUAL_MEM_API_SUPPORTED: {
*((bool*)value) = core::Runtime::runtime_singleton_->VirtualMemApiSupported();
break;
}
default:
return HSA_STATUS_ERROR_INVALID_ARGUMENT;
}
@@ -1462,6 +1467,9 @@ hsa_status_t Runtime::Load() {
// Load tools libraries
LoadTools();
// Initialize libdrm helper function
CheckVirtualMemApiSupport();
// Load svm profiler
svm_profile_.reset(new AMD::SvmProfileControl);
@@ -1578,6 +1586,35 @@ static std::vector<std::string> parse_tool_names(std::string tool_names) {
return names;
}
static int (*fn_amdgpu_device_get_fd)(HsaAMDGPUDeviceHandle device_handle) = NULL;
int fn_amdgpu_device_get_fd_nosupport(HsaAMDGPUDeviceHandle device_handle) {
fprintf(stderr, "amdgpu_device_get_fd not available. Please update version of libdrm");
return -1;
}
void Runtime::CheckVirtualMemApiSupport() {
virtual_mem_api_supported_ = false;
// TODO: May have to change the minor version required once Thunk merges changes into amd-staging
auto kfd_version = core::Runtime::runtime_singleton_->KfdVersion().version;
if (kfd_version.KernelInterfaceMajorVersion > 1 ||
kfd_version.KernelInterfaceMajorVersion == 1 &&
kfd_version.KernelInterfaceMinorVersion >= 12) {
char* error;
fn_amdgpu_device_get_fd =
(int (*)(HsaAMDGPUDeviceHandle device_handle))dlsym(RTLD_DEFAULT, "amdgpu_device_get_fd");
if ((error = dlerror()) != NULL) {
debug_warning("amdgpu_device_get_fd not available. Please update version of libdrm");
fn_amdgpu_device_get_fd = &fn_amdgpu_device_get_fd_nosupport;
} else {
virtual_mem_api_supported_ = true;
}
}
}
void Runtime::LoadTools() {
typedef bool (*tool_init_t)(::HsaApiTable*, uint64_t, uint64_t,
const char* const*);
+6 -1
Просмотреть файл
@@ -504,7 +504,12 @@ typedef enum {
* Returns true if DMABUF APIs are supported by the driver. The type of
* this attribute is bool.
*/
HSA_AMD_SYSTEM_INFO_DMABUF_SUPPORTED = 0x204
HSA_AMD_SYSTEM_INFO_DMABUF_SUPPORTED = 0x204,
/**
* Returns true if Virtual Memory APIs are supported by the driver. The type of
* this attribute is bool.
*/
HSA_AMD_SYSTEM_INFO_VIRTUAL_MEM_API_SUPPORTED = 0x205,
} hsa_system_info_t;
/**