SWDEV-353742 - Port smilib function to amdsmi
Change-Id: I99df249755a5c665a8dd1777fa82d046e139bd77
Signed-off-by: Dalibor Stanisavljevic <Dalibor.Stanisavljevic@amd.com>
[ROCm/amdsmi commit: 3daf9c1063]
This commit is contained in:
committed by
Bill(Shuzhou) Liu
parent
cf09c187f1
commit
bd4ff14bd0
@@ -58,7 +58,13 @@ class AMDSmiDrm {
|
||||
public:
|
||||
amdsmi_status_t init();
|
||||
amdsmi_status_t cleanup();
|
||||
int get_drm_fd_by_index(uint32_t gpu_index) const;
|
||||
amdsmi_status_t get_drm_fd_by_index(uint32_t gpu_index, uint32_t *fd_info) const;
|
||||
amdsmi_status_t get_bdf_by_index(uint32_t gpu_index, amdsmi_bdf_t *bdf_info) const;
|
||||
amdsmi_status_t get_drm_path_by_index(uint32_t gpu_index, std::string *drm_path) const;
|
||||
std::vector<amdsmi_bdf_t> get_bdfs();
|
||||
std::vector<std::string>& get_drm_paths();
|
||||
bool check_if_drm_is_supported();
|
||||
|
||||
amdsmi_status_t amdgpu_query_info(int fd, unsigned info_id,
|
||||
unsigned size, void *value);
|
||||
amdsmi_status_t amdgpu_query_fw(int fd, unsigned info_id, unsigned fw_type,
|
||||
@@ -70,6 +76,9 @@ class AMDSmiDrm {
|
||||
private:
|
||||
using DrmCmdWriteFunc = int (*)(int, unsigned long, void *, unsigned long);
|
||||
std::vector<int> drm_fds_; // drm file descriptor by gpu_index
|
||||
std::vector<std::string> drm_paths_; // drm path (renderD128 for example)
|
||||
std::vector<amdsmi_bdf_t> drm_bdfs_; // bdf
|
||||
|
||||
AMDSmiLibraryLoader lib_loader_; // lazy load libdrm
|
||||
DrmCmdWriteFunc drm_cmd_write_; // drmCommandWrite
|
||||
std::mutex drm_mutex_;
|
||||
|
||||
@@ -47,16 +47,32 @@
|
||||
#include "amd_smi/amd_smi.h"
|
||||
#include "amd_smi/impl/amd_smi_device.h"
|
||||
#include "amd_smi/impl/amd_smi_drm.h"
|
||||
#include "shared_mutex.h" // NOLINT
|
||||
|
||||
namespace amd {
|
||||
namespace smi {
|
||||
|
||||
class AMDSmiGPUDevice: public AMDSmiDevice {
|
||||
public:
|
||||
explicit AMDSmiGPUDevice(uint32_t gpu_id, AMDSmiDrm& drm):
|
||||
AMDSmiDevice(AMD_GPU), gpu_id_(gpu_id), drm_(drm) {}
|
||||
AMDSmiGPUDevice(uint32_t gpu_id, uint32_t fd, std::string path, amdsmi_bdf_t bdf, AMDSmiDrm& drm):
|
||||
AMDSmiDevice(AMD_GPU), gpu_id_(gpu_id), fd_(fd), path_(path), bdf_(bdf), drm_(drm) {}
|
||||
|
||||
AMDSmiGPUDevice(uint32_t gpu_id, AMDSmiDrm& drm):
|
||||
AMDSmiDevice(AMD_GPU), gpu_id_(gpu_id), drm_(drm) {
|
||||
if (check_if_drm_is_supported()) this->get_drm_data();
|
||||
}
|
||||
~AMDSmiGPUDevice() {
|
||||
if (check_if_drm_is_supported()) shared_mutex_close(mutex_);
|
||||
}
|
||||
|
||||
amdsmi_status_t get_drm_data();
|
||||
pthread_mutex_t* get_mutex();
|
||||
uint32_t get_gpu_id() const;
|
||||
uint32_t get_gpu_fd() const;
|
||||
std::string& get_gpu_path();
|
||||
amdsmi_bdf_t get_bdf();
|
||||
bool check_if_drm_is_supported() { return drm_.check_if_drm_is_supported(); }
|
||||
|
||||
amdsmi_status_t amdgpu_query_info(unsigned info_id,
|
||||
unsigned size, void *value) const;
|
||||
amdsmi_status_t amdgpu_query_hw_ip(unsigned info_id, unsigned hw_ip_type,
|
||||
@@ -66,7 +82,11 @@ class AMDSmiGPUDevice: public AMDSmiDevice {
|
||||
amdsmi_status_t amdgpu_query_vbios(void *info) const;
|
||||
private:
|
||||
uint32_t gpu_id_;
|
||||
uint32_t fd_;
|
||||
std::string path_;
|
||||
amdsmi_bdf_t bdf_;
|
||||
AMDSmiDrm& drm_;
|
||||
shared_mutex_t mutex_;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -60,6 +60,7 @@ class AMDSmiSocket {
|
||||
const std::string& get_socket_id() const { return socket_identifier_;}
|
||||
void add_device(AMDSmiDevice* device) { devices_.push_back(device); }
|
||||
std::vector<AMDSmiDevice*>& get_devices() { return devices_;}
|
||||
amdsmi_status_t get_device_count(uint32_t* device_count) const;
|
||||
private:
|
||||
std::string socket_identifier_;
|
||||
std::vector<AMDSmiDevice*> devices_;
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/* * Copyright (C) 2022 Advanced Micro Devices. All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* 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:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* 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 AUTHORS 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 IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef AMD_SMI_INCLUDE_AMD_SMI_UTILS_H_
|
||||
#define AMD_SMI_INCLUDE_AMD_SMI_UTILS_H_
|
||||
|
||||
#include "amd_smi/amd_smi.h"
|
||||
#include "amd_smi/impl/amd_smi_gpu_device.h"
|
||||
#include "rocm_smi/rocm_smi_utils.h"
|
||||
|
||||
|
||||
#define SMIGPUDEVICE_MUTEX(MUTEX) \
|
||||
amd::smi::pthread_wrap _pw(*(MUTEX)); \
|
||||
amd::smi::ScopedPthread _lock(_pw, true); \
|
||||
if (_lock.mutex_not_acquired()) { \
|
||||
return AMDSMI_STATUS_BUSY; \
|
||||
}
|
||||
|
||||
amdsmi_status_t smi_amdgpu_find_hwmon_dir(amd::smi::AMDSmiGPUDevice* device, std::string* full_path);
|
||||
amdsmi_status_t smi_amdgpu_get_board_info(amd::smi::AMDSmiGPUDevice* device, amdsmi_board_info_t *info);
|
||||
amdsmi_status_t smi_amdgpu_get_power_cap(amd::smi::AMDSmiGPUDevice* device, int *cap);
|
||||
amdsmi_status_t smi_amdgpu_get_ranges(amd::smi::AMDSmiGPUDevice* device, amdsmi_clk_type_t domain, int *max_freq, int *min_freq, int *num_dpm);
|
||||
amdsmi_status_t smi_amdgpu_get_enabled_blocks(amd::smi::AMDSmiGPUDevice* device, uint64_t *enabled_blocks);
|
||||
amdsmi_status_t smi_amdgpu_get_bad_page_info(amd::smi::AMDSmiGPUDevice* device, uint32_t *num_pages, amdsmi_retired_page_record_t *info);
|
||||
amdsmi_status_t smi_amdgpu_get_ecc_error_count(amd::smi::AMDSmiGPUDevice* device, amdsmi_error_count_t *err_cnt);
|
||||
|
||||
#endif //
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2022 Advanced Micro Devices, Inc.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in 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:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* 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 COPYRIGHT HOLDER(S) OR AUTHOR(S) 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 IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __FDINFO__
|
||||
#define __FDINFO__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
amdsmi_status_t gpuvsmi_get_pids(const amdsmi_bdf_t &bdf, std::vector<long int> &pids, uint64_t *size);
|
||||
amdsmi_status_t gpuvsmi_get_pid_info(const amdsmi_bdf_t &bdf, long int pid, amdsmi_proc_info_t &info);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user