[SWDEV-529030/SWDEV-531217] Fix tests & output for partitioned configurations (CPX, DPX, QPX, etc.)
Changes:
- Updated AMD SMI firmware to display "N/A" for unavailable firmware in partitioned environments, improving clarity.
Example (in DPX):
$ amd-smi firmware
GPU: 0
FW_LIST:
...
FW 12:
FW_ID: PM
FW_VERSION: 00.86.39.00
GPU: 1
FW_LIST: N/A
- Fixed amd-smi partition not showing current partition information on
asics with inablity to set memory or accelerator partitions.
$ amd-smi partition -c -m
CURRENT_PARTITION:
GPU_ID MEMORY ACCELERATOR_TYPE ACCELERATOR_PROFILE_INDEX PARTITION_ID
0 NPS1 CPX 2 0
1 N/A N/A N/A 1
2 N/A N/A N/A 2
3 N/A N/A N/A 3
4 N/A N/A N/A 4
5 N/A N/A N/A 5
6 NPS1 SPX 0 0
7 NPS1 SPX 0 0
8 NPS1 SPX 0 0
MEMORY_PARTITION:
GPU_ID MEMORY_PARTITION_CAPS CURRENT_MEMORY_PARTITION
0 N/A NPS1
1 N/A N/A
2 N/A N/A
3 N/A N/A
4 N/A N/A
5 N/A N/A
6 N/A NPS1
7 N/A NPS1
8 N/A NPS1
- Refactored amd_smi_drm_example.cc:
- Grouped partition changes and restores original partition settings.
- Now handles partitioned environments allowing example to continue even if some APIs are not supported in partitioned configurations.
- Modified amdsmi_asic_info_t (see amdsmi_get_gpu_asic_info()) to report OAM ID as N/A if 0xFFFFFFFF (was 0xFFFF).
Allows for better handling of OAM IDs in partitioned environments (DNE for non-primary nodes,
since its a physical identifier). Easier to handle in tests and example code (ie. now consistent w/ max size of the structure's value).
- Introduced amdsmi_RAII_open_FD() (internal API) to manage file descriptors using RAII, ensuring proper closure and preventing resource leaks.
Updated the following APIs to use this function:
- amdsmi_get_gpu_asic_info(), amdsmi_get_gpu_vram_usage(),
amdsmi_get_gpu_vram_info(), amdsmi_get_gpu_vbios_info(),
amdsmi_get_gpu_driver_info(), amdsmi_get_gpu_virtualization_mode()
- Updated AMD SMI test_base.cc/.h:
- Improved output and handling for partitioned environments.
- Added detailed ASIC information logging to align with structure changes.
- Enhanced error messages for better context before ASSERT checks.
- Resolved test failures in partitioned environments by updating
logic and handling for partition-specific configurations.
Fixed tests include:
- computepartition_read_write.cc, frequencies_read_write.cc,
gpu_metrics_read.cc, mem_util_read.cc, memorypartition_read_write.cc,
perf_level_read.cc, perf_level_read_write.cc, power_cap_read_write.cc,
power_read.cc, sys_info_read.cc, gpu_busy_read.cc
Change-Id: I36e903f8fddd714c74c719459c71aba8bbb77e6f
Signed-off-by: Charis Poag <Charis.Poag@amd.com>
Resetting head + adding fixes for tests ran in partitions
Change-Id: I0c1e9ac07488b50c95f3bc6d8a724e67d2c715dc
Signed-off-by: Charis Poag <Charis.Poag@amd.com>
Este commit está contenido en:
+195
-163
@@ -898,24 +898,28 @@ amdsmi_status_t amdsmi_get_gpu_vram_usage(amdsmi_processor_handle processor_hand
|
||||
|
||||
SMIGPUDEVICE_MUTEX(gpu_device->get_mutex());
|
||||
std::string render_name = gpu_device->get_gpu_path();
|
||||
int drm_fd = -1;
|
||||
std::string path = "/dev/dri/" + render_name;
|
||||
if (render_name != "") {
|
||||
drm_fd = open(path.c_str(), O_RDWR | O_CLOEXEC);
|
||||
} else {
|
||||
close(drm_fd);
|
||||
if (render_name.empty()) {
|
||||
return AMDSMI_STATUS_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
std::string path = "/dev/dri/" + render_name;
|
||||
auto drm_fd = amdsmi_RAII_FD_handler(path.c_str(), O_RDWR | O_CLOEXEC);
|
||||
ss << __PRETTY_FUNCTION__
|
||||
<< " | open(" << path << ") returned: " << strerror(errno) << "\n"
|
||||
<< " | drm_fd: " << std::dec << drm_fd << "\n"
|
||||
<< " | drm_fd: " << (drm_fd == nullptr ? "nullptr" : std::to_string(*drm_fd)) << "\n"
|
||||
<< " | render_name: " << render_name << "\n";
|
||||
LOG_INFO(ss);
|
||||
if (!drm_fd) {
|
||||
ss << __PRETTY_FUNCTION__
|
||||
<< " | Failed to open " << path << ": " << strerror(errno)
|
||||
<< "; Returning: " << smi_amdgpu_get_status_string(AMDSMI_STATUS_FILE_ERROR, false);
|
||||
LOG_ERROR(ss);
|
||||
return AMDSMI_STATUS_FILE_ERROR;
|
||||
}
|
||||
|
||||
amd::smi::AMDSmiLibraryLoader libdrm;
|
||||
amdsmi_status_t status = libdrm.load("libdrm.so.2");
|
||||
if (status != AMDSMI_STATUS_SUCCESS) {
|
||||
close(drm_fd);
|
||||
libdrm.unload();
|
||||
ss << __PRETTY_FUNCTION__
|
||||
<< " | Failed to load libdrm.so.2: " << strerror(errno)
|
||||
@@ -938,7 +942,6 @@ amdsmi_status_t amdsmi_get_gpu_vram_usage(amdsmi_processor_handle processor_hand
|
||||
status = libdrm.load_symbol(reinterpret_cast<drmCommandWrite_t *>(&drmCommandWrite),
|
||||
"drmCommandWrite");
|
||||
if (status != AMDSMI_STATUS_SUCCESS) {
|
||||
close(drm_fd);
|
||||
libdrm.unload();
|
||||
ss << __PRETTY_FUNCTION__
|
||||
<< " | Failed to load drmCommandWrite symbol"
|
||||
@@ -950,7 +953,6 @@ amdsmi_status_t amdsmi_get_gpu_vram_usage(amdsmi_processor_handle processor_hand
|
||||
<< " | drmCommandWrite symbol loaded successfully";
|
||||
LOG_INFO(ss);
|
||||
|
||||
|
||||
uint64_t total = 0;
|
||||
r = rsmi_wrapper(rsmi_dev_memory_total_get, processor_handle, 0,
|
||||
RSMI_MEM_TYPE_VRAM, &total);
|
||||
@@ -964,10 +966,9 @@ amdsmi_status_t amdsmi_get_gpu_vram_usage(amdsmi_processor_handle processor_hand
|
||||
request.return_pointer = reinterpret_cast<unsigned long long>(&vram_used);
|
||||
request.return_size = sizeof(vram_used);
|
||||
request.query = AMDGPU_INFO_VRAM_USAGE;
|
||||
auto drm_write = drmCommandWrite(drm_fd, DRM_AMDGPU_INFO, &request,
|
||||
sizeof(struct drm_amdgpu_info));
|
||||
auto drm_write = drmCommandWrite(*drm_fd, DRM_AMDGPU_INFO, &request,
|
||||
sizeof(struct drm_amdgpu_info));
|
||||
if (drm_write != 0) {
|
||||
close(drm_fd);
|
||||
libdrm.unload();
|
||||
ss << __PRETTY_FUNCTION__
|
||||
<< " | Issue - drm_write failed, drm_write (AMDGPU_INFO_VRAM_USAGE): "
|
||||
@@ -978,7 +979,6 @@ amdsmi_status_t amdsmi_get_gpu_vram_usage(amdsmi_processor_handle processor_hand
|
||||
}
|
||||
|
||||
vram_info->vram_used = static_cast<uint32_t>(vram_used / (1024 * 1024));
|
||||
close(drm_fd);
|
||||
libdrm.unload();
|
||||
ss << __PRETTY_FUNCTION__
|
||||
<< " | vram_info->vram_total (MB): " << std::dec << vram_info->vram_total << "\n"
|
||||
@@ -1531,6 +1531,19 @@ amdsmi_get_gpu_asic_info(amdsmi_processor_handle processor_handle, amdsmi_asic_i
|
||||
uint16_t subvendor_id = 0;
|
||||
uint16_t device_id = 0;
|
||||
uint16_t subsystem_id = 0;
|
||||
char temp_market_name[AMDSMI_MAX_STRING_LENGTH] = {0};
|
||||
smi_clear_char_and_reinitialize(info->market_name, AMDSMI_MAX_STRING_LENGTH, temp_market_name);
|
||||
info->market_name[0] = '\0';
|
||||
info->vendor_id = std::numeric_limits<uint32_t>::max();
|
||||
info->vendor_name[0] = '\0';
|
||||
info->subvendor_id = std::numeric_limits<uint32_t>::max();
|
||||
info->device_id = std::numeric_limits<uint64_t>::max();
|
||||
info->rev_id = std::numeric_limits<uint16_t>::max();
|
||||
info->asic_serial[0] = '\0';
|
||||
info->oam_id = std::numeric_limits<uint32_t>::max();
|
||||
info->num_of_compute_units = std::numeric_limits<uint32_t>::max();
|
||||
info->target_graphics_version = std::numeric_limits<uint64_t>::max();
|
||||
info->subsystem_id = std::numeric_limits<uint32_t>::max();
|
||||
|
||||
std::ostringstream ss;
|
||||
amd::smi::AMDSmiGPUDevice* gpu_device = nullptr;
|
||||
@@ -1539,80 +1552,6 @@ amdsmi_get_gpu_asic_info(amdsmi_processor_handle processor_handle, amdsmi_asic_i
|
||||
return r;
|
||||
}
|
||||
SMIGPUDEVICE_MUTEX(gpu_device->get_mutex())
|
||||
amdsmi_status_t status = smi_amdgpu_get_market_name_from_dev_id(gpu_device, info->market_name);
|
||||
if (status != AMDSMI_STATUS_SUCCESS) {
|
||||
rsmi_wrapper(rsmi_dev_brand_get, processor_handle, 0,
|
||||
info->market_name, AMDSMI_MAX_STRING_LENGTH);
|
||||
}
|
||||
|
||||
std::string render_name = gpu_device->get_gpu_path();
|
||||
int drm_fd = -1;
|
||||
std::string path = "/dev/dri/" + render_name;
|
||||
if (render_name != "") {
|
||||
drm_fd = open(path.c_str(), O_RDWR | O_CLOEXEC);
|
||||
} else {
|
||||
close(drm_fd);
|
||||
return AMDSMI_STATUS_NOT_SUPPORTED;
|
||||
}
|
||||
ss << __PRETTY_FUNCTION__
|
||||
<< " | open(" << path << ") returned: " << strerror(errno) << "\n"
|
||||
<< " | drm_fd: " << std::dec << drm_fd << "\n"
|
||||
<< " | render_name: " << render_name << "\n";
|
||||
LOG_INFO(ss);
|
||||
|
||||
amd::smi::AMDSmiLibraryLoader libdrm;
|
||||
status = libdrm.load("libdrm.so.2");
|
||||
if (status != AMDSMI_STATUS_SUCCESS) {
|
||||
close(drm_fd);
|
||||
libdrm.unload();
|
||||
ss << __PRETTY_FUNCTION__
|
||||
<< " | Failed to load libdrm.so.2: " << strerror(errno)
|
||||
<< "; Returning: " << smi_amdgpu_get_status_string(status, false);
|
||||
LOG_ERROR(ss);
|
||||
return status;
|
||||
}
|
||||
|
||||
// extern int drmCommandWrite(int fd, unsigned long drmCommandIndex,
|
||||
// void *data, unsigned long size);
|
||||
typedef int (*drmCommandWrite_t)(int fd, unsigned long drmCommandIndex,
|
||||
void *data, unsigned long size);
|
||||
drmCommandWrite_t drmCommandWrite = nullptr;
|
||||
|
||||
// load symbol from libdrm
|
||||
status = libdrm.load_symbol(reinterpret_cast<drmCommandWrite_t *>(&drmCommandWrite),
|
||||
"drmCommandWrite");
|
||||
if (status != AMDSMI_STATUS_SUCCESS) {
|
||||
close(drm_fd);
|
||||
libdrm.unload();
|
||||
ss << __PRETTY_FUNCTION__
|
||||
<< " | Failed to load drmCommandWrite symbol"
|
||||
<< " | Returning: " << smi_amdgpu_get_status_string(status, false);
|
||||
LOG_ERROR(ss);
|
||||
return status;
|
||||
}
|
||||
|
||||
// Get the device info
|
||||
memset(&dev_info, 0, sizeof(struct drm_amdgpu_info_device));
|
||||
struct drm_amdgpu_info request = {};
|
||||
memset(&request, 0, sizeof(request));
|
||||
request.return_pointer = reinterpret_cast<unsigned long long>(&dev_info);
|
||||
request.return_size = sizeof(struct drm_amdgpu_info_device);
|
||||
request.query = AMDGPU_INFO_DEV_INFO;
|
||||
auto drm_write = drmCommandWrite(drm_fd, DRM_AMDGPU_INFO, &request,
|
||||
sizeof(struct drm_amdgpu_info));
|
||||
if (drm_write != 0) {
|
||||
libdrm.unload();
|
||||
close(drm_fd);
|
||||
ss << __PRETTY_FUNCTION__
|
||||
<< " | Issue - drm_write failed, drm_write: " << std::dec << drm_write << "\n"
|
||||
<< "; Returning: " << smi_amdgpu_get_status_string(AMDSMI_STATUS_DRM_ERROR, false);
|
||||
LOG_ERROR(ss);
|
||||
return AMDSMI_STATUS_DRM_ERROR;
|
||||
}
|
||||
// TODO(cpoag): check if this is correct, might be able to go through KGD/KFD
|
||||
info->rev_id = static_cast<uint32_t>(dev_info.pci_rev);
|
||||
libdrm.unload();
|
||||
close(drm_fd);
|
||||
|
||||
/**
|
||||
* For other sysfs related information, get from rocm-smi
|
||||
@@ -1622,7 +1561,8 @@ amdsmi_get_gpu_asic_info(amdsmi_processor_handle processor_handle, amdsmi_asic_i
|
||||
std::string max_uint64_str = "ffffffffffffffff";
|
||||
smi_clear_char_and_reinitialize(info->asic_serial, AMDSMI_MAX_STRING_LENGTH, max_uint64_str);
|
||||
uint64_t device_uuid = 0;
|
||||
status = rsmi_wrapper(rsmi_dev_unique_id_get, processor_handle, 0, &device_uuid);
|
||||
amdsmi_status_t status = rsmi_wrapper(rsmi_dev_unique_id_get, processor_handle, 0,
|
||||
&device_uuid);
|
||||
if (status == AMDSMI_STATUS_SUCCESS) {
|
||||
ss.clear();
|
||||
ss << std::hex << std::setw(16) << std::setfill('0') << device_uuid;
|
||||
@@ -1647,31 +1587,32 @@ amdsmi_get_gpu_asic_info(amdsmi_processor_handle processor_handle, amdsmi_asic_i
|
||||
&subsystem_id);
|
||||
if (status == AMDSMI_STATUS_SUCCESS) info->subsystem_id = subsystem_id;
|
||||
|
||||
char temp_vendor_name[AMDSMI_MAX_STRING_LENGTH] = {0};
|
||||
status = rsmi_wrapper(rsmi_dev_pcie_vendor_name_get, processor_handle, 0,
|
||||
info->vendor_name, AMDSMI_MAX_STRING_LENGTH);
|
||||
temp_vendor_name, AMDSMI_MAX_STRING_LENGTH);
|
||||
if (status == AMDSMI_STATUS_SUCCESS) {
|
||||
smi_clear_char_and_reinitialize(info->vendor_name, AMDSMI_MAX_STRING_LENGTH,
|
||||
temp_vendor_name);
|
||||
}
|
||||
|
||||
// default to 0xffff as not supported
|
||||
info->oam_id = std::numeric_limits<uint16_t>::max();
|
||||
uint16_t tmp_oam_id = 0;
|
||||
status = rsmi_wrapper(rsmi_dev_xgmi_physical_id_get, processor_handle, 0,
|
||||
&(tmp_oam_id));
|
||||
info->oam_id = tmp_oam_id;
|
||||
if (status == AMDSMI_STATUS_SUCCESS) {
|
||||
info->oam_id = tmp_oam_id;
|
||||
}
|
||||
|
||||
// default to 0xffffffff as not supported
|
||||
info->num_of_compute_units = std::numeric_limits<uint32_t>::max();
|
||||
auto tmp_num_of_compute_units = uint32_t(0);
|
||||
status = rsmi_wrapper(amd::smi::rsmi_dev_number_of_computes_get, processor_handle, 0,
|
||||
&(tmp_num_of_compute_units));
|
||||
if (status == amdsmi_status_t::AMDSMI_STATUS_SUCCESS) {
|
||||
if (status == AMDSMI_STATUS_SUCCESS) {
|
||||
info->num_of_compute_units = tmp_num_of_compute_units;
|
||||
}
|
||||
|
||||
// default to 0xffffffffffffffff as not supported
|
||||
info->target_graphics_version = std::numeric_limits<uint64_t>::max();
|
||||
auto tmp_target_gfx_version = uint64_t(0);
|
||||
status = rsmi_wrapper(rsmi_dev_target_graphics_version_get, processor_handle, 0,
|
||||
&(tmp_target_gfx_version));
|
||||
if (status == amdsmi_status_t::AMDSMI_STATUS_SUCCESS) {
|
||||
if (status == AMDSMI_STATUS_SUCCESS) {
|
||||
info->target_graphics_version = tmp_target_gfx_version;
|
||||
}
|
||||
|
||||
@@ -1685,16 +1626,12 @@ amdsmi_get_gpu_asic_info(amdsmi_processor_handle processor_handle, amdsmi_asic_i
|
||||
LOG_INFO(ss);
|
||||
if (status == AMDSMI_STATUS_SUCCESS) {
|
||||
info->device_id = static_cast<uint64_t>(device_id);
|
||||
} else {
|
||||
info->device_id = std::numeric_limits<uint64_t>::max();
|
||||
}
|
||||
info->rev_id = dev_info.pci_rev;
|
||||
status = rsmi_wrapper(rsmi_dev_vendor_id_get, processor_handle, 0,
|
||||
&vendor_id);
|
||||
if (status == AMDSMI_STATUS_SUCCESS) {
|
||||
info->vendor_id = vendor_id;
|
||||
} else {
|
||||
info->vendor_id = std::numeric_limits<uint32_t>::max();
|
||||
}
|
||||
|
||||
// If vendor name is empty and the vendor id is 0x1002, set vendor name to AMD vendor string
|
||||
@@ -1703,6 +1640,95 @@ amdsmi_get_gpu_asic_info(amdsmi_processor_handle processor_handle, amdsmi_asic_i
|
||||
smi_clear_char_and_reinitialize(info->vendor_name, AMDSMI_MAX_STRING_LENGTH, amd_name);
|
||||
}
|
||||
|
||||
status = smi_amdgpu_get_market_name_from_dev_id(gpu_device, info->market_name);
|
||||
if (status != AMDSMI_STATUS_SUCCESS) {
|
||||
status = rsmi_wrapper(rsmi_dev_brand_get, processor_handle, 0,
|
||||
temp_market_name, AMDSMI_MAX_STRING_LENGTH);
|
||||
if (status == AMDSMI_STATUS_SUCCESS) {
|
||||
ss << __PRETTY_FUNCTION__
|
||||
<< " | rsmi_dev_brand_get() returned: "
|
||||
<< smi_amdgpu_get_status_string(status, false) << "\n"
|
||||
<< " ; temp_market_name: " << temp_market_name << "\n";
|
||||
LOG_INFO(ss);
|
||||
smi_clear_char_and_reinitialize(info->market_name, AMDSMI_MAX_STRING_LENGTH,
|
||||
temp_market_name);
|
||||
} else {
|
||||
ss << __PRETTY_FUNCTION__
|
||||
<< " | rsmi_dev_brand_get() failed: "
|
||||
<< smi_amdgpu_get_status_string(status, false) << "\n";
|
||||
LOG_INFO(ss);
|
||||
}
|
||||
}
|
||||
|
||||
std::string render_name = gpu_device->get_gpu_path();
|
||||
if (render_name.empty()) {
|
||||
return AMDSMI_STATUS_NOT_SUPPORTED;
|
||||
}
|
||||
std::string path = "/dev/dri/" + render_name;
|
||||
auto drm_fd = amdsmi_RAII_FD_handler(path.c_str(), O_RDWR | O_CLOEXEC);
|
||||
ss << __PRETTY_FUNCTION__
|
||||
<< " | open(" << path << ") returned: " << strerror(errno) << "\n"
|
||||
<< " | drm_fd: " << (drm_fd == nullptr ? "nullptr" : std::to_string(*drm_fd)) << "\n"
|
||||
<< " | render_name: " << render_name << "\n";
|
||||
LOG_INFO(ss);
|
||||
if (!drm_fd) {
|
||||
ss << __PRETTY_FUNCTION__
|
||||
<< " | Failed to open " << path << ": " << strerror(errno)
|
||||
<< "; Returning: " << smi_amdgpu_get_status_string(AMDSMI_STATUS_FILE_ERROR, false);
|
||||
LOG_ERROR(ss);
|
||||
return AMDSMI_STATUS_FILE_ERROR;
|
||||
}
|
||||
|
||||
amd::smi::AMDSmiLibraryLoader libdrm;
|
||||
status = libdrm.load("libdrm.so.2");
|
||||
if (status != AMDSMI_STATUS_SUCCESS) {
|
||||
libdrm.unload();
|
||||
ss << __PRETTY_FUNCTION__
|
||||
<< " | Failed to load libdrm.so.2: " << strerror(errno)
|
||||
<< "; Returning: " << smi_amdgpu_get_status_string(status, false);
|
||||
LOG_ERROR(ss);
|
||||
return status;
|
||||
}
|
||||
|
||||
// extern int drmCommandWrite(int fd, unsigned long drmCommandIndex,
|
||||
// void *data, unsigned long size);
|
||||
typedef int (*drmCommandWrite_t)(int fd, unsigned long drmCommandIndex,
|
||||
void *data, unsigned long size);
|
||||
drmCommandWrite_t drmCommandWrite = nullptr;
|
||||
|
||||
// load symbol from libdrm
|
||||
status = libdrm.load_symbol(reinterpret_cast<drmCommandWrite_t *>(&drmCommandWrite),
|
||||
"drmCommandWrite");
|
||||
if (status != AMDSMI_STATUS_SUCCESS) {
|
||||
libdrm.unload();
|
||||
ss << __PRETTY_FUNCTION__
|
||||
<< " | Failed to load drmCommandWrite symbol"
|
||||
<< " | Returning: " << smi_amdgpu_get_status_string(status, false);
|
||||
LOG_ERROR(ss);
|
||||
return status;
|
||||
}
|
||||
|
||||
// Get the device info
|
||||
memset(&dev_info, 0, sizeof(struct drm_amdgpu_info_device));
|
||||
struct drm_amdgpu_info request = {};
|
||||
memset(&request, 0, sizeof(request));
|
||||
request.return_pointer = reinterpret_cast<unsigned long long>(&dev_info);
|
||||
request.return_size = sizeof(struct drm_amdgpu_info_device);
|
||||
request.query = AMDGPU_INFO_DEV_INFO;
|
||||
auto drm_write = drmCommandWrite(*drm_fd, DRM_AMDGPU_INFO, &request,
|
||||
sizeof(struct drm_amdgpu_info));
|
||||
if (drm_write != 0) {
|
||||
libdrm.unload();
|
||||
ss << __PRETTY_FUNCTION__
|
||||
<< " | Issue - drm_write failed, drm_write: " << std::dec << drm_write << "\n"
|
||||
<< "; Returning: " << smi_amdgpu_get_status_string(AMDSMI_STATUS_DRM_ERROR, false);
|
||||
LOG_ERROR(ss);
|
||||
return AMDSMI_STATUS_DRM_ERROR;
|
||||
}
|
||||
// TODO(cpoag): check if this is correct, might be able to go through KGD/KFD
|
||||
info->rev_id = static_cast<uint32_t>(dev_info.pci_rev);
|
||||
libdrm.unload();
|
||||
|
||||
ss << __PRETTY_FUNCTION__
|
||||
<< " | info->market_name: " << info->market_name << "\n"
|
||||
<< " | info->vendor_id (dec): " << std::dec << info->vendor_id << "\n"
|
||||
@@ -1862,24 +1888,28 @@ amdsmi_status_t amdsmi_get_gpu_vram_info(
|
||||
|
||||
SMIGPUDEVICE_MUTEX(gpu_device->get_mutex());
|
||||
std::string render_name = gpu_device->get_gpu_path();
|
||||
int drm_fd = -1;
|
||||
std::string path = "/dev/dri/" + render_name;
|
||||
if (render_name != "") {
|
||||
drm_fd = open(path.c_str(), O_RDWR | O_CLOEXEC);
|
||||
} else {
|
||||
close(drm_fd);
|
||||
if (render_name.empty()) {
|
||||
return AMDSMI_STATUS_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
auto drm_fd = amdsmi_RAII_FD_handler(path.c_str(), O_RDWR | O_CLOEXEC);
|
||||
ss << __PRETTY_FUNCTION__
|
||||
<< " | open(" << path << ") returned: " << strerror(errno) << "\n"
|
||||
<< " | drm_fd: " << std::dec << drm_fd << "\n"
|
||||
<< " | drm_fd: " << (drm_fd == nullptr ? "nullptr" : std::to_string(*drm_fd)) << "\n"
|
||||
<< " | render_name: " << render_name << "\n";
|
||||
LOG_INFO(ss);
|
||||
if (!drm_fd) {
|
||||
ss << __PRETTY_FUNCTION__
|
||||
<< " | Failed to open " << path << ": " << strerror(errno)
|
||||
<< "; Returning: " << smi_amdgpu_get_status_string(AMDSMI_STATUS_FILE_ERROR, false);
|
||||
LOG_ERROR(ss);
|
||||
return AMDSMI_STATUS_FILE_ERROR;
|
||||
}
|
||||
|
||||
amd::smi::AMDSmiLibraryLoader libdrm;
|
||||
amdsmi_status_t status = libdrm.load("libdrm.so.2");
|
||||
if (status != AMDSMI_STATUS_SUCCESS) {
|
||||
close(drm_fd);
|
||||
libdrm.unload();
|
||||
ss << __PRETTY_FUNCTION__
|
||||
<< " | Failed to load libdrm.so.2: " << strerror(errno)
|
||||
@@ -1902,7 +1932,6 @@ amdsmi_status_t amdsmi_get_gpu_vram_info(
|
||||
status = libdrm.load_symbol(reinterpret_cast<drmCommandWrite_t *>(&drmCommandWrite),
|
||||
"drmCommandWrite");
|
||||
if (status != AMDSMI_STATUS_SUCCESS) {
|
||||
close(drm_fd);
|
||||
libdrm.unload();
|
||||
ss << __PRETTY_FUNCTION__
|
||||
<< " | Failed to load drmCommandWrite symbol"
|
||||
@@ -1921,10 +1950,9 @@ amdsmi_status_t amdsmi_get_gpu_vram_info(
|
||||
request.return_pointer = reinterpret_cast<unsigned long long>(&dev_info);
|
||||
request.return_size = sizeof(struct drm_amdgpu_info_device);
|
||||
request.query = AMDGPU_INFO_DEV_INFO;
|
||||
auto drm_write = drmCommandWrite(drm_fd, DRM_AMDGPU_INFO, &request,
|
||||
auto drm_write = drmCommandWrite(*drm_fd, DRM_AMDGPU_INFO, &request,
|
||||
sizeof(struct drm_amdgpu_info));
|
||||
if (drm_write != 0) {
|
||||
close(drm_fd);
|
||||
libdrm.unload();
|
||||
ss << __PRETTY_FUNCTION__
|
||||
<< " | Issue - drm_write failed, drm_write: " << std::dec << drm_write << "\n"
|
||||
@@ -1935,8 +1963,9 @@ amdsmi_status_t amdsmi_get_gpu_vram_info(
|
||||
|
||||
info->vram_type = amd::smi::vram_type_value(dev_info.vram_type);
|
||||
info->vram_bit_width = dev_info.vram_bit_width;
|
||||
close(drm_fd);
|
||||
libdrm.unload();
|
||||
// if vram type is greater than the max enum set it to unknown
|
||||
if (info->vram_type > AMDSMI_VRAM_TYPE__MAX) info->vram_type = AMDSMI_VRAM_TYPE_UNKNOWN;
|
||||
|
||||
// set info->vram_max_bandwidth to gpu_metrics vram_max_bandwidth if it is not set
|
||||
amdsmi_gpu_metrics_t metric_info = {};
|
||||
@@ -1945,10 +1974,6 @@ amdsmi_status_t amdsmi_get_gpu_vram_info(
|
||||
info->vram_max_bandwidth = metric_info.vram_max_bandwidth;
|
||||
}
|
||||
|
||||
// if vram type is greater than the max enum set it to unknown
|
||||
if (info->vram_type > AMDSMI_VRAM_TYPE__MAX)
|
||||
info->vram_type = AMDSMI_VRAM_TYPE_UNKNOWN;
|
||||
|
||||
// map the vendor name to enum
|
||||
char brand[256] = {'\0'};
|
||||
r = rsmi_wrapper(rsmi_dev_vram_vendor_get, processor_handle, 0, brand, 255);
|
||||
@@ -2949,8 +2974,8 @@ amdsmi_get_gpu_accelerator_partition_profile(amdsmi_processor_handle processor_h
|
||||
constexpr uint32_t kCurrentPartitionSize = 5;
|
||||
char current_partition[kCurrentPartitionSize];
|
||||
std::string current_partition_str = "N/A";
|
||||
status = amdsmi_get_gpu_compute_partition(processor_handle, current_partition,
|
||||
kCurrentPartitionSize);
|
||||
amdsmi_status_t compute_status = amdsmi_get_gpu_compute_partition(processor_handle,
|
||||
current_partition, kCurrentPartitionSize);
|
||||
ss << __PRETTY_FUNCTION__ << " | amdsmi_get_gpu_compute_partition() current_partition = |"
|
||||
<< current_partition << "|";
|
||||
LOG_DEBUG(ss);
|
||||
@@ -2965,7 +2990,8 @@ amdsmi_get_gpu_accelerator_partition_profile(amdsmi_processor_handle processor_h
|
||||
if (accelerator_capabilities.find(current_partition_str) != std::string::npos) {
|
||||
auto it = std::find(tokens.begin(), tokens.end(), current_partition_str);
|
||||
if (it != tokens.end()) {
|
||||
profile->profile_index = static_cast<uint32_t>(std::distance(tokens.begin(), it));
|
||||
profile->profile_index = static_cast<uint32_t>(std::distance(
|
||||
tokens.begin(), it));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3056,7 +3082,7 @@ amdsmi_get_gpu_accelerator_partition_profile(amdsmi_processor_handle processor_h
|
||||
profile->memory_caps = flags;
|
||||
|
||||
ss << __PRETTY_FUNCTION__
|
||||
<< " | END returning " << smi_amdgpu_get_status_string(status, false) << "\n"
|
||||
<< " | END returning " << smi_amdgpu_get_status_string(compute_status, false) << "\n"
|
||||
<< " | accelerator_capabilities: " << accelerator_capabilities << "\n"
|
||||
<< " | current_partition_str: " << current_partition_str << "\n"
|
||||
<< " | std::vector<std::string> tokens: " << ss_1.str() << "\n"
|
||||
@@ -3072,7 +3098,9 @@ amdsmi_get_gpu_accelerator_partition_profile(amdsmi_processor_handle processor_h
|
||||
<< " | partition_id: " << ss_2.str();
|
||||
LOG_INFO(ss);
|
||||
|
||||
return status;
|
||||
return compute_status; // only return status from amdsmi_get_gpu_compute_partition
|
||||
// as this is the only function that can fail
|
||||
// if the device does not support partitions
|
||||
}
|
||||
|
||||
amdsmi_status_t
|
||||
@@ -3373,7 +3401,9 @@ amdsmi_status_t
|
||||
amdsmi_status_t amdsmi_get_gpu_perf_level(amdsmi_processor_handle processor_handle,
|
||||
amdsmi_dev_perf_level_t *perf) {
|
||||
AMDSMI_CHECK_INIT();
|
||||
// nullptr api supported
|
||||
if (!perf) {
|
||||
return AMDSMI_STATUS_INVAL;
|
||||
}
|
||||
|
||||
return rsmi_wrapper(rsmi_dev_perf_level_get, processor_handle, 0,
|
||||
reinterpret_cast<rsmi_dev_perf_level_t*>(perf));
|
||||
@@ -3681,6 +3711,9 @@ amdsmi_status_t amdsmi_get_gpu_bdf_id(
|
||||
|
||||
amdsmi_status_t amdsmi_get_gpu_topo_numa_affinity(
|
||||
amdsmi_processor_handle processor_handle, int32_t *numa_node) {
|
||||
if (!numa_node) {
|
||||
return AMDSMI_STATUS_INVAL;
|
||||
}
|
||||
return rsmi_wrapper(rsmi_topo_numa_affinity_get, processor_handle, 0,
|
||||
numa_node);
|
||||
}
|
||||
@@ -3716,24 +3749,28 @@ amdsmi_get_gpu_vbios_info(amdsmi_processor_handle processor_handle, amdsmi_vbios
|
||||
|
||||
SMIGPUDEVICE_MUTEX(gpu_device->get_mutex());
|
||||
std::string render_name = gpu_device->get_gpu_path();
|
||||
int drm_fd = -1;
|
||||
std::string path = "/dev/dri/" + render_name;
|
||||
if (render_name != "") {
|
||||
drm_fd = open(path.c_str(), O_RDWR | O_CLOEXEC);
|
||||
} else {
|
||||
close(drm_fd);
|
||||
if (render_name.empty()) {
|
||||
return AMDSMI_STATUS_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
auto drm_fd = amdsmi_RAII_FD_handler(path.c_str(), O_RDWR | O_CLOEXEC);
|
||||
ss << __PRETTY_FUNCTION__
|
||||
<< " | open(" << path << ") returned: " << strerror(errno) << "\n"
|
||||
<< " | drm_fd: " << std::dec << drm_fd << "\n"
|
||||
<< " | drm_fd: " << (drm_fd == nullptr ? "nullptr" : std::to_string(*drm_fd)) << "\n"
|
||||
<< " | render_name: " << render_name << "\n";
|
||||
LOG_INFO(ss);
|
||||
if (!drm_fd) {
|
||||
ss << __PRETTY_FUNCTION__
|
||||
<< " | Failed to open " << path << ": " << strerror(errno)
|
||||
<< "; Returning: " << smi_amdgpu_get_status_string(AMDSMI_STATUS_FILE_ERROR, false);
|
||||
LOG_ERROR(ss);
|
||||
return AMDSMI_STATUS_FILE_ERROR;
|
||||
}
|
||||
|
||||
amd::smi::AMDSmiLibraryLoader libdrm;
|
||||
status = libdrm.load("libdrm.so.2");
|
||||
if (status != AMDSMI_STATUS_SUCCESS) {
|
||||
close(drm_fd);
|
||||
libdrm.unload();
|
||||
ss << __PRETTY_FUNCTION__
|
||||
<< " | Failed to load libdrm.so.2: " << strerror(errno)
|
||||
@@ -3757,7 +3794,6 @@ amdsmi_get_gpu_vbios_info(amdsmi_processor_handle processor_handle, amdsmi_vbios
|
||||
"drmCommandWrite");
|
||||
if (status != AMDSMI_STATUS_SUCCESS) {
|
||||
libdrm.unload();
|
||||
close(drm_fd);
|
||||
ss << __PRETTY_FUNCTION__
|
||||
<< " | Failed to load drmCommandWrite symbol"
|
||||
<< " | Returning: " << smi_amdgpu_get_status_string(status, false);
|
||||
@@ -3775,7 +3811,7 @@ amdsmi_get_gpu_vbios_info(amdsmi_processor_handle processor_handle, amdsmi_vbios
|
||||
request.return_size = sizeof(drm_amdgpu_info_vbios);
|
||||
request.query = AMDGPU_INFO_VBIOS;
|
||||
request.vbios_info.type = AMDGPU_INFO_VBIOS_INFO;
|
||||
auto drm_write = drmCommandWrite(drm_fd, DRM_AMDGPU_INFO, &request,
|
||||
auto drm_write = drmCommandWrite(*drm_fd, DRM_AMDGPU_INFO, &request,
|
||||
sizeof(struct drm_amdgpu_info));
|
||||
|
||||
if (drm_write == 0) {
|
||||
@@ -3799,7 +3835,6 @@ amdsmi_get_gpu_vbios_info(amdsmi_processor_handle processor_handle, amdsmi_vbios
|
||||
vbios_version, AMDSMI_MAX_STRING_LENGTH);
|
||||
}
|
||||
}
|
||||
close(drm_fd);
|
||||
libdrm.unload();
|
||||
ss << __PRETTY_FUNCTION__
|
||||
<< " | drmCommandWrite returned: " << strerror(errno) << "\n"
|
||||
@@ -4283,19 +4318,22 @@ amdsmi_status_t amdsmi_get_gpu_driver_info(amdsmi_processor_handle processor_han
|
||||
|
||||
SMIGPUDEVICE_MUTEX(gpu_device->get_mutex())
|
||||
std::string render_name = gpu_device->get_gpu_path();
|
||||
int drm_fd = -1;
|
||||
std::string path = "/dev/dri/" + render_name;
|
||||
if (render_name != "") {
|
||||
drm_fd = open(path.c_str(), O_RDWR | O_CLOEXEC);
|
||||
} else {
|
||||
close(drm_fd);
|
||||
if (render_name.empty()) {
|
||||
return AMDSMI_STATUS_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
auto drm_fd = amdsmi_RAII_FD_handler(path.c_str(), O_RDWR | O_CLOEXEC);
|
||||
if (!drm_fd) {
|
||||
ss << __PRETTY_FUNCTION__
|
||||
<< " | Failed to open " << path << ": " << strerror(errno)
|
||||
<< "; Returning: " << smi_amdgpu_get_status_string(AMDSMI_STATUS_FILE_ERROR, false);
|
||||
LOG_ERROR(ss);
|
||||
return AMDSMI_STATUS_FILE_ERROR;
|
||||
}
|
||||
amd::smi::AMDSmiLibraryLoader libdrm;
|
||||
status = libdrm.load("libdrm.so.2");
|
||||
if (status != AMDSMI_STATUS_SUCCESS) {
|
||||
close(drm_fd);
|
||||
libdrm.unload();
|
||||
ss << __PRETTY_FUNCTION__
|
||||
<< " | Failed to load libdrm.so.2"
|
||||
@@ -4313,7 +4351,6 @@ amdsmi_status_t amdsmi_get_gpu_driver_info(amdsmi_processor_handle processor_han
|
||||
status = libdrm.load_symbol(
|
||||
reinterpret_cast<drmGetVersion_t *>(&drm_get_version), "drmGetVersion");
|
||||
if (status != AMDSMI_STATUS_SUCCESS) {
|
||||
close(drm_fd);
|
||||
libdrm.unload();
|
||||
ss << __PRETTY_FUNCTION__
|
||||
<< " | Failed to load drmGetVersion symbol"
|
||||
@@ -4324,7 +4361,6 @@ amdsmi_status_t amdsmi_get_gpu_driver_info(amdsmi_processor_handle processor_han
|
||||
status = libdrm.load_symbol(
|
||||
reinterpret_cast<drmGetVersion_t *>(&drm_free_version), "drmFreeVersion");
|
||||
if (status != AMDSMI_STATUS_SUCCESS) {
|
||||
close(drm_fd);
|
||||
libdrm.unload();
|
||||
ss << __PRETTY_FUNCTION__
|
||||
<< " | Failed to load drmFreeVersion symbol"
|
||||
@@ -4335,9 +4371,8 @@ amdsmi_status_t amdsmi_get_gpu_driver_info(amdsmi_processor_handle processor_han
|
||||
|
||||
// Get the driver date
|
||||
std::string driver_date;
|
||||
auto version = drm_get_version(drm_fd);
|
||||
auto version = drm_get_version(*drm_fd);
|
||||
if (version == nullptr) {
|
||||
close(drm_fd);
|
||||
libdrm.unload();
|
||||
ss << __PRETTY_FUNCTION__
|
||||
<< " | Failed to get driver version"
|
||||
@@ -4358,7 +4393,6 @@ amdsmi_status_t amdsmi_get_gpu_driver_info(amdsmi_processor_handle processor_han
|
||||
std::string driver_name = version->name;
|
||||
strncpy(info->driver_name, driver_name.c_str(), AMDSMI_MAX_STRING_LENGTH-1);
|
||||
drm_free_version(version);
|
||||
close(drm_fd);
|
||||
libdrm.unload();
|
||||
ss << __PRETTY_FUNCTION__
|
||||
<< " | Driver version: " << info->driver_version << "\n"
|
||||
@@ -4402,9 +4436,9 @@ amdsmi_status_t amdsmi_get_pcie_info(amdsmi_processor_handle processor_handle, a
|
||||
} else {
|
||||
ss << __PRETTY_FUNCTION__
|
||||
<< " | Failed to open file: " << path_max_link_width
|
||||
<< " | returning AMDSMI_STATUS_API_FAILED";
|
||||
<< " | returning AMDSMI_STATUS_NOT_SUPPORTED";
|
||||
LOG_ERROR(ss);
|
||||
return AMDSMI_STATUS_API_FAILED;
|
||||
return AMDSMI_STATUS_NOT_SUPPORTED;
|
||||
}
|
||||
info->pcie_static.max_pcie_width = (uint16_t)pcie_width;
|
||||
|
||||
@@ -4760,19 +4794,23 @@ amdsmi_get_gpu_virtualization_mode(amdsmi_processor_handle processor_handle,
|
||||
SMIGPUDEVICE_MUTEX(gpu_device->get_mutex())
|
||||
|
||||
std::string render_name = gpu_device->get_gpu_path();
|
||||
int drm_fd = -1;
|
||||
std::string path = "/dev/dri/" + render_name;
|
||||
if (render_name != "") {
|
||||
drm_fd = open(path.c_str(), O_RDWR | O_CLOEXEC);
|
||||
} else {
|
||||
close(drm_fd);
|
||||
if (render_name.empty()) {
|
||||
return AMDSMI_STATUS_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
auto drm_fd = amdsmi_RAII_FD_handler(path.c_str(), O_RDWR | O_CLOEXEC);
|
||||
if (!drm_fd) {
|
||||
ss << __PRETTY_FUNCTION__
|
||||
<< " | Failed to open " << path << ": " << strerror(errno)
|
||||
<< "; Returning: " << smi_amdgpu_get_status_string(AMDSMI_STATUS_FILE_ERROR, false);
|
||||
LOG_ERROR(ss);
|
||||
return AMDSMI_STATUS_FILE_ERROR;
|
||||
}
|
||||
|
||||
amd::smi::AMDSmiLibraryLoader libdrm;
|
||||
status = libdrm.load("libdrm.so.2");
|
||||
if (status != AMDSMI_STATUS_SUCCESS) {
|
||||
close(drm_fd);
|
||||
libdrm.unload();
|
||||
ss << __PRETTY_FUNCTION__
|
||||
<< " | Failed to load libdrm.so.2"
|
||||
@@ -4790,9 +4828,7 @@ amdsmi_get_gpu_virtualization_mode(amdsmi_processor_handle processor_handle,
|
||||
status = libdrm.load_symbol(reinterpret_cast<drmGetVersion_t *>(&drm_get_version),
|
||||
"drmGetVersion");
|
||||
if (status != AMDSMI_STATUS_SUCCESS) {
|
||||
drm_get_version = nullptr;
|
||||
libdrm.unload();
|
||||
close(drm_fd);
|
||||
ss << __PRETTY_FUNCTION__
|
||||
<< " | Failed to load drmGetVersion symbol"
|
||||
<< "; Returning: " << smi_amdgpu_get_status_string(status, false);
|
||||
@@ -4806,7 +4842,6 @@ amdsmi_get_gpu_virtualization_mode(amdsmi_processor_handle processor_handle,
|
||||
if (status != AMDSMI_STATUS_SUCCESS) {
|
||||
drm_free_version = nullptr;
|
||||
libdrm.unload();
|
||||
close(drm_fd);
|
||||
ss << __PRETTY_FUNCTION__
|
||||
<< " | Failed to load drmFreeVersion symbol"
|
||||
<< "; Returning: " << smi_amdgpu_get_status_string(status, false);
|
||||
@@ -4815,7 +4850,7 @@ amdsmi_get_gpu_virtualization_mode(amdsmi_processor_handle processor_handle,
|
||||
}
|
||||
|
||||
// get drm version. If it's older than 3.62.0, then say not supported and exit.
|
||||
auto drm_version = drm_get_version(drm_fd);
|
||||
auto drm_version = drm_get_version(*drm_fd);
|
||||
// minimum version that supports getting of virtualization mode
|
||||
int major_version = 3;
|
||||
int minor_version = 62;
|
||||
@@ -4840,7 +4875,6 @@ amdsmi_get_gpu_virtualization_mode(amdsmi_processor_handle processor_handle,
|
||||
// If not, then return not supported
|
||||
if (isDRMVersionSupported == false) {
|
||||
drm_free_version(drm_version);
|
||||
close(drm_fd);
|
||||
libdrm.unload();
|
||||
return AMDSMI_STATUS_NOT_SUPPORTED;
|
||||
}
|
||||
@@ -4855,11 +4889,10 @@ amdsmi_get_gpu_virtualization_mode(amdsmi_processor_handle processor_handle,
|
||||
"drmCommandWrite");
|
||||
if (status != AMDSMI_STATUS_SUCCESS) {
|
||||
drm_free_version(drm_version);
|
||||
close(drm_fd);
|
||||
libdrm.unload();
|
||||
ss << __PRETTY_FUNCTION__
|
||||
<< " | Failed to load drmCommandWrite symbol: " << strerror(errno)
|
||||
<< " | returning AMDSMI_STATUS_DRM_ERROR";
|
||||
<< "; Returning: " << smi_amdgpu_get_status_string(status, false);
|
||||
LOG_ERROR(ss);
|
||||
return status;
|
||||
}
|
||||
@@ -4871,10 +4904,10 @@ amdsmi_get_gpu_virtualization_mode(amdsmi_processor_handle processor_handle,
|
||||
request.return_pointer = reinterpret_cast<unsigned long long>(&dev_info);
|
||||
request.return_size = sizeof(struct drm_amdgpu_info_device);
|
||||
request.query = AMDGPU_INFO_DEV_INFO;
|
||||
auto drm_write = drmCommandWrite(drm_fd, DRM_AMDGPU_INFO, &request,
|
||||
auto drm_write = drmCommandWrite(*drm_fd, DRM_AMDGPU_INFO, &request,
|
||||
sizeof(struct drm_amdgpu_info));
|
||||
ss << __PRETTY_FUNCTION__
|
||||
<< " | drm_fd: " << std::dec << drm_fd << "\n"
|
||||
<< " | drm_fd: " << std::dec << *drm_fd << "\n"
|
||||
<< " | path: " << path << "\n"
|
||||
<< " | drmCommandWrite: " << drm_write << "\n"
|
||||
<< " | drmCommandWrite returned: " << strerror(errno) << "\n"
|
||||
@@ -4917,7 +4950,6 @@ amdsmi_get_gpu_virtualization_mode(amdsmi_processor_handle processor_handle,
|
||||
status = AMDSMI_STATUS_DRM_ERROR;
|
||||
}
|
||||
drm_free_version(drm_version);
|
||||
close(drm_fd);
|
||||
libdrm.unload();
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include <string.h>
|
||||
#include <memory>
|
||||
#include <regex>
|
||||
#include "amd_smi/impl/amd_smi_utils.h"
|
||||
#include "amd_smi/impl/amd_smi_drm.h"
|
||||
#include "amd_smi/impl/amd_smi_common.h"
|
||||
#include "rocm_smi/rocm_smi.h"
|
||||
@@ -59,8 +60,6 @@ std::string AMDSmiDrm::find_file_in_folder(const std::string& folder,
|
||||
|
||||
amdsmi_status_t AMDSmiDrm::init() {
|
||||
std::ostringstream ss;
|
||||
int fd = -1;
|
||||
|
||||
|
||||
amdsmi_status_t status = lib_loader_.load("libdrm.so.2");
|
||||
if (status != AMDSMI_STATUS_SUCCESS) {
|
||||
@@ -131,27 +130,18 @@ amdsmi_status_t AMDSmiDrm::init() {
|
||||
|
||||
// looking for /sys/class/drm/card0/../renderD*
|
||||
std::string render_name = find_file_in_folder(renderD_folder, regex);
|
||||
fd = -1;
|
||||
std::string name = "/dev/dri/" + render_name;
|
||||
if (render_name != "") {
|
||||
fd = open(name.c_str(), O_RDWR | O_CLOEXEC);
|
||||
}
|
||||
auto fd = amdsmi_RAII_FD_handler(name.c_str(), O_RDWR | O_CLOEXEC);
|
||||
|
||||
amdsmi_bdf_t bdf;
|
||||
if (fd >= 0) {
|
||||
auto version = drm_get_version(fd);
|
||||
if (strcmp("amdgpu", version->name)) { // only amdgpu
|
||||
close(fd);
|
||||
fd = -1;
|
||||
}
|
||||
if (fd >= 0 && drm_get_device(fd, &device) != 0) {
|
||||
if (*fd >= 0) {
|
||||
auto version = drm_get_version(*fd);
|
||||
if (*fd >= 0 && drm_get_device(*fd, &device) != 0) {
|
||||
drm_free_device(&device);
|
||||
close(fd);
|
||||
fd = -1;
|
||||
}
|
||||
ss << __PRETTY_FUNCTION__ << " | "
|
||||
<< " render file name: " << name << "\n"
|
||||
<< "; fd: " << std::dec << fd << "\n"
|
||||
<< "; fd: " << std::dec << *fd << "\n"
|
||||
<< "; drm version->name: " << version->name << "\n"
|
||||
<< "; drm version->date: " << version->date << "\n"
|
||||
<< "; drm version_major.version_minor.version_patchlevel: "
|
||||
@@ -174,11 +164,12 @@ amdsmi_status_t AMDSmiDrm::init() {
|
||||
drm_free_version(version);
|
||||
}
|
||||
|
||||
drm_fds_.push_back(fd);
|
||||
drm_fds_.push_back(*fd);
|
||||
drm_paths_.push_back(render_name);
|
||||
// even if fail, still add to prevent mismatch the index
|
||||
if (fd < 0) {
|
||||
if (*fd < 0) {
|
||||
drm_bdfs_.push_back(bdf);
|
||||
drm_free_device(&device);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -215,7 +206,6 @@ amdsmi_status_t AMDSmiDrm::init() {
|
||||
|
||||
drm_bdfs_.push_back(bdf);
|
||||
drm_free_device(&device);
|
||||
close(fd);
|
||||
}
|
||||
|
||||
// cannot find any valid fds.
|
||||
@@ -223,7 +213,6 @@ amdsmi_status_t AMDSmiDrm::init() {
|
||||
drm_bdfs_.clear();
|
||||
return AMDSMI_STATUS_INIT_ERROR;
|
||||
}
|
||||
|
||||
return AMDSMI_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@@ -404,6 +404,7 @@ amdsmi_status_t AMDSmiSystem::cleanup() {
|
||||
// we do not need to delete the sockets/processors, clear takes care of this
|
||||
if (!processors_.empty()) {processors_.clear();}
|
||||
if (!sockets_.empty()) {sockets_.clear();}
|
||||
drm_.cleanup();
|
||||
init_flag_ &= ~AMDSMI_INIT_AMD_GPUS;
|
||||
rsmi_status_t ret = rsmi_shut_down();
|
||||
if (ret != RSMI_STATUS_SUCCESS) {
|
||||
|
||||
@@ -583,31 +583,40 @@ amdsmi_status_t smi_amdgpu_get_pcie_speed_from_pcie_type(uint16_t pcie_type, uin
|
||||
|
||||
amdsmi_status_t smi_amdgpu_get_market_name_from_dev_id(amd::smi::AMDSmiGPUDevice* device,
|
||||
char *market_name) {
|
||||
SMIGPUDEVICE_MUTEX(device->get_mutex())
|
||||
if (market_name == nullptr || device == nullptr) {
|
||||
return AMDSMI_STATUS_ARG_PTR_NULL;
|
||||
}
|
||||
// initialize the market_name to empty string
|
||||
std::string empty = "";
|
||||
std::strncpy(market_name, empty.c_str(), AMDSMI_MAX_STRING_LENGTH - 1);
|
||||
|
||||
std::ostringstream ss;
|
||||
std::string render_name = device->get_gpu_path();
|
||||
int fd = -1;
|
||||
std::string path = "/dev/dri/" + render_name;
|
||||
|
||||
if (render_name != "") {
|
||||
fd = open(path.c_str(), O_RDWR | O_CLOEXEC);
|
||||
} else {
|
||||
market_name[0] = '\0';
|
||||
close(fd);
|
||||
if (render_name.empty()) {
|
||||
return AMDSMI_STATUS_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
auto fd = amdsmi_RAII_FD_handler(path.c_str(), O_RDWR | O_CLOEXEC);
|
||||
ss << __PRETTY_FUNCTION__ << " | Render Name: "
|
||||
<< render_name << "; path: " << path << "; fd: " << fd;
|
||||
<< render_name << "; path: " << path << "; fd: "
|
||||
<< (fd == nullptr ? "nullptr" : std::to_string(*fd)) << "\n";
|
||||
LOG_DEBUG(ss);
|
||||
if (!fd) {
|
||||
ss << __PRETTY_FUNCTION__ << " | Render Name: "
|
||||
<< render_name << "; path: " << path << "; fd: "
|
||||
<< (fd == nullptr ? "nullptr" : std::to_string(*fd)) << "\n"
|
||||
<< "; Returning: "
|
||||
<< smi_amdgpu_get_status_string(AMDSMI_STATUS_FILE_ERROR, false) << "\n";
|
||||
LOG_INFO(ss);
|
||||
return AMDSMI_STATUS_FILE_ERROR;
|
||||
}
|
||||
|
||||
amd::smi::AMDSmiLibraryLoader libdrm_amdgpu_;
|
||||
amdsmi_status_t status = libdrm_amdgpu_.load("libdrm_amdgpu.so");
|
||||
if (status != AMDSMI_STATUS_SUCCESS) {
|
||||
close(fd);
|
||||
libdrm_amdgpu_.AMDSmiLibraryLoader::unload();
|
||||
libdrm_amdgpu_.unload();
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -621,60 +630,46 @@ amdsmi_status_t smi_amdgpu_get_market_name_from_dev_id(amd::smi::AMDSmiGPUDevice
|
||||
amdgpu_device_deinitialize_t amdgpu_device_deinitialize = nullptr;
|
||||
amdgpu_get_marketing_name_t amdgpu_get_marketing_name = nullptr;
|
||||
|
||||
status = libdrm_amdgpu_.load_symbol(
|
||||
reinterpret_cast<amdgpu_device_initialize_t *>(&amdgpu_device_initialize),
|
||||
"amdgpu_device_initialize");
|
||||
status = libdrm_amdgpu_.load_symbol(reinterpret_cast<void**>(&amdgpu_device_deinitialize),
|
||||
"amdgpu_device_deinitialize");
|
||||
if (status != AMDSMI_STATUS_SUCCESS) {
|
||||
close(fd);
|
||||
libdrm_amdgpu_.AMDSmiLibraryLoader::unload();
|
||||
libdrm_amdgpu_.unload();
|
||||
return status;
|
||||
}
|
||||
|
||||
status = libdrm_amdgpu_.load_symbol(reinterpret_cast<void**>(&amdgpu_device_initialize),
|
||||
"amdgpu_device_initialize");
|
||||
if (status != AMDSMI_STATUS_SUCCESS) {
|
||||
libdrm_amdgpu_.unload();
|
||||
return status;
|
||||
}
|
||||
|
||||
amdgpu_device_handle device_handle = nullptr;
|
||||
uint32_t major_version, minor_version;
|
||||
int ret = amdgpu_device_initialize(fd, &major_version, &minor_version, &device_handle);
|
||||
int ret = amdgpu_device_initialize(*fd, &major_version, &minor_version, &device_handle);
|
||||
if (ret != 0) {
|
||||
close(fd);
|
||||
libdrm_amdgpu_.AMDSmiLibraryLoader::unload();
|
||||
amdgpu_device_deinitialize(device_handle);
|
||||
libdrm_amdgpu_.unload();
|
||||
return AMDSMI_STATUS_DRM_ERROR;
|
||||
}
|
||||
|
||||
status = libdrm_amdgpu_.load_symbol(
|
||||
reinterpret_cast<amdgpu_get_marketing_name_t *>(
|
||||
&amdgpu_get_marketing_name), "amdgpu_get_marketing_name");
|
||||
status = libdrm_amdgpu_.load_symbol(reinterpret_cast<void**>(&amdgpu_get_marketing_name),
|
||||
"amdgpu_get_marketing_name");
|
||||
if (status != AMDSMI_STATUS_SUCCESS) {
|
||||
close(fd);
|
||||
libdrm_amdgpu_.AMDSmiLibraryLoader::unload();
|
||||
amdgpu_device_deinitialize(device_handle);
|
||||
libdrm_amdgpu_.unload();
|
||||
return status;
|
||||
}
|
||||
|
||||
status = libdrm_amdgpu_.load_symbol(reinterpret_cast<amdgpu_device_deinitialize_t *>(
|
||||
&amdgpu_device_deinitialize), "amdgpu_device_deinitialize");
|
||||
if (status != AMDSMI_STATUS_SUCCESS) {
|
||||
close(fd);
|
||||
libdrm_amdgpu_.AMDSmiLibraryLoader::unload();
|
||||
return status;
|
||||
}
|
||||
|
||||
ret = amdgpu_device_initialize(fd, &major_version, &minor_version, &device_handle);
|
||||
if (ret != 0) {
|
||||
std::string empty = "";
|
||||
std::strncpy(market_name, empty.c_str(), AMDSMI_MAX_STRING_LENGTH - 1);
|
||||
amdgpu_device_deinitialize(device_handle);
|
||||
close(fd);
|
||||
return AMDSMI_STATUS_DRM_ERROR;
|
||||
}
|
||||
|
||||
// Get the marketing name using libdrm's API
|
||||
const char *name = amdgpu_get_marketing_name(device_handle);
|
||||
if (name != nullptr) {
|
||||
std::strncpy(market_name, name, AMDSMI_MAX_STRING_LENGTH - 1);
|
||||
market_name[AMDSMI_MAX_STRING_LENGTH - 1] = '\0';
|
||||
amdgpu_device_deinitialize(device_handle);
|
||||
close(fd);
|
||||
libdrm_amdgpu_.AMDSmiLibraryLoader::unload();
|
||||
libdrm_amdgpu_.unload();
|
||||
ss << __PRETTY_FUNCTION__ << " | path: " << path << "\n"
|
||||
<< " | fd: "<< std::dec << fd << "\n"
|
||||
<< " | fd: "<< std::dec << *fd << "\n"
|
||||
<< " | Marketing Name: " << market_name << "\n"
|
||||
<< " | Returning: "
|
||||
<< smi_amdgpu_get_status_string(AMDSMI_STATUS_SUCCESS, false) << "\n";
|
||||
@@ -683,10 +678,9 @@ amdsmi_status_t smi_amdgpu_get_market_name_from_dev_id(amd::smi::AMDSmiGPUDevice
|
||||
}
|
||||
|
||||
amdgpu_device_deinitialize(device_handle);
|
||||
close(fd);
|
||||
libdrm_amdgpu_.AMDSmiLibraryLoader::unload();
|
||||
libdrm_amdgpu_.unload();
|
||||
ss << __PRETTY_FUNCTION__ << " | path: " << path << "\n"
|
||||
<< " | fd: "<< std::dec << fd << "\n"
|
||||
<< " | fd: "<< std::dec << *fd << "\n"
|
||||
<< " | Marketing Name: " << market_name << "\n"
|
||||
<< " | Returning: "
|
||||
<< smi_amdgpu_get_status_string(AMDSMI_STATUS_DRM_ERROR, false) << "\n";
|
||||
@@ -804,7 +798,6 @@ amdsmi_status_t smi_amdgpu_get_device_index(amdsmi_processor_handle processor_ha
|
||||
<< "Returning device_index: " << *device_index << "\nSocket #: " << i
|
||||
<< "; Device #: " << j << "; current_device_index #: " << current_device_index
|
||||
<< "\n";
|
||||
// std::cout << ss.str();
|
||||
LOG_DEBUG(ss);
|
||||
return AMDSMI_STATUS_SUCCESS;
|
||||
}
|
||||
@@ -913,8 +906,6 @@ amdsmi_status_t smi_amdgpu_get_processor_handle_by_index(
|
||||
LOG_DEBUG(ss);
|
||||
|
||||
for (uint32_t j = 0; j < device_count; j++) {
|
||||
// std::cout << "current_device_index: " << current_device_index
|
||||
// << " device_index: " << device_index << std::endl;
|
||||
if (current_device_index == device_index) {
|
||||
*processor_handle = processor_handles[j];
|
||||
ss << __PRETTY_FUNCTION__ << " | AMDSMI_STATUS_SUCCESS"
|
||||
@@ -924,7 +915,6 @@ amdsmi_status_t smi_amdgpu_get_processor_handle_by_index(
|
||||
<< "; processor_handle: " << *processor_handle
|
||||
<< "; processor_handles[j]: " << processor_handles[j]
|
||||
<< "\n";
|
||||
// std::cout << ss.str();
|
||||
LOG_DEBUG(ss);
|
||||
return AMDSMI_STATUS_SUCCESS;
|
||||
}
|
||||
@@ -959,3 +949,58 @@ void amdsmi_wait_for_user_input(void) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<int> amdsmi_RAII_FD_handler(const std::string& path, int flags) {
|
||||
static std::mutex fd_mutex;
|
||||
static std::map<std::string, std::weak_ptr<int>> open_files;
|
||||
static std::ostringstream ss;
|
||||
|
||||
std::lock_guard<std::mutex> lock(fd_mutex);
|
||||
|
||||
// Clean up expired entries from the cache
|
||||
for (auto it = open_files.begin(); it != open_files.end();) {
|
||||
if (it->second.expired()) {
|
||||
it = open_files.erase(it);
|
||||
} else {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
// Try to reuse an existing open FD
|
||||
auto it = open_files.find(path);
|
||||
if (it != open_files.end()) {
|
||||
if (auto existing_fd = it->second.lock()) {
|
||||
ss <<__PRETTY_FUNCTION__ << " | Reusing FD for path: " << path;
|
||||
LOG_INFO(ss);
|
||||
return existing_fd;
|
||||
}
|
||||
}
|
||||
|
||||
// Open a new file descriptor
|
||||
int fd = open(path.c_str(), flags);
|
||||
if (fd < 0) {
|
||||
ss << __PRETTY_FUNCTION__ << " | Failed to open file: " << path
|
||||
<< " | Error: " << strerror(errno);
|
||||
LOG_INFO(ss);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ss << __PRETTY_FUNCTION__ << " | Opened FD: " << std::to_string(fd)
|
||||
<< " for path: " << path;
|
||||
LOG_INFO(ss);
|
||||
|
||||
// Create a shared_ptr with a custom deleter to close the FD
|
||||
auto fd_ptr = std::shared_ptr<int>(new int(fd), [path](int* fd) {
|
||||
if (fd && *fd >= 0) {
|
||||
ss << __PRETTY_FUNCTION__ << " | Closing FD: " << std::to_string(*fd)
|
||||
<< " | Path: " << path << std::endl;
|
||||
LOG_INFO(ss);
|
||||
close(*fd);
|
||||
delete fd;
|
||||
}
|
||||
});
|
||||
|
||||
// Store weak_ptr in cache for reuse
|
||||
open_files[path] = fd_ptr;
|
||||
return fd_ptr;
|
||||
}
|
||||
|
||||
Referencia en una nueva incidencia
Block a user