Add rsmi_dev_pci_id_get() to return BDFID for given device
Also:
* add some exception handling;
* chop newline character off of device name returned from
rsmi_dev_id_get()
[ROCm/amdsmi commit: 59a952666f]
This commit is contained in:
@@ -84,6 +84,9 @@ typedef enum {
|
||||
RSMI_STATUS_INTERNAL_EXCEPTION, //!< An internal exception was caught
|
||||
RSMI_STATUS_INPUT_OUT_OF_BOUNDS, //!< The provided input is out of
|
||||
//!< allowable or safe range
|
||||
RSMI_INITIALIZATION_ERROR, //!< An error occurred when rsmi
|
||||
//!< initializing internal data
|
||||
//!< structures
|
||||
RSMI_STATUS_UNKNOWN_ERROR = 0xFFFFFFFF, //!< An unknown error occurred
|
||||
} rsmi_status_t;
|
||||
|
||||
@@ -271,13 +274,35 @@ rsmi_status_t rsmi_shut_down(void);
|
||||
*/
|
||||
rsmi_status_t rsmi_num_monitor_devices(uint32_t *num_devices);
|
||||
|
||||
/**
|
||||
* @brief Get the unique PCI device identifier associated for a device
|
||||
*
|
||||
* @details Give a device index @p dev_ind and a pointer to a uint64_t @p
|
||||
* bdfid, this function will write the Bus/Device/Function PCI identifier
|
||||
* (BDFID) associated with device @p dev_ind to the value pointed to by
|
||||
* @bdfid.
|
||||
*
|
||||
* @param[in] dv_ind a device index
|
||||
*
|
||||
* @param[inout] bdfid a pointer to uint64_t to which the device bdfid value
|
||||
* will be written
|
||||
*
|
||||
* @retval RSMI_STATUS_SUCCESS is returned upon successful call.
|
||||
|
||||
*/
|
||||
rsmi_status_t rsmi_dev_pci_id_get(uint32_t dev_ind, uint64_t *bdfid);
|
||||
|
||||
/**
|
||||
* @brief Get the device id associated with the device with provided device
|
||||
* index.
|
||||
*
|
||||
* @details Given a device index @p dv_ind and a pointer to a uint32_t @p id,
|
||||
* this function will write the device id value to the uint64_t pointed to by
|
||||
* @p id
|
||||
* @p id. This ID is an identification of the type of device, so calling this
|
||||
* function for different devices will give the same value if they are kind
|
||||
* of device. Consequently, this function should not be used to distinguish
|
||||
* one device from another. rsmi_dev_pci_id_get() should be used to get a
|
||||
* unique identifier.
|
||||
*
|
||||
* @param[in] dv_ind a device index
|
||||
*
|
||||
|
||||
@@ -86,6 +86,9 @@ class Device {
|
||||
uint32_t index(void) const {return index_;}
|
||||
void set_index(uint32_t index) {index_ = index;}
|
||||
static rsmi_dev_perf_level perfLvlStrToEnum(std::string s);
|
||||
uint64_t bdfid(void) const {return bdfid_;}
|
||||
void set_bdfid(uint64_t val) {bdfid_ = val;}
|
||||
uint64_t get_bdfid(void) const {return bdfid_;}
|
||||
|
||||
private:
|
||||
std::shared_ptr<Monitor> monitor_;
|
||||
@@ -97,6 +100,7 @@ class Device {
|
||||
int readDevInfoMultiLineStr(DevInfoTypes type,
|
||||
std::vector<std::string> *retVec);
|
||||
int writeDevInfoStr(DevInfoTypes type, std::string valStr);
|
||||
uint64_t bdfid_;
|
||||
};
|
||||
|
||||
} // namespace smi
|
||||
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* =============================================================================
|
||||
* ROC Runtime Conformance Release License
|
||||
* =============================================================================
|
||||
* The University of Illinois/NCSA
|
||||
* Open Source License (NCSA)
|
||||
*
|
||||
* Copyright (c) 2018, 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_EXCEPTION_H_
|
||||
#define INCLUDE_ROCM_SMI_ROCM_SMI_EXCEPTION_H_
|
||||
|
||||
#include <exception>
|
||||
#include <string>
|
||||
|
||||
namespace amd {
|
||||
namespace smi {
|
||||
|
||||
/// @brief Exception type which carries an error code to return to the user.
|
||||
class rsmi_exception : public std::exception {
|
||||
public:
|
||||
rsmi_exception(rsmi_status_t error, const char* description) :
|
||||
err_(error), desc_(description) {}
|
||||
rsmi_status_t error_code() const noexcept { return err_; }
|
||||
const char* what() const noexcept override { return desc_.c_str(); }
|
||||
|
||||
private:
|
||||
rsmi_status_t err_;
|
||||
std::string desc_;
|
||||
};
|
||||
|
||||
} // namespace smi
|
||||
} // namespace amd
|
||||
|
||||
#endif // INCLUDE_ROCM_SMI_ROCM_SMI_EXCEPTION_H_
|
||||
|
||||
@@ -74,9 +74,9 @@ class RocmSMI {
|
||||
uint32_t DiscoverAMDPowerMonitors(bool force_update = false);
|
||||
|
||||
// Will execute "func" for every Device object known about, or until func
|
||||
// returns true;
|
||||
void IterateSMIDevices(
|
||||
std::function<bool(std::shared_ptr<Device>&, void *)> func, void *);
|
||||
// returns non-zero;
|
||||
uint32_t IterateSMIDevices(
|
||||
std::function<uint32_t(std::shared_ptr<Device>&, void *)> func, void *);
|
||||
|
||||
private:
|
||||
std::vector<std::shared_ptr<Device>> devices_;
|
||||
|
||||
Reference in New Issue
Block a user