DRM - Remove FD usage
Change-Id: I77dfa778ccd0d39a03289c2e11cf10357566ff16 Signed-off-by: Galantsev, Dmitrii <dmitrii.galantsev@amd.com>
This commit is contained in:
1 förälder
202b46d96f
incheckning
9b5bbf555a
13 files changed
+128
-319
No files matched your search
@@ -25,6 +25,7 @@ set(SRC_LIST
|
||||
"${SRC_DIR}/amd_smi_system.cc"
|
||||
"${SRC_DIR}/amd_smi_utils.cc"
|
||||
"${SRC_DIR}/amd_smi_uuid.cc"
|
||||
"${SRC_DIR}/scoped_fd.cc"
|
||||
"${SRC_DIR}/fdinfo.cc"
|
||||
"${CMN_SRC_LIST}")
|
||||
set(INC_LIST
|
||||
@@ -37,6 +38,9 @@ set(INC_LIST
|
||||
"${INC_DIR}/impl/amd_smi_lib_loader.h"
|
||||
"${INC_DIR}/impl/amd_smi_socket.h"
|
||||
"${INC_DIR}/impl/amd_smi_system.h"
|
||||
"${INC_DIR}/impl/amd_smi_utils.h"
|
||||
"${INC_DIR}/impl/amd_smi_uuid.h"
|
||||
"${INC_DIR}/impl/scoped_fd.h"
|
||||
"${PROJECT_SOURCE_DIR}/rocm_smi/include/rocm_smi/rocm_smi.h"
|
||||
"${PROJECT_SOURCE_DIR}/rocm_smi/include/rocm_smi/rocm_smi_utils.h")
|
||||
|
||||
|
||||
+14
-14
@@ -905,7 +905,7 @@ amdsmi_status_t amdsmi_get_gpu_vram_usage(amdsmi_processor_handle processor_hand
|
||||
|
||||
std::string path = "/dev/dri/" + render_name;
|
||||
ScopedFD drm_fd(path.c_str(), O_RDWR | O_CLOEXEC);
|
||||
if (!drm_fd) {
|
||||
if (!drm_fd.valid()) {
|
||||
ss << __PRETTY_FUNCTION__
|
||||
<< " | Failed to open " << path << ": " << strerror(errno)
|
||||
<< "; Returning: " << smi_amdgpu_get_status_string(AMDSMI_STATUS_FILE_ERROR, false);
|
||||
@@ -962,7 +962,7 @@ 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,
|
||||
auto drm_write = drmCommandWrite(drm_fd, DRM_AMDGPU_INFO, &request,
|
||||
sizeof(struct drm_amdgpu_info));
|
||||
if (drm_write != 0) {
|
||||
libdrm.unload();
|
||||
@@ -1662,7 +1662,7 @@ amdsmi_get_gpu_asic_info(amdsmi_processor_handle processor_handle, amdsmi_asic_i
|
||||
}
|
||||
std::string path = "/dev/dri/" + render_name;
|
||||
ScopedFD drm_fd(path.c_str(), O_RDWR | O_CLOEXEC);
|
||||
if (!drm_fd) {
|
||||
if (!drm_fd.valid()) {
|
||||
ss << __PRETTY_FUNCTION__
|
||||
<< " | Failed to open " << path << ": " << strerror(errno)
|
||||
<< "; Returning: " << smi_amdgpu_get_status_string(AMDSMI_STATUS_FILE_ERROR, false);
|
||||
@@ -1706,7 +1706,7 @@ amdsmi_get_gpu_asic_info(amdsmi_processor_handle processor_handle, amdsmi_asic_i
|
||||
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) {
|
||||
libdrm.unload();
|
||||
@@ -1885,7 +1885,7 @@ amdsmi_status_t amdsmi_get_gpu_vram_info(
|
||||
}
|
||||
|
||||
ScopedFD drm_fd(path.c_str(), O_RDWR | O_CLOEXEC);
|
||||
if (!drm_fd) {
|
||||
if (!drm_fd.valid()) {
|
||||
ss << __PRETTY_FUNCTION__
|
||||
<< " | Failed to open " << path << ": " << strerror(errno)
|
||||
<< "; Returning: " << smi_amdgpu_get_status_string(AMDSMI_STATUS_FILE_ERROR, false);
|
||||
@@ -1936,7 +1936,7 @@ 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) {
|
||||
libdrm.unload();
|
||||
@@ -3743,7 +3743,7 @@ amdsmi_get_gpu_vbios_info(amdsmi_processor_handle processor_handle, amdsmi_vbios
|
||||
}
|
||||
|
||||
ScopedFD drm_fd(path.c_str(), O_RDWR | O_CLOEXEC);
|
||||
if (!drm_fd) {
|
||||
if (!drm_fd.valid()) {
|
||||
ss << __PRETTY_FUNCTION__
|
||||
<< " | Failed to open " << path << ": " << strerror(errno)
|
||||
<< "; Returning: " << smi_amdgpu_get_status_string(AMDSMI_STATUS_FILE_ERROR, false);
|
||||
@@ -3794,7 +3794,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) {
|
||||
@@ -4306,7 +4306,7 @@ amdsmi_status_t amdsmi_get_gpu_driver_info(amdsmi_processor_handle processor_han
|
||||
}
|
||||
|
||||
ScopedFD drm_fd(path.c_str(), O_RDWR | O_CLOEXEC);
|
||||
if (!drm_fd) {
|
||||
if (!drm_fd.valid()) {
|
||||
ss << __PRETTY_FUNCTION__
|
||||
<< " | Failed to open " << path << ": " << strerror(errno)
|
||||
<< "; Returning: " << smi_amdgpu_get_status_string(AMDSMI_STATUS_FILE_ERROR, false);
|
||||
@@ -4353,7 +4353,7 @@ 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) {
|
||||
libdrm.unload();
|
||||
ss << __PRETTY_FUNCTION__
|
||||
@@ -4782,7 +4782,7 @@ amdsmi_get_gpu_virtualization_mode(amdsmi_processor_handle processor_handle,
|
||||
}
|
||||
|
||||
ScopedFD drm_fd(path.c_str(), O_RDWR | O_CLOEXEC);
|
||||
if (!drm_fd) {
|
||||
if (!drm_fd.valid()) {
|
||||
ss << __PRETTY_FUNCTION__
|
||||
<< " | Failed to open " << path << ": " << strerror(errno)
|
||||
<< "; Returning: " << smi_amdgpu_get_status_string(AMDSMI_STATUS_FILE_ERROR, false);
|
||||
@@ -4832,7 +4832,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;
|
||||
@@ -4886,10 +4886,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"
|
||||
|
||||
@@ -27,9 +27,9 @@
|
||||
#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 "impl/scoped_fd.h"
|
||||
#include "rocm_smi/rocm_smi.h"
|
||||
#include "rocm_smi/rocm_smi_main.h"
|
||||
#include "rocm_smi/rocm_smi_utils.h"
|
||||
@@ -59,8 +59,6 @@ std::string AMDSmiDrm::find_file_in_folder(const std::string& folder,
|
||||
}
|
||||
|
||||
amdsmi_status_t AMDSmiDrm::init() {
|
||||
std::ostringstream ss;
|
||||
|
||||
amdsmi_status_t status = lib_loader_.load("libdrm.so.2");
|
||||
if (status != AMDSMI_STATUS_SUCCESS) {
|
||||
return status;
|
||||
@@ -121,7 +119,6 @@ amdsmi_status_t AMDSmiDrm::init() {
|
||||
bool has_valid_fds = false;
|
||||
for (uint32_t i=0; i < devices.size(); i++) {
|
||||
auto rocm_smi_device = devices[i];
|
||||
std::string render_file_name;
|
||||
drmDevicePtr device;
|
||||
|
||||
const std::string regex("renderD([0-9]+)");
|
||||
@@ -134,70 +131,27 @@ amdsmi_status_t AMDSmiDrm::init() {
|
||||
ScopedFD fd(name.c_str(), O_RDWR | O_CLOEXEC);
|
||||
|
||||
amdsmi_bdf_t bdf;
|
||||
if (*fd >= 0) {
|
||||
auto version = drm_get_version(*fd);
|
||||
if (drm_get_device(*fd, &device) != 0) {
|
||||
if (fd.valid()) {
|
||||
auto version = drm_get_version(fd);
|
||||
if (drm_get_device(fd, &device) != 0) {
|
||||
drm_free_device(&device);
|
||||
}
|
||||
ss << __PRETTY_FUNCTION__ << " | "
|
||||
<< " render file name: " << name << "\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: "
|
||||
<< std::dec << version->version_major << "."
|
||||
<< version->version_minor << "."
|
||||
<< version->version_patchlevel << "\n"
|
||||
<< "; device->deviceinfo.pci->vendor_id: 0x"
|
||||
<< std::hex << std::setfill('0') << std::setw(4)
|
||||
<< static_cast<uint32_t>(device->deviceinfo.pci->vendor_id) << "\n"
|
||||
<< "; device->deviceinfo.pci->device_id: 0x"
|
||||
<< std::hex << std::setfill('0') << std::setw(4)
|
||||
<< static_cast<uint32_t>(device->deviceinfo.pci->device_id) << "\n"
|
||||
<< "; device->deviceinfo.pci->revision_id: 0x"
|
||||
<< std::hex << std::setfill('0') << std::setw(4)
|
||||
<< static_cast<uint32_t>(device->deviceinfo.pci->revision_id) << "\n"
|
||||
<< "; device->deviceinfo.pci->subdevice_id: 0x"
|
||||
<< std::hex << std::setfill('0') << std::setw(4)
|
||||
<< static_cast<uint32_t>(device->deviceinfo.pci->subdevice_id) << "\n";
|
||||
LOG_INFO(ss);
|
||||
drm_free_version(version);
|
||||
has_valid_fds = true;
|
||||
}
|
||||
|
||||
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 (!has_valid_fds) {
|
||||
drm_bdfs_.push_back(bdf);
|
||||
drm_free_device(&device);
|
||||
continue;
|
||||
}
|
||||
|
||||
has_valid_fds = true;
|
||||
std::ostringstream ss;
|
||||
uint64_t bdf_rocm = 0;
|
||||
rsmi_dev_pci_id_get(i, &bdf_rocm);
|
||||
|
||||
vendor_id = device->deviceinfo.pci->vendor_id;
|
||||
std::ostringstream bdf_sstream;
|
||||
bdf_sstream << std::hex << std::setfill('0') << std::setw(4)
|
||||
<< ((bdf_rocm >> 32) & 0xFFFFFFFF) << ":" // DOMAIN
|
||||
<< std::hex << std::setfill('0') << std::setw(2)
|
||||
<< ((bdf_rocm >> 8) & 0xFF) << ":" // BUS
|
||||
<< std::hex << std::setfill('0') << std::setw(2)
|
||||
<< ((bdf_rocm >> 3) & 0x1F) << "." // DEVICE
|
||||
<< std::hex << std::setfill('0') << +(bdf_rocm & 0x7); // FUNCTION
|
||||
bdf_sstream << "\n[Option 1] Partition ID ((pci_id >> 28) & 0xf): " << std::dec
|
||||
<< static_cast<int>((bdf_rocm >> 28) & 0xf);
|
||||
bdf_sstream << "\n[Option 2] Partition ID (pci_id & 0x7): " << std::dec
|
||||
<< static_cast<int>(bdf_rocm & 0x7);
|
||||
ss << __PRETTY_FUNCTION__ << " | "
|
||||
<< "bdf_rocm | Received bdf: "
|
||||
<< "\nWhole BDF: " << amd::smi::print_unsigned_hex_and_int(bdf_rocm)
|
||||
<< "\nBDF = "
|
||||
<< bdf_sstream.str() << "\n"
|
||||
<< "; Vendor ID: 0x" << std::hex << std::setfill('0') << std::setw(4) << vendor_id;
|
||||
LOG_INFO(ss);
|
||||
|
||||
bdf.domain_number = static_cast<uint64_t>(((bdf_rocm >> 32) & 0xFFFFFFFF));
|
||||
bdf.bus_number = static_cast<uint64_t>(((bdf_rocm >> 8) & 0xFF));
|
||||
@@ -217,41 +171,17 @@ amdsmi_status_t AMDSmiDrm::init() {
|
||||
}
|
||||
|
||||
amdsmi_status_t AMDSmiDrm::cleanup() {
|
||||
for (unsigned int i=0; i < drm_fds_.size(); i++) {
|
||||
close(drm_fds_[i]);
|
||||
}
|
||||
|
||||
if (!drm_fds_.empty()) {drm_fds_.clear();}
|
||||
if (!drm_paths_.empty()) {drm_paths_.clear();}
|
||||
if (!drm_bdfs_.empty()) {drm_bdfs_.clear();}
|
||||
lib_loader_.unload();
|
||||
return AMDSMI_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
amdsmi_status_t AMDSmiDrm::get_drm_fd_by_index(uint32_t gpu_index, uint32_t *fd_info) const {
|
||||
if (gpu_index + 1 > drm_fds_.size()) return AMDSMI_STATUS_NOT_SUPPORTED;
|
||||
if (drm_fds_[gpu_index] < 0 ) return AMDSMI_STATUS_NOT_SUPPORTED;
|
||||
*fd_info = drm_fds_[gpu_index];
|
||||
return AMDSMI_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
amdsmi_status_t AMDSmiDrm::get_bdf_by_index(uint32_t gpu_index, amdsmi_bdf_t *bdf_info) const {
|
||||
std::ostringstream ss;
|
||||
if (gpu_index + 1 > drm_bdfs_.size()) {
|
||||
ss << __PRETTY_FUNCTION__ << " | gpu_index = " << gpu_index
|
||||
<< "; \nReturning = AMDSMI_STATUS_NOT_SUPPORTED";
|
||||
LOG_INFO(ss);
|
||||
// std::cout << ss.str() << std::endl;
|
||||
return AMDSMI_STATUS_NOT_SUPPORTED;
|
||||
}
|
||||
*bdf_info = drm_bdfs_[gpu_index];
|
||||
ss << __PRETTY_FUNCTION__ << " | gpu_index = " << gpu_index
|
||||
<< "; \nreceived bdf: Domain = " << bdf_info->domain_number
|
||||
<< "; \nBus# = " << bdf_info->bus_number
|
||||
<< "; \nDevice# = " << bdf_info->device_number
|
||||
<< "; \nFunction# = " << bdf_info->function_number
|
||||
<< "\nReturning = AMDSMI_STATUS_SUCCESS";
|
||||
LOG_INFO(ss);
|
||||
return AMDSMI_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,16 +20,12 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <unordered_set>
|
||||
#include <dirent.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "amd_smi/impl/amd_smi_gpu_device.h"
|
||||
#include "amd_smi/impl/amd_smi_common.h"
|
||||
#include "amd_smi/impl/amd_smi_utils.h"
|
||||
#include "amd_smi/impl/fdinfo.h"
|
||||
#include "rocm_smi/rocm_smi_kfd.h"
|
||||
#include "rocm_smi/rocm_smi_utils.h"
|
||||
@@ -43,7 +39,6 @@ uint32_t AMDSmiGPUDevice::get_gpu_id() const {
|
||||
}
|
||||
|
||||
uint32_t AMDSmiGPUDevice::get_card_id() {
|
||||
std::ostringstream ss;
|
||||
// Should never return not_supported, but just in case
|
||||
rsmi_status_t ret = rsmi_status_t::RSMI_STATUS_NOT_SUPPORTED;
|
||||
uint32_t gpu_index = this->get_gpu_id();
|
||||
@@ -55,24 +50,10 @@ uint32_t AMDSmiGPUDevice::get_card_id() {
|
||||
this->card_index_ = identifiers.card_index;
|
||||
}
|
||||
|
||||
ss << __PRETTY_FUNCTION__
|
||||
<< " | rsmi_dev_identifiers_get status: " << getRSMIStatusString(ret, false) << "\n"
|
||||
<< " | gpu_id_: " << gpu_id_ << "\n"
|
||||
<< " | identifiers.card_index: " << identifiers.card_index << "\n"
|
||||
<< " | identifiers.drm_render_minor: " << identifiers.drm_render_minor << "\n"
|
||||
<< " | identifiers.bdfid: " << std::hex << "0x" << identifiers.bdfid << "\n"
|
||||
<< " | identifiers.kfd_gpu_id: " << std::dec << identifiers.kfd_gpu_id << "\n"
|
||||
<< " | identifiers.partition_id: " << identifiers.partition_id << "\n"
|
||||
<< " | identifiers.smi_device_id: " << identifiers.smi_device_id << "\n"
|
||||
<< " | returning card_index_: "
|
||||
<< this->card_index_ << std::endl;
|
||||
// std::cout << ss.str();
|
||||
LOG_DEBUG(ss);
|
||||
return this->card_index_;
|
||||
}
|
||||
|
||||
uint32_t AMDSmiGPUDevice::get_drm_render_minor() {
|
||||
std::ostringstream ss;
|
||||
// Should never return not_supported, but just in case
|
||||
rsmi_status_t ret = rsmi_status_t::RSMI_STATUS_NOT_SUPPORTED;
|
||||
uint32_t gpu_index = this->get_gpu_id();
|
||||
@@ -84,24 +65,10 @@ uint32_t AMDSmiGPUDevice::get_drm_render_minor() {
|
||||
this->drm_render_minor_ = identifiers.drm_render_minor;
|
||||
}
|
||||
|
||||
ss << __PRETTY_FUNCTION__
|
||||
<< " | rsmi_dev_identifiers_get status: " << getRSMIStatusString(ret, false) << "\n"
|
||||
<< " | gpu_id_: " << gpu_id_ << "\n"
|
||||
<< " | identifiers.card_index: " << identifiers.card_index << "\n"
|
||||
<< " | identifiers.drm_render_minor: " << identifiers.drm_render_minor << "\n"
|
||||
<< " | identifiers.bdfid: " << std::hex << "0x" << identifiers.bdfid << "\n"
|
||||
<< " | identifiers.kfd_gpu_id: " << std::dec << identifiers.kfd_gpu_id << "\n"
|
||||
<< " | identifiers.partition_id: " << identifiers.partition_id << "\n"
|
||||
<< " | identifiers.smi_device_id: " << identifiers.smi_device_id << "\n"
|
||||
<< " | returning drm_render_minor_: "
|
||||
<< this->drm_render_minor_ << std::endl;
|
||||
// std::cout << ss.str();
|
||||
LOG_DEBUG(ss);
|
||||
return this->drm_render_minor_;
|
||||
}
|
||||
|
||||
uint64_t AMDSmiGPUDevice::get_kfd_gpu_id() {
|
||||
std::ostringstream ss;
|
||||
// Should never return not_supported, but just in case
|
||||
rsmi_status_t ret = rsmi_status_t::RSMI_STATUS_NOT_SUPPORTED;
|
||||
uint32_t gpu_index = this->get_gpu_id();
|
||||
@@ -113,26 +80,9 @@ uint64_t AMDSmiGPUDevice::get_kfd_gpu_id() {
|
||||
this->kfd_gpu_id_ = identifiers.kfd_gpu_id;
|
||||
}
|
||||
|
||||
ss << __PRETTY_FUNCTION__
|
||||
<< " | rsmi_dev_identifiers_get status: " << getRSMIStatusString(ret, false) << "\n"
|
||||
<< " | gpu_id_: " << gpu_id_ << "\n"
|
||||
<< " | identifiers.card_index: " << identifiers.card_index << "\n"
|
||||
<< " | identifiers.drm_render_minor: " << identifiers.drm_render_minor << "\n"
|
||||
<< " | identifiers.bdfid: " << std::hex << "0x" << identifiers.bdfid << "\n"
|
||||
<< " | identifiers.kfd_gpu_id: " << std::dec << identifiers.kfd_gpu_id << "\n"
|
||||
<< " | identifiers.partition_id: " << identifiers.partition_id << "\n"
|
||||
<< " | identifiers.smi_device_id: " << identifiers.smi_device_id << "\n"
|
||||
<< " | returning kfd_gpu_id_: "
|
||||
<< this->kfd_gpu_id_ << std::endl;
|
||||
// std::cout << ss.str();
|
||||
LOG_DEBUG(ss);
|
||||
return this->kfd_gpu_id_;
|
||||
}
|
||||
|
||||
uint32_t AMDSmiGPUDevice::get_gpu_fd() const {
|
||||
return fd_;
|
||||
}
|
||||
|
||||
std::string& AMDSmiGPUDevice::get_gpu_path() {
|
||||
return path_;
|
||||
}
|
||||
@@ -147,38 +97,14 @@ uint32_t AMDSmiGPUDevice::get_vendor_id() {
|
||||
|
||||
amdsmi_status_t AMDSmiGPUDevice::get_drm_data() {
|
||||
amdsmi_status_t ret;
|
||||
uint32_t fd = 0;
|
||||
std::string path;
|
||||
amdsmi_bdf_t bdf;
|
||||
std::ostringstream ss;
|
||||
ret = drm_.get_drm_fd_by_index(gpu_id_, &fd);
|
||||
ss << __PRETTY_FUNCTION__ << " | gpu_id_: " << gpu_id_
|
||||
<< "; fd: " << fd
|
||||
<< "; drm_.get_drm_fd_by_index(gpu_id_, &fd): "
|
||||
<< smi_amdgpu_get_status_string(ret, false) << std::endl;
|
||||
// std::cout << ss.str();
|
||||
LOG_DEBUG(ss);
|
||||
if (ret != AMDSMI_STATUS_SUCCESS) return AMDSMI_STATUS_NOT_SUPPORTED;
|
||||
ret = drm_.get_drm_path_by_index(gpu_id_, &path);
|
||||
ss << __PRETTY_FUNCTION__ << " | gpu_id_: " << gpu_id_
|
||||
<< "; path: " << path
|
||||
<< "; drm_.get_drm_fd_by_index(gpu_id_, &path): "
|
||||
<< smi_amdgpu_get_status_string(ret, false) << std::endl;
|
||||
// std::cout << ss.str();
|
||||
LOG_DEBUG(ss);
|
||||
if (ret != AMDSMI_STATUS_SUCCESS) return AMDSMI_STATUS_NOT_SUPPORTED;
|
||||
ret = drm_.get_bdf_by_index(gpu_id_, &bdf);
|
||||
ss << __PRETTY_FUNCTION__ << " | gpu_id_: " << gpu_id_
|
||||
<< "; domain: " << bdf.domain_number
|
||||
<< "; bus: " << bdf.bus_number
|
||||
<< "; device: " << bdf.device_number
|
||||
<< "; drm_.get_drm_fd_by_index(gpu_id_, &bdf): "
|
||||
<< smi_amdgpu_get_status_string(ret, false) << std::endl;
|
||||
// std::cout << ss.str();
|
||||
LOG_DEBUG(ss);
|
||||
if (ret != AMDSMI_STATUS_SUCCESS) return AMDSMI_STATUS_NOT_SUPPORTED;
|
||||
|
||||
bdf_ = bdf, path_ = path, fd_ = fd;
|
||||
bdf_ = bdf, path_ = path;
|
||||
vendor_id_ = drm_.get_vendor_id();
|
||||
|
||||
return AMDSMI_STATUS_SUCCESS;
|
||||
@@ -280,15 +206,7 @@ int32_t AMDSmiGPUDevice::get_compute_process_list_impl(GPUComputeProcessList_t&
|
||||
}
|
||||
}
|
||||
kfd_file.close();
|
||||
} else {
|
||||
std::ostringstream ss;
|
||||
ss << __PRETTY_FUNCTION__ << " | Failed to open KFD file: " << kfd_path;
|
||||
LOG_DEBUG(ss);
|
||||
}
|
||||
} else {
|
||||
std::ostringstream ss;
|
||||
ss << __PRETTY_FUNCTION__ << " | KFD file not accessible: " << kfd_path;
|
||||
LOG_DEBUG(ss);
|
||||
}
|
||||
|
||||
return status_code;
|
||||
|
||||
@@ -672,10 +672,10 @@ amdsmi_status_t smi_amdgpu_get_market_name_from_dev_id(amd::smi::AMDSmiGPUDevice
|
||||
}
|
||||
|
||||
ScopedFD fd(path.c_str(), O_RDWR | O_CLOEXEC);
|
||||
if (!fd) {
|
||||
if (!fd.valid()) {
|
||||
ss << __PRETTY_FUNCTION__ << " | Render Name: "
|
||||
<< render_name << "; path: " << path << "; fd: "
|
||||
<< (fd < 0 ? "less than 0" : std::to_string(*fd)) << "\n"
|
||||
<< (fd < 0 ? "less than 0" : std::to_string(fd)) << "\n"
|
||||
<< "; Returning: "
|
||||
<< smi_amdgpu_get_status_string(AMDSMI_STATUS_FILE_ERROR, false) << "\n";
|
||||
LOG_INFO(ss);
|
||||
@@ -715,7 +715,7 @@ amdsmi_status_t smi_amdgpu_get_market_name_from_dev_id(amd::smi::AMDSmiGPUDevice
|
||||
|
||||
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) {
|
||||
amdgpu_device_deinitialize(device_handle);
|
||||
libdrm_amdgpu_.unload();
|
||||
@@ -737,19 +737,13 @@ amdsmi_status_t smi_amdgpu_get_market_name_from_dev_id(amd::smi::AMDSmiGPUDevice
|
||||
market_name[AMDSMI_MAX_STRING_LENGTH - 1] = '\0';
|
||||
amdgpu_device_deinitialize(device_handle);
|
||||
libdrm_amdgpu_.unload();
|
||||
ss << __PRETTY_FUNCTION__ << " | path: " << path << "\n"
|
||||
<< " | fd: "<< std::dec << *fd << "\n"
|
||||
<< " | Marketing Name: " << market_name << "\n"
|
||||
<< " | Returning: "
|
||||
<< smi_amdgpu_get_status_string(AMDSMI_STATUS_SUCCESS, false) << "\n";
|
||||
LOG_INFO(ss);
|
||||
return AMDSMI_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
amdgpu_device_deinitialize(device_handle);
|
||||
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";
|
||||
@@ -1001,75 +995,3 @@ struct CperFileCtx {
|
||||
std::unique_ptr<char[]> buffer;
|
||||
long file_size = 0;
|
||||
};
|
||||
|
||||
|
||||
void amdsmi_wait_for_user_input(void) {
|
||||
for (;;) {
|
||||
std::cout << "\n\t**Press any key to continue**" << std::endl;
|
||||
int input = std::cin.get();
|
||||
if (input == EOF) {
|
||||
std::cout << "EOF detected. Exiting." << std::endl;
|
||||
return;
|
||||
}
|
||||
char input_char = static_cast<char>(input);
|
||||
std::cout << "User entered: " << input_char << std::endl;
|
||||
if (input_char == '\n') {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ScopedFD::ScopedFD(const std::string& path, int flags)
|
||||
: fd_(open(path.c_str(), flags)), path_(path) {
|
||||
std::ostringstream ss;
|
||||
if (fd_ >= 0) {
|
||||
ss << __PRETTY_FUNCTION__ << " | Opened FD: " << fd_
|
||||
<< " for path: " << path_;
|
||||
LOG_INFO(ss);
|
||||
} else {
|
||||
ss << __PRETTY_FUNCTION__ << " | Failed to open file: " << path_
|
||||
<< " | Error: " << strerror(errno);
|
||||
LOG_ERROR(ss);
|
||||
}
|
||||
}
|
||||
|
||||
ScopedFD::~ScopedFD() {
|
||||
if (fd_ >= 0) {
|
||||
std::ostringstream ss;
|
||||
ss << __PRETTY_FUNCTION__ << " | Closing FD: " << fd_
|
||||
<< " for path: " << path_;
|
||||
LOG_INFO(ss);
|
||||
close(fd_);
|
||||
}
|
||||
}
|
||||
|
||||
ScopedFD::ScopedFD(ScopedFD&& other) noexcept
|
||||
: fd_(other.fd_), path_(std::move(other.path_)) {
|
||||
other.fd_ = -1;
|
||||
}
|
||||
|
||||
ScopedFD& ScopedFD::operator=(ScopedFD&& other) noexcept {
|
||||
if (this != &other) {
|
||||
if (fd_ >= 0) close(fd_);
|
||||
fd_ = other.fd_;
|
||||
path_ = std::move(other.path_);
|
||||
other.fd_ = -1;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
int ScopedFD::get() const {
|
||||
return fd_;
|
||||
}
|
||||
|
||||
bool ScopedFD::valid() const {
|
||||
return fd_ >= 0;
|
||||
}
|
||||
|
||||
ScopedFD::operator int() const {
|
||||
return fd_;
|
||||
}
|
||||
|
||||
int ScopedFD::operator*() const {
|
||||
return fd_;
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
#include "amd_smi/impl/scoped_fd.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
#include "rocm_smi/rocm_smi_logger.h"
|
||||
|
||||
ScopedFD::ScopedFD(const std::string& path, int flags)
|
||||
: fd_(open(path.c_str(), flags)), path_(path) {
|
||||
std::ostringstream ss;
|
||||
if (fd_ < 0) {
|
||||
ss << __PRETTY_FUNCTION__ << " | Failed to open file: " << path_
|
||||
<< " | Error: " << strerror(errno);
|
||||
LOG_ERROR(ss);
|
||||
}
|
||||
}
|
||||
|
||||
ScopedFD::~ScopedFD() {
|
||||
if (fd_ >= 0) {
|
||||
close(fd_);
|
||||
}
|
||||
}
|
||||
|
||||
ScopedFD::ScopedFD(ScopedFD&& other) noexcept : fd_(other.fd_), path_(std::move(other.path_)) {
|
||||
other.fd_ = -1;
|
||||
}
|
||||
|
||||
ScopedFD& ScopedFD::operator=(ScopedFD&& other) noexcept {
|
||||
if (this != &other) {
|
||||
if (fd_ >= 0) close(fd_);
|
||||
fd_ = other.fd_;
|
||||
path_ = std::move(other.path_);
|
||||
other.fd_ = -1;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
int ScopedFD::get() const { return fd_; }
|
||||
|
||||
bool ScopedFD::valid() const { return fd_ >= 0; }
|
||||
|
||||
ScopedFD::operator int() const { return fd_; }
|
||||
Reference in new issue
Block a user