Restructure the folder

Move rocm_smi related function to rocm_smi folder. Move amd_smi to
top level include/ and src/ folder. Remove obsolte oam folder.
Change the CMakeLists.txt to update folder locations.

Change-Id: I52e6be739e49f3b0545865f25364787f5985e9c3
This commit is contained in:
Bill(Shuzhou) Liu
2022-09-20 14:57:30 -04:00
parent 1ec3a2182e
commit 0c91ef919d
98 changed files with 177 additions and 1715 deletions
File diff suppressed because it is too large Load Diff
+52
View File
@@ -0,0 +1,52 @@
/*
* =============================================================================
* The University of Illinois/NCSA
* Open Source License (NCSA)
*
* Copyright (c) 2022, Advanced Micro Devices, Inc.
* All rights reserved.
*
* Developed by:
*
* AMD Research and AMD ROC Software Development
*
* Advanced Micro Devices, Inc.
*
* www.amd.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal with the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimers.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimers in
* the documentation and/or other materials provided with the distribution.
* - Neither the names of <Name of Development Group, Name of Institution>,
* nor the names of its contributors may be used to endorse or promote
* products derived from this Software without specific prior written
* permission.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS WITH THE SOFTWARE.
*
*/
#include <functional>
#include "amd_smi/impl/amd_smi_common.h"
namespace amd {
namespace smi {
} // namespace smi
} // namespace amd
+200
View File
@@ -0,0 +1,200 @@
/*
* =============================================================================
* The University of Illinois/NCSA
* Open Source License (NCSA)
*
* Copyright (c) 2022, Advanced Micro Devices, Inc.
* All rights reserved.
*
* Developed by:
*
* AMD Research and AMD ROC Software Development
*
* Advanced Micro Devices, Inc.
*
* www.amd.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal with the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimers.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimers in
* the documentation and/or other materials provided with the distribution.
* - Neither the names of <Name of Development Group, Name of Institution>,
* nor the names of its contributors may be used to endorse or promote
* products derived from this Software without specific prior written
* permission.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS WITH THE SOFTWARE.
*
*/
#include <sys/types.h>
#include <dirent.h>
#include <fcntl.h>
#include <unistd.h>
#include <xf86drm.h>
#include <string.h>
#include <memory>
#include "amd_smi/impl/amd_smi_drm.h"
#include "amd_smi/impl/amdgpu_drm.h"
namespace amd {
namespace smi {
amdsmi_status_t AMDSmiDrm::init() {
// A few RAII handler
using dir_ptr = std::unique_ptr<DIR, decltype(&closedir)>;
using drm_version_ptr = std::unique_ptr<drmVersion,
decltype(&drmFreeVersion)>;
struct dirent *dir = nullptr;
int fd = -1;
amdsmi_status_t status = lib_loader_.load("libdrm.so");
if (status != AMDSMI_STATUS_SUCCESS) {
return status;
}
// load symbol from libdrm
drm_cmd_write_ = nullptr;
status = lib_loader_.load_symbol(&drm_cmd_write_, "drmCommandWrite");
if (status != AMDSMI_STATUS_SUCCESS) {
return status;
}
using drmGetVersionType = drmVersionPtr (*)(int); // drmGetVersion
using drmFreeVersionType = void (*)(drmVersionPtr); // drmFreeVersion
drmGetVersionType drm_get_version = nullptr;
drmFreeVersionType drm_free_version = nullptr;
status = lib_loader_.load_symbol(&drm_get_version, "drmGetVersion");
if (status != AMDSMI_STATUS_SUCCESS) {
return status;
}
status = lib_loader_.load_symbol(&drm_free_version, "drmFreeVersion");
if (status != AMDSMI_STATUS_SUCCESS) {
return status;
}
auto d = dir_ptr(opendir("/dev/dri/"), &closedir);
if (d == nullptr) return AMDSMI_STATUS_NOT_INIT;
while ((dir = readdir(d.get())) != NULL) {
char* name_cstr = new char[sizeof(dir->d_name) + 10];
auto name = std::unique_ptr<char[]>(name_cstr);
snprintf(name.get(), sizeof(dir->d_name) + 10,
"/dev/dri/%s", dir->d_name);
fd = open(name.get(), O_RDWR | O_CLOEXEC);
if (fd < 0) continue;
auto version = drm_version_ptr(drm_get_version(fd), drm_free_version);
if (strcmp("amdgpu", version->name) ||
strstr(name.get(), "render") == nullptr) {
close(fd);
continue;
}
drm_fds_.push_back(fd);
}
return AMDSMI_STATUS_SUCCESS;
}
amdsmi_status_t AMDSmiDrm::cleanup() {
for (unsigned int i=0; i < drm_fds_.size(); i++) {
close(drm_fds_[i]);
}
drm_fds_.clear();
lib_loader_.unload();
return AMDSMI_STATUS_SUCCESS;
}
amdsmi_status_t AMDSmiDrm::amdgpu_query_info(int fd, unsigned info_id,
unsigned size, void *value) {
if (drm_cmd_write_ == nullptr) return AMDSMI_STATUS_NOT_SUPPORTED;
std::lock_guard<std::mutex> guard(drm_mutex_);
struct drm_amdgpu_info request;
memset(&request, 0, sizeof(request));
request.return_pointer = (uintptr_t)value;
request.return_size = size;
request.query = info_id;
int status = drm_cmd_write_(fd, DRM_AMDGPU_INFO,
&request, sizeof(struct drm_amdgpu_info));
if (status == 0) return AMDSMI_STATUS_SUCCESS;
return AMDSMI_STATUS_DRM_ERROR;
}
amdsmi_status_t AMDSmiDrm::amdgpu_query_fw(int fd, unsigned info_id,
unsigned fw_type, unsigned size, void *value) {
if (drm_cmd_write_ == nullptr) return AMDSMI_STATUS_NOT_SUPPORTED;
std::lock_guard<std::mutex> guard(drm_mutex_);
struct drm_amdgpu_info request;
memset(&request, 0, sizeof(request));
request.return_pointer = (uintptr_t)value;
request.return_size = size;
request.query = info_id;
request.query_fw.fw_type = fw_type;
int status = drm_cmd_write_(fd, DRM_AMDGPU_INFO, &request,
sizeof(struct drm_amdgpu_info));
if (status == 0) return AMDSMI_STATUS_SUCCESS;
return AMDSMI_STATUS_DRM_ERROR;
}
amdsmi_status_t AMDSmiDrm::amdgpu_query_hw_ip(int fd, unsigned info_id,
unsigned hw_ip_type, unsigned size, void *value) {
if (drm_cmd_write_ == nullptr) return AMDSMI_STATUS_NOT_SUPPORTED;
std::lock_guard<std::mutex> guard(drm_mutex_);
struct drm_amdgpu_info request;
memset(&request, 0, sizeof(request));
request.return_pointer = (uintptr_t)value;
request.return_size = size;
request.query = info_id;
request.query_hw_ip.type = hw_ip_type;
int status = drm_cmd_write_(fd, DRM_AMDGPU_INFO, &request,
sizeof(struct drm_amdgpu_info));
if (status == 0) return AMDSMI_STATUS_SUCCESS;
return AMDSMI_STATUS_DRM_ERROR;
}
amdsmi_status_t AMDSmiDrm::amdgpu_query_vbios(int fd, void *info) {
if (drm_cmd_write_ == nullptr) return AMDSMI_STATUS_NOT_SUPPORTED;
std::lock_guard<std::mutex> guard(drm_mutex_);
struct drm_amdgpu_info request;
memset(&request, 0, sizeof request);
request.return_pointer = (uint64_t) info;
request.return_size = sizeof(drm_amdgpu_info_vbios);
request.query = AMDGPU_INFO_VBIOS;
request.vbios_info.type = AMDGPU_INFO_VBIOS_INFO;
int status = drm_cmd_write_(fd, DRM_AMDGPU_INFO, &request,
sizeof(struct drm_amdgpu_info));
if (status == 0) return AMDSMI_STATUS_SUCCESS;
return AMDSMI_STATUS_DRM_ERROR;
}
int AMDSmiDrm::get_drm_fd_by_index(uint32_t gpu_index) const {
if (gpu_index + 1 > drm_fds_.size()) return -1;
return drm_fds_[gpu_index];
}
} // namespace smi
} // namespace amd
+88
View File
@@ -0,0 +1,88 @@
/*
* =============================================================================
* The University of Illinois/NCSA
* Open Source License (NCSA)
*
* Copyright (c) 2022, Advanced Micro Devices, Inc.
* All rights reserved.
*
* Developed by:
*
* AMD Research and AMD ROC Software Development
*
* Advanced Micro Devices, Inc.
*
* www.amd.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal with the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimers.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimers in
* the documentation and/or other materials provided with the distribution.
* - Neither the names of <Name of Development Group, Name of Institution>,
* nor the names of its contributors may be used to endorse or promote
* products derived from this Software without specific prior written
* permission.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS WITH THE SOFTWARE.
*
*/
#include <functional>
#include "amd_smi/impl/amd_smi_gpu_device.h"
namespace amd {
namespace smi {
uint32_t AMDSmiGPUDevice::get_gpu_id() const {
return gpu_id_;
}
amdsmi_status_t AMDSmiGPUDevice::amdgpu_query_info(unsigned info_id,
unsigned size, void *value) const {
int fd = drm_.get_drm_fd_by_index(gpu_id_);
if (fd == -1) return AMDSMI_STATUS_NOT_SUPPORTED;
return drm_.amdgpu_query_info(fd, info_id, size, value);
}
amdsmi_status_t AMDSmiGPUDevice::amdgpu_query_hw_ip(unsigned info_id,
unsigned hw_ip_type, unsigned size, void *value) const {
int fd = drm_.get_drm_fd_by_index(gpu_id_);
if (fd == -1) return AMDSMI_STATUS_NOT_SUPPORTED;
return drm_.amdgpu_query_hw_ip(fd, info_id, hw_ip_type, size, value);
}
amdsmi_status_t AMDSmiGPUDevice::amdgpu_query_fw(unsigned info_id,
unsigned fw_type, unsigned size, void *value) const {
int fd = drm_.get_drm_fd_by_index(gpu_id_);
if (fd == -1) return AMDSMI_STATUS_NOT_SUPPORTED;
return drm_.amdgpu_query_fw(fd, info_id, fw_type, size, value);
}
amdsmi_status_t AMDSmiGPUDevice::amdgpu_query_vbios(void *info) const {
int fd = drm_.get_drm_fd_by_index(gpu_id_);
if (fd == -1) return AMDSMI_STATUS_NOT_SUPPORTED;
return drm_.amdgpu_query_vbios(fd, info);
}
} // namespace smi
} // namespace amd
+87
View File
@@ -0,0 +1,87 @@
/*
* =============================================================================
* The University of Illinois/NCSA
* Open Source License (NCSA)
*
* Copyright (c) 2022, Advanced Micro Devices, Inc.
* All rights reserved.
*
* Developed by:
*
* AMD Research and AMD ROC Software Development
*
* Advanced Micro Devices, Inc.
*
* www.amd.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal with the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimers.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimers in
* the documentation and/or other materials provided with the distribution.
* - Neither the names of <Name of Development Group, Name of Institution>,
* nor the names of its contributors may be used to endorse or promote
* products derived from this Software without specific prior written
* permission.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS WITH THE SOFTWARE.
*
*/
#include "amd_smi/impl/amd_smi_lib_loader.h"
#include <iostream>
namespace amd {
namespace smi {
AMDSmiLibraryLoader::AMDSmiLibraryLoader(): libHandler_(nullptr) {
}
amdsmi_status_t AMDSmiLibraryLoader::load(const char* filename) {
if (filename == nullptr) {
return AMDSMI_STATUS_FAIL_LOAD_MODULE;
}
if (libHandler_) {
unload();
}
std::lock_guard<std::mutex> guard(library_mutex_);
libHandler_ = dlopen(filename, RTLD_LAZY);
if (!libHandler_) {
char* error = dlerror();
std::cerr << "Fail to open " << filename <<": " << error
<< std::endl;
return AMDSMI_STATUS_FAIL_LOAD_MODULE;
}
return AMDSMI_STATUS_SUCCESS;
}
amdsmi_status_t AMDSmiLibraryLoader::unload() {
std::lock_guard<std::mutex> guard(library_mutex_);
if (libHandler_) {
dlclose(libHandler_);
libHandler_ = nullptr;
}
return AMDSMI_STATUS_SUCCESS;
}
AMDSmiLibraryLoader::~AMDSmiLibraryLoader() {
unload();
}
} // namespace rdc
} // namespace amd
+60
View File
@@ -0,0 +1,60 @@
/*
* =============================================================================
* The University of Illinois/NCSA
* Open Source License (NCSA)
*
* Copyright (c) 2022, Advanced Micro Devices, Inc.
* All rights reserved.
*
* Developed by:
*
* AMD Research and AMD ROC Software Development
*
* Advanced Micro Devices, Inc.
*
* www.amd.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal with the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimers.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimers in
* the documentation and/or other materials provided with the distribution.
* - Neither the names of <Name of Development Group, Name of Institution>,
* nor the names of its contributors may be used to endorse or promote
* products derived from this Software without specific prior written
* permission.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS WITH THE SOFTWARE.
*
*/
#include <functional>
#include "amd_smi/impl/amd_smi_socket.h"
namespace amd {
namespace smi {
AMDSmiSocket::~AMDSmiSocket() {
for (uint32_t i = 0; i < devices_.size(); i++) {
delete devices_[i];
}
devices_.clear();
}
} // namespace smi
} // namespace amd
+185
View File
@@ -0,0 +1,185 @@
/*
* =============================================================================
* The University of Illinois/NCSA
* Open Source License (NCSA)
*
* Copyright (c) 2022, Advanced Micro Devices, Inc.
* All rights reserved.
*
* Developed by:
*
* AMD Research and AMD ROC Software Development
*
* Advanced Micro Devices, Inc.
*
* www.amd.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal with the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimers.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimers in
* the documentation and/or other materials provided with the distribution.
* - Neither the names of <Name of Development Group, Name of Institution>,
* nor the names of its contributors may be used to endorse or promote
* products derived from this Software without specific prior written
* permission.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS WITH THE SOFTWARE.
*
*/
#include <sstream>
#include <iomanip>
#include "amd_smi/impl/amd_smi_system.h"
#include "amd_smi/impl/amd_smi_gpu_device.h"
#include "rocm_smi/rocm_smi.h"
namespace amd {
namespace smi {
#define AMD_SMI_INIT_FLAG_RESRV_TEST1 0x800000000000000 //!< Reserved for test
amdsmi_status_t AMDSmiSystem::init(uint64_t flags) {
init_flag_ = flags;
// populate sockets and devices
if (flags & AMDSMI_INIT_AMD_GPUS) {
drm_.init();
// init rsmi
rsmi_status_t ret = rsmi_init(flags);
if (ret != RSMI_STATUS_SUCCESS) {
return static_cast<amdsmi_status_t>(ret);
}
uint32_t device_count = 0;
ret = rsmi_num_monitor_devices(&device_count);
if (ret != RSMI_STATUS_SUCCESS) {
return static_cast<amdsmi_status_t>(ret);
}
for (uint32_t i=0; i < device_count; i++) {
uint64_t bdfid = 0;
ret = rsmi_dev_pci_id_get(i, &bdfid);
if (ret != RSMI_STATUS_SUCCESS) {
return static_cast<amdsmi_status_t>(ret);
}
uint64_t domain = (bdfid >> 32) & 0xffffffff;
uint64_t bus = (bdfid >> 8) & 0xff;
uint64_t device_id = (bdfid >> 3) & 0x1f;
uint64_t function = bdfid & 0x7;
std::stringstream ss;
ss << std::setfill('0') << std::uppercase << std::hex
<< std::setw(4) << domain << ":" << std::setw(2) << bus << ":"
<< std::setw(2) << device_id << "." << std::setw(2) << function;
// Multiple devices may share the same socket
auto socket_id = ss.str();
AMDSmiSocket* socket = nullptr;
for (unsigned int j=0; j < sockets_.size(); j++) {
if (sockets_[j]->get_socket_id() == socket_id) {
socket = sockets_[j];
break;
}
}
if (socket == nullptr) {
socket = new AMDSmiSocket(ss.str());
sockets_.push_back(socket);
}
AMDSmiDevice* device = new AMDSmiGPUDevice(i, drm_);
socket->add_device(device);
devices_.insert(device);
}
} else {
return AMDSMI_STATUS_NOT_SUPPORTED;
}
return AMDSMI_STATUS_SUCCESS;
}
amdsmi_status_t AMDSmiSystem::cleanup() {
for (uint32_t i = 0; i < sockets_.size(); i++) {
delete sockets_[i];
}
devices_.clear();
sockets_.clear();
init_flag_ = AMDSMI_INIT_ALL_DEVICES;
rsmi_status_t ret = rsmi_shut_down();
if (ret != RSMI_STATUS_SUCCESS) {
return static_cast<amdsmi_status_t>(ret);
}
drm_.cleanup();
return AMDSMI_STATUS_SUCCESS;
}
amdsmi_status_t AMDSmiSystem::handle_to_socket(
amdsmi_socket_handle socket_handle,
AMDSmiSocket** socket) {
if (socket_handle == nullptr || socket == nullptr) {
return AMDSMI_STATUS_INVAL;
}
*socket = static_cast<AMDSmiSocket*>(socket_handle);
// double check handlers is here
if (std::find(sockets_.begin(), sockets_.end(), *socket)
!= sockets_.end()) {
return AMDSMI_STATUS_SUCCESS;
}
return AMDSMI_STATUS_INVAL;
}
amdsmi_status_t AMDSmiSystem::handle_to_device(
amdsmi_device_handle device_handle,
AMDSmiDevice** device) {
if (device_handle == nullptr || device == nullptr) {
return AMDSMI_STATUS_INVAL;
}
*device = static_cast<AMDSmiDevice*>(device_handle);
// double check handlers is here
if (std::find(devices_.begin(), devices_.end(), *device)
!= devices_.end()) {
return AMDSMI_STATUS_SUCCESS;
}
return AMDSMI_STATUS_INVAL;
}
amdsmi_status_t AMDSmiSystem::gpu_index_to_handle(uint32_t gpu_index,
amdsmi_device_handle* device_handle) {
if (device_handle == nullptr)
return AMDSMI_STATUS_INVAL;
auto iter = devices_.begin();
for (; iter != devices_.end(); iter++) {
auto cur_device = (*iter);
if (cur_device->get_device_type() != AMD_GPU)
continue;
amd::smi::AMDSmiGPUDevice* gpu_device =
static_cast<amd::smi::AMDSmiGPUDevice*>(cur_device);
uint32_t cur_gpu_index = gpu_device->get_gpu_id();
if (gpu_index == cur_gpu_index) {
*device_handle = cur_device;
return AMDSMI_STATUS_SUCCESS;
}
}
return AMDSMI_STATUS_INVAL;
}
} // namespace smi
} // namespace amd