Rename NPS -> memory partition + compute partition node fix

* Updates:
        - rocm_smi_lib + CLI:
          Rename all "NPS mode" -> "memory partition"
          related files/functions/API/CLI to align with correct
          technical naming
        - rocm_smi_main: fixed identifying primary card's unique id
          utilize rsmi_dev_unique_id_get to map which
          KFD nodes belong to it
        - rsmi_dev_*_partition*: now have better logging output
        - compute partition tests:
          Added 20 sec delay for workaround until GPU
          busy is confirmed as the issue
        - CPPLint fixes/formatting
        - [Example] Moved all endl to "\n" for efficiency
        - [Example] Added Edge & Junction temperature examples
        - [Example] Added rsmi_minmax_bandwidth_get() example - WIP

Change-Id: Ida6db6fda7e0ac9d696a34cb15b4746e69d58d51
Signed-off-by: Charis Poag <Charis.Poag@amd.com>


[ROCm/rocm_smi_lib commit: b251bb0c9f]
This commit is contained in:
Charis Poag
2023-09-21 14:53:35 -05:00
parent fce4f5fa08
commit d57d65a607
12 changed files with 847 additions and 503 deletions
@@ -40,8 +40,8 @@
* DEALINGS WITH THE SOFTWARE. * DEALINGS WITH THE SOFTWARE.
* *
*/ */
#ifndef INCLUDE_ROCM_SMI_ROCM_SMI_H_ #ifndef ROCM_SMI_ROCM_SMI_H_
#define INCLUDE_ROCM_SMI_ROCM_SMI_H_ #define ROCM_SMI_ROCM_SMI_H_
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@@ -379,27 +379,27 @@ typedef rsmi_compute_partition_type_t rsmi_compute_partition_type;
/// \endcond /// \endcond
/** /**
* @brief NPS Modes. This enum is used to identify various * @brief Memory Partitions. This enum is used to identify various
* NPS mode types. * memory partition types.
*/ */
typedef enum { typedef enum {
RSMI_MEMORY_PARTITION_UNKNOWN = 0, RSMI_MEMORY_PARTITION_UNKNOWN = 0,
RSMI_MEMORY_PARTITION_NPS1, //!< NPS1 - All CCD & XCD data is interleaved RSMI_MEMORY_PARTITION_NPS1, //!< NPS1 - All CCD & XCD data is interleaved
//!< accross all 8 HBM stacks (all stacks/1). //!< accross all 8 HBM stacks (all stacks/1).
RSMI_MEMORY_PARTITION_NPS2, //!< NPS2 - 2 sets of CCDs or 4 XCD interleaved RSMI_MEMORY_PARTITION_NPS2, //!< NPS2 - 2 sets of CCDs or 4 XCD interleaved
//!< accross the 4 HBM stacks per AID pair //!< accross the 4 HBM stacks per AID pair
//!< (8 stacks/2). //!< (8 stacks/2).
RSMI_MEMORY_PARTITION_NPS4, //!< NPS4 - Each XCD data is interleaved accross RSMI_MEMORY_PARTITION_NPS4, //!< NPS4 - Each XCD data is interleaved accross
//!< accross 2 (or single) HBM stacks //!< accross 2 (or single) HBM stacks
//!< (8 stacks/8 or 8 stacks/4). //!< (8 stacks/8 or 8 stacks/4).
RSMI_MEMORY_PARTITION_NPS8, //!< NPS8 - Each XCD uses a single HBM stack RSMI_MEMORY_PARTITION_NPS8, //!< NPS8 - Each XCD uses a single HBM stack
//!< (8 stacks/8). Or each XCD uses a single //!< (8 stacks/8). Or each XCD uses a single
//!< HBM stack & CCDs share 2 non-interleaved //!< HBM stack & CCDs share 2 non-interleaved
//!< HBM stacks on its AID //!< HBM stacks on its AID
//!< (AID[1,2,3] = 6 stacks/6). //!< (AID[1,2,3] = 6 stacks/6).
} rsmi_nps_mode_type_t; } rsmi_memory_partition_type_t;
/// \cond Ignore in docs. /// \cond Ignore in docs.
typedef rsmi_nps_mode_type_t rsmi_nps_mode_type; typedef rsmi_memory_partition_type_t rsmi_memory_partition_type;
/// \endcond /// \endcond
/** /**
@@ -2413,7 +2413,8 @@ rsmi_status_t rsmi_dev_perf_level_get(uint32_t dv_ind,
* @retval ::RSMI_STATUS_INVALID_ARGS the provided arguments are not valid * @retval ::RSMI_STATUS_INVALID_ARGS the provided arguments are not valid
* *
*/ */
rsmi_status_t rsmi_perf_determinism_mode_set(uint32_t dv_ind, uint64_t clkvalue); rsmi_status_t rsmi_perf_determinism_mode_set(uint32_t dv_ind,
uint64_t clkvalue);
/** /**
* @brief Get the overdrive percent associated with the device with provided * @brief Get the overdrive percent associated with the device with provided
@@ -3767,27 +3768,28 @@ rsmi_status_t rsmi_dev_compute_partition_reset(uint32_t dv_ind);
/** @} */ // end of ComputePartition /** @} */ // end of ComputePartition
/*****************************************************************************/ /*****************************************************************************/
/** @defgroup NPSMode NPS Mode Functions /** @defgroup memory_partition The Memory Partition Functions
* These functions are used to query the device's NPS mode (memory partition). * These functions are used to query and set the device's current memory
* partition.
* @{ * @{
*/ */
/** /**
* @brief Retrieves the NPS mode (memory partition) for a desired device * @brief Retrieves the current memory partition for a desired device
* *
* @details * @details
* Given a device index @p dv_ind and a string @p nps_mode , * Given a device index @p dv_ind and a string @p memory_partition ,
* and uint32 @p len , this function will attempt to obtain the device's * and uint32 @p len , this function will attempt to obtain the device's
* nps mode string. Upon successful retreival, the obtained device's * memory partition string. Upon successful retreival, the obtained device's
* nps mode string shall be stored in the passed @p nps_mode char string * memory partition string shall be stored in the passed @p memory_partition
* variable. * char string variable.
* *
* @param[in] dv_ind a device index * @param[in] dv_ind a device index
* *
* @param[inout] nps_mode a pointer to a char string variable, * @param[inout] memory_partition a pointer to a char string variable,
* which the device's nps mode will be written to. * which the device's memory partition will be written to.
* *
* @param[in] len the length of the caller provided buffer @p nps_mode , * @param[in] len the length of the caller provided buffer @p memory_partition ,
* suggested length is 5 or greater. * suggested length is 5 or greater.
* *
* @retval ::RSMI_STATUS_SUCCESS call was successful * @retval ::RSMI_STATUS_SUCCESS call was successful
@@ -3796,24 +3798,25 @@ rsmi_status_t rsmi_dev_compute_partition_reset(uint32_t dv_ind);
* @retval ::RSMI_STATUS_NOT_SUPPORTED installed software or hardware does not * @retval ::RSMI_STATUS_NOT_SUPPORTED installed software or hardware does not
* support this function * support this function
* @retval ::RSMI_STATUS_INSUFFICIENT_SIZE is returned if @p len bytes is not * @retval ::RSMI_STATUS_INSUFFICIENT_SIZE is returned if @p len bytes is not
* large enough to hold the entire nps mode value. In this case, * large enough to hold the entire memory partition value. In this case,
* only @p len bytes will be written. * only @p len bytes will be written.
* *
*/ */
rsmi_status_t rsmi_status_t
rsmi_dev_nps_mode_get(uint32_t dv_ind, char *nps_mode, uint32_t len); rsmi_dev_memory_partition_get(uint32_t dv_ind, char *memory_partition,
uint32_t len);
/** /**
* @brief Modifies a selected device's NPS mode (memory partition) setting. * @brief Modifies a selected device's current memory partition setting.
* *
* @details Given a device index @p dv_ind and a type of nps mode * @details Given a device index @p dv_ind and a type of memory partition
* @p nps_mode, this function will attempt to update the selected * @p memory_partition, this function will attempt to update the selected
* device's nps mode setting. * device's memory partition setting.
* *
* @param[in] dv_ind a device index * @param[in] dv_ind a device index
* *
* @param[in] nps_mode using enum ::rsmi_nps_mode_type_t, * @param[in] memory_partition using enum ::rsmi_memory_partition_type_t,
* define what the selected device's NPS mode setting should be updated to. * define what the selected device's current mode setting should be updated to.
* *
* @retval ::RSMI_STATUS_SUCCESS call was successful * @retval ::RSMI_STATUS_SUCCESS call was successful
* @retval ::RSMI_STATUS_PERMISSION function requires root access * @retval ::RSMI_STATUS_PERMISSION function requires root access
@@ -3825,14 +3828,15 @@ rsmi_dev_nps_mode_get(uint32_t dv_ind, char *nps_mode, uint32_t len);
* *
*/ */
rsmi_status_t rsmi_status_t
rsmi_dev_nps_mode_set(uint32_t dv_ind, rsmi_nps_mode_type_t nps_mode); rsmi_dev_memory_partition_set(uint32_t dv_ind,
rsmi_memory_partition_type_t memory_partition);
/** /**
* @brief Reverts a selected device's NPS mode setting back to its * @brief Reverts a selected device's memory partition setting back to its
* boot state. * boot state.
* *
* @details Given a device index @p dv_ind , this function will attempt to * @details Given a device index @p dv_ind , this function will attempt to
* revert its NPS mode setting back to its boot state. * revert its current memory partition setting back to its boot state.
* *
* @param[in] dv_ind a device index * @param[in] dv_ind a device index
* *
@@ -3844,9 +3848,9 @@ rsmi_dev_nps_mode_set(uint32_t dv_ind, rsmi_nps_mode_type_t nps_mode);
* the amdgpu driver * the amdgpu driver
* *
*/ */
rsmi_status_t rsmi_dev_nps_mode_reset(uint32_t dv_ind); rsmi_status_t rsmi_dev_memory_partition_reset(uint32_t dv_ind);
/** @} */ // end of NPSMode /** @} */ // end of memory_partition
/*****************************************************************************/ /*****************************************************************************/
/** @defgroup APISupport Supported Functions /** @defgroup APISupport Supported Functions
@@ -4193,4 +4197,4 @@ rsmi_status_t rsmi_event_notification_stop(uint32_t dv_ind);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif // __cplusplus #endif // __cplusplus
#endif // INCLUDE_ROCM_SMI_ROCM_SMI_H_ #endif // ROCM_SMI_ROCM_SMI_H_
@@ -43,6 +43,9 @@ JSON_DATA = {}
# Version of the JSON output used to save clocks # Version of the JSON output used to save clocks
CLOCK_JSON_VERSION = 1 CLOCK_JSON_VERSION = 1
# Apply max buffer to all data allocation
MAX_BUFF_SIZE = 256
headerString = ' ROCm System Management Interface ' headerString = ' ROCm System Management Interface '
footerString = ' End of ROCm SMI Log ' footerString = ' End of ROCm SMI Log '
# Output formatting # Output formatting
@@ -529,8 +532,8 @@ def getComputePartition(device, silent=True):
@param silent=Turn on to silence error output @param silent=Turn on to silence error output
(you plan to handle manually). Default is on. (you plan to handle manually). Default is on.
""" """
currentComputePartition = create_string_buffer(256) currentComputePartition = create_string_buffer(MAX_BUFF_SIZE)
ret = rocmsmi.rsmi_dev_compute_partition_get(device, currentComputePartition, 256) ret = rocmsmi.rsmi_dev_compute_partition_get(device, currentComputePartition, MAX_BUFF_SIZE)
if rsmi_ret_ok(ret, device, 'get_compute_partition', silent) and currentComputePartition.value.decode(): if rsmi_ret_ok(ret, device, 'get_compute_partition', silent) and currentComputePartition.value.decode():
return str(currentComputePartition.value.decode()) return str(currentComputePartition.value.decode())
return "N/A" return "N/A"
@@ -543,10 +546,10 @@ def getMemoryPartition(device, silent=True):
@param silent=Turn on to silence error output @param silent=Turn on to silence error output
(you plan to handle manually). Default is on. (you plan to handle manually). Default is on.
""" """
currentNPSMode = create_string_buffer(256) currentMemoryPartition = create_string_buffer(MAX_BUFF_SIZE)
ret = rocmsmi.rsmi_dev_nps_mode_get(device, currentNPSMode, 256) ret = rocmsmi.rsmi_dev_memory_partition_get(device, currentMemoryPartition, MAX_BUFF_SIZE)
if rsmi_ret_ok(ret, device, 'get_NPS_mode', silent) and currentNPSMode.value.decode(): if rsmi_ret_ok(ret, device, 'get_memory_partition', silent) and currentMemoryPartition.value.decode():
return str(currentNPSMode.value.decode()) return str(currentMemoryPartition.value.decode())
return "N/A" return "N/A"
@@ -969,20 +972,20 @@ def resetComputePartition(deviceList):
printLogSpacer() printLogSpacer()
def resetNpsMode(deviceList): def resetMemoryPartition(deviceList):
""" Reset NPS mode to its boot state """ Reset current memory partition to its boot state
@param deviceList: List of DRM devices (can be a single-item list) @param deviceList: List of DRM devices (can be a single-item list)
""" """
printLogSpacer(" Reset nps mode to its boot state ") printLogSpacer(" Reset memory partition to its boot state ")
for device in deviceList: for device in deviceList:
originalPartition = getMemoryPartition(device) originalPartition = getMemoryPartition(device)
t1 = multiprocessing.Process(target=showProgressbar, t1 = multiprocessing.Process(target=showProgressbar,
args=("Resetting NPS mode",13,)) args=("Resetting memory partition",13,))
t1.start() t1.start()
addExtraLine=True addExtraLine=True
start=time.time() start=time.time()
ret = rocmsmi.rsmi_dev_nps_mode_reset(device) ret = rocmsmi.rsmi_dev_memory_partition_reset(device)
stop=time.time() stop=time.time()
duration=stop-start duration=stop-start
if t1.is_alive(): if t1.is_alive():
@@ -990,9 +993,9 @@ def resetNpsMode(deviceList):
t1.join() t1.join()
if duration < float(0.1): # For longer runs, add extra line before output if duration < float(0.1): # For longer runs, add extra line before output
addExtraLine=False # This is to prevent overriding progress bar addExtraLine=False # This is to prevent overriding progress bar
if rsmi_ret_ok(ret, device, 'reset_NPS_mode', silent=True): if rsmi_ret_ok(ret, device, 'reset_memory_partition', silent=True):
resetBootState = getMemoryPartition(device) resetBootState = getMemoryPartition(device)
printLog(device, "Successfully reset nps mode (" + printLog(device, "Successfully reset memory partition (" +
originalPartition + ") to boot state (" + originalPartition + ") to boot state (" +
resetBootState + ")", None, addExtraLine) resetBootState + ")", None, addExtraLine)
elif ret == rsmi_status_t.RSMI_STATUS_PERMISSION: elif ret == rsmi_status_t.RSMI_STATUS_PERMISSION:
@@ -1000,8 +1003,8 @@ def resetNpsMode(deviceList):
elif ret == rsmi_status_t.RSMI_STATUS_NOT_SUPPORTED: elif ret == rsmi_status_t.RSMI_STATUS_NOT_SUPPORTED:
printLog(device, 'Not supported on the given system', None, addExtraLine) printLog(device, 'Not supported on the given system', None, addExtraLine)
else: else:
rsmi_ret_ok(ret, device, 'reset_NPS_mode') rsmi_ret_ok(ret, device, 'reset_memory_partition')
printErrLog(device, 'Failed to reset nps mode to boot state') printErrLog(device, 'Failed to reset memory partition to boot state')
printLogSpacer() printLogSpacer()
@@ -1631,29 +1634,29 @@ def showProgressbar(title="", timeInSeconds=13):
time.sleep(1) time.sleep(1)
def setNPSMode(deviceList, npsMode): def setMemoryPartition(deviceList, memoryPartition):
""" Sets nps mode (memory partition) for a list of devices """ Sets memory partition (memory partition) for a list of devices
@param deviceList: List of DRM devices (can be a single-item list) @param deviceList: List of DRM devices (can be a single-item list)
@param npsMode: NPS Mode type to set as @param memoryPartition: Memory Partition type to set as
""" """
printLogSpacer(' Set nps mode to %s ' % (str(npsMode).upper())) printLogSpacer(' Set memory partition to %s ' % (str(memoryPartition).upper()))
for device in deviceList: for device in deviceList:
npsMode = npsMode.upper() memoryPartition = memoryPartition.upper()
if npsMode not in nps_mode_type_l: if memoryPartition not in memory_partition_type_l:
printErrLog(device, 'Invalid nps mode type %s' printErrLog(device, 'Invalid memory partition type %s'
'\nValid nps mode types are %s' '\nValid memory partition types are %s'
% ( npsMode.upper(), % ( memoryPartition.upper(),
(', '.join(map(str, nps_mode_type_l))) )) (', '.join(map(str, memory_partition_type_l))) ))
return (None, None) return (None, None)
t1 = multiprocessing.Process(target=showProgressbar, t1 = multiprocessing.Process(target=showProgressbar,
args=("Updating NPS mode",13,)) args=("Updating memory partition",13,))
t1.start() t1.start()
addExtraLine=True addExtraLine=True
start=time.time() start=time.time()
ret = rocmsmi.rsmi_dev_nps_mode_set(device, ret = rocmsmi.rsmi_dev_memory_partition_set(device,
rsmi_nps_mode_type_dict[npsMode]) rsmi_memory_partition_type_dict[memoryPartition])
stop=time.time() stop=time.time()
duration=stop-start duration=stop-start
if t1.is_alive(): if t1.is_alive():
@@ -1662,17 +1665,17 @@ def setNPSMode(deviceList, npsMode):
if duration < float(0.1): # For longer runs, add extra line before output if duration < float(0.1): # For longer runs, add extra line before output
addExtraLine=False # This is to prevent overriding progress bar addExtraLine=False # This is to prevent overriding progress bar
if rsmi_ret_ok(ret, device, 'set_NPS_mode', silent=True): if rsmi_ret_ok(ret, device, 'set_memory_partition', silent=True):
printLog(device, printLog(device,
'Successfully set nps mode to %s' % (npsMode), 'Successfully set memory partition to %s' % (memoryPartition),
None, addExtraLine) None, addExtraLine)
elif ret == rsmi_status_t.RSMI_STATUS_PERMISSION: elif ret == rsmi_status_t.RSMI_STATUS_PERMISSION:
printLog(device, 'Permission denied', None, addExtraLine) printLog(device, 'Permission denied', None, addExtraLine)
elif ret == rsmi_status_t.RSMI_STATUS_NOT_SUPPORTED: elif ret == rsmi_status_t.RSMI_STATUS_NOT_SUPPORTED:
printLog(device, 'Not supported on the given system', None, addExtraLine) printLog(device, 'Not supported on the given system', None, addExtraLine)
else: else:
rsmi_ret_ok(ret, device, 'set_NPS_mode') rsmi_ret_ok(ret, device, 'set_memory_partition')
printErrLog(device, 'Failed to retrieve NPS mode, even though device supports it.') printErrLog(device, 'Failed to retrieve memory partition, even though device supports it.')
printLogSpacer() printLogSpacer()
def showVersion(isCSV=False): def showVersion(isCSV=False):
@@ -2580,7 +2583,6 @@ def getDevProductInfo(device, silent=False):
""" """
# Retrieve card vendor # Retrieve card vendor
MAX_BUFF_SIZE = 256
MAX_DESC_SIZE = 20 MAX_DESC_SIZE = 20
device_series = "N/A" device_series = "N/A"
device_model = "N/A" device_model = "N/A"
@@ -3344,22 +3346,22 @@ def showComputePartition(deviceList):
printErrLog(device, 'Failed to retrieve compute partition, even though device supports it.') printErrLog(device, 'Failed to retrieve compute partition, even though device supports it.')
printLogSpacer() printLogSpacer()
def showNPSMode(deviceList): def showMemoryPartition(deviceList):
""" Returns the current NPS mode for a list of devices """ Returns the current memory partition for a list of devices
@param deviceList: List of DRM devices (can be a single-item list) @param deviceList: List of DRM devices (can be a single-item list)
""" """
npsMode = create_string_buffer(256) memoryPartition = create_string_buffer(256)
printLogSpacer(' Current NPS Mode ') printLogSpacer(' Current Memory Partition ')
for device in deviceList: for device in deviceList:
ret = rocmsmi.rsmi_dev_nps_mode_get(device, npsMode, 256) ret = rocmsmi.rsmi_dev_memory_partition_get(device, memoryPartition, 256)
if rsmi_ret_ok(ret, device, 'get_NPS_mode',silent=True) and npsMode.value.decode(): if rsmi_ret_ok(ret, device, 'get_memory_partition',silent=True) and memoryPartition.value.decode():
printLog(device, 'NPS Mode', npsMode.value.decode()) printLog(device, 'Memory Partition', memoryPartition.value.decode())
elif ret == rsmi_status_t.RSMI_STATUS_NOT_SUPPORTED: elif ret == rsmi_status_t.RSMI_STATUS_NOT_SUPPORTED:
printLog(device, 'Not supported on the given system', None) printLog(device, 'Not supported on the given system', None)
else: else:
rsmi_ret_ok(ret, device, 'get_NPS_mode') rsmi_ret_ok(ret, device, 'get_memory_partition')
printErrLog(device, 'Failed to retrieve NPS mode, even though device supports it.') printErrLog(device, 'Failed to retrieve current memory partition, even though device supports it.')
printLogSpacer() printLogSpacer()
@@ -3556,6 +3558,9 @@ def rsmi_ret_ok(my_ret, device=None, metric=None, silent=False):
if my_ret != rsmi_status_t.RSMI_STATUS_SUCCESS: if my_ret != rsmi_status_t.RSMI_STATUS_SUCCESS:
err_str = c_char_p() err_str = c_char_p()
rocmsmi.rsmi_status_string(my_ret, byref(err_str)) rocmsmi.rsmi_status_string(my_ret, byref(err_str))
# leaving the commented out prints/logs to help identify errors in the future
# print("error string = " + str(err_str))
# print("error string (w/ decode)= " + str(err_str.value.decode()))
returnString = '' returnString = ''
if device is not None: if device is not None:
returnString += '%s GPU[%s]:' % (my_ret, device) returnString += '%s GPU[%s]:' % (my_ret, device)
@@ -3566,6 +3571,7 @@ def rsmi_ret_ok(my_ret, device=None, metric=None, silent=False):
if err_str.value is not None: if err_str.value is not None:
returnString += '%s\t' % (err_str.value.decode()) returnString += '%s\t' % (err_str.value.decode())
if not PRINT_JSON: if not PRINT_JSON:
# logging.debug('%s', returnString)
if not silent: if not silent:
logging.debug('%s', returnString) logging.debug('%s', returnString)
if my_ret in rsmi_status_verbose_err_out: if my_ret in rsmi_status_verbose_err_out:
@@ -3722,7 +3728,7 @@ if __name__ == '__main__':
action='store_true') action='store_true')
groupDisplay.add_argument('--shownodesbw', help='Shows the numa nodes ', action='store_true') groupDisplay.add_argument('--shownodesbw', help='Shows the numa nodes ', action='store_true')
groupDisplay.add_argument('--showcomputepartition', help='Shows current compute partitioning ', action='store_true') groupDisplay.add_argument('--showcomputepartition', help='Shows current compute partitioning ', action='store_true')
groupDisplay.add_argument('--shownpsmode', help='Shows current NPS mode ', action='store_true') groupDisplay.add_argument('--showmemorypartition', help='Shows current memory partition ', action='store_true')
groupActionReset.add_argument('-r', '--resetclocks', help='Reset clocks and OverDrive to default', groupActionReset.add_argument('-r', '--resetclocks', help='Reset clocks and OverDrive to default',
action='store_true') action='store_true')
@@ -3734,7 +3740,7 @@ if __name__ == '__main__':
groupActionReset.add_argument('--resetxgmierr', help='Reset XGMI error count', action='store_true') groupActionReset.add_argument('--resetxgmierr', help='Reset XGMI error count', action='store_true')
groupActionReset.add_argument('--resetperfdeterminism', help='Disable performance determinism', action='store_true') groupActionReset.add_argument('--resetperfdeterminism', help='Disable performance determinism', action='store_true')
groupActionReset.add_argument('--resetcomputepartition', help='Resets to boot compute partition state', action='store_true') groupActionReset.add_argument('--resetcomputepartition', help='Resets to boot compute partition state', action='store_true')
groupActionReset.add_argument('--resetnpsmode', help='Resets to boot NPS mode state', action='store_true') groupActionReset.add_argument('--resetmemorypartition', help='Resets to boot memory partition state', action='store_true')
groupAction.add_argument('--setclock', groupAction.add_argument('--setclock',
help='Set Clock Frequency Level(s) for specified clock (requires manual Perf level)', help='Set Clock Frequency Level(s) for specified clock (requires manual Perf level)',
metavar=('TYPE','LEVEL'), nargs=2) metavar=('TYPE','LEVEL'), nargs=2)
@@ -3772,8 +3778,8 @@ if __name__ == '__main__':
groupAction.add_argument('--setcomputepartition', help='Set compute partition', groupAction.add_argument('--setcomputepartition', help='Set compute partition',
choices=compute_partition_type_l + [x.lower() for x in compute_partition_type_l], choices=compute_partition_type_l + [x.lower() for x in compute_partition_type_l],
type=str, nargs=1) type=str, nargs=1)
groupAction.add_argument('--setnpsmode', help='Set nps mode', groupAction.add_argument('--setmemorypartition', help='Set memory partition',
choices=nps_mode_type_l + [x.lower() for x in nps_mode_type_l], choices=memory_partition_type_l + [x.lower() for x in memory_partition_type_l],
type=str, nargs=1) type=str, nargs=1)
groupAction.add_argument('--rasenable', help='Enable RAS for specified block and error type', type=str, nargs=2, groupAction.add_argument('--rasenable', help='Enable RAS for specified block and error type', type=str, nargs=2,
metavar=('BLOCK', 'ERRTYPE')) metavar=('BLOCK', 'ERRTYPE'))
@@ -3823,7 +3829,7 @@ if __name__ == '__main__':
or args.setpoweroverdrive or args.resetpoweroverdrive or args.rasenable or args.rasdisable or \ or args.setpoweroverdrive or args.resetpoweroverdrive or args.rasenable or args.rasdisable or \
args.rasinject or args.gpureset or args.setperfdeterminism or args.setslevel or args.setmlevel or \ args.rasinject or args.gpureset or args.setperfdeterminism or args.setslevel or args.setmlevel or \
args.setvc or args.setsrange or args.setmrange or args.setclock or \ args.setvc or args.setsrange or args.setmrange or args.setclock or \
args.setcomputepartition or args.setnpsmode or args.resetcomputepartition or args.resetnpsmode: args.setcomputepartition or args.setmemorypartition or args.resetcomputepartition or args.resetmemorypartition:
relaunchAsSudo() relaunchAsSudo()
# If there is one or more device specified, use that for all commands, otherwise use a # If there is one or more device specified, use that for all commands, otherwise use a
@@ -3886,7 +3892,7 @@ if __name__ == '__main__':
args.showreplaycount = True args.showreplaycount = True
args.showvc = True args.showvc = True
args.showcomputepartition = True args.showcomputepartition = True
args.shownpsmode = True args.showmemorypartition = True
if not PRINT_JSON: if not PRINT_JSON:
args.showprofile = True args.showprofile = True
@@ -4015,8 +4021,8 @@ if __name__ == '__main__':
showEnergy(deviceList) showEnergy(deviceList)
if args.showcomputepartition: if args.showcomputepartition:
showComputePartition(deviceList) showComputePartition(deviceList)
if args.shownpsmode: if args.showmemorypartition:
showNPSMode(deviceList) showMemoryPartition(deviceList)
if args.setclock: if args.setclock:
setClocks(deviceList, args.setclock[0], [int(args.setclock[1])]) setClocks(deviceList, args.setclock[0], [int(args.setclock[1])])
if args.setsclk: if args.setsclk:
@@ -4057,8 +4063,8 @@ if __name__ == '__main__':
setPerfDeterminism(deviceList, args.setperfdeterminism[0]) setPerfDeterminism(deviceList, args.setperfdeterminism[0])
if args.setcomputepartition: if args.setcomputepartition:
setComputePartition(deviceList, args.setcomputepartition[0]) setComputePartition(deviceList, args.setcomputepartition[0])
if args.setnpsmode: if args.setmemorypartition:
setNPSMode(deviceList, args.setnpsmode[0]) setMemoryPartition(deviceList, args.setmemorypartition[0])
if args.resetprofile: if args.resetprofile:
resetProfile(deviceList) resetProfile(deviceList)
if args.resetxgmierr: if args.resetxgmierr:
@@ -4067,8 +4073,8 @@ if __name__ == '__main__':
resetPerfDeterminism(deviceList) resetPerfDeterminism(deviceList)
if args.resetcomputepartition: if args.resetcomputepartition:
resetComputePartition(deviceList) resetComputePartition(deviceList)
if args.resetnpsmode: if args.resetmemorypartition:
resetNpsMode(deviceList) resetMemoryPartition(deviceList)
if args.rasenable: if args.rasenable:
setRas(deviceList, 'enable', args.rasenable[0], args.rasenable[1]) setRas(deviceList, 'enable', args.rasenable[0], args.rasenable[1])
if args.rasdisable: if args.rasdisable:
@@ -634,27 +634,27 @@ rsmi_compute_partition_type = rsmi_compute_partition_type_t
# will return string 'CPX' # will return string 'CPX'
compute_partition_type_l = ['CPX', 'SPX', 'DPX', 'TPX', 'QPX'] compute_partition_type_l = ['CPX', 'SPX', 'DPX', 'TPX', 'QPX']
class rsmi_nps_mode_type_t(c_int): class rsmi_memory_partition_type_t(c_int):
RSMI_MEMORY_PARTITION_UNKNOWN = 0 RSMI_MEMORY_PARTITION_UNKNOWN = 0
RSMI_MEMORY_PARTITION_NPS1 = 1 RSMI_MEMORY_PARTITION_NPS1 = 1
RSMI_MEMORY_PARTITION_NPS2 = 2 RSMI_MEMORY_PARTITION_NPS2 = 2
RSMI_MEMORY_PARTITION_NPS4 = 3 RSMI_MEMORY_PARTITION_NPS4 = 3
RSMI_MEMORY_PARTITION_NPS8 = 4 RSMI_MEMORY_PARTITION_NPS8 = 4
rsmi_nps_mode_type_dict = { rsmi_memory_partition_type_dict = {
'NPS1': 1, 'NPS1': 1,
'NPS2': 2, 'NPS2': 2,
'NPS4': 3, 'NPS4': 3,
'NPS8': 4 'NPS8': 4
} }
rsmi_nps_mode_type = rsmi_nps_mode_type_t rsmi_memory_partition_type = rsmi_memory_partition_type_t
# nps_mode_type_l includes string names for the rsmi_compute_partition_type_t # memory_partition_type_l includes string names for the rsmi_compute_partition_type_t
# Usage example to get corresponding names: # Usage example to get corresponding names:
# nps_mode_type_l[rsmi_nps_mode_type_t.RSMI_MEMORY_PARTITION_NPS2] # memory_partition_type_l[rsmi_memory_partition_type_t.RSMI_MEMORY_PARTITION_NPS2]
# will return string 'NPS2' # will return string 'NPS2'
nps_mode_type_l = ['NPS1', 'NPS2', 'NPS4', 'NPS8'] memory_partition_type_l = ['NPS1', 'NPS2', 'NPS4', 'NPS8']
class rsmi_power_label(str, Enum): class rsmi_power_label(str, Enum):
AVG_POWER = '(Avg)' AVG_POWER = '(Avg)'
@@ -58,9 +58,9 @@
if (RET != RSMI_STATUS_SUCCESS) { \ if (RET != RSMI_STATUS_SUCCESS) { \
const char *err_str; \ const char *err_str; \
std::cout << "[ERROR] RSMI call returned " << (RET) \ std::cout << "[ERROR] RSMI call returned " << (RET) \
<< " at line " << __LINE__ << std::endl; \ << " at line " << __LINE__ << "\n"; \
rsmi_status_string((RET), &err_str); \ rsmi_status_string((RET), &err_str); \
std::cout << err_str << std::endl; \ std::cout << err_str << "\n"; \
} \ } \
} }
@@ -100,10 +100,10 @@
} \ } \
} else if ((RET) == RSMI_STATUS_NOT_SUPPORTED) { \ } else if ((RET) == RSMI_STATUS_NOT_SUPPORTED) { \
std::cout << "Not Supported." \ std::cout << "Not Supported." \
<< std::endl; \ << "\n"; \
} else if ((RET) == RSMI_STATUS_NOT_YET_IMPLEMENTED) { \ } else if ((RET) == RSMI_STATUS_NOT_YET_IMPLEMENTED) { \
std::cout << "Not Yet Implemented." \ std::cout << "Not Yet Implemented." \
<< std::endl; \ << "\n"; \
} else { \ } else { \
CHK_RSMI_RET(RET) \ CHK_RSMI_RET(RET) \
} \ } \
@@ -112,7 +112,7 @@
#define CHK_RSMI_NOT_SUPPORTED_RET(RET) { \ #define CHK_RSMI_NOT_SUPPORTED_RET(RET) { \
if ((RET) == RSMI_STATUS_NOT_SUPPORTED) { \ if ((RET) == RSMI_STATUS_NOT_SUPPORTED) { \
std::cout << "Not Supported." \ std::cout << "Not Supported." \
<< std::endl; \ << "\n"; \
} else { \ } else { \
CHK_RSMI_RET(RET) \ CHK_RSMI_RET(RET) \
} \ } \
@@ -121,10 +121,10 @@
#define CHK_RSMI_NOT_SUPPORTED_OR_UNEXPECTED_DATA_RET(RET) { \ #define CHK_RSMI_NOT_SUPPORTED_OR_UNEXPECTED_DATA_RET(RET) { \
if ((RET) == RSMI_STATUS_NOT_SUPPORTED) { \ if ((RET) == RSMI_STATUS_NOT_SUPPORTED) { \
std::cout << "Not Supported." \ std::cout << "Not Supported." \
<< std::endl; \ << "\n"; \
} else if ((RET) == RSMI_STATUS_UNEXPECTED_DATA) { \ } else if ((RET) == RSMI_STATUS_UNEXPECTED_DATA) { \
std::cout << "[ERROR] RSMI_STATUS_UNEXPECTED_DATA retrieved." \ std::cout << "[ERROR] RSMI_STATUS_UNEXPECTED_DATA retrieved." \
<< std::endl; \ << "\n"; \
} else { \ } else { \
CHK_RSMI_RET(RET) \ CHK_RSMI_RET(RET) \
} \ } \
@@ -133,10 +133,10 @@
#define CHK_RSMI_NOT_SUPPORTED_OR_SETTING_UNAVAILABLE_RET(RET) {\ #define CHK_RSMI_NOT_SUPPORTED_OR_SETTING_UNAVAILABLE_RET(RET) {\
if ((RET) == RSMI_STATUS_NOT_SUPPORTED) { \ if ((RET) == RSMI_STATUS_NOT_SUPPORTED) { \
std::cout << "Not Supported."\ std::cout << "Not Supported."\
<< std::endl; \ << "\n"; \
} else if ((RET) == RSMI_STATUS_SETTING_UNAVAILABLE) { \ } else if ((RET) == RSMI_STATUS_SETTING_UNAVAILABLE) { \
std::cout << "[WARN] RSMI_STATUS_SETTING_UNAVAILABLE retrieved." \ std::cout << "[WARN] RSMI_STATUS_SETTING_UNAVAILABLE retrieved." \
<< std::endl; \ << "\n"; \
} else { \ } else { \
CHK_RSMI_RET(RET) \ CHK_RSMI_RET(RET) \
} \ } \
@@ -145,27 +145,27 @@
#define CHK_NOT_SUPPORTED_OR_UNEXPECTED_DATA_OR_INSUFFICIENT_SIZE_RET(RET) { \ #define CHK_NOT_SUPPORTED_OR_UNEXPECTED_DATA_OR_INSUFFICIENT_SIZE_RET(RET) { \
if ((RET) == RSMI_STATUS_NOT_SUPPORTED) { \ if ((RET) == RSMI_STATUS_NOT_SUPPORTED) { \
std::cout << "Not Supported." \ std::cout << "Not Supported." \
<< std::endl; \ << "\n"; \
} else if ((RET) == RSMI_STATUS_UNEXPECTED_DATA) { \ } else if ((RET) == RSMI_STATUS_UNEXPECTED_DATA) { \
std::cout << "[WARN] RSMI_STATUS_UNEXPECTED_DATA retrieved." \ std::cout << "[WARN] RSMI_STATUS_UNEXPECTED_DATA retrieved." \
<< std::endl; \ << "\n"; \
} else if ((RET) == RSMI_STATUS_INSUFFICIENT_SIZE) { \ } else if ((RET) == RSMI_STATUS_INSUFFICIENT_SIZE) { \
std::cout << "[WARN] RSMI_STATUS_INSUFFICIENT_SIZE retrieved." \ std::cout << "[WARN] RSMI_STATUS_INSUFFICIENT_SIZE retrieved." \
<< std::endl; \ << "\n"; \
} else { \ } else { \
CHK_RSMI_RET(RET) \ CHK_RSMI_RET(RET) \
} \ } \
} }
static void print_test_header(const char *str, uint32_t dv_ind) { static void print_test_header(const char *str, uint32_t dv_ind) {
std::cout << "********************************" << std::endl; std::cout << "********************************" << "\n";
std::cout << "*** " << str << std::endl; std::cout << "*** " << str << "\n";
std::cout << "********************************" << std::endl; std::cout << "********************************" << "\n";
std::cout << "Device index: " << dv_ind << std::endl; std::cout << "Device index: " << dv_ind << "\n";
} }
static void print_mini_header(const char *str) { static void print_mini_header(const char *str) {
std::cout << "\n>> " << str << " <<" << std::endl; std::cout << "\n>> " << str << " <<" << "\n";
} }
static const char * static const char *
@@ -189,7 +189,7 @@ power_profile_string(rsmi_power_profile_preset_masks_t profile) {
} }
static const std::string static const std::string
compute_partition_string(rsmi_compute_partition_type partition) { compute_partition_string(rsmi_compute_partition_type_t partition) {
switch (partition) { switch (partition) {
case RSMI_COMPUTE_PARTITION_CPX: case RSMI_COMPUTE_PARTITION_CPX:
return "CPX"; return "CPX";
@@ -216,7 +216,7 @@ mapStringToRSMIComputePartitionTypes {
}; };
static const std::string static const std::string
nps_mode_string(rsmi_nps_mode_type_t partition) { memory_partition_string(rsmi_memory_partition_type_t partition) {
switch (partition) { switch (partition) {
case RSMI_MEMORY_PARTITION_NPS1: case RSMI_MEMORY_PARTITION_NPS1:
return "NPS1"; return "NPS1";
@@ -231,8 +231,8 @@ nps_mode_string(rsmi_nps_mode_type_t partition) {
} }
} }
static std::map<std::string, rsmi_nps_mode_type_t> static std::map<std::string, rsmi_memory_partition_type_t>
mapStringToRSMINpsModeTypes { mapStringToRSMIMemoryPartitionTypes {
{"NPS1", RSMI_MEMORY_PARTITION_NPS1}, {"NPS1", RSMI_MEMORY_PARTITION_NPS1},
{"NPS2", RSMI_MEMORY_PARTITION_NPS2}, {"NPS2", RSMI_MEMORY_PARTITION_NPS2},
{"NPS4", RSMI_MEMORY_PARTITION_NPS4}, {"NPS4", RSMI_MEMORY_PARTITION_NPS4},
@@ -274,7 +274,7 @@ static bool isFileWritable(rsmi_status_t response) {
bool fileWritable = true; bool fileWritable = true;
if (isUserRunningAsSudo() && (response == RSMI_STATUS_PERMISSION)) { if (isUserRunningAsSudo() && (response == RSMI_STATUS_PERMISSION)) {
std::cout << "[WARN] User is running with sudo " std::cout << "[WARN] User is running with sudo "
<< "permissions, file is not writable." << std::endl; << "permissions, file is not writable." << "\n";
fileWritable = false; fileWritable = false;
} else { } else {
CHK_AND_PRINT_RSMI_ERR_RET(response) CHK_AND_PRINT_RSMI_ERR_RET(response)
@@ -292,23 +292,23 @@ static rsmi_status_t test_power_profile(uint32_t dv_ind) {
ret = rsmi_dev_power_profile_presets_get(dv_ind, 0, &status); ret = rsmi_dev_power_profile_presets_get(dv_ind, 0, &status);
CHK_RSMI_NOT_SUPPORTED_RET(ret) CHK_RSMI_NOT_SUPPORTED_RET(ret)
if (ret != RSMI_STATUS_SUCCESS) { if (ret != RSMI_STATUS_SUCCESS) {
std::cout << "***Skipping Power Profile test." << std::endl; std::cout << "***Skipping Power Profile test." << "\n";
return RSMI_STATUS_SUCCESS; return RSMI_STATUS_SUCCESS;
} }
CHK_RSMI_RET(ret) CHK_RSMI_RET(ret)
std::cout << "The available power profiles are:" << std::endl; std::cout << "The available power profiles are:" << "\n";
uint64_t tmp = 1; uint64_t tmp = 1;
while (tmp <= RSMI_PWR_PROF_PRST_LAST) { while (tmp <= RSMI_PWR_PROF_PRST_LAST) {
if ((tmp & status.available_profiles) == tmp) { if ((tmp & status.available_profiles) == tmp) {
std::cout << "\t" << std::cout << "\t" <<
power_profile_string((rsmi_power_profile_preset_masks_t)tmp) << std::endl; power_profile_string((rsmi_power_profile_preset_masks_t)tmp) << "\n";
} }
tmp = tmp << 1; tmp = tmp << 1;
} }
std::cout << "The current power profile is: " << std::cout << "The current power profile is: " <<
power_profile_string(status.current) << std::endl; power_profile_string(status.current) << "\n";
// Try setting the profile to a different power profile // Try setting the profile to a different power profile
rsmi_bit_field_t diff_profiles; rsmi_bit_field_t diff_profiles;
@@ -326,40 +326,40 @@ static rsmi_status_t test_power_profile(uint32_t dv_ind) {
} else if (diff_profiles & RSMI_PWR_PROF_PRST_3D_FULL_SCR_MASK) { } else if (diff_profiles & RSMI_PWR_PROF_PRST_3D_FULL_SCR_MASK) {
new_prof = RSMI_PWR_PROF_PRST_3D_FULL_SCR_MASK; new_prof = RSMI_PWR_PROF_PRST_3D_FULL_SCR_MASK;
} else { } else {
std::cout << "No other non-custom power profiles to set to" << std::endl; std::cout << "No other non-custom power profiles to set to" << "\n";
return ret; return ret;
} }
std::cout << "Setting power profile to " << power_profile_string(new_prof) std::cout << "Setting power profile to " << power_profile_string(new_prof)
<< "..." << std::endl; << "..." << "\n";
ret = rsmi_dev_power_profile_set(dv_ind, 0, new_prof); ret = rsmi_dev_power_profile_set(dv_ind, 0, new_prof);
CHK_RSMI_RET(ret) CHK_RSMI_RET(ret)
std::cout << "Done." << std::endl; std::cout << "Done." << "\n";
rsmi_dev_perf_level_t pfl; rsmi_dev_perf_level_t pfl;
ret = rsmi_dev_perf_level_get(dv_ind, &pfl); ret = rsmi_dev_perf_level_get(dv_ind, &pfl);
CHK_RSMI_RET(ret) CHK_RSMI_RET(ret)
std::cout << "Performance Level is now " << std::cout << "Performance Level is now " <<
perf_level_string(pfl) << std::endl; perf_level_string(pfl) << "\n";
ret = rsmi_dev_power_profile_presets_get(dv_ind, 0, &status); ret = rsmi_dev_power_profile_presets_get(dv_ind, 0, &status);
CHK_RSMI_RET(ret) CHK_RSMI_RET(ret)
std::cout << "The current power profile is: " << std::cout << "The current power profile is: " <<
power_profile_string(status.current) << std::endl; power_profile_string(status.current) << "\n";
std::cout << "Resetting perf level to auto..." << std::endl; std::cout << "Resetting perf level to auto..." << "\n";
ret = rsmi_dev_perf_level_set_v1(dv_ind, RSMI_DEV_PERF_LEVEL_AUTO); ret = rsmi_dev_perf_level_set_v1(dv_ind, RSMI_DEV_PERF_LEVEL_AUTO);
CHK_RSMI_RET(ret) CHK_RSMI_RET(ret)
std::cout << "Done." << std::endl; std::cout << "Done." << "\n";
ret = rsmi_dev_perf_level_get(dv_ind, &pfl); ret = rsmi_dev_perf_level_get(dv_ind, &pfl);
CHK_RSMI_RET(ret) CHK_RSMI_RET(ret)
std::cout << "Performance Level is now " << std::cout << "Performance Level is now " <<
perf_level_string(pfl) << std::endl; perf_level_string(pfl) << "\n";
ret = rsmi_dev_power_profile_presets_get(dv_ind, 0, &status); ret = rsmi_dev_power_profile_presets_get(dv_ind, 0, &status);
CHK_RSMI_RET(ret) CHK_RSMI_RET(ret)
std::cout << "The current power profile is: " << std::cout << "The current power profile is: " <<
power_profile_string(status.current) << std::endl; power_profile_string(status.current) << "\n";
return ret; return ret;
} }
@@ -376,12 +376,12 @@ static rsmi_status_t test_power_cap(uint32_t dv_ind) {
ret = rsmi_dev_power_cap_get(dv_ind, 0, &orig); ret = rsmi_dev_power_cap_get(dv_ind, 0, &orig);
CHK_RSMI_RET(ret) CHK_RSMI_RET(ret)
std::cout << "Original Power Cap: " << orig << " uW" << std::endl; std::cout << "Original Power Cap: " << orig << " uW" << "\n";
std::cout << "Power Cap Range: " << max << " uW to " << min << std::cout << "Power Cap Range: " << max << " uW to " << min <<
" uW" << std::endl; " uW" << "\n";
new_cap = (max + min)/2; new_cap = (max + min)/2;
std::cout << "Setting new cap to " << new_cap << "..." << std::endl; std::cout << "Setting new cap to " << new_cap << "..." << "\n";
ret = rsmi_dev_power_cap_set(dv_ind, 0, new_cap); ret = rsmi_dev_power_cap_set(dv_ind, 0, new_cap);
CHK_RSMI_RET(ret) CHK_RSMI_RET(ret)
@@ -389,15 +389,15 @@ static rsmi_status_t test_power_cap(uint32_t dv_ind) {
ret = rsmi_dev_power_cap_get(dv_ind, 0, &new_cap); ret = rsmi_dev_power_cap_get(dv_ind, 0, &new_cap);
CHK_RSMI_RET(ret) CHK_RSMI_RET(ret)
std::cout << "New Power Cap: " << new_cap << " uW" << std::endl; std::cout << "New Power Cap: " << new_cap << " uW" << "\n";
std::cout << "Resetting cap to " << orig << "..." << std::endl; std::cout << "Resetting cap to " << orig << "..." << "\n";
ret = rsmi_dev_power_cap_set(dv_ind, 0, orig); ret = rsmi_dev_power_cap_set(dv_ind, 0, orig);
CHK_RSMI_RET(ret) CHK_RSMI_RET(ret)
ret = rsmi_dev_power_cap_get(dv_ind, 0, &new_cap); ret = rsmi_dev_power_cap_get(dv_ind, 0, &new_cap);
CHK_RSMI_RET(ret) CHK_RSMI_RET(ret)
std::cout << "Current Power Cap: " << new_cap << " uW" << std::endl; std::cout << "Current Power Cap: " << new_cap << " uW" << "\n";
return ret; return ret;
} }
@@ -407,21 +407,21 @@ static rsmi_status_t test_set_overdrive(uint32_t dv_ind) {
uint32_t val; uint32_t val;
print_test_header("Overdrive Control", dv_ind); print_test_header("Overdrive Control", dv_ind);
std::cout << "Set Overdrive level to 0%..." << std::endl; std::cout << "Set Overdrive level to 0%..." << "\n";
ret = rsmi_dev_overdrive_level_set_v1(dv_ind, 0); ret = rsmi_dev_overdrive_level_set_v1(dv_ind, 0);
CHK_RSMI_RET(ret) CHK_RSMI_RET(ret)
std::cout << "Set Overdrive level to 10%..." << std::endl; std::cout << "Set Overdrive level to 10%..." << "\n";
ret = rsmi_dev_overdrive_level_set_v1(dv_ind, 10); ret = rsmi_dev_overdrive_level_set_v1(dv_ind, 10);
CHK_RSMI_RET(ret) CHK_RSMI_RET(ret)
ret = rsmi_dev_overdrive_level_get(dv_ind, &val); ret = rsmi_dev_overdrive_level_get(dv_ind, &val);
CHK_RSMI_RET(ret) CHK_RSMI_RET(ret)
std::cout << "\t**New OverDrive Level:" << std::dec << val << std::endl; std::cout << "\t**New OverDrive Level:" << std::dec << val << "\n";
std::cout << "Reset Overdrive level to 0%..." << std::endl; std::cout << "Reset Overdrive level to 0%..." << "\n";
ret = rsmi_dev_overdrive_level_set_v1(dv_ind, 0); ret = rsmi_dev_overdrive_level_set_v1(dv_ind, 0);
CHK_RSMI_RET(ret) CHK_RSMI_RET(ret)
ret = rsmi_dev_overdrive_level_get(dv_ind, &val); ret = rsmi_dev_overdrive_level_get(dv_ind, &val);
CHK_RSMI_RET(ret) CHK_RSMI_RET(ret)
std::cout << "\t**New OverDrive Level:" << std::dec << val << std::endl; std::cout << "\t**New OverDrive Level:" << std::dec << val << "\n";
return ret; return ret;
} }
@@ -437,21 +437,21 @@ static rsmi_status_t test_set_fan_speed(uint32_t dv_ind) {
std::cout << "Original fan speed: "; std::cout << "Original fan speed: ";
ret = rsmi_dev_fan_speed_get(dv_ind, 0, &orig_speed); ret = rsmi_dev_fan_speed_get(dv_ind, 0, &orig_speed);
if (ret == RSMI_STATUS_SUCCESS) { if (ret == RSMI_STATUS_SUCCESS) {
std::cout << orig_speed << std::endl; std::cout << orig_speed << "\n";
} else { } else {
CHK_RSMI_NOT_SUPPORTED_RET(ret) CHK_RSMI_NOT_SUPPORTED_RET(ret)
std::cout << "***Skipping Fan Speed Control test." << std::endl; std::cout << "***Skipping Fan Speed Control test." << "\n";
return RSMI_STATUS_SUCCESS; return RSMI_STATUS_SUCCESS;
} }
if (orig_speed == 0) { if (orig_speed == 0) {
std::cout << "***System fan speed value is 0. Skip fan test." << std::endl; std::cout << "***System fan speed value is 0. Skip fan test." << "\n";
return RSMI_STATUS_SUCCESS; return RSMI_STATUS_SUCCESS;
} }
new_speed = 1.1 * static_cast<double>(orig_speed); new_speed = 1.1 * static_cast<double>(orig_speed);
std::cout << "Setting fan speed to " << new_speed << std::endl; std::cout << "Setting fan speed to " << new_speed << "\n";
ret = rsmi_dev_fan_speed_set(dv_ind, 0, static_cast<uint64_t>(new_speed)); ret = rsmi_dev_fan_speed_set(dv_ind, 0, static_cast<uint64_t>(new_speed));
CHK_RSMI_RET(ret) CHK_RSMI_RET(ret)
@@ -461,7 +461,7 @@ static rsmi_status_t test_set_fan_speed(uint32_t dv_ind) {
ret = rsmi_dev_fan_speed_get(dv_ind, 0, &cur_spd); ret = rsmi_dev_fan_speed_get(dv_ind, 0, &cur_spd);
CHK_RSMI_RET(ret) CHK_RSMI_RET(ret)
std::cout << "New fan speed: " << cur_spd << std::endl; std::cout << "New fan speed: " << cur_spd << "\n";
assert( assert(
(cur_spd > static_cast<int64_t>(0.95 * static_cast<double>(new_speed)) && (cur_spd > static_cast<int64_t>(0.95 * static_cast<double>(new_speed)) &&
@@ -469,7 +469,7 @@ static rsmi_status_t test_set_fan_speed(uint32_t dv_ind) {
(cur_spd > (cur_spd >
static_cast<int64_t>(0.95 * static_cast<double>(RSMI_MAX_FAN_SPEED)))); static_cast<int64_t>(0.95 * static_cast<double>(RSMI_MAX_FAN_SPEED))));
std::cout << "Resetting fan control to auto..." << std::endl; std::cout << "Resetting fan control to auto..." << "\n";
ret = rsmi_dev_fan_reset(dv_ind, 0); ret = rsmi_dev_fan_reset(dv_ind, 0);
CHK_RSMI_RET(ret) CHK_RSMI_RET(ret)
@@ -479,7 +479,7 @@ static rsmi_status_t test_set_fan_speed(uint32_t dv_ind) {
ret = rsmi_dev_fan_speed_get(dv_ind, 0, &cur_spd); ret = rsmi_dev_fan_speed_get(dv_ind, 0, &cur_spd);
CHK_RSMI_RET(ret) CHK_RSMI_RET(ret)
std::cout << "End fan speed: " << cur_spd << std::endl; std::cout << "End fan speed: " << cur_spd << "\n";
return ret; return ret;
} }
@@ -494,29 +494,29 @@ static rsmi_status_t test_set_perf_level(uint32_t dv_ind) {
ret = rsmi_dev_perf_level_get(dv_ind, &orig_pfl); ret = rsmi_dev_perf_level_get(dv_ind, &orig_pfl);
CHK_RSMI_RET(ret) CHK_RSMI_RET(ret)
std::cout << "\t**Original Perf Level:" << perf_level_string(orig_pfl) << std::cout << "\t**Original Perf Level:" << perf_level_string(orig_pfl) <<
std::endl; "\n";
pfl = pfl =
(rsmi_dev_perf_level_t)((orig_pfl + 1) % (RSMI_DEV_PERF_LEVEL_LAST + 1)); (rsmi_dev_perf_level_t)((orig_pfl + 1) % (RSMI_DEV_PERF_LEVEL_LAST + 1));
std::cout << "Set Performance Level to " << (uint32_t)pfl << " ..." << std::cout << "Set Performance Level to " << (uint32_t)pfl << " ..." <<
std::endl; "\n";
ret = rsmi_dev_perf_level_set_v1(dv_ind, pfl); ret = rsmi_dev_perf_level_set_v1(dv_ind, pfl);
if (ret != RSMI_STATUS_SUCCESS) { if (ret != RSMI_STATUS_SUCCESS) {
CHK_RSMI_NOT_SUPPORTED_RET(ret) CHK_RSMI_NOT_SUPPORTED_RET(ret)
std::cout << "***Skipping Performance Level Control test." << std::endl; std::cout << "***Skipping Performance Level Control test." << "\n";
return RSMI_STATUS_SUCCESS; return RSMI_STATUS_SUCCESS;
} }
CHK_RSMI_RET(ret) CHK_RSMI_RET(ret)
ret = rsmi_dev_perf_level_get(dv_ind, &pfl); ret = rsmi_dev_perf_level_get(dv_ind, &pfl);
CHK_RSMI_RET(ret) CHK_RSMI_RET(ret)
std::cout << "\t**New Perf Level:" << perf_level_string(pfl) << std::endl; std::cout << "\t**New Perf Level:" << perf_level_string(pfl) << "\n";
std::cout << "Reset Perf level to " << orig_pfl << " ..." << std::endl; std::cout << "Reset Perf level to " << orig_pfl << " ..." << "\n";
ret = rsmi_dev_perf_level_set_v1(dv_ind, orig_pfl); ret = rsmi_dev_perf_level_set_v1(dv_ind, orig_pfl);
CHK_RSMI_RET(ret) CHK_RSMI_RET(ret)
ret = rsmi_dev_perf_level_get(dv_ind, &pfl); ret = rsmi_dev_perf_level_get(dv_ind, &pfl);
CHK_RSMI_RET(ret) CHK_RSMI_RET(ret)
std::cout << "\t**New Perf Level:" << perf_level_string(pfl) << std::endl; std::cout << "\t**New Perf Level:" << perf_level_string(pfl) << "\n";
return ret; return ret;
} }
@@ -541,7 +541,7 @@ static rsmi_status_t test_set_freq(uint32_t dv_ind) {
CHK_FILE_PERMISSIONS_AND_NOT_SUPPORTED_OR_UNIMPLEMENTED(ret) CHK_FILE_PERMISSIONS_AND_NOT_SUPPORTED_OR_UNIMPLEMENTED(ret)
std::cout << "Initial frequency for clock" << rsmi_clk << " is " << std::cout << "Initial frequency for clock" << rsmi_clk << " is " <<
f.current << std::endl; f.current << "\n";
// Set clocks to something other than the usual default of the lowest // Set clocks to something other than the usual default of the lowest
// frequency. // frequency.
@@ -554,7 +554,7 @@ static rsmi_status_t test_set_freq(uint32_t dv_ind) {
freq_bm_str.size()-1)); freq_bm_str.size()-1));
std::cout << "Setting frequency mask for clock " << rsmi_clk << std::cout << "Setting frequency mask for clock " << rsmi_clk <<
" to 0b" << freq_bm_str << " ..." << std::endl; " to 0b" << freq_bm_str << " ..." << "\n";
ret = rsmi_dev_gpu_clk_freq_set(dv_ind, rsmi_clk, freq_bitmask); ret = rsmi_dev_gpu_clk_freq_set(dv_ind, rsmi_clk, freq_bitmask);
CHK_FILE_PERMISSIONS_AND_NOT_SUPPORTED_OR_UNIMPLEMENTED(ret) CHK_FILE_PERMISSIONS_AND_NOT_SUPPORTED_OR_UNIMPLEMENTED(ret)
@@ -562,15 +562,15 @@ static rsmi_status_t test_set_freq(uint32_t dv_ind) {
ret = rsmi_dev_gpu_clk_freq_get(dv_ind, rsmi_clk, &f); ret = rsmi_dev_gpu_clk_freq_get(dv_ind, rsmi_clk, &f);
CHK_FILE_PERMISSIONS_AND_NOT_SUPPORTED_OR_UNIMPLEMENTED(ret) CHK_FILE_PERMISSIONS_AND_NOT_SUPPORTED_OR_UNIMPLEMENTED(ret)
std::cout << "Frequency is now index " << f.current << std::endl; std::cout << "Frequency is now index " << f.current << "\n";
std::cout << "Resetting mask to all frequencies." << std::endl; std::cout << "Resetting mask to all frequencies." << "\n";
ret = rsmi_dev_gpu_clk_freq_set(dv_ind, rsmi_clk, 0xFFFFFFFF); ret = rsmi_dev_gpu_clk_freq_set(dv_ind, rsmi_clk, 0xFFFFFFFF);
CHK_FILE_PERMISSIONS_AND_NOT_SUPPORTED_OR_UNIMPLEMENTED(ret) CHK_FILE_PERMISSIONS_AND_NOT_SUPPORTED_OR_UNIMPLEMENTED(ret)
ret = rsmi_dev_perf_level_set_v1(dv_ind, RSMI_DEV_PERF_LEVEL_AUTO); ret = rsmi_dev_perf_level_set_v1(dv_ind, RSMI_DEV_PERF_LEVEL_AUTO);
CHK_FILE_PERMISSIONS(ret) CHK_FILE_PERMISSIONS(ret)
} }
std::cout << std::endl; std::cout << "\n";
return RSMI_STATUS_SUCCESS; return RSMI_STATUS_SUCCESS;
} }
@@ -581,19 +581,19 @@ static void print_frequencies(rsmi_frequencies_t *f) {
if (j == f->current) { if (j == f->current) {
std::cout << " *"; std::cout << " *";
} }
std::cout << std::endl; std::cout << "\n";
} }
} }
static rsmi_status_t test_set_compute_partitioning(uint32_t dv_ind) { static rsmi_status_t test_set_compute_partitioning(uint32_t dv_ind) {
rsmi_status_t ret; rsmi_status_t ret;
uint32_t buffer_len = 10; const uint32_t kLength = 10;
char originalComputePartition[buffer_len]; char originalComputePartition[kLength];
originalComputePartition[0] = '\0'; originalComputePartition[0] = '\0';
print_test_header("Compute Partitioning Control", dv_ind); print_test_header("Compute Partitioning Control", dv_ind);
ret = rsmi_dev_compute_partition_get(dv_ind, originalComputePartition, ret = rsmi_dev_compute_partition_get(dv_ind, originalComputePartition,
buffer_len); kLength);
CHK_RSMI_NOT_SUPPORTED_OR_UNEXPECTED_DATA_RET(ret) CHK_RSMI_NOT_SUPPORTED_OR_UNEXPECTED_DATA_RET(ret)
if (ret == RSMI_STATUS_NOT_SUPPORTED) { if (ret == RSMI_STATUS_NOT_SUPPORTED) {
return RSMI_STATUS_SUCCESS; return RSMI_STATUS_SUCCESS;
@@ -604,95 +604,94 @@ static rsmi_status_t test_set_compute_partitioning(uint32_t dv_ind) {
|| ((originalComputePartition != nullptr) || ((originalComputePartition != nullptr)
&& (originalComputePartition[0] == '\0'))) && (originalComputePartition[0] == '\0')))
? "UNKNOWN" : originalComputePartition) ? "UNKNOWN" : originalComputePartition)
<< std::endl << std::endl; << "\n" << "\n";
for (int newComputePartition = RSMI_COMPUTE_PARTITION_CPX; for (int newComputePartition = RSMI_COMPUTE_PARTITION_CPX;
newComputePartition <= RSMI_COMPUTE_PARTITION_QPX; newComputePartition <= RSMI_COMPUTE_PARTITION_QPX;
newComputePartition++) { newComputePartition++) {
rsmi_compute_partition_type newPartition rsmi_compute_partition_type_t newPartition
= static_cast<rsmi_compute_partition_type>(newComputePartition); = static_cast<rsmi_compute_partition_type_t>(newComputePartition);
std::cout << "Attempting to set compute partition to " std::cout << "Attempting to set compute partition to "
<< compute_partition_string(newPartition) << "..." << compute_partition_string(newPartition) << "..."
<< std::endl; << "\n";
ret = rsmi_dev_compute_partition_set(dv_ind, newPartition); ret = rsmi_dev_compute_partition_set(dv_ind, newPartition);
CHK_RSMI_NOT_SUPPORTED_OR_SETTING_UNAVAILABLE_RET(ret) CHK_RSMI_NOT_SUPPORTED_OR_SETTING_UNAVAILABLE_RET(ret)
std::cout << "Done setting compute partition to " std::cout << "Done setting compute partition to "
<< compute_partition_string(newPartition) << "." << std::endl; << compute_partition_string(newPartition) << "." << "\n";
std::cout << std::endl << std::endl; std::cout << "\n" << "\n";
} }
std::cout << "About to initate compute partition reset..." << std::endl; std::cout << "About to initate compute partition reset..." << "\n";
ret = rsmi_dev_compute_partition_reset(dv_ind); ret = rsmi_dev_compute_partition_reset(dv_ind);
CHK_RSMI_NOT_SUPPORTED_RET(ret) CHK_RSMI_NOT_SUPPORTED_RET(ret)
std::cout << "Done resetting compute partition." << std::endl; std::cout << "Done resetting compute partition." << "\n";
std::string myComputePartition = originalComputePartition; std::string myComputePartition = originalComputePartition;
if (myComputePartition.empty() == false) { if (myComputePartition.empty() == false) {
std::cout << "Resetting back to original compute partition to " std::cout << "Resetting back to original compute partition to "
<< originalComputePartition << "... " << std::endl; << originalComputePartition << "... " << "\n";
rsmi_compute_partition_type origComputePartitionType rsmi_compute_partition_type origComputePartitionType
= mapStringToRSMIComputePartitionTypes[originalComputePartition]; = mapStringToRSMIComputePartitionTypes[originalComputePartition];
ret = rsmi_dev_compute_partition_set(dv_ind, origComputePartitionType); ret = rsmi_dev_compute_partition_set(dv_ind, origComputePartitionType);
CHK_RSMI_NOT_SUPPORTED_OR_SETTING_UNAVAILABLE_RET(ret) CHK_RSMI_NOT_SUPPORTED_OR_SETTING_UNAVAILABLE_RET(ret)
std::cout << "Done" << std::endl; std::cout << "Done" << "\n";
} }
return RSMI_STATUS_SUCCESS; return RSMI_STATUS_SUCCESS;
} }
static rsmi_status_t test_set_nps_mode(uint32_t dv_ind) { static rsmi_status_t test_set_memory_partition(uint32_t dv_ind) {
rsmi_status_t ret; rsmi_status_t ret;
uint32_t buffer_len = 10; const uint32_t kLength = 10;
char originalNpsMode[buffer_len]; char originalMemoryPartition[kLength];
originalNpsMode[0] = '\0'; originalMemoryPartition[0] = '\0';
print_test_header("NPS Mode Control", dv_ind); print_test_header("Memory Partition Control", dv_ind);
ret = rsmi_dev_nps_mode_get(dv_ind, originalNpsMode, buffer_len); ret = rsmi_dev_memory_partition_get(dv_ind, originalMemoryPartition, kLength);
CHK_RSMI_NOT_SUPPORTED_OR_UNEXPECTED_DATA_RET(ret) CHK_RSMI_NOT_SUPPORTED_OR_UNEXPECTED_DATA_RET(ret)
if (ret == RSMI_STATUS_NOT_SUPPORTED) { if (ret == RSMI_STATUS_NOT_SUPPORTED) {
return RSMI_STATUS_SUCCESS; return RSMI_STATUS_SUCCESS;
} }
std::cout << "Original NPS Mode: " std::cout << "Original Memory Partition: "
<< (((originalNpsMode == nullptr) << (((originalMemoryPartition == nullptr)
|| ((originalNpsMode != nullptr) || ((originalMemoryPartition != nullptr)
&& (originalNpsMode[0] == '\0'))) && (originalMemoryPartition[0] == '\0')))
? "UNKNOWN" : originalNpsMode) ? "UNKNOWN" : originalMemoryPartition)
<< std::endl << std::endl; << "\n\n";
for (int newNpsMode = RSMI_MEMORY_PARTITION_NPS1; for (int newMemPartition = RSMI_MEMORY_PARTITION_NPS1;
newNpsMode <= RSMI_MEMORY_PARTITION_NPS8; newMemPartition <= RSMI_MEMORY_PARTITION_NPS8;
newNpsMode++) { newMemPartition++) {
rsmi_nps_mode_type_t newMemoryPartition rsmi_memory_partition_type_t newMemoryPartition
= static_cast<rsmi_nps_mode_type_t>(newNpsMode); = static_cast<rsmi_memory_partition_type_t>(newMemPartition);
std::cout << "Attempting to set NPS mode to " std::cout << "Attempting to set memory partition to "
<< nps_mode_string(newMemoryPartition) << "..." << memory_partition_string(newMemoryPartition) << "..."
<< std::endl; << "\n";
ret = rsmi_dev_nps_mode_set(dv_ind, newMemoryPartition); ret = rsmi_dev_memory_partition_set(dv_ind, newMemoryPartition);
CHK_RSMI_NOT_SUPPORTED_RET(ret) CHK_RSMI_NOT_SUPPORTED_RET(ret)
if (ret == RSMI_STATUS_NOT_SUPPORTED) { if (ret == RSMI_STATUS_NOT_SUPPORTED) {
// do not continue attempting to set, device does not support setting // do not continue attempting to set, device does not support setting
return RSMI_STATUS_SUCCESS; return RSMI_STATUS_SUCCESS;
} }
std::cout << "Done setting NPS mode to " std::cout << "Done setting memory partition to "
<< nps_mode_string(newMemoryPartition) << memory_partition_string(newMemoryPartition)
<< "." << std::endl; << "." << "\n\n\n";
std::cout << std::endl << std::endl;
} }
std::cout << "About to initate nps mode reset..." << std::endl; std::cout << "About to initate memory partition reset...\n";
ret = rsmi_dev_nps_mode_reset(dv_ind); ret = rsmi_dev_memory_partition_reset(dv_ind);
CHK_RSMI_NOT_SUPPORTED_RET(ret) CHK_RSMI_NOT_SUPPORTED_RET(ret)
std::cout << "Done resetting nps mode." << std::endl; std::cout << "Done resetting memory partition.\n";
std::string myNpsMode = originalNpsMode; std::string myMemPart = originalMemoryPartition;
if (myNpsMode.empty() == false) { if (myMemPart.empty() == false) {
std::cout << "Resetting compute partition to " << originalNpsMode std::cout << "Resetting memory partition to " << originalMemoryPartition
<< "... " << std::endl; << "...\n";
rsmi_nps_mode_type_t origNpsModeType rsmi_memory_partition_type_t origMemoryPartitionType
= mapStringToRSMINpsModeTypes[originalNpsMode]; = mapStringToRSMIMemoryPartitionTypes[originalMemoryPartition];
ret = rsmi_dev_nps_mode_set(dv_ind, origNpsModeType); ret = rsmi_dev_memory_partition_set(dv_ind, origMemoryPartitionType);
CHK_RSMI_NOT_SUPPORTED_RET(ret) CHK_RSMI_NOT_SUPPORTED_RET(ret)
std::cout << "Done" << std::endl; std::cout << "Done\n";
} }
return RSMI_STATUS_SUCCESS; return RSMI_STATUS_SUCCESS;
} }
@@ -717,10 +716,10 @@ int main() {
for (uint32_t i = 0; i < num_monitor_devs; ++i) { for (uint32_t i = 0; i < num_monitor_devs; ++i) {
ret = rsmi_dev_id_get(i, &val_ui16); ret = rsmi_dev_id_get(i, &val_ui16);
CHK_RSMI_RET_I(ret) CHK_RSMI_RET_I(ret)
std::cout << "\t**Device ID: 0x" << std::hex << val_ui16 << std::endl; std::cout << "\t**Device ID: 0x" << std::hex << val_ui16 << "\n";
ret = rsmi_dev_revision_get(i, &val_ui16); ret = rsmi_dev_revision_get(i, &val_ui16);
CHK_RSMI_RET_I(ret) CHK_RSMI_RET_I(ret)
std::cout << "\t**Dev.Rev.ID: 0x" << std::hex << val_ui16 << std::endl; std::cout << "\t**Dev.Rev.ID: 0x" << std::hex << val_ui16 << "\n";
char current_compute_partition[256]; char current_compute_partition[256];
current_compute_partition[0] = '\0'; current_compute_partition[0] = '\0';
@@ -732,69 +731,92 @@ int main() {
? "UNKNOWN" : current_compute_partition); ? "UNKNOWN" : current_compute_partition);
if (ret != RSMI_STATUS_SUCCESS) { if (ret != RSMI_STATUS_SUCCESS) {
std::cout << ", RSMI_STATUS = "; std::cout << ", RSMI_STATUS = ";
} else { } else {
std::cout << std::endl; std::cout << "\n";
} }
CHK_RSMI_NOT_SUPPORTED_OR_UNEXPECTED_DATA_RET(ret) CHK_RSMI_NOT_SUPPORTED_OR_UNEXPECTED_DATA_RET(ret)
uint32_t len = 5; const uint32_t kLength = 5;
char nps_mode[len]; char memory_partition[kLength];
nps_mode[0] = '\0'; memory_partition[0] = '\0';
ret = rsmi_dev_nps_mode_get(i, nps_mode, len); ret = rsmi_dev_memory_partition_get(i, memory_partition, kLength);
std::cout << "\t**NPS Mode: " std::cout << "\t**Current Memory Partition: "
<< (((nps_mode == nullptr) << (((memory_partition == nullptr)
|| ((nps_mode != nullptr) || ((memory_partition != nullptr)
&& (nps_mode[0] == '\0'))) && (memory_partition[0] == '\0')))
? "UNKNOWN" : nps_mode); ? "UNKNOWN" : memory_partition);
if (ret != RSMI_STATUS_SUCCESS) { if (ret != RSMI_STATUS_SUCCESS) {
std::cout << ", RSMI_STATUS = "; std::cout << ", RSMI_STATUS = ";
} else { } else {
std::cout << std::endl; std::cout << "\n";
} }
CHK_NOT_SUPPORTED_OR_UNEXPECTED_DATA_OR_INSUFFICIENT_SIZE_RET(ret) CHK_NOT_SUPPORTED_OR_UNEXPECTED_DATA_OR_INSUFFICIENT_SIZE_RET(ret)
std::cout << "\t**rsmi_minmax_bandwidth_get(0, " << i << ", ...): ";
ret = rsmi_dev_pci_id_get(0, &val_ui64);
ret = rsmi_dev_pci_id_get(i, &val2_ui64);
if (i > 0 && val_ui64 != val2_ui64) {
uint64_t min_bandwidth = 0;
uint64_t max_bandwidth = 0;
ret = rsmi_minmax_bandwidth_get(0, i, &min_bandwidth, &max_bandwidth);
CHK_RSMI_NOT_SUPPORTED_OR_UNEXPECTED_DATA_RET(ret)
std::cout << "\nMinimum Bandwidth: " << min_bandwidth
<< "\nMaximum Bandwidth: " << max_bandwidth;
} else {
std::cout << "Not Supported\n";
}
ret = rsmi_dev_gpu_metrics_info_get(i, &p); ret = rsmi_dev_gpu_metrics_info_get(i, &p);
CHK_AND_PRINT_RSMI_ERR_RET(ret) CHK_AND_PRINT_RSMI_ERR_RET(ret)
std::cout << "\t**GPU METRICS" << std::endl; std::cout << "\t**GPU METRICS" << "\n";
ret = rsmi_dev_perf_level_get(i, &pfl); ret = rsmi_dev_perf_level_get(i, &pfl);
CHK_AND_PRINT_RSMI_ERR_RET(ret) CHK_AND_PRINT_RSMI_ERR_RET(ret)
std::cout << "\t**Performance Level:" << std::cout << "\t**Performance Level:" <<
perf_level_string(pfl) << std::endl; perf_level_string(pfl) << "\n";
ret = rsmi_dev_overdrive_level_get(i, &val_ui32); ret = rsmi_dev_overdrive_level_get(i, &val_ui32);
CHK_AND_PRINT_RSMI_ERR_RET(ret) CHK_AND_PRINT_RSMI_ERR_RET(ret)
std::cout << "\t**OverDrive Level:" << val_ui32 << std::endl; std::cout << "\t**OverDrive Level:" << val_ui32 << "\n";
ret = rsmi_dev_gpu_clk_freq_get(i, RSMI_CLK_TYPE_MEM, &f); ret = rsmi_dev_gpu_clk_freq_get(i, RSMI_CLK_TYPE_MEM, &f);
CHK_AND_PRINT_RSMI_ERR_RET(ret) CHK_AND_PRINT_RSMI_ERR_RET(ret)
std::cout << "\t**Supported GPU Memory clock frequencies: "; std::cout << "\t**Supported GPU Memory clock frequencies: ";
std::cout << f.num_supported << std::endl; std::cout << f.num_supported << "\n";
print_frequencies(&f); print_frequencies(&f);
ret = rsmi_dev_gpu_clk_freq_get(i, RSMI_CLK_TYPE_SYS, &f); ret = rsmi_dev_gpu_clk_freq_get(i, RSMI_CLK_TYPE_SYS, &f);
CHK_AND_PRINT_RSMI_ERR_RET(ret) CHK_AND_PRINT_RSMI_ERR_RET(ret)
std::cout << "\t**Supported GPU clock frequencies: "; std::cout << "\t**Supported GPU clock frequencies: ";
std::cout << f.num_supported << std::endl; std::cout << f.num_supported << "\n";
print_frequencies(&f); print_frequencies(&f);
ret = rsmi_dev_gpu_clk_freq_get(i, RSMI_CLK_TYPE_SOC, &f); ret = rsmi_dev_gpu_clk_freq_get(i, RSMI_CLK_TYPE_SOC, &f);
CHK_RSMI_NOT_SUPPORTED_OR_UNEXPECTED_DATA_RET(ret) CHK_RSMI_NOT_SUPPORTED_OR_UNEXPECTED_DATA_RET(ret)
std::cout << "\t**Supported GPU clock frequencies (SOC clk): "; std::cout << "\t**Supported GPU clock frequencies (SOC clk): ";
std::cout << f.num_supported << std::endl; std::cout << f.num_supported << "\n";
std::cout << "\t**Current value (SOC clk): "; std::cout << "\t**Current value (SOC clk): ";
std::cout << f.current << std::endl; std::cout << f.current << "\n";
print_frequencies(&f); print_frequencies(&f);
std::cout << "\t**Monitor name: "; std::cout << "\t**Monitor name: ";
char name[128]; char name[128];
ret = rsmi_dev_name_get(i, name, 128); ret = rsmi_dev_name_get(i, name, 128);
CHK_AND_PRINT_RSMI_ERR_RET(ret) CHK_AND_PRINT_RSMI_ERR_RET(ret)
std::cout << name << std::endl; std::cout << name << "\n";
std::cout << "\t**Temperature: "; std::cout << "\t**Temperature (edge): ";
ret = rsmi_dev_temp_metric_get(i, 0, RSMI_TEMP_CURRENT, &val_i64); ret = rsmi_dev_temp_metric_get(i, RSMI_TEMP_TYPE_EDGE,
rsmi_temperature_metric_t::RSMI_TEMP_CURRENT, &val_i64);
if (ret == RSMI_STATUS_SUCCESS) { if (ret == RSMI_STATUS_SUCCESS) {
std::cout << val_i64/1000 << "C" << std::endl; std::cout << val_i64/1000 << "C" << "\n";
}
CHK_RSMI_NOT_SUPPORTED_RET(ret)
std::cout << "\t**Temperature (junction): ";
ret = rsmi_dev_temp_metric_get(i, RSMI_TEMP_TYPE_JUNCTION,
rsmi_temperature_metric_t::RSMI_TEMP_CURRENT, &val_i64);
if (ret == RSMI_STATUS_SUCCESS) {
std::cout << val_i64/1000 << "C" << "\n";
} }
CHK_RSMI_NOT_SUPPORTED_RET(ret) CHK_RSMI_NOT_SUPPORTED_RET(ret)
@@ -802,7 +824,7 @@ int main() {
ret = rsmi_dev_volt_metric_get(i, RSMI_VOLT_TYPE_VDDGFX, ret = rsmi_dev_volt_metric_get(i, RSMI_VOLT_TYPE_VDDGFX,
RSMI_VOLT_CURRENT, &val_i64); RSMI_VOLT_CURRENT, &val_i64);
if (ret == RSMI_STATUS_SUCCESS) { if (ret == RSMI_STATUS_SUCCESS) {
std::cout << val_i64 << "mV" << std::endl; std::cout << val_i64 << "mV" << "\n";
} }
CHK_RSMI_NOT_SUPPORTED_RET(ret) CHK_RSMI_NOT_SUPPORTED_RET(ret)
@@ -813,21 +835,21 @@ int main() {
CHK_AND_PRINT_RSMI_ERR_RET(ret) CHK_AND_PRINT_RSMI_ERR_RET(ret)
std::cout << (static_cast<float>(val_i64)/val_ui64) * 100; std::cout << (static_cast<float>(val_i64)/val_ui64) * 100;
std::cout << "% (" << std::dec << val_i64 << "/" std::cout << "% (" << std::dec << val_i64 << "/"
<< std::dec << val_ui64 << ")" << std::endl; << std::dec << val_ui64 << ")" << "\n";
} }
CHK_RSMI_NOT_SUPPORTED_RET(ret) CHK_RSMI_NOT_SUPPORTED_RET(ret)
std::cout << "\t**Current fan RPMs: "; std::cout << "\t**Current fan RPMs: ";
ret = rsmi_dev_fan_rpms_get(i, 0, &val_i64); ret = rsmi_dev_fan_rpms_get(i, 0, &val_i64);
if (ret == RSMI_STATUS_SUCCESS) { if (ret == RSMI_STATUS_SUCCESS) {
std::cout << std::dec << val_i64 << std::endl; std::cout << std::dec << val_i64 << "\n";
} }
CHK_RSMI_NOT_SUPPORTED_RET(ret) CHK_RSMI_NOT_SUPPORTED_RET(ret)
std::cout << "\t**Current Power Cap: "; std::cout << "\t**Current Power Cap: ";
ret = rsmi_dev_power_cap_get(i, 0, &val_ui64); ret = rsmi_dev_power_cap_get(i, 0, &val_ui64);
if (ret == RSMI_STATUS_SUCCESS) { if (ret == RSMI_STATUS_SUCCESS) {
std::cout << std::dec << val_ui64 << "uW" <<std::endl; std::cout << std::dec << val_ui64 << "uW" <<"\n";
} }
CHK_RSMI_NOT_SUPPORTED_RET(ret) CHK_RSMI_NOT_SUPPORTED_RET(ret)
@@ -835,23 +857,23 @@ int main() {
ret = rsmi_dev_power_cap_range_get(i, 0, &val_ui64, &val2_ui64); ret = rsmi_dev_power_cap_range_get(i, 0, &val_ui64, &val2_ui64);
if (ret == RSMI_STATUS_SUCCESS) { if (ret == RSMI_STATUS_SUCCESS) {
std::cout << std::dec << val2_ui64 << " to " std::cout << std::dec << val2_ui64 << " to "
<< std::dec << val_ui64 << " uW" << std::endl; << std::dec << val_ui64 << " uW" << "\n";
} }
CHK_RSMI_NOT_SUPPORTED_RET(ret) CHK_RSMI_NOT_SUPPORTED_RET(ret)
std::cout << "\t**Average Power Usage: "; std::cout << "\t**Average Power Usage: ";
ret = rsmi_dev_power_ave_get(i, 0, &val_ui64); ret = rsmi_dev_power_ave_get(i, 0, &val_ui64);
if (ret == RSMI_STATUS_SUCCESS) { if (ret == RSMI_STATUS_SUCCESS) {
std::cout << static_cast<float>(val_ui64)/1000 << " W" << std::endl; std::cout << static_cast<float>(val_ui64)/1000 << " W" << "\n";
} }
CHK_RSMI_NOT_SUPPORTED_RET(ret) CHK_RSMI_NOT_SUPPORTED_RET(ret)
std::cout << "\t=======" << std::endl; std::cout << "\t=======" << "\n";
} }
std::cout << "***** Testing write api's" << std::endl; std::cout << "***** Testing write api's" << "\n";
if (isUserRunningAsSudo() == false) { if (isUserRunningAsSudo() == false) {
std::cout << "Write APIs require users to execute with sudo. " std::cout << "Write APIs require users to execute with sudo. "
<< "Cannot proceed." << std::endl; << "Cannot proceed." << "\n";
return 0; return 0;
} }
@@ -877,7 +899,7 @@ int main() {
ret = test_set_freq(i); ret = test_set_freq(i);
CHK_AND_PRINT_RSMI_ERR_RET(ret) CHK_AND_PRINT_RSMI_ERR_RET(ret)
ret = test_set_nps_mode(i); ret = test_set_memory_partition(i);
CHK_AND_PRINT_RSMI_ERR_RET(ret) CHK_AND_PRINT_RSMI_ERR_RET(ret)
} }
+286 -47
View File
@@ -417,7 +417,6 @@ static rsmi_status_t set_dev_mon_value(amd::smi::MonitorTypes type,
if (ret == ENOENT) { if (ret == ENOENT) {
return rsmi_status_t::RSMI_STATUS_NOT_SUPPORTED; return rsmi_status_t::RSMI_STATUS_NOT_SUPPORTED;
} }
return amd::smi::ErrnoToRsmiStatus(ret); return amd::smi::ErrnoToRsmiStatus(ret);
} }
@@ -1823,8 +1822,8 @@ mapRSMIToStringComputePartitionTypes {
{RSMI_COMPUTE_PARTITION_QPX, "QPX"} {RSMI_COMPUTE_PARTITION_QPX, "QPX"}
}; };
std::map<rsmi_nps_mode_type_t, std::string> std::map<rsmi_memory_partition_type_t, std::string>
mapRSMIToStringNPSModeTypes { mapRSMIToStringMemoryPartitionTypes {
{RSMI_MEMORY_PARTITION_UNKNOWN, "UNKNOWN"}, {RSMI_MEMORY_PARTITION_UNKNOWN, "UNKNOWN"},
{RSMI_MEMORY_PARTITION_NPS1, "NPS1"}, {RSMI_MEMORY_PARTITION_NPS1, "NPS1"},
{RSMI_MEMORY_PARTITION_NPS2, "NPS2"}, {RSMI_MEMORY_PARTITION_NPS2, "NPS2"},
@@ -1832,8 +1831,8 @@ mapRSMIToStringNPSModeTypes {
{RSMI_MEMORY_PARTITION_NPS8, "NPS8"} {RSMI_MEMORY_PARTITION_NPS8, "NPS8"}
}; };
std::map<std::string, rsmi_nps_mode_type_t> std::map<std::string, rsmi_memory_partition_type_t>
mapStringToNPSModeTypes { mapStringToMemoryPartitionTypes {
{"NPS1", RSMI_MEMORY_PARTITION_NPS1}, {"NPS1", RSMI_MEMORY_PARTITION_NPS1},
{"NPS2", RSMI_MEMORY_PARTITION_NPS2}, {"NPS2", RSMI_MEMORY_PARTITION_NPS2},
{"NPS4", RSMI_MEMORY_PARTITION_NPS4}, {"NPS4", RSMI_MEMORY_PARTITION_NPS4},
@@ -4240,7 +4239,7 @@ rsmi_topo_get_link_weight(uint32_t dv_ind_src, uint32_t dv_ind_dst,
rsmi_status_t rsmi_status_t
rsmi_minmax_bandwidth_get(uint32_t dv_ind_src, uint32_t dv_ind_dst, rsmi_minmax_bandwidth_get(uint32_t dv_ind_src, uint32_t dv_ind_dst,
uint64_t *min_bandwidth, uint64_t *max_bandwidth){ uint64_t *min_bandwidth, uint64_t *max_bandwidth) {
TRY TRY
uint32_t dv_ind = dv_ind_src; uint32_t dv_ind = dv_ind_src;
@@ -4438,9 +4437,20 @@ rsmi_dev_compute_partition_get(uint32_t dv_ind, char *compute_partition,
uint32_t len) { uint32_t len) {
TRY TRY
std::ostringstream ss; std::ostringstream ss;
ss << __PRETTY_FUNCTION__ << "| ======= start ======="; ss << __PRETTY_FUNCTION__ << "| ======= start =======, dv_ind = "
<< dv_ind;
LOG_TRACE(ss); LOG_TRACE(ss);
if ((len == 0) || (compute_partition == nullptr)) { if ((len == 0) || (compute_partition == nullptr)) {
ss << __PRETTY_FUNCTION__
<< " | ======= end ======= "
<< " | Fail "
<< " | Device #: " << dv_ind
<< " | Type: "
<< RocmSMI::devInfoTypesStrings.at(amd::smi::kDevComputePartition)
<< " | Cause: len was 0 or compute_partition variable was null"
<< " | Returning = "
<< getRSMIStatusString(RSMI_STATUS_INVALID_ARGS) << " |";
LOG_ERROR(ss);
return RSMI_STATUS_INVALID_ARGS; return RSMI_STATUS_INVALID_ARGS;
} }
CHK_SUPPORT_NAME_ONLY(compute_partition) CHK_SUPPORT_NAME_ONLY(compute_partition)
@@ -4449,14 +4459,46 @@ rsmi_dev_compute_partition_get(uint32_t dv_ind, char *compute_partition,
rsmi_status_t ret = get_compute_partition(dv_ind, rsmi_status_t ret = get_compute_partition(dv_ind,
returning_compute_partition); returning_compute_partition);
if (ret != RSMI_STATUS_SUCCESS) { return ret; } if (ret != RSMI_STATUS_SUCCESS) {
ss << __PRETTY_FUNCTION__
<< " | ======= end ======= "
<< " | Fail "
<< " | Device #: " << dv_ind
<< " | Type: "
<< RocmSMI::devInfoTypesStrings.at(amd::smi::kDevComputePartition)
<< " | Cause: could not retrieve current compute partition"
<< " | Returning = "
<< getRSMIStatusString(ret) << " |";
LOG_ERROR(ss);
return ret;
}
std::size_t length = returning_compute_partition.copy(compute_partition, len); std::size_t length = returning_compute_partition.copy(compute_partition, len);
compute_partition[length]='\0'; compute_partition[length]='\0';
if (len < (returning_compute_partition.size() + 1)) { if (len < (returning_compute_partition.size() + 1)) {
ss << __PRETTY_FUNCTION__
<< " | ======= end ======= "
<< " | Fail "
<< " | Device #: " << dv_ind
<< " | Type: "
<< RocmSMI::devInfoTypesStrings.at(amd::smi::kDevComputePartition)
<< " | Cause: requested size was insufficient"
<< " | Returning = "
<< getRSMIStatusString(RSMI_STATUS_INSUFFICIENT_SIZE) << " |";
LOG_ERROR(ss);
return RSMI_STATUS_INSUFFICIENT_SIZE; return RSMI_STATUS_INSUFFICIENT_SIZE;
} }
ss << __PRETTY_FUNCTION__
<< " | ======= end ======= "
<< " | Success "
<< " | Device #: " << dv_ind
<< " | Type: "
<< RocmSMI::devInfoTypesStrings.at(amd::smi::kDevComputePartition)
<< " | Data: " << compute_partition
<< " | Returning = "
<< getRSMIStatusString(ret) << " |";
LOG_TRACE(ss);
return ret; return ret;
CATCH CATCH
} }
@@ -4504,6 +4546,16 @@ rsmi_dev_compute_partition_set(uint32_t dv_ind,
break; break;
case RSMI_COMPUTE_PARTITION_INVALID: case RSMI_COMPUTE_PARTITION_INVALID:
default: default:
ss << __PRETTY_FUNCTION__
<< " | ======= end ======= "
<< " | Fail "
<< " | Device #: " << dv_ind
<< " | Type: "
<< RocmSMI::devInfoTypesStrings.at(amd::smi::kDevComputePartition)
<< " | Cause: requested setting was invalid"
<< " | Returning = "
<< getRSMIStatusString(RSMI_STATUS_INVALID_ARGS) << " |";
LOG_ERROR(ss);
return RSMI_STATUS_INVALID_ARGS; return RSMI_STATUS_INVALID_ARGS;
} }
@@ -4512,32 +4564,78 @@ rsmi_dev_compute_partition_set(uint32_t dv_ind,
rsmi_status_t available_ret = rsmi_status_t available_ret =
is_available_compute_partition(dv_ind, newComputePartitionStr); is_available_compute_partition(dv_ind, newComputePartitionStr);
if (available_ret != RSMI_STATUS_SUCCESS) { if (available_ret != RSMI_STATUS_SUCCESS) {
ss << __PRETTY_FUNCTION__
<< " | ======= end ======= "
<< " | Fail "
<< " | Device #: " << dv_ind
<< " | Type: "
<< RocmSMI::devInfoTypesStrings.at(amd::smi::kDevComputePartition)
<< " | Cause: not an available compute partition setting"
<< " | Returning = "
<< getRSMIStatusString(available_ret) << " |";
LOG_ERROR(ss);
return available_ret; return available_ret;
} }
// do nothing if compute_partition is the current compute partition // do nothing if compute_partition is the current compute partition
rsmi_status_t ret_get = get_compute_partition(dv_ind, currentComputePartition); rsmi_status_t ret_get =
get_compute_partition(dv_ind, currentComputePartition);
// we can try to set, even if we get unexpected data // we can try to set, even if we get unexpected data
if (ret_get != RSMI_STATUS_SUCCESS if (ret_get != RSMI_STATUS_SUCCESS
&& ret_get != RSMI_STATUS_UNEXPECTED_DATA) { && ret_get != RSMI_STATUS_UNEXPECTED_DATA) {
ss << __PRETTY_FUNCTION__
<< " | ======= end ======= "
<< " | Fail "
<< " | Device #: " << dv_ind
<< " | Type: "
<< RocmSMI::devInfoTypesStrings.at(amd::smi::kDevComputePartition)
<< " | Cause: could retrieve current compute partition or retrieved"
<< " unexpected data"
<< " | Returning = "
<< getRSMIStatusString(ret_get) << " |";
LOG_ERROR(ss);
return ret_get; return ret_get;
} }
rsmi_compute_partition_type_t currRSMIComputePartition rsmi_compute_partition_type_t currRSMIComputePartition
= mapStringToRSMIComputePartitionTypes[currentComputePartition]; = mapStringToRSMIComputePartitionTypes[currentComputePartition];
if (currRSMIComputePartition == compute_partition) { if (currRSMIComputePartition == compute_partition) {
ss << __PRETTY_FUNCTION__
<< " | ======= end ======= "
<< " | Success - compute partition was already set at requested value"
<< " | Device #: " << dv_ind
<< " | Type: "
<< RocmSMI::devInfoTypesStrings.at(amd::smi::kDevComputePartition)
<< " | Data: " << newComputePartitionStr
<< " | Returning = "
<< getRSMIStatusString(RSMI_STATUS_SUCCESS) << " |";
LOG_TRACE(ss);
return RSMI_STATUS_SUCCESS; return RSMI_STATUS_SUCCESS;
} }
GET_DEV_FROM_INDX GET_DEV_FROM_INDX
int ret = dev->writeDevInfo(amd::smi::kDevComputePartition, int ret = dev->writeDevInfo(amd::smi::kDevComputePartition,
newComputePartitionStr); newComputePartitionStr);
return amd::smi::ErrnoToRsmiStatus(ret); rsmi_status_t returnResponse = amd::smi::ErrnoToRsmiStatus(ret);
ss << __PRETTY_FUNCTION__
<< " | ======= end ======= "
<< " | Success "
<< " | Device #: " << dv_ind
<< " | Type: "
<< RocmSMI::devInfoTypesStrings.at(amd::smi::kDevComputePartition)
<< " | Data: " << newComputePartitionStr
<< " | Returning = "
<< getRSMIStatusString(returnResponse) << " |";
LOG_TRACE(ss);
// TODO(charpoag): investigate providing GPU busy state occured with
return returnResponse;
CATCH CATCH
} }
static rsmi_status_t get_nps_mode(uint32_t dv_ind, std::string &nps_mode) { static rsmi_status_t get_memory_partition(uint32_t dv_ind,
std::string &memory_partition) {
TRY TRY
CHK_SUPPORT_NAME_ONLY(nps_mode.c_str()) CHK_SUPPORT_NAME_ONLY(memory_partition.c_str())
std::string val_str; std::string val_str;
DEVICE_MUTEX DEVICE_MUTEX
@@ -4548,7 +4646,7 @@ static rsmi_status_t get_nps_mode(uint32_t dv_ind, std::string &nps_mode) {
return ret; return ret;
} }
switch (mapStringToNPSModeTypes[val_str]) { switch (mapStringToMemoryPartitionTypes[val_str]) {
case RSMI_MEMORY_PARTITION_NPS1: case RSMI_MEMORY_PARTITION_NPS1:
case RSMI_MEMORY_PARTITION_NPS2: case RSMI_MEMORY_PARTITION_NPS2:
case RSMI_MEMORY_PARTITION_NPS4: case RSMI_MEMORY_PARTITION_NPS4:
@@ -4556,16 +4654,17 @@ static rsmi_status_t get_nps_mode(uint32_t dv_ind, std::string &nps_mode) {
break; break;
case RSMI_MEMORY_PARTITION_UNKNOWN: case RSMI_MEMORY_PARTITION_UNKNOWN:
default: default:
// Retrieved an unknown NPS mode // Retrieved an unknown memory partition
return RSMI_STATUS_UNEXPECTED_DATA; return RSMI_STATUS_UNEXPECTED_DATA;
} }
nps_mode = val_str; memory_partition = val_str;
return RSMI_STATUS_SUCCESS; return RSMI_STATUS_SUCCESS;
CATCH CATCH
} }
rsmi_status_t rsmi_status_t
rsmi_dev_nps_mode_set(uint32_t dv_ind, rsmi_nps_mode_type_t nps_mode) { rsmi_dev_memory_partition_set(uint32_t dv_ind,
rsmi_memory_partition_type_t memory_partition) {
TRY TRY
std::ostringstream ss; std::ostringstream ss;
ss << __PRETTY_FUNCTION__ << "| ======= start ======="; ss << __PRETTY_FUNCTION__ << "| ======= start =======";
@@ -4575,7 +4674,7 @@ rsmi_dev_nps_mode_set(uint32_t dv_ind, rsmi_nps_mode_type_t nps_mode) {
bool isCorrectDevice = false; bool isCorrectDevice = false;
char boardName[128]; char boardName[128];
boardName[0] = '\0'; boardName[0] = '\0';
// rsmi_dev_nps_mode_set is only available for for discrete variant, // rsmi_dev_memory_partition_set is only available for for discrete variant,
// others are required to update through bios settings // others are required to update through bios settings
rsmi_dev_name_get(dv_ind, boardName, 128); rsmi_dev_name_get(dv_ind, boardName, 128);
std::string myBoardName = boardName; std::string myBoardName = boardName;
@@ -4589,14 +4688,24 @@ rsmi_dev_nps_mode_set(uint32_t dv_ind, rsmi_nps_mode_type_t nps_mode) {
} }
if (!isCorrectDevice) { if (!isCorrectDevice) {
ss << __PRETTY_FUNCTION__
<< " | ======= end ======= "
<< " | Fail "
<< " | Device #: " << dv_ind
<< " | Type: "
<< RocmSMI::devInfoTypesStrings.at(amd::smi::kDevMemoryPartition)
<< " | Cause: device board name does not support this action"
<< " | Returning = "
<< getRSMIStatusString(RSMI_STATUS_INVALID_ARGS) << " |";
LOG_ERROR(ss);
return RSMI_STATUS_NOT_SUPPORTED; return RSMI_STATUS_NOT_SUPPORTED;
} }
std::string newNPSMode std::string newMemoryPartition
= mapRSMIToStringNPSModeTypes[nps_mode]; = mapRSMIToStringMemoryPartitionTypes[memory_partition];
std::string currentNPSMode; std::string currentMemoryPartition;
switch (nps_mode) { switch (memory_partition) {
case RSMI_MEMORY_PARTITION_NPS1: case RSMI_MEMORY_PARTITION_NPS1:
case RSMI_MEMORY_PARTITION_NPS2: case RSMI_MEMORY_PARTITION_NPS2:
case RSMI_MEMORY_PARTITION_NPS4: case RSMI_MEMORY_PARTITION_NPS4:
@@ -4604,57 +4713,156 @@ rsmi_dev_nps_mode_set(uint32_t dv_ind, rsmi_nps_mode_type_t nps_mode) {
break; break;
case RSMI_MEMORY_PARTITION_UNKNOWN: case RSMI_MEMORY_PARTITION_UNKNOWN:
default: default:
ss << __PRETTY_FUNCTION__
<< " | ======= end ======= "
<< " | Fail "
<< " | Device #: " << dv_ind
<< " | Type: "
<< RocmSMI::devInfoTypesStrings.at(amd::smi::kDevMemoryPartition)
<< " | Cause: requested setting was invalid"
<< " | Returning = "
<< getRSMIStatusString(RSMI_STATUS_INVALID_ARGS) << " |";
LOG_ERROR(ss);
return RSMI_STATUS_INVALID_ARGS; return RSMI_STATUS_INVALID_ARGS;
} }
// do nothing if nps_mode is the current NPS mode // do nothing if memory_partition is the current mode
rsmi_status_t ret_get = get_nps_mode(dv_ind, currentNPSMode); rsmi_status_t ret_get = get_memory_partition(dv_ind, currentMemoryPartition);
// we can try to set, even if we get unexpected data // we can try to set, even if we get unexpected data
if (ret_get != RSMI_STATUS_SUCCESS if (ret_get != RSMI_STATUS_SUCCESS
&& ret_get != RSMI_STATUS_UNEXPECTED_DATA) { && ret_get != RSMI_STATUS_UNEXPECTED_DATA) {
ss << __PRETTY_FUNCTION__
<< " | ======= end ======= "
<< " | Fail "
<< " | Device #: " << dv_ind
<< " | Type: "
<< RocmSMI::devInfoTypesStrings.at(amd::smi::kDevMemoryPartition)
<< " | Cause: could retrieve current memory partition or retrieved"
<< " unexpected data"
<< " | Returning = "
<< getRSMIStatusString(ret_get) << " |";
LOG_ERROR(ss);
return ret_get; return ret_get;
} }
rsmi_nps_mode_type_t currRSMINpsMode rsmi_memory_partition_type_t currRSMIMemoryPartition
= mapStringToNPSModeTypes[currentNPSMode]; = mapStringToMemoryPartitionTypes[currentMemoryPartition];
if (currRSMINpsMode == nps_mode) { if (currRSMIMemoryPartition == memory_partition) {
ss << __PRETTY_FUNCTION__
<< " | ======= end ======= "
<< " | Success - no change, current memory partition was already requested"
<< " setting"
<< " | Device #: " << dv_ind
<< " | Type: "
<< RocmSMI::devInfoTypesStrings.at(amd::smi::kDevMemoryPartition)
<< " | Data: " << newMemoryPartition
<< " | Returning = "
<< getRSMIStatusString(RSMI_STATUS_SUCCESS) << " |";
LOG_TRACE(ss);
return RSMI_STATUS_SUCCESS; return RSMI_STATUS_SUCCESS;
} }
GET_DEV_FROM_INDX GET_DEV_FROM_INDX
int ret = dev->writeDevInfo(amd::smi::kDevMemoryPartition, newNPSMode); int ret = dev->writeDevInfo(amd::smi::kDevMemoryPartition,
newMemoryPartition);
if (amd::smi::ErrnoToRsmiStatus(ret) != RSMI_STATUS_SUCCESS) { if (amd::smi::ErrnoToRsmiStatus(ret) != RSMI_STATUS_SUCCESS) {
return amd::smi::ErrnoToRsmiStatus(ret); rsmi_status_t err = amd::smi::ErrnoToRsmiStatus(ret);
ss << __PRETTY_FUNCTION__
<< " | ======= end ======= "
<< " | Fail "
<< " | Device #: " << dv_ind
<< " | Type: "
<< RocmSMI::devInfoTypesStrings.at(amd::smi::kDevMemoryPartition)
<< " | Cause: issue writing reqested setting of " + newMemoryPartition
<< " | Returning = "
<< getRSMIStatusString(err) << " |";
LOG_ERROR(ss);
return err;
} }
return dev->restartAMDGpuDriver(); rsmi_status_t restartRet = dev->restartAMDGpuDriver();
ss << __PRETTY_FUNCTION__
<< " | ======= end ======= "
<< " | Success - if restart completed successfully"
<< " | Device #: " << dv_ind
<< " | Type: "
<< RocmSMI::devInfoTypesStrings.at(amd::smi::kDevMemoryPartition)
<< " | Data: " << newMemoryPartition
<< " | Returning = "
<< getRSMIStatusString(restartRet) << " |";
LOG_TRACE(ss);
return restartRet;
CATCH CATCH
} }
rsmi_status_t rsmi_status_t
rsmi_dev_nps_mode_get(uint32_t dv_ind, char *nps_mode, rsmi_dev_memory_partition_get(uint32_t dv_ind, char *memory_partition,
uint32_t len) { uint32_t len) {
TRY TRY
std::ostringstream ss; std::ostringstream ss;
ss << __PRETTY_FUNCTION__ << "| ======= start ======="; ss << __PRETTY_FUNCTION__ << "| ======= start =======";
LOG_TRACE(ss); LOG_TRACE(ss);
if ((len == 0) || (nps_mode == nullptr)) { if ((len == 0) || (memory_partition == nullptr)) {
ss << __PRETTY_FUNCTION__
<< " | ======= end ======= "
<< " | Fail "
<< " | Device #: " << dv_ind
<< " | Type: "
<< RocmSMI::devInfoTypesStrings.at(amd::smi::kDevMemoryPartition)
<< " | Cause: user sent invalid arguments, len = 0 or memory partition"
<< " was a null ptr"
<< " | Returning = "
<< getRSMIStatusString(RSMI_STATUS_INVALID_ARGS) << " |";
LOG_ERROR(ss);
return RSMI_STATUS_INVALID_ARGS; return RSMI_STATUS_INVALID_ARGS;
} }
CHK_SUPPORT_NAME_ONLY(nps_mode) CHK_SUPPORT_NAME_ONLY(memory_partition)
std::string returning_nps_mode; std::string returning_memory_partition;
rsmi_status_t ret = get_nps_mode(dv_ind, rsmi_status_t ret = get_memory_partition(dv_ind,
returning_nps_mode); returning_memory_partition);
if (ret != RSMI_STATUS_SUCCESS) { return ret; } if (ret != RSMI_STATUS_SUCCESS) {
ss << __PRETTY_FUNCTION__
<< " | ======= end ======= "
<< " | Fail "
<< " | Device #: " << dv_ind
<< " | Type: "
<< RocmSMI::devInfoTypesStrings.at(amd::smi::kDevMemoryPartition)
<< " | Cause: could not successfully retrieve current memory partition "
<< " | Returning = "
<< getRSMIStatusString(ret) << " |";
LOG_ERROR(ss);
return ret;
}
std::size_t length = returning_nps_mode.copy(nps_mode, len); std::size_t buff_size =
nps_mode[length]='\0'; returning_memory_partition.copy(memory_partition, len);
memory_partition[buff_size] = '\0';
if (len < (returning_nps_mode.size() + 1)) { if (len < (returning_memory_partition.size() + 1)) {
ss << __PRETTY_FUNCTION__
<< " | ======= end ======= "
<< " | Fail "
<< " | Device #: " << dv_ind
<< " | Type: "
<< RocmSMI::devInfoTypesStrings.at(amd::smi::kDevMemoryPartition)
<< " | Cause: could not successfully retrieve current memory partition "
<< " | Returning = "
<< getRSMIStatusString(ret) << " |";
LOG_ERROR(ss);
return RSMI_STATUS_INSUFFICIENT_SIZE; return RSMI_STATUS_INSUFFICIENT_SIZE;
} }
ss << __PRETTY_FUNCTION__
<< " | ======= end ======= "
<< " | Success "
<< " | Device #: " << dv_ind
<< " | Type: "
<< RocmSMI::devInfoTypesStrings.at(amd::smi::kDevMemoryPartition)
<< " | Data: " << memory_partition
<< " | Returning = "
<< getRSMIStatusString(ret) << " |";
LOG_TRACE(ss);
return ret; return ret;
CATCH CATCH
} }
@@ -4668,22 +4876,37 @@ rsmi_status_t rsmi_dev_compute_partition_reset(uint32_t dv_ind) {
DEVICE_MUTEX DEVICE_MUTEX
GET_DEV_FROM_INDX GET_DEV_FROM_INDX
rsmi_status_t ret = RSMI_STATUS_NOT_SUPPORTED; rsmi_status_t ret = RSMI_STATUS_NOT_SUPPORTED;
// read temp file
// Only use 1st index, rest are there in-case of future issues
// NOTE: Partitions sets cause rocm-smi indexes to fluctuate
// since the nodes are grouped in respect to primary node - why we only use
// 1st node/device id to reset
std::string bootState = std::string bootState =
dev->readBootPartitionState<rsmi_compute_partition_type_t>(dv_ind); dev->readBootPartitionState<rsmi_compute_partition_type_t>(0);
// Initiate reset // Initiate reset
// If bootState is UNKNOWN, we cannot reset - return RSMI_STATUS_NOT_SUPPORTED // If bootState is UNKNOWN, we cannot reset - return RSMI_STATUS_NOT_SUPPORTED
// Likely due to device not supporting it // Likely due to device not supporting it
if (bootState != "UNKNOWN") { if (bootState != "UNKNOWN") {
rsmi_compute_partition_type_t compute_partition = rsmi_compute_partition_type_t compute_partition =
mapStringToRSMIComputePartitionTypes[bootState]; mapStringToRSMIComputePartitionTypes[bootState];
ret = rsmi_dev_compute_partition_set(dv_ind, compute_partition); ret = rsmi_dev_compute_partition_set(dv_ind, compute_partition);
} }
ss << __PRETTY_FUNCTION__
<< " | ======= end ======= "
<< " | Success - if original boot state was not unknown or valid setting"
<< " | Device #: " << dv_ind
<< " | Type: "
<< RocmSMI::devInfoTypesStrings.at(amd::smi::kDevComputePartition)
<< " | Data: " << bootState
<< " | Returning = "
<< getRSMIStatusString(ret) << " |";
LOG_TRACE(ss);
return ret; return ret;
CATCH CATCH
} }
rsmi_status_t rsmi_dev_nps_mode_reset(uint32_t dv_ind) { rsmi_status_t rsmi_dev_memory_partition_reset(uint32_t dv_ind) {
TRY TRY
std::ostringstream ss; std::ostringstream ss;
ss << __PRETTY_FUNCTION__ << "| ======= start ======="; ss << __PRETTY_FUNCTION__ << "| ======= start =======";
@@ -4692,16 +4915,32 @@ rsmi_status_t rsmi_dev_nps_mode_reset(uint32_t dv_ind) {
DEVICE_MUTEX DEVICE_MUTEX
GET_DEV_FROM_INDX GET_DEV_FROM_INDX
rsmi_status_t ret = RSMI_STATUS_NOT_SUPPORTED; rsmi_status_t ret = RSMI_STATUS_NOT_SUPPORTED;
// read temp file
// Only use 1st index, rest are there in-case of future issues
// NOTE: Partitions sets cause rocm-smi indexes to fluctuate.
// Since the nodes are grouped in respect to primary node - why we only use
// 1st node/device id to reset
std::string bootState = std::string bootState =
dev->readBootPartitionState<rsmi_nps_mode_type_t>(dv_ind); dev->readBootPartitionState<rsmi_memory_partition_type_t>(0);
// Initiate reset // Initiate reset
// If bootState is UNKNOWN, we cannot reset - return RSMI_STATUS_NOT_SUPPORTED // If bootState is UNKNOWN, we cannot reset - return RSMI_STATUS_NOT_SUPPORTED
// Likely due to device not supporting it // Likely due to device not supporting it
if (bootState != "UNKNOWN") { if (bootState != "UNKNOWN") {
rsmi_nps_mode_type_t nps_mode = mapStringToNPSModeTypes[bootState]; rsmi_memory_partition_type_t memory_partition =
ret = rsmi_dev_nps_mode_set(dv_ind, nps_mode); mapStringToMemoryPartitionTypes[bootState];
ret = rsmi_dev_memory_partition_set(dv_ind, memory_partition);
} }
ss << __PRETTY_FUNCTION__
<< " | ======= end ======= "
<< " | Success - if original boot state was not unknown or valid setting"
<< " | Device #: " << dv_ind
<< " | Type: "
<< RocmSMI::devInfoTypesStrings.at(amd::smi::kDevMemoryPartition)
<< " | Data: " << bootState
<< " | Returning = "
<< getRSMIStatusString(ret) << " |";
LOG_TRACE(ss);
return ret; return ret;
CATCH CATCH
} }
+20 -18
View File
@@ -1272,7 +1272,7 @@ template <typename T> rsmi_status_t storeParameter(uint32_t dv_ind);
// Uses template specialization, to restrict types to identify // Uses template specialization, to restrict types to identify
// calls needed to complete the function. // calls needed to complete the function.
// typename - restricted to // typename - restricted to
// rsmi_compute_partition_type_t or rsmi_compute_partition_type_t // rsmi_compute_partition_type_t or rsmi_memory_partition_type_t
// dv_ind - device index // dv_ind - device index
// tempFileName - base file name // tempFileName - base file name
template <> template <>
@@ -1286,9 +1286,9 @@ rsmi_status_t storeParameter<rsmi_compute_partition_type_t>(uint32_t dv_ind) {
if (doesFileExist) { if (doesFileExist) {
return returnStatus; return returnStatus;
} }
uint32_t length = 128; const uint32_t kLen = 128;
char data[length]; char data[kLen];
rsmi_status_t ret = rsmi_dev_compute_partition_get(dv_ind, data, length); rsmi_status_t ret = rsmi_dev_compute_partition_get(dv_ind, data, kLen);
rsmi_status_t storeRet; rsmi_status_t storeRet;
if (ret == RSMI_STATUS_SUCCESS) { if (ret == RSMI_STATUS_SUCCESS) {
@@ -1312,31 +1312,32 @@ rsmi_status_t storeParameter<rsmi_compute_partition_type_t>(uint32_t dv_ind) {
// Uses template specialization, to restrict types to identify // Uses template specialization, to restrict types to identify
// calls needed to complete the function. // calls needed to complete the function.
// typename - restricted to // typename - restricted to
// rsmi_compute_partition_type_t or rsmi_compute_partition_type_t // rsmi_compute_partition_type_t or rsmi_memory_partition_type_t
// dv_ind - device index // dv_ind - device index
// tempFileName - base file name // tempFileName - base file name
template <> rsmi_status_t storeParameter<rsmi_nps_mode_type_t>(uint32_t dv_ind) { template <>
rsmi_status_t storeParameter<rsmi_memory_partition_type_t>(uint32_t dv_ind) {
rsmi_status_t returnStatus = RSMI_STATUS_SUCCESS; rsmi_status_t returnStatus = RSMI_STATUS_SUCCESS;
uint32_t length = 128; uint32_t kDatalength = 128;
char data[length]; char data[kDatalength];
bool doesFileExist; bool doesFileExist;
std::tie(doesFileExist, std::ignore) = readTmpFile(dv_ind, "boot", std::tie(doesFileExist, std::ignore) = readTmpFile(dv_ind, "boot",
"nps_mode"); "memory_partition");
// if temporary file exists -> we do not need to store anything new // if temporary file exists -> we do not need to store anything new
// if not, read & store the state value // if not, read & store the state value
if (doesFileExist) { if (doesFileExist) {
return returnStatus; return returnStatus;
} }
rsmi_status_t ret = rsmi_dev_nps_mode_get(dv_ind, data, length); rsmi_status_t ret = rsmi_dev_memory_partition_get(dv_ind, data, kDatalength);
rsmi_status_t storeRet; rsmi_status_t storeRet;
if (ret == RSMI_STATUS_SUCCESS) { if (ret == RSMI_STATUS_SUCCESS) {
storeRet = storeTmpFile(dv_ind, "nps_mode", "boot", data); storeRet = storeTmpFile(dv_ind, "memory_partition", "boot", data);
} else if (ret == RSMI_STATUS_NOT_SUPPORTED) { } else if (ret == RSMI_STATUS_NOT_SUPPORTED) {
// not supported is ok // not supported is ok
storeRet = storeTmpFile(dv_ind, "nps_mode", "boot", "UNKNOWN"); storeRet = storeTmpFile(dv_ind, "memory_partition", "boot", "UNKNOWN");
} else { } else {
storeRet = storeTmpFile(dv_ind, "nps_mode", "boot", "UNKNOWN"); storeRet = storeTmpFile(dv_ind, "memory_partition", "boot", "UNKNOWN");
returnStatus = ret; returnStatus = ret;
} }
@@ -1350,9 +1351,9 @@ template <> rsmi_status_t storeParameter<rsmi_nps_mode_type_t>(uint32_t dv_ind)
rsmi_status_t Device::storeDevicePartitions(uint32_t dv_ind) { rsmi_status_t Device::storeDevicePartitions(uint32_t dv_ind) {
rsmi_status_t returnStatus = RSMI_STATUS_SUCCESS; rsmi_status_t returnStatus = RSMI_STATUS_SUCCESS;
returnStatus = storeParameter<rsmi_compute_partition_type_t>(dv_ind); returnStatus = storeParameter<rsmi_compute_partition_type_t>(dv_ind);
rsmi_status_t npsRet = storeParameter<rsmi_nps_mode_type_t>(dv_ind); rsmi_status_t ret = storeParameter<rsmi_memory_partition_type_t>(dv_ind);
if (returnStatus == RSMI_STATUS_SUCCESS) { // only record earliest error if (returnStatus == RSMI_STATUS_SUCCESS) { // only record earliest error
returnStatus = npsRet; returnStatus = ret;
} }
return returnStatus; return returnStatus;
} }
@@ -1381,10 +1382,11 @@ std::string Device::readBootPartitionState<rsmi_compute_partition_type_t>(
// or rsmi_compute_partition_type_t // or rsmi_compute_partition_type_t
// dv_ind - device index // dv_ind - device index
template <> template <>
std::string Device::readBootPartitionState<rsmi_nps_mode_type_t>( std::string Device::readBootPartitionState<rsmi_memory_partition_type_t>(
uint32_t dv_ind) { uint32_t dv_ind) {
std::string boot_state; std::string boot_state;
std::tie(std::ignore, boot_state) = readTmpFile(dv_ind, "boot", "nps_mode"); std::tie(std::ignore, boot_state) = readTmpFile(dv_ind, "boot",
"memory_partition");
return boot_state; return boot_state;
} }
+15 -3
View File
@@ -56,6 +56,7 @@
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <unordered_set> #include <unordered_set>
#include <regex>
#include "rocm_smi/rocm_smi_io_link.h" #include "rocm_smi/rocm_smi_io_link.h"
#include "rocm_smi/rocm_smi_kfd.h" #include "rocm_smi/rocm_smi_kfd.h"
@@ -183,6 +184,7 @@ int ReadKFDDeviceProperties(uint32_t kfd_node_id,
int ret; int ret;
std::ifstream fs; std::ifstream fs;
std::string properties_path; std::string properties_path;
std::ostringstream ss;
assert(retVec != nullptr); assert(retVec != nullptr);
@@ -192,9 +194,14 @@ int ReadKFDDeviceProperties(uint32_t kfd_node_id,
return ret; return ret;
} }
ss << __PRETTY_FUNCTION__ << " | properties file contains = {";
while (std::getline(fs, line)) { while (std::getline(fs, line)) {
retVec->push_back(line); retVec->push_back(line);
ss << line << ",\n";
} }
ss << "}";
// Leaving below to debug any future properties file changes
// LOG_DEBUG(ss);
if (retVec->empty()) { if (retVec->empty()) {
fs.close(); fs.close();
@@ -616,15 +623,20 @@ int KFDNode::ReadProperties(void) {
} }
std::string key_str; std::string key_str;
// std::string val_str; std::string val_str;
uint64_t val_int; // Assume all properties are unsigned integers for now uint64_t val_int; // Assume all properties are unsigned integers for now
std::istringstream fs; std::istringstream fs;
std::ostringstream ss;
for (const auto & i : propVec) { for (const auto & i : propVec) {
fs.str(i); fs.str(i);
fs >> key_str; fs >> key_str;
fs >> val_int; fs >> val_str;
// Leaving below to debug any new properties file changes
// ss << __PRETTY_FUNCTION__ << " | key = " << key_str
// << "; val = " << val_str;
// LOG_TRACE(ss);
val_int = std::stoull(val_str);
properties_[key_str] = val_int; properties_[key_str] = val_int;
fs.str(""); fs.str("");
+94 -67
View File
@@ -59,6 +59,7 @@
#include <unordered_map> #include <unordered_map>
#include <utility> #include <utility>
#include <vector> #include <vector>
#include <climits>
#include "rocm_smi/rocm_smi.h" #include "rocm_smi/rocm_smi.h"
#include "rocm_smi/rocm_smi_device.h" #include "rocm_smi/rocm_smi_device.h"
@@ -780,7 +781,7 @@ uint32_t RocmSMI::DiscoverAmdgpuDevices(void) {
myNode.s_node_id = node_id; myNode.s_node_id = node_id;
myNode.s_gpu_id = gpu_id; myNode.s_gpu_id = gpu_id;
myNode.s_unique_id = unique_id; myNode.s_unique_id = unique_id;
if(gpu_id != 0) { // only add gpu nodes, 0 = CPU if (gpu_id != 0) { // only add gpu nodes, 0 = CPU
allSystemNodes.emplace(unique_id, myNode); allSystemNodes.emplace(unique_id, myNode);
} }
} else { } else {
@@ -790,93 +791,119 @@ uint32_t RocmSMI::DiscoverAmdgpuDevices(void) {
} }
ss << __PRETTY_FUNCTION__ << " | Ordered system nodes found = {"; ss << __PRETTY_FUNCTION__ << " | Ordered system nodes found = {";
for(auto i: allSystemNodes) { for (auto i : allSystemNodes) {
ss << "\n[node_id = " << std::to_string(i.second.s_node_id) ss << "\n[node_id = " << std::to_string(i.second.s_node_id)
<< "; gpu_id = " << std::to_string(i.second.s_gpu_id) << "; gpu_id = " << std::to_string(i.second.s_gpu_id)
<< "; unique_id = " << std::to_string(i.second.s_unique_id) << "; unique_id = " << std::to_string(i.second.s_unique_id)
<< "], " << "], ";
;
} }
ss << "}"; ss << "}";
LOG_DEBUG(ss); LOG_DEBUG(ss);
uint32_t cardAdded = 0;
// Discover all root cards & gpu partitions associated with each // Discover all root cards & gpu partitions associated with each
for (uint32_t node_id = 0; node_id < count; node_id++) { for (uint32_t cardId = 0; cardId < count; cardId++) {
std::string path = kPathDRMRoot; std::string path = kPathDRMRoot;
path += "/card"; path += "/card";
path += std::to_string(node_id); path += std::to_string(cardId);
uint64_t primary_unique_id = 0; uint64_t primary_unique_id = 0;
// each identified gpu card node is a primary node for // each identified gpu card node is a primary node for
// potential matching unique ids // potential matching unique ids
if (isAMDGPU(path) || if (isAMDGPU(path) ||
(init_options_ & RSMI_INIT_FLAG_ALL_GPUS)) { (init_options_ & RSMI_INIT_FLAG_ALL_GPUS)) {
std::string d_name = "card"; std::string d_name = "card";
d_name += std::to_string(node_id); d_name += std::to_string(cardId);
AddToDeviceList(d_name); AddToDeviceList(d_name);
ss << __PRETTY_FUNCTION__ ss << __PRETTY_FUNCTION__
<< " | Ordered system nodes seen in lookup = {"; << " | Ordered system nodes seen in lookup = {";
for (auto i : allSystemNodes) { for (auto i : allSystemNodes) {
ss << "\n[node_id = " << std::to_string(i.second.s_node_id) ss << "\n[node_id = " << std::to_string(i.second.s_node_id)
<< "; gpu_id = " << std::to_string(i.second.s_gpu_id) << "; gpu_id = " << std::to_string(i.second.s_gpu_id)
<< "; unique_id = " << std::to_string(i.second.s_unique_id) << "; unique_id = " << std::to_string(i.second.s_unique_id)
<< "], "; << "], ";
} }
ss << "}"; ss << "}";
LOG_DEBUG(ss); LOG_DEBUG(ss);
uint64_t temp_primary_unique_id = 0; uint64_t temp_primary_unique_id = 0;
if (allSystemNodes.empty()) { if (allSystemNodes.empty()) {
continue; cardAdded++;
} ss << __PRETTY_FUNCTION__
<< " | allSystemNodes.empty() = true, continue...";
LOG_DEBUG(ss);
continue;
}
// get lowest key 1st to keep order of nodes matching card // get current partition
uint32_t lowest_NodeId = 0; const int kSize = 256;
uint32_t curr_NodeId = 0; char computePartition[kSize];
std::string strCompPartition = "UNKNOWN";
uint32_t numMonDevices = 0;
rsmi_num_monitor_devices(&numMonDevices);
if (rsmi_dev_compute_partition_get(cardAdded, computePartition, kSize)
== RSMI_STATUS_SUCCESS) {
strCompPartition = computePartition;
}
uint64_t device_uuid = 0;
if (rsmi_dev_unique_id_get(cardAdded, &device_uuid)
!= RSMI_STATUS_SUCCESS) {
cardAdded++;
allSystemNodes.erase(device_uuid);
ss << __PRETTY_FUNCTION__
<< " | rsmi_dev_unique_id_get(cardId, &device_uuid)"
<< " was not successful, continue.. ";
LOG_DEBUG(ss);
continue;
}
for (auto it = allSystemNodes.begin(), end = allSystemNodes.end(); temp_primary_unique_id =
it != end; it = allSystemNodes.upper_bound(it->first)) { allSystemNodes.find(device_uuid)->second.s_unique_id;
curr_NodeId = it->second.s_node_id; auto temp_numb_nodes = allSystemNodes.count(temp_primary_unique_id);
if (it == allSystemNodes.begin()) {
lowest_NodeId = it->second.s_node_id;
}
if (curr_NodeId <= lowest_NodeId) {
lowest_NodeId = curr_NodeId;
temp_primary_unique_id = it->second.s_unique_id;
}
}
ss << __PRETTY_FUNCTION__
<< " | lowest_NodeId = " << std::to_string(lowest_NodeId)
<< " | curr_NodeId = " << std::to_string(curr_NodeId)
<< " | temp_primary_unique_id = "
<< std::to_string(temp_primary_unique_id);
LOG_DEBUG(ss);
if (temp_primary_unique_id != 0) { ss << __PRETTY_FUNCTION__
primary_unique_id = temp_primary_unique_id; << " | device/node id (cardId) = " << std::to_string(cardId)
} else { << " | card id (cardAdded) = " << std::to_string(cardAdded)
allSystemNodes.erase(primary_unique_id); << " | numMonDevices = " << std::to_string(numMonDevices)
continue; << " | compute partition = " << strCompPartition
} << " | temp_primary_unique_id = "
<< std::to_string(temp_primary_unique_id)
<< " | Num of nodes matching temp_primary_unique_id = "
<< temp_numb_nodes
<< " | device_uuid (hex/uint) = "
<< print_unsigned_hex_and_int(device_uuid)
<< " | device_uuid (uint64_t) = " << device_uuid;
LOG_DEBUG(ss);
auto numb_nodes = allSystemNodes.count(primary_unique_id); if (temp_primary_unique_id != 0) {
ss << __PRETTY_FUNCTION__ << " | REFRESH - primary_unique_id = " primary_unique_id = temp_primary_unique_id;
<< std::to_string(primary_unique_id) << " has " } else {
<< std::to_string(numb_nodes) << " known gpu nodes"; cardAdded++;
LOG_DEBUG(ss); // remove already added nodes associated with current card
while (numb_nodes > 1) { auto erasedNodes = allSystemNodes.erase(0);
std::string secNode = "card"; continue;
secNode += std::to_string(node_id); // add the primary node id }
AddToDeviceList(secNode);
numb_nodes--; auto numb_nodes = allSystemNodes.count(primary_unique_id);
} ss << __PRETTY_FUNCTION__ << " | REFRESH - primary_unique_id = "
// remove already added nodes associated with current card << std::to_string(primary_unique_id) << " has "
auto erasedNodes = allSystemNodes.erase(primary_unique_id); << std::to_string(numb_nodes) << " known gpu nodes";
ss << __PRETTY_FUNCTION__ << " | After finding primary_unique_id = " LOG_DEBUG(ss);
<< std::to_string(primary_unique_id) << " erased " while (numb_nodes > 1) {
<< std::to_string(erasedNodes) << " nodes"; std::string secNode = "card";
LOG_DEBUG(ss); secNode += std::to_string(cardId); // add the primary node id
AddToDeviceList(secNode);
numb_nodes--;
cardAdded++;
}
// remove already added nodes associated with current card
auto erasedNodes = allSystemNodes.erase(primary_unique_id);
ss << __PRETTY_FUNCTION__ << " | After finding primary_unique_id = "
<< std::to_string(primary_unique_id) << " erased "
<< std::to_string(erasedNodes) << " nodes";
LOG_DEBUG(ss);
cardAdded++;
} }
} }
@@ -45,8 +45,12 @@
#include <stdint.h> #include <stdint.h>
#include <stddef.h> #include <stddef.h>
#include <unistd.h>
#include <iostream> #include <iostream>
#include <chrono> // NOLINT [build]
#include <map>
#include <string>
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "rocm_smi/rocm_smi.h" #include "rocm_smi/rocm_smi.h"
@@ -134,6 +138,26 @@ void TestComputePartitionReadWrite::Run(void) {
return; return;
} }
// Confirm system supports compute partition, before executing wait
ret = rsmi_dev_compute_partition_get(0, orig_char_computePartition, 255);
if (ret == RSMI_STATUS_SUCCESS) {
// Adding a delay - since changing partitions depends on gpus not
// being in an active state, we'll wait a few seconds before starting
// full testing
auto start = std::chrono::high_resolution_clock::now();
int waitTime = 20;
std::cout << "** Waiting for "
<< std::dec << waitTime
<< " seconds, for any GPU"
<< " activity to clear up. **" << std::endl;
sleep(waitTime);
auto stop = std::chrono::high_resolution_clock::now();
auto duration =
std::chrono::duration_cast<std::chrono::microseconds>(stop - start);
std::cout << "** Waiting took " << duration.count() / 1000000
<< " seconds **" << std::endl;
}
for (uint32_t dv_ind = 0; dv_ind < num_monitor_devs(); ++dv_ind) { for (uint32_t dv_ind = 0; dv_ind < num_monitor_devs(); ++dv_ind) {
if (dv_ind != 0) { if (dv_ind != 0) {
IF_VERB(STANDARD) { IF_VERB(STANDARD) {
@@ -142,7 +166,7 @@ void TestComputePartitionReadWrite::Run(void) {
} }
PrintDeviceHeader(dv_ind); PrintDeviceHeader(dv_ind);
//Standard checks to see if API is supported, before running full tests // Standard checks to see if API is supported, before running full tests
ret = rsmi_dev_compute_partition_get(dv_ind, orig_char_computePartition, ret = rsmi_dev_compute_partition_get(dv_ind, orig_char_computePartition,
255); 255);
if (ret == RSMI_STATUS_NOT_SUPPORTED) { if (ret == RSMI_STATUS_NOT_SUPPORTED) {
@@ -169,12 +193,12 @@ void TestComputePartitionReadWrite::Run(void) {
ASSERT_EQ(RSMI_STATUS_SUCCESS, ret); ASSERT_EQ(RSMI_STATUS_SUCCESS, ret);
// Verify api support checking functionality is working // Verify api support checking functionality is working
uint32_t length = 2; uint32_t kLength = 2;
char smallBuffer[length]; char smallBuffer[kLength];
err = rsmi_dev_compute_partition_get(dv_ind, smallBuffer, length); err = rsmi_dev_compute_partition_get(dv_ind, smallBuffer, kLength);
size_t size = sizeof(smallBuffer)/sizeof(*smallBuffer); size_t size = sizeof(smallBuffer)/sizeof(*smallBuffer);
ASSERT_EQ(err, RSMI_STATUS_INSUFFICIENT_SIZE); ASSERT_EQ(err, RSMI_STATUS_INSUFFICIENT_SIZE);
ASSERT_EQ((size_t)length, size); ASSERT_EQ((size_t)kLength, size);
IF_VERB(STANDARD) { IF_VERB(STANDARD) {
if (err == RSMI_STATUS_INSUFFICIENT_SIZE) { if (err == RSMI_STATUS_INSUFFICIENT_SIZE) {
std::cout << "\t**" std::cout << "\t**"
@@ -207,9 +231,9 @@ void TestComputePartitionReadWrite::Run(void) {
} }
// Verify api support checking functionality is working // Verify api support checking functionality is working
rsmi_compute_partition_type new_computePartition rsmi_compute_partition_type_t newPartition
= rsmi_compute_partition_type::RSMI_COMPUTE_PARTITION_INVALID; = rsmi_compute_partition_type_t::RSMI_COMPUTE_PARTITION_INVALID;
err = rsmi_dev_compute_partition_set(dv_ind, new_computePartition); err = rsmi_dev_compute_partition_set(dv_ind, newPartition);
ASSERT_TRUE((err == RSMI_STATUS_INVALID_ARGS) || ASSERT_TRUE((err == RSMI_STATUS_INVALID_ARGS) ||
(err == RSMI_STATUS_NOT_SUPPORTED) || (err == RSMI_STATUS_NOT_SUPPORTED) ||
(err == RSMI_STATUS_PERMISSION)); (err == RSMI_STATUS_PERMISSION));
@@ -246,24 +270,24 @@ void TestComputePartitionReadWrite::Run(void) {
* //!< work together with shared memory * //!< work together with shared memory
*/ */
for (int partition = RSMI_COMPUTE_PARTITION_CPX; for (int partition =
partition <= RSMI_COMPUTE_PARTITION_QPX; rsmi_compute_partition_type_t::RSMI_COMPUTE_PARTITION_CPX;
partition <= rsmi_compute_partition_type_t::RSMI_COMPUTE_PARTITION_QPX;
partition++) { partition++) {
new_computePartition newPartition = static_cast<rsmi_compute_partition_type_t>(partition);
= static_cast<rsmi_compute_partition_type>(partition);
IF_VERB(STANDARD) { IF_VERB(STANDARD) {
std::cout << std::endl; std::cout << std::endl;
std::cout << "\t**" std::cout << "\t**"
<< "======== TEST RSMI_COMPUTE_PARTITION_" << "======== TEST RSMI_COMPUTE_PARTITION_"
<< computePartitionString(new_computePartition) << computePartitionString(newPartition)
<< " ===============" << std::endl; << " ===============" << std::endl;
} }
IF_VERB(STANDARD) { IF_VERB(STANDARD) {
std::cout << "\t**" std::cout << "\t**"
<< "Attempting to set compute partition to: " << "Attempting to set compute partition to: "
<< computePartitionString(new_computePartition) << std::endl; << computePartitionString(newPartition) << std::endl;
} }
ret = rsmi_dev_compute_partition_set(dv_ind, new_computePartition); ret = rsmi_dev_compute_partition_set(dv_ind, newPartition);
bool isSettingUnavailable = false; bool isSettingUnavailable = false;
ASSERT_TRUE((ret == RSMI_STATUS_SUCCESS) || ASSERT_TRUE((ret == RSMI_STATUS_SUCCESS) ||
(ret == RSMI_STATUS_SETTING_UNAVAILABLE)); (ret == RSMI_STATUS_SETTING_UNAVAILABLE));
@@ -282,7 +306,7 @@ void TestComputePartitionReadWrite::Run(void) {
} }
if (isSettingUnavailable) { if (isSettingUnavailable) {
ASSERT_EQ(RSMI_STATUS_SETTING_UNAVAILABLE, ret); ASSERT_EQ(RSMI_STATUS_SETTING_UNAVAILABLE, ret);
ASSERT_STRNE(computePartitionString(new_computePartition).c_str(), ASSERT_STRNE(computePartitionString(newPartition).c_str(),
current_char_computePartition); current_char_computePartition);
IF_VERB(STANDARD) { IF_VERB(STANDARD) {
std::cout << "\t**" std::cout << "\t**"
@@ -290,19 +314,19 @@ void TestComputePartitionReadWrite::Run(void) {
<< "RSMI_STATUS_SETTING_UNAVAILABLE,\n\t current compute " << "RSMI_STATUS_SETTING_UNAVAILABLE,\n\t current compute "
<< "partition (" << current_char_computePartition << "partition (" << current_char_computePartition
<< ") did not update to (" << ") did not update to ("
<< computePartitionString(new_computePartition) << ")" << computePartitionString(newPartition) << ")"
<< std::endl; << std::endl;
} }
} else { } else {
ASSERT_EQ(RSMI_STATUS_SUCCESS, ret); ASSERT_EQ(RSMI_STATUS_SUCCESS, ret);
ASSERT_STREQ(computePartitionString(new_computePartition).c_str(), ASSERT_STREQ(computePartitionString(newPartition).c_str(),
current_char_computePartition); current_char_computePartition);
IF_VERB(STANDARD) { IF_VERB(STANDARD) {
std::cout << "\t**" std::cout << "\t**"
<< "Confirmed current compute partition (" << "Confirmed current compute partition ("
<< current_char_computePartition << ") matches" << current_char_computePartition << ") matches"
<< "\n\t requested compute partition (" << "\n\t requested compute partition ("
<< computePartitionString(new_computePartition) << ")" << computePartitionString(newPartition) << ")"
<< std::endl; << std::endl;
} }
} }
@@ -355,26 +379,27 @@ void TestComputePartitionReadWrite::Run(void) {
<< "=========== TEST RETURN TO ORIGINAL COMPUTE PARTITION " << "=========== TEST RETURN TO ORIGINAL COMPUTE PARTITION "
<< "SETTING ========" << std::endl; << "SETTING ========" << std::endl;
} }
new_computePartition newPartition
= mapStringToRSMIComputePartitionTypes.at(orig_char_computePartition); = mapStringToRSMIComputePartitionTypes.at(
ret = rsmi_dev_compute_partition_set(dv_ind, new_computePartition); std::string(orig_char_computePartition));
ret = rsmi_dev_compute_partition_set(dv_ind, newPartition);
CHK_ERR_ASRT(ret) CHK_ERR_ASRT(ret)
IF_VERB(STANDARD) { IF_VERB(STANDARD) {
std::cout << "\t**" << "Returning compute partition to: " std::cout << "\t**" << "Returning compute partition to: "
<< computePartitionString(new_computePartition) << std::endl; << computePartitionString(newPartition) << std::endl;
} }
ret = rsmi_dev_compute_partition_get(dv_ind, current_char_computePartition, ret = rsmi_dev_compute_partition_get(dv_ind, current_char_computePartition,
255); 255);
CHK_ERR_ASRT(ret) CHK_ERR_ASRT(ret)
IF_VERB(STANDARD) { IF_VERB(STANDARD) {
std::cout << "\t**" << "Attempted to set compute partition: " std::cout << "\t**" << "Attempted to set compute partition: "
<< computePartitionString(new_computePartition) << std::endl << computePartitionString(newPartition) << std::endl
<< "\t**" << "Current compute partition: " << "\t**" << "Current compute partition: "
<< current_char_computePartition << current_char_computePartition
<< std::endl; << std::endl;
} }
ASSERT_EQ(RSMI_STATUS_SUCCESS, ret); ASSERT_EQ(RSMI_STATUS_SUCCESS, ret);
ASSERT_STREQ(computePartitionString(new_computePartition).c_str(), ASSERT_STREQ(computePartitionString(newPartition).c_str(),
current_char_computePartition); current_char_computePartition);
} }
} }
@@ -47,45 +47,47 @@
#include <stddef.h> #include <stddef.h>
#include <iostream> #include <iostream>
#include <string>
#include <map>
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "rocm_smi/rocm_smi.h" #include "rocm_smi/rocm_smi.h"
#include "rocm_smi_test/functional/npsmode_read_write.h" #include "rocm_smi_test/functional/memorypartition_read_write.h"
#include "rocm_smi_test/test_common.h" #include "rocm_smi_test/test_common.h"
TestNPSModeReadWrite::TestNPSModeReadWrite() : TestBase() { TestMemoryPartitionReadWrite::TestMemoryPartitionReadWrite() : TestBase() {
set_title("RSMI NPS Mode Read Test"); set_title("RSMI Memory Partition Read Test");
set_description("The NPS Mode tests verifies that the memory " set_description("The memory partition tests verifies that the memory "
"parition setting can be read and updated properly."); "partition settings can be read and updated properly.");
} }
TestNPSModeReadWrite::~TestNPSModeReadWrite(void) { TestMemoryPartitionReadWrite::~TestMemoryPartitionReadWrite(void) {
} }
void TestNPSModeReadWrite::SetUp(void) { void TestMemoryPartitionReadWrite::SetUp(void) {
TestBase::SetUp(); TestBase::SetUp();
return; return;
} }
void TestNPSModeReadWrite::DisplayTestInfo(void) { void TestMemoryPartitionReadWrite::DisplayTestInfo(void) {
TestBase::DisplayTestInfo(); TestBase::DisplayTestInfo();
} }
void TestNPSModeReadWrite::DisplayResults(void) const { void TestMemoryPartitionReadWrite::DisplayResults(void) const {
TestBase::DisplayResults(); TestBase::DisplayResults();
return; return;
} }
void TestNPSModeReadWrite::Close() { void TestMemoryPartitionReadWrite::Close() {
// This will close handles opened within rsmitst utility calls and call // This will close handles opened within rsmitst utility calls and call
// rsmi_shut_down(), so it should be done after other hsa cleanup // rsmi_shut_down(), so it should be done after other hsa cleanup
TestBase::Close(); TestBase::Close();
} }
static const std::string static const std::string
npsModeString(rsmi_nps_mode_type npsModeType) { memoryPartitionString(rsmi_memory_partition_type memoryPartitionType) {
switch (npsModeType) { switch (memoryPartitionType) {
case RSMI_MEMORY_PARTITION_NPS1: case RSMI_MEMORY_PARTITION_NPS1:
return "NPS1"; return "NPS1";
case RSMI_MEMORY_PARTITION_NPS2: case RSMI_MEMORY_PARTITION_NPS2:
@@ -99,20 +101,20 @@ npsModeString(rsmi_nps_mode_type npsModeType) {
} }
} }
static const std::map<std::string, rsmi_nps_mode_type_t> static const std::map<std::string, rsmi_memory_partition_type_t>
mapStringToRSMINpsModeTypes { mapStringToRSMIMemoryPartitionTypes {
{"NPS1", RSMI_MEMORY_PARTITION_NPS1}, {"NPS1", RSMI_MEMORY_PARTITION_NPS1},
{"NPS2", RSMI_MEMORY_PARTITION_NPS2}, {"NPS2", RSMI_MEMORY_PARTITION_NPS2},
{"NPS4", RSMI_MEMORY_PARTITION_NPS4}, {"NPS4", RSMI_MEMORY_PARTITION_NPS4},
{"NPS8", RSMI_MEMORY_PARTITION_NPS8} {"NPS8", RSMI_MEMORY_PARTITION_NPS8}
}; };
void TestNPSModeReadWrite::Run(void) { void TestMemoryPartitionReadWrite::Run(void) {
rsmi_status_t ret, err; rsmi_status_t ret, err;
char orig_nps_mode[255]; char orig_memory_partition[255];
char current_nps_mode[255]; char current_memory_partition[255];
orig_nps_mode[0] = '\0'; orig_memory_partition[0] = '\0';
current_nps_mode[0] = '\0'; current_memory_partition[0] = '\0';
TestBase::Run(); TestBase::Run();
if (setup_failed_) { if (setup_failed_) {
@@ -128,8 +130,8 @@ void TestNPSModeReadWrite::Run(void) {
} }
PrintDeviceHeader(dv_ind); PrintDeviceHeader(dv_ind);
//Standard checks to see if API is supported, before running full tests // Standard checks to see if API is supported, before running full tests
ret = rsmi_dev_nps_mode_get(dv_ind, orig_nps_mode, 255); ret = rsmi_dev_memory_partition_get(dv_ind, orig_memory_partition, 255);
if (ret == RSMI_STATUS_NOT_SUPPORTED) { if (ret == RSMI_STATUS_NOT_SUPPORTED) {
IF_VERB(STANDARD) { IF_VERB(STANDARD) {
std::cout << "\t**" << ": " std::cout << "\t**" << ": "
@@ -140,36 +142,35 @@ void TestNPSModeReadWrite::Run(void) {
CHK_ERR_ASRT(ret) CHK_ERR_ASRT(ret)
} }
IF_VERB(STANDARD) { IF_VERB(STANDARD) {
std::cout << std::endl << "\t**" std::cout << std::endl << "\t**Current Memory Partition: "
<< "NPS Mode: " << orig_memory_partition << std::endl;
<< orig_nps_mode << std::endl;
} }
if ((orig_nps_mode == nullptr) || if ((orig_memory_partition == nullptr) ||
(orig_nps_mode[0] == '\0')) { (orig_memory_partition[0] == '\0')) {
std::cout << "***System nps mode value is not defined or received unexpected data. " std::cout << "***System memory partition value is not defined or received"
"Skip nps mode test." << std::endl; " unexpected data. Skip memory partition test." << std::endl;
continue; continue;
} }
ASSERT_TRUE(ret == RSMI_STATUS_SUCCESS); ASSERT_TRUE(ret == RSMI_STATUS_SUCCESS);
// Verify api support checking functionality is working // Verify api support checking functionality is working
uint32_t length = 2; uint32_t kLen = 2;
char smallBuffer[length]; char smallBuffer[kLen];
err = rsmi_dev_nps_mode_get(dv_ind, smallBuffer, length); err = rsmi_dev_memory_partition_get(dv_ind, smallBuffer, kLen);
size_t size = sizeof(smallBuffer)/sizeof(*smallBuffer); size_t size = sizeof(smallBuffer)/sizeof(*smallBuffer);
ASSERT_EQ(err, RSMI_STATUS_INSUFFICIENT_SIZE); ASSERT_EQ(err, RSMI_STATUS_INSUFFICIENT_SIZE);
ASSERT_EQ((size_t)length, size); ASSERT_EQ((size_t)kLen, size);
if (err == RSMI_STATUS_INSUFFICIENT_SIZE) { if (err == RSMI_STATUS_INSUFFICIENT_SIZE) {
IF_VERB(STANDARD) { IF_VERB(STANDARD) {
std::cout << "\t**" std::cout << "\t**"
<< "Confirmed RSMI_STATUS_INSUFFICIENT_SIZE was returned " << "Confirmed RSMI_STATUS_INSUFFICIENT_SIZE was returned "
<< "and size matches length requested." << std::endl; << "and size matches kLen requested." << std::endl;
} }
} }
// Verify api support checking functionality is working // Verify api support checking functionality is working
err = rsmi_dev_nps_mode_get(dv_ind, nullptr, 255); err = rsmi_dev_memory_partition_get(dv_ind, nullptr, 255);
ASSERT_EQ(err, RSMI_STATUS_INVALID_ARGS); ASSERT_EQ(err, RSMI_STATUS_INVALID_ARGS);
if (err == RSMI_STATUS_INVALID_ARGS) { if (err == RSMI_STATUS_INVALID_ARGS) {
@@ -181,7 +182,7 @@ void TestNPSModeReadWrite::Run(void) {
} }
// Verify api support checking functionality is working // Verify api support checking functionality is working
err = rsmi_dev_nps_mode_get(dv_ind, orig_nps_mode, 0); err = rsmi_dev_memory_partition_get(dv_ind, orig_memory_partition, 0);
ASSERT_TRUE((err == RSMI_STATUS_INVALID_ARGS) || ASSERT_TRUE((err == RSMI_STATUS_INVALID_ARGS) ||
(err == RSMI_STATUS_NOT_SUPPORTED)); (err == RSMI_STATUS_NOT_SUPPORTED));
if (err == RSMI_STATUS_INVALID_ARGS) { if (err == RSMI_STATUS_INVALID_ARGS) {
@@ -193,12 +194,12 @@ void TestNPSModeReadWrite::Run(void) {
} }
/******************************/ /******************************/
/* rsmi_dev_nps_mode_set(...) */ /* rsmi_dev_memory_partition_set(...) */
/******************************/ /******************************/
// Verify api support checking functionality is working // Verify api support checking functionality is working
rsmi_nps_mode_type new_nps_mode; rsmi_memory_partition_type new_memory_partition;
err = rsmi_dev_nps_mode_set(dv_ind, new_nps_mode); err = rsmi_dev_memory_partition_set(dv_ind, new_memory_partition);
// Note: new_nps_mode is not set // Note: new_memory_partition is not set
ASSERT_TRUE((err == RSMI_STATUS_INVALID_ARGS) || ASSERT_TRUE((err == RSMI_STATUS_INVALID_ARGS) ||
(err == RSMI_STATUS_NOT_SUPPORTED)); (err == RSMI_STATUS_NOT_SUPPORTED));
if (err == RSMI_STATUS_INVALID_ARGS) { if (err == RSMI_STATUS_INVALID_ARGS) {
@@ -210,9 +211,9 @@ void TestNPSModeReadWrite::Run(void) {
} else if (err == RSMI_STATUS_NOT_SUPPORTED) { } else if (err == RSMI_STATUS_NOT_SUPPORTED) {
IF_VERB(STANDARD) { IF_VERB(STANDARD) {
std::cout << "\t**" << ": " std::cout << "\t**" << ": "
<< "rsmi_dev_nps_mode_set not supported on this device" << "rsmi_dev_memory_partition_set not supported on this "
<< "\n\t (if rsmi_dev_nps_mode_get works, then likely " << "device\n\t (if rsmi_dev_memory_partition_get works, "
<< "need to set in bios)" << "then likely need to set in bios)"
<< std::endl; << std::endl;
} }
continue; continue;
@@ -222,8 +223,9 @@ void TestNPSModeReadWrite::Run(void) {
ASSERT_FALSE(err == RSMI_STATUS_PERMISSION); ASSERT_FALSE(err == RSMI_STATUS_PERMISSION);
// Verify api support checking functionality is working // Verify api support checking functionality is working
new_nps_mode = rsmi_nps_mode_type::RSMI_MEMORY_PARTITION_UNKNOWN; new_memory_partition =
err = rsmi_dev_nps_mode_set(dv_ind, new_nps_mode); rsmi_memory_partition_type::RSMI_MEMORY_PARTITION_UNKNOWN;
err = rsmi_dev_memory_partition_set(dv_ind, new_memory_partition);
ASSERT_TRUE((err == RSMI_STATUS_INVALID_ARGS) || ASSERT_TRUE((err == RSMI_STATUS_INVALID_ARGS) ||
(err == RSMI_STATUS_NOT_SUPPORTED) || (err == RSMI_STATUS_NOT_SUPPORTED) ||
(err == RSMI_STATUS_PERMISSION)); (err == RSMI_STATUS_PERMISSION));
@@ -242,101 +244,106 @@ void TestNPSModeReadWrite::Run(void) {
} }
// Re-run original get, so we can reset to later // Re-run original get, so we can reset to later
ret = rsmi_dev_nps_mode_get(dv_ind, orig_nps_mode, 255); ret = rsmi_dev_memory_partition_get(dv_ind, orig_memory_partition, 255);
ASSERT_EQ(RSMI_STATUS_SUCCESS, ret); ASSERT_EQ(RSMI_STATUS_SUCCESS, ret);
for (int partition = RSMI_MEMORY_PARTITION_NPS1; for (int partition = RSMI_MEMORY_PARTITION_NPS1;
partition <= RSMI_MEMORY_PARTITION_NPS8; partition <= RSMI_MEMORY_PARTITION_NPS8;
partition++) { partition++) {
new_nps_mode = static_cast<rsmi_nps_mode_type>(partition); new_memory_partition = static_cast<rsmi_memory_partition_type>(partition);
IF_VERB(STANDARD) { IF_VERB(STANDARD) {
std::cout << std::endl; std::cout << std::endl;
std::cout << "\t**" std::cout << "\t**"
<< "======== TEST RSMI_MEMORY_PARTITION_" << "======== TEST RSMI_MEMORY_PARTITION_"
<< npsModeString(new_nps_mode) << memoryPartitionString(new_memory_partition)
<< " ===============" << std::endl; << " ===============" << std::endl;
} }
IF_VERB(STANDARD) { IF_VERB(STANDARD) {
std::cout << "\t**" std::cout << "\t**"
<< "Attempting to set nps mode to: " << "Attempting to set memory partition to: "
<< npsModeString(new_nps_mode) << std::endl; << memoryPartitionString(new_memory_partition) << std::endl;
} }
ret = rsmi_dev_nps_mode_set(dv_ind, new_nps_mode); ret = rsmi_dev_memory_partition_set(dv_ind, new_memory_partition);
CHK_ERR_ASRT(ret) CHK_ERR_ASRT(ret)
ret = rsmi_dev_nps_mode_get(dv_ind, current_nps_mode, 255); ret = rsmi_dev_memory_partition_get(dv_ind, current_memory_partition,
255);
CHK_ERR_ASRT(ret) CHK_ERR_ASRT(ret)
IF_VERB(STANDARD) { IF_VERB(STANDARD) {
std::cout << "\t**" std::cout << "\t**"
<< "Current nps mode: " << current_nps_mode << std::endl; << "Current memory partition: " << current_memory_partition
<< std::endl;
} }
ASSERT_EQ(RSMI_STATUS_SUCCESS, ret); ASSERT_EQ(RSMI_STATUS_SUCCESS, ret);
ASSERT_STREQ(npsModeString(new_nps_mode).c_str(), current_nps_mode); ASSERT_STREQ(memoryPartitionString(new_memory_partition).c_str(),
current_memory_partition);
} }
/* TEST RETURN TO BOOT NPS MODE SETTING */ /* TEST RETURN TO BOOT MEMORY PARTITION SETTING */
IF_VERB(STANDARD) { IF_VERB(STANDARD) {
std::cout << std::endl; std::cout << std::endl;
std::cout << "\t**" std::cout << "\t**"
<< "=========== TEST RETURN TO BOOT NPS MODE SETTING " << "=========== TEST RETURN TO BOOT MEMORY PARTITION "
<< "========" << std::endl; << "SETTING ========" << std::endl;
} }
std::string oldMode = current_nps_mode; std::string oldMode = current_memory_partition;
bool wasResetSuccess = false; bool wasResetSuccess = false;
ret = rsmi_dev_nps_mode_reset(dv_ind); ret = rsmi_dev_memory_partition_reset(dv_ind);
ASSERT_TRUE((ret == RSMI_STATUS_SUCCESS) || ASSERT_TRUE((ret == RSMI_STATUS_SUCCESS) ||
(ret == RSMI_STATUS_NOT_SUPPORTED)); (ret == RSMI_STATUS_NOT_SUPPORTED));
if (ret == RSMI_STATUS_SUCCESS) { if (ret == RSMI_STATUS_SUCCESS) {
wasResetSuccess = true; wasResetSuccess = true;
} }
ret = rsmi_dev_nps_mode_get(dv_ind, current_nps_mode, 255); ret = rsmi_dev_memory_partition_get(dv_ind, current_memory_partition, 255);
CHK_ERR_ASRT(ret) CHK_ERR_ASRT(ret)
IF_VERB(STANDARD) { IF_VERB(STANDARD) {
std::cout << "\t**" std::cout << "\t**"
<< "Current nps mode: " << current_nps_mode << std::endl; << "Current memory partition: " << current_memory_partition
<< std::endl;
} }
if (wasResetSuccess) { if (wasResetSuccess) {
ASSERT_STRNE(oldMode.c_str(), current_nps_mode); ASSERT_STRNE(oldMode.c_str(), current_memory_partition);
IF_VERB(STANDARD) { IF_VERB(STANDARD) {
std::cout << "\t**" std::cout << "\t**"
<< "Confirmed prior nps mode (" << oldMode << ") is not " << "Confirmed prior memory partition (" << oldMode << ") is "
<< "equal to current nps mode (" << "not equal to current memory partition ("
<< current_nps_mode << ")" << std::endl; << current_memory_partition << ")" << std::endl;
} }
} else { } else {
ASSERT_STREQ(oldMode.c_str(), current_nps_mode); ASSERT_STREQ(oldMode.c_str(), current_memory_partition);
IF_VERB(STANDARD) { IF_VERB(STANDARD) {
std::cout << "\t**" std::cout << "\t**"
<< "Confirmed prior nps mode (" << oldMode << ") is equal" << "Confirmed prior memory partition (" << oldMode << ") is "
<< " to current nps mode (" << "equal to current memory partition ("
<< current_nps_mode << ")" << std::endl; << current_memory_partition << ")" << std::endl;
} }
} }
/* TEST RETURN TO ORIGINAL NPS MODE SETTING */ /* TEST RETURN TO ORIGINAL MEMORY PARTITION SETTING */
IF_VERB(STANDARD) { IF_VERB(STANDARD) {
std::cout << std::endl; std::cout << std::endl;
std::cout << "\t**" std::cout << "\t**"
<< "=========== TEST RETURN TO ORIGINAL NPS MODE " << "=========== TEST RETURN TO ORIGINAL MEMORY PARTITION "
<< "SETTING ========" << std::endl; << "SETTING ========" << std::endl;
} }
new_nps_mode new_memory_partition
= mapStringToRSMINpsModeTypes.at(orig_nps_mode); = mapStringToRSMIMemoryPartitionTypes.at(orig_memory_partition);
IF_VERB(STANDARD) { IF_VERB(STANDARD) {
std::cout << "\t**" << "Returning nps mode to: " std::cout << "\t**" << "Returning memory partition to: "
<< npsModeString(new_nps_mode) << std::endl; << memoryPartitionString(new_memory_partition) << std::endl;
} }
ret = rsmi_dev_nps_mode_set(dv_ind, new_nps_mode); ret = rsmi_dev_memory_partition_set(dv_ind, new_memory_partition);
CHK_ERR_ASRT(ret) CHK_ERR_ASRT(ret)
ret = rsmi_dev_nps_mode_get(dv_ind, current_nps_mode, 255); ret = rsmi_dev_memory_partition_get(dv_ind, current_memory_partition, 255);
CHK_ERR_ASRT(ret) CHK_ERR_ASRT(ret)
IF_VERB(STANDARD) { IF_VERB(STANDARD) {
std::cout << "\t**" << "Attempted to set nps mode: " std::cout << "\t**" << "Attempted to set memory partition: "
<< npsModeString(new_nps_mode) << std::endl << memoryPartitionString(new_memory_partition) << std::endl
<< "\t**" << "Current nps mode: " << current_nps_mode << "\t**" << "Current memory partition: "
<< current_memory_partition
<< std::endl; << std::endl;
} }
ASSERT_EQ(RSMI_STATUS_SUCCESS, ret); ASSERT_EQ(RSMI_STATUS_SUCCESS, ret);
ASSERT_STREQ(npsModeString(new_nps_mode).c_str(), current_nps_mode); ASSERT_STREQ(memoryPartitionString(new_memory_partition).c_str(), current_memory_partition);
} }
} }
@@ -42,17 +42,17 @@
* DEALINGS WITH THE SOFTWARE. * DEALINGS WITH THE SOFTWARE.
* *
*/ */
#ifndef TESTS_ROCM_SMI_TEST_FUNCTIONAL_NPSMODE_READ_WRITE_H_ #ifndef TESTS_ROCM_SMI_TEST_FUNCTIONAL_MEMORYPARTITION_READ_WRITE_H_
#define TESTS_ROCM_SMI_TEST_FUNCTIONAL_NPSMODE_READ_WRITE_H_ #define TESTS_ROCM_SMI_TEST_FUNCTIONAL_MEMORYPARTITION_READ_WRITE_H_
#include "rocm_smi_test/test_base.h" #include "rocm_smi_test/test_base.h"
class TestNPSModeReadWrite : public TestBase { class TestMemoryPartitionReadWrite : public TestBase {
public: public:
TestNPSModeReadWrite(); TestMemoryPartitionReadWrite();
// @Brief: Destructor for test case of TestNPSModeReadWrite // @Brief: Destructor for test case of TestMemoryPartitionReadWrite
virtual ~TestNPSModeReadWrite(); virtual ~TestMemoryPartitionReadWrite();
// @Brief: Setup the environment for measurement // @Brief: Setup the environment for measurement
virtual void SetUp(); virtual void SetUp();
@@ -70,4 +70,4 @@ class TestNPSModeReadWrite : public TestBase {
virtual void DisplayTestInfo(void); virtual void DisplayTestInfo(void);
}; };
#endif // TESTS_ROCM_SMI_TEST_FUNCTIONAL_NPSMODE_READ_WRITE_H_ #endif // TESTS_ROCM_SMI_TEST_FUNCTIONAL_MEMORYPARTITION_READ_WRITE_H_
@@ -87,7 +87,7 @@
#include "rocm_smi_test/functional/gpu_metrics_read.h" #include "rocm_smi_test/functional/gpu_metrics_read.h"
#include "rocm_smi_test/functional/metrics_counter_read.h" #include "rocm_smi_test/functional/metrics_counter_read.h"
#include "rocm_smi_test/functional/perf_determinism.h" #include "rocm_smi_test/functional/perf_determinism.h"
#include "functional/npsmode_read_write.h" #include "functional/memorypartition_read_write.h"
static RSMITstGlobals *sRSMIGlvalues = nullptr; static RSMITstGlobals *sRSMIGlvalues = nullptr;
@@ -271,8 +271,8 @@ TEST(rsmitstReadWrite, TestComputePartitionReadWrite) {
TestComputePartitionReadWrite tst; TestComputePartitionReadWrite tst;
RunGenericTest(&tst); RunGenericTest(&tst);
} }
TEST(rsmitstReadWrite, TestNPSModeReadWrite) { TEST(rsmitstReadWrite, TestMemoryPartitionReadWrite) {
TestNPSModeReadWrite tst; TestMemoryPartitionReadWrite tst;
RunGenericTest(&tst); RunGenericTest(&tst);
} }
TEST(rsmitstReadWrite, TestEvtNotifReadWrite) { TEST(rsmitstReadWrite, TestEvtNotifReadWrite) {