Files
rocm-systems/include/amd_smi/impl/amd_smi_drm.h
T
Poag, Charis b5a43b7744 [SWDEV-528647/SWDEV-528450] Reduce API load times and libdrm/libdrm_amdgpu dynamic loading (#333)
Changes:
- Removed libdrm/libdrm_amdgpu dependencies
- Added/updated new internal libdrm/libdrm_amdgpu/xf86drm APIs
  to allow our APIs to reference before dynamic loading
  the libdrm/libdrm_amdgpu libraries:
  1. amdgpu_drm.h to what's seen in mainline
  2. Added xf86drm.h to whats seen in mainline
- Modified internal DRM capabilities:
  1. Require each API to independently connect to libdrm/libdrm_amdgpu
     + validate API handles reponses accordingly
  2. Initialization of AMD SMI no longer has as strong of a tie to
     libdrm
- Updated internal implementations of several APIs which have
connections to libdrm/libdrm_amdgpu or APIs which have conflicts
with open libdrm/libdrm_amdgpu connections:
  1. amdsmi_init()
  2. amdsmi_get_gpu_vram_usage()
  3. amdsmi_get_gpu_asic_info()
  4. amdsmi_get_gpu_vram_info()
  5. amdsmi_get_gpu_vbios_info()
  6. amdsmi_get_gpu_driver_info()
  7. amdsmi_get_gpu_virtualization_mode()
  8. amdsmi_set_gpu_memory_partition()
  9. amdsmi_set_gpu_memory_partition_mode()
- Cleaned up effected tests/APIs

Change-Id: I96e2cf1b06b0cfee1b01a5e991ccc6116c4245a8
2025-05-02 21:58:53 -05:00

72 rivejä
2.6 KiB
C++

/*
* 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_AMD_SMI_DRM_H_
#define AMD_SMI_INCLUDE_IMPL_AMD_SMI_DRM_H_
#include <unistd.h>
#include <vector>
#include <memory>
#include <mutex> // NOLINT
#include <string>
#include "amd_smi/amdsmi.h"
#include "amd_smi/impl/amd_smi_lib_loader.h"
#include "amd_smi/impl/amdgpu_drm.h"
#include "amd_smi/impl/xf86drm.h"
namespace amd {
namespace smi {
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();
std::vector<std::string>& get_drm_paths();
bool check_if_drm_is_supported();
uint32_t get_vendor_id();
private:
// 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;
AMDSmiLibraryLoader lib_loader_; // lazy load libdrm
std::mutex drm_mutex_;
};
} // namespace smi
} // namespace amd
#endif // AMD_SMI_INCLUDE_IMPL_AMD_SMI_DRM_H_