DRM - Remove FD usage

Change-Id: I77dfa778ccd0d39a03289c2e11cf10357566ff16
Signed-off-by: Galantsev, Dmitrii <dmitrii.galantsev@amd.com>
This commit is contained in:
Galantsev, Dmitrii
2025-06-17 16:47:25 -05:00
committad av Arif, Maisam
förälder 202b46d96f
incheckning 9b5bbf555a
13 ändrade filer med 128 tillägg och 319 borttagningar
+1 -2
Visa fil
@@ -34,6 +34,7 @@
#include "amd_smi/impl/amd_smi_lib_loader.h"
#include "amd_smi/impl/amdgpu_drm.h"
#include "amd_smi/impl/xf86drm.h"
#include "amd_smi/impl/scoped_fd.h"
namespace amd {
namespace smi {
@@ -42,7 +43,6 @@ class AMDSmiDrm {
public:
amdsmi_status_t init();
amdsmi_status_t cleanup();
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();
@@ -54,7 +54,6 @@ class AMDSmiDrm {
// when file is not found, the empty string will be returned
std::string find_file_in_folder(const std::string& folder,
const std::string& regex);
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
uint32_t vendor_id;
+2 -4
Visa fil
@@ -46,8 +46,8 @@ enum class ComputeProcessListType_t : ComputeProcessListClassType_t
class AMDSmiGPUDevice: public AMDSmiProcessor {
public:
AMDSmiGPUDevice(uint32_t gpu_id, uint32_t fd, std::string path, amdsmi_bdf_t bdf, AMDSmiDrm& drm):
AMDSmiProcessor(AMDSMI_PROCESSOR_TYPE_AMD_GPU), gpu_id_(gpu_id), fd_(fd), path_(path), bdf_(bdf), drm_(drm) {}
AMDSmiGPUDevice(uint32_t gpu_id, std::string path, amdsmi_bdf_t bdf, AMDSmiDrm& drm):
AMDSmiProcessor(AMDSMI_PROCESSOR_TYPE_AMD_GPU), gpu_id_(gpu_id), path_(path), bdf_(bdf), drm_(drm) {}
AMDSmiGPUDevice(uint32_t gpu_id, AMDSmiDrm& drm):
AMDSmiProcessor(AMDSMI_PROCESSOR_TYPE_AMD_GPU), gpu_id_(gpu_id), drm_(drm) {
@@ -59,7 +59,6 @@ class AMDSmiGPUDevice: public AMDSmiProcessor {
amdsmi_status_t get_drm_data();
pthread_mutex_t* get_mutex();
uint32_t get_gpu_id() const;
uint32_t get_gpu_fd() const;
uint32_t get_card_id(); // -e feature + we can get card_id for our internal functions
uint32_t get_drm_render_minor(); // -e feature + we can get card_id for our internal functions
uint64_t get_kfd_gpu_id(); // Used to decode vram usage for KFD processes
@@ -76,7 +75,6 @@ class AMDSmiGPUDevice: public AMDSmiProcessor {
private:
uint32_t gpu_id_;
uint32_t fd_;
std::string path_;
amdsmi_bdf_t bdf_;
uint32_t vendor_id_;
-42
Visa fil
@@ -60,20 +60,6 @@ std::string smi_amdgpu_get_status_string(amdsmi_status_t ret, bool fullStatus);
amdsmi_status_t smi_clear_char_and_reinitialize(char buffer[], uint32_t len,
std::string newString);
/**
* @brief Wait for user input, a debugging function to pause the program
*
* @details This function will wait for user input before continuing.
* It is useful for debugging purposes to allow the user to inspect the state of the program
* before it continues. The function will print a message to the console and then wait for
* the user to press Enter. Once Enter is pressed, the function will return and the program
* will continue executing.
*
* @note This function is intended for debugging purposes only and should not be used in production code.
* It will block the program execution and cause it to wait indefinitely for user input.
*/
void amdsmi_wait_for_user_input(void);
/**
* @brief Get the device index given the processor handle.
*
@@ -188,31 +174,3 @@ void fill_2d_array(A& arr, T value) {
}
#endif // AMD_SMI_INCLUDE_AMD_SMI_UTILS_H_
#ifndef SCOPED_FD_H
#define SCOPED_FD_H
class ScopedFD {
private:
int fd_;
std::string path_;
public:
ScopedFD(const std::string& path, int flags);
~ScopedFD();
// Non-copyable
ScopedFD(const ScopedFD&) = delete;
ScopedFD& operator=(const ScopedFD&) = delete;
// Movable
ScopedFD(ScopedFD&& other) noexcept;
ScopedFD& operator=(ScopedFD&& other) noexcept;
int get() const;
bool valid() const;
operator int() const; // Allows direct use as int
int operator*() const; // Allows *fd usage like your current code
};
#endif // SCOPED_FD_H
+52
Visa fil
@@ -0,0 +1,52 @@
/*
* Copyright (c) Advanced Micro Devices, Inc. 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_IMPL_SCOPED_FD_H_
#define AMD_SMI_INCLUDE_IMPL_SCOPED_FD_H_
#include <unistd.h>
#include <string>
class ScopedFD {
private:
int fd_;
std::string path_;
public:
ScopedFD(const std::string& path, int flags);
~ScopedFD();
// Non-copyable
ScopedFD(const ScopedFD&) = delete;
ScopedFD& operator=(const ScopedFD&) = delete;
// Movable
ScopedFD(ScopedFD&& other) noexcept;
ScopedFD& operator=(ScopedFD&& other) noexcept;
int get() const;
bool valid() const;
operator int() const; // Allows direct use as int
};
#endif // AMD_SMI_INCLUDE_IMPL_SCOPED_FD_H_