libhsakmt: Query KFD version once after opening /dev/kfd

Query the KFD interface version once and store it in a global variable.
This makes it more efficient for KFD APIs to query the API version
later.

Signed-off-by: Felix Kuehling <Felix.Kuehling@amd.com>
Change-Id: I267f3465f754e78fb21a7c42c5877cd68eaa9d05


[ROCm/ROCR-Runtime commit: 43ce63b68b]
Cette révision appartient à :
Felix Kuehling
2020-07-11 23:37:32 -04:00
Parent 3f3b280a4c
révision f267a5251c
3 fichiers modifiés avec 27 ajouts et 2 suppressions
+8
Voir le fichier
@@ -38,6 +38,8 @@ extern bool hsakmt_forked;
extern pthread_mutex_t hsakmt_mutex;
extern bool is_dgpu;
extern HsaVersionInfo kfd_version_info;
extern int force_asic;
extern char force_asic_name[HSA_PUBLIC_NAME_SIZE];
extern struct hsa_gfxip_table force_asic_entry;
@@ -54,6 +56,10 @@ extern struct hsa_gfxip_table force_asic_entry;
#define CHECK_KFD_OPEN() \
do { if (kfd_open_count == 0 || hsakmt_forked) return HSAKMT_STATUS_KERNEL_IO_CHANNEL_NOT_OPENED; } while (0)
#define CHECK_KFD_MINOR_VERSION(minor) \
do { if ((minor) > kfd_version_info.KernelInterfaceMinorVersion)\
return HSAKMT_STATUS_NOT_SUPPORTED; } while (0)
extern int PAGE_SIZE;
extern int PAGE_SHIFT;
@@ -145,6 +151,8 @@ struct hsa_gfxip_table {
enum asic_family_type asic_family; // Device family id
};
HSAKMT_STATUS init_kfd_version(void);
#define IS_SOC15(chip) ((chip) >= CHIP_VEGA10)
HSAKMT_STATUS validate_nodeid(uint32_t nodeid, uint32_t *gpu_id);
+5
Voir le fichier
@@ -196,6 +196,10 @@ HSAKMT_STATUS HSAKMTAPI hsaKmtOpenKFD(void)
init_page_size();
result = init_kfd_version();
if (result != HSAKMT_STATUS_SUCCESS)
goto kfd_version_failed;
result = topology_sysfs_get_system_props(&sys_props);
if (result != HSAKMT_STATUS_SUCCESS)
goto topology_sysfs_failed;
@@ -238,6 +242,7 @@ init_doorbell_failed:
fmm_destroy_process_apertures();
init_process_aperture_failed:
topology_sysfs_failed:
kfd_version_failed:
close(fd);
open_failed:
pthread_mutex_unlock(&hsakmt_mutex);
+14 -2
Voir le fichier
@@ -28,17 +28,29 @@
#include <string.h>
#include "linux/kfd_ioctl.h"
HsaVersionInfo kfd_version_info;
HSAKMT_STATUS HSAKMTAPI hsaKmtGetVersion(HsaVersionInfo *VersionInfo)
{
CHECK_KFD_OPEN();
*VersionInfo = kfd_version_info;
return HSAKMT_STATUS_SUCCESS;
}
HSAKMT_STATUS init_kfd_version(void)
{
struct kfd_ioctl_get_version_args args = {0};
if (kmtIoctl(kfd_fd, AMDKFD_IOC_GET_VERSION, &args) == -1)
return HSAKMT_STATUS_ERROR;
VersionInfo->KernelInterfaceMajorVersion = args.major_version;
VersionInfo->KernelInterfaceMinorVersion = args.minor_version;
kfd_version_info.KernelInterfaceMajorVersion = args.major_version;
kfd_version_info.KernelInterfaceMinorVersion = args.minor_version;
if (args.major_version != 1)
return HSAKMT_STATUS_DRIVER_MISMATCH;
return HSAKMT_STATUS_SUCCESS;
}