Add functions that are used to query Hardware topology.

Change-Id: I0f4cd02b237bde4d6dccfb0e83e65376ecb1cfaa
Signed-off-by: Mike Li <Tianxinmike.Li@amd.com>
This commit is contained in:
Mike Li
2020-05-07 11:37:14 -07:00
committed by Mike (Tianxin) Li
parent f8d623cb44
commit c7d349183a
12 changed files with 1190 additions and 1 deletions
+90
View File
@@ -522,6 +522,17 @@ typedef enum {
RSMI_MEM_PAGE_STATUS_UNRESERVABLE //!< Unable to reserve this page
} rsmi_memory_page_status_t;
/**
* @brief Types for IO Link
*/
typedef enum _RSMI_IO_LINK_TYPE {
RSMI_IOLINK_TYPE_UNDEFINED = 0, //!< unknown type.
RSMI_IOLINK_TYPE_PCIEXPRESS = 1, //!< PCI Express
RSMI_IOLINK_TYPE_XGMI = 2, //!< XGMI
RSMI_IOLINK_TYPE_NUMIOLINKTYPES, //!< Number of IO Link types
RSMI_IOLINK_TYPE_SIZE = 0xFFFFFFFF //!< Max of IO Link types
} RSMI_IO_LINK_TYPE;
/**
* @brief Reserved Memory Page Record
*/
@@ -2615,6 +2626,85 @@ rsmi_dev_xgmi_error_reset(uint32_t dv_ind);
/** @} */ // end of SysInfo
/*****************************************************************************/
/** @defgroup HWTopo Hardware Topology Functions
* These functions are used to query Hardware topology.
* @{
*/
/**
* @brief Retrieve the NUMA CPU node number for a device
*
* @details Given a device index @p dv_ind, and a pointer to an
* uint32_t @p numa_node, this function will write the
* node number of NUMA CPU for the device @p dv_ind to the memory
* pointed to by @p numa_node.
*
* @param[in] dv_ind a device index
*
* @param[inout] numa_node A pointer to an uint32_t to which the
* numa node number should be written.
*
* @retval ::RSMI_STATUS_SUCCESS call was successful
* @retval ::RSMI_STATUS_INVALID_ARGS the provided arguments are not valid
*
*/
rsmi_status_t
rsmi_topo_get_numa_node_number(uint32_t dv_ind, uint32_t *numa_node);
/**
* @brief Retrieve the weight for a connection between 2 GPUs
*
* @details Given a source device index @p dv_ind_src and
* a destination device index @p dv_ind_dst, and a pointer to an
* uint64_t @p weight, this function will write the
* weight for the connection between the device @p dv_ind_src
* and @p dv_ind_dst to the memory pointed to by @p weight.
*
* @param[in] dv_ind_src the source device index
*
* @param[in] dv_ind_dst the destination device index
*
* @param[inout] weight A pointer to an uint64_t to which the
* weight for the connection should be written.
*
* @retval ::RSMI_STATUS_SUCCESS call was successful
* @retval ::RSMI_STATUS_INVALID_ARGS the provided arguments are not valid
*
*/
rsmi_status_t
rsmi_topo_get_link_weight(uint32_t dv_ind_src, uint32_t dv_ind_dst,
uint64_t *weight);
/**
* @brief Retrieve the hops and the connection type between 2 GPUs
*
* @details Given a source device index @p dv_ind_src and
* a destination device index @p dv_ind_dst, and a pointer to an
* uint64_t @p hops and a pointer to an RSMI_IO_LINK_TYPE @p type,
* this function will write the number of hops and the connection type
* between the device @p dv_ind_src and @p dv_ind_dst to the memory
* pointed to by @p hops and @p type.
*
* @param[in] dv_ind_src the source device index
*
* @param[in] dv_ind_dst the destination device index
*
* @param[inout] hops A pointer to an uint64_t to which the
* hops for the connection should be written.
*
* @param[inout] type A pointer to an ::RSMI_IO_LINK_TYPE to which the
* type for the connection should be written.
*
* @retval ::RSMI_STATUS_SUCCESS call was successful
* @retval ::RSMI_STATUS_INVALID_ARGS the provided arguments are not valid
*
*/
rsmi_status_t
rsmi_topo_get_link_type(uint32_t dv_ind_src, uint32_t dv_ind_dst,
uint64_t *hops, RSMI_IO_LINK_TYPE *type);
/** @} */ // end of HWTopo
/*****************************************************************************/
/** @defgroup APISupport Supported Functions
+116
View File
@@ -0,0 +1,116 @@
/*
* =============================================================================
* The University of Illinois/NCSA
* Open Source License (NCSA)
*
* Copyright (c) 2020, 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.
*
*/
#ifndef INCLUDE_ROCM_SMI_ROCM_SMI_IO_LINK_H_
#define INCLUDE_ROCM_SMI_ROCM_SMI_IO_LINK_H_
#include <string>
#include <vector>
#include <unordered_set>
#include <memory>
#include <map>
#include "rocm_smi/rocm_smi.h"
namespace amd {
namespace smi {
typedef enum _IO_LINK_TYPE {
IOLINK_TYPE_UNDEFINED = 0,
IOLINK_TYPE_HYPERTRANSPORT = 1,
IOLINK_TYPE_PCIEXPRESS = 2,
IOLINK_TYPE_AMBA = 3,
IOLINK_TYPE_MIPI = 4,
IOLINK_TYPE_QPI_1_1 = 5,
IOLINK_TYPE_RESERVED1 = 6,
IOLINK_TYPE_RESERVED2 = 7,
IOLINK_TYPE_RAPID_IO = 8,
IOLINK_TYPE_INFINIBAND = 9,
IOLINK_TYPE_RESERVED3 = 10,
IOLINK_TYPE_XGMI = 11,
IOLINK_TYPE_XGOP = 12,
IOLINK_TYPE_GZ = 13,
IOLINK_TYPE_ETHERNET_RDMA = 14,
IOLINK_TYPE_RDMA_OTHER = 15,
IOLINK_TYPE_OTHER = 16,
IOLINK_TYPE_NUMIOLINKTYPES,
IOLINK_TYPE_SIZE = 0xFFFFFFFF
} IO_LINK_TYPE;
class IOLink {
public:
explicit IOLink(uint32_t node_indx, uint32_t link_indx) :
node_indx_(node_indx), link_indx_(link_indx) {}
~IOLink();
int Initialize();
int ReadProperties(void);
int get_property_value(std::string property, uint64_t *value);
uint32_t get_node_indx(void) const {return node_indx_;}
uint32_t get_link_indx(void) const {return link_indx_;}
IO_LINK_TYPE type(void) const {return type_;}
uint32_t node_from(void) const {return node_from_;}
uint32_t node_to(void) const {return node_to_;}
uint64_t weight(void) const {return weight_;}
private:
uint32_t node_indx_;
uint32_t link_indx_;
IO_LINK_TYPE type_;
uint32_t node_from_;
uint32_t node_to_;
uint64_t weight_;
std::map<std::string, uint64_t> properties_;
};
int
DiscoverIOLinksPerNode(uint32_t node_indx, std::map<uint32_t,
std::shared_ptr<IOLink>> *links);
int
DiscoverIOLinks(std::map<std::pair<uint32_t, uint32_t>,
std::shared_ptr<IOLink>> *links);
} // namespace smi
} // namespace amd
#endif // INCLUDE_ROCM_SMI_ROCM_SMI_IO_LINK_H_
+13
View File
@@ -51,6 +51,7 @@
#include "rocm_smi/rocm_smi.h"
#include "rocm_smi/rocm_smi_device.h"
#include "rocm_smi/rocm_smi_io_link.h"
namespace amd {
namespace smi {
@@ -65,6 +66,12 @@ class KFDNode {
int get_property_value(std::string property, uint64_t *value);
uint64_t gpu_id(void) const {return gpu_id_;}
std::string name(void) const {return name_;}
uint32_t node_index(void) const {return node_indx_;}
uint32_t numa_node_number(void) const {return numa_node_number_;}
uint64_t numa_node_weight(void) const {return numa_node_weight_;}
IO_LINK_TYPE numa_node_type(void) const {return numa_node_type_;}
int get_io_link_type(uint32_t node_to, IO_LINK_TYPE *type);
int get_io_link_weight(uint32_t node_to, uint64_t *weight);
std::shared_ptr<Device> amdgpu_device(void) const {return amdgpu_device_;}
uint32_t amdgpu_dev_index(void) const {return amdgpu_dev_index_;}
void set_amdgpu_dev_index(uint32_t val) {amdgpu_dev_index_ = val;}
@@ -74,6 +81,12 @@ class KFDNode {
uint32_t amdgpu_dev_index_;
uint64_t gpu_id_;
std::string name_;
uint32_t numa_node_number_;
uint64_t numa_node_weight_;
IO_LINK_TYPE numa_node_type_;
std::map<uint32_t, IO_LINK_TYPE> io_link_type_;
std::map<uint32_t, uint64_t> io_link_weight_;
std::map<uint32_t, std::shared_ptr<IOLink>> io_link_map_;
std::map<std::string, uint64_t> properties_;
std::shared_ptr<Device> amdgpu_device_;
};
+7
View File
@@ -55,6 +55,7 @@
#include <map>
#include <mutex> // NOLINT
#include "rocm_smi/rocm_smi_io_link.h"
#include "rocm_smi/rocm_smi_kfd.h"
#include "rocm_smi/rocm_smi_device.h"
#include "rocm_smi/rocm_smi_monitor.h"
@@ -106,6 +107,9 @@ class RocmSMI {
return ++kfd_notif_evt_fh_refcnt_;}
uint32_t kfd_notif_evt_fh_refcnt_dec(void) {
return --kfd_notif_evt_fh_refcnt_;}
int get_io_link_weight(uint32_t node_from, uint32_t node_to,
uint64_t *weight);
int get_node_index(uint32_t dv_ind, uint32_t *node_ind);
private:
std::vector<std::shared_ptr<Device>> devices_;
@@ -113,6 +117,9 @@ class RocmSMI {
std::vector<std::shared_ptr<Monitor>> monitors_;
std::vector<std::shared_ptr<PowerMon>> power_mons_;
std::set<std::string> amd_monitor_types_;
std::map<std::pair<uint32_t, uint32_t>, std::shared_ptr<IOLink>>
io_link_map_;
std::map<uint32_t, uint32_t> dev_ind_to_node_ind_map_;
void AddToDeviceList(std::string dev_name);
void GetEnvVariables(void);
uint32_t DiscoverAMDMonitors(void);