From 21fa9c09503ba1f25df03df87baa5990d94e6d3e Mon Sep 17 00:00:00 2001 From: "Galantsev, Dmitrii" Date: Fri, 27 Oct 2023 03:12:46 -0500 Subject: [PATCH] SWDEV-424983 - Fix supported metrics api checks Change-Id: I5c95bb3057dd7546036cbd87bbf7025469d2b3d5 Signed-off-by: Galantsev, Dmitrii [ROCm/amdsmi commit: 88d5e011e69ed9230a39faf2027b63bdbd446400] --- projects/amdsmi/src/amd_smi/amd_smi.cc | 57 ++++++++++--------- .../amd_smi_test/functional/err_cnt_read.cc | 4 +- .../tests/amd_smi_test/functional/fan_read.cc | 3 + .../functional/frequencies_read.cc | 2 +- 4 files changed, 36 insertions(+), 30 deletions(-) diff --git a/projects/amdsmi/src/amd_smi/amd_smi.cc b/projects/amdsmi/src/amd_smi/amd_smi.cc index 66088cd7e2..ca5b1aa47a 100644 --- a/projects/amdsmi/src/amd_smi/amd_smi.cc +++ b/projects/amdsmi/src/amd_smi/amd_smi.cc @@ -446,7 +446,7 @@ amdsmi_status_t amdsmi_get_gpu_board_info(amdsmi_processor_handle processor_hand AMDSMI_CHECK_INIT(); - if (board_info == NULL) { + if (board_info == nullptr) { return AMDSMI_STATUS_INVAL; } @@ -532,7 +532,7 @@ amdsmi_status_t amdsmi_get_gpu_vram_usage(amdsmi_processor_handle processor_hand AMDSMI_CHECK_INIT(); - if (vram_info == NULL) { + if (vram_info == nullptr) { return AMDSMI_STATUS_INVAL; } @@ -1086,9 +1086,8 @@ amdsmi_get_gpu_compute_process_gpus(uint32_t pid, uint32_t *dv_indices, amdsmi_status_t amdsmi_get_gpu_ecc_count(amdsmi_processor_handle processor_handle, amdsmi_gpu_block_t block, amdsmi_error_count_t *ec) { AMDSMI_CHECK_INIT(); + // nullptr api supported - if (ec == nullptr) - return AMDSMI_STATUS_INVAL; return rsmi_wrapper(rsmi_dev_ecc_count_get, processor_handle, static_cast(block), reinterpret_cast(ec)); @@ -1096,9 +1095,8 @@ amdsmi_status_t amdsmi_get_gpu_ecc_count(amdsmi_processor_handle processor_hand amdsmi_status_t amdsmi_get_gpu_ecc_enabled(amdsmi_processor_handle processor_handle, uint64_t *enabled_blocks) { AMDSMI_CHECK_INIT(); + // nullptr api supported - if (enabled_blocks == nullptr) - return AMDSMI_STATUS_INVAL; return rsmi_wrapper(rsmi_dev_ecc_enabled_get, processor_handle, enabled_blocks); } @@ -1106,9 +1104,8 @@ amdsmi_status_t amdsmi_get_gpu_ecc_status(amdsmi_processor_handle processor_han amdsmi_gpu_block_t block, amdsmi_ras_err_state_t *state) { AMDSMI_CHECK_INIT(); + // nullptr api supported - if (state == nullptr) - return AMDSMI_STATUS_INVAL; return rsmi_wrapper(rsmi_dev_ecc_status_get, processor_handle, static_cast(block), reinterpret_cast(state)); @@ -1118,9 +1115,8 @@ amdsmi_status_t amdsmi_get_gpu_metrics_info( amdsmi_processor_handle processor_handle, amdsmi_gpu_metrics_t *pgpu_metrics) { AMDSMI_CHECK_INIT(); + // nullptr api supported - if (pgpu_metrics == nullptr) - return AMDSMI_STATUS_INVAL; return rsmi_wrapper(rsmi_dev_gpu_metrics_info_get, processor_handle, reinterpret_cast(pgpu_metrics)); } @@ -1207,9 +1203,8 @@ amdsmi_status_t uint32_t sensor_ind, amdsmi_power_profile_status_t *status) { AMDSMI_CHECK_INIT(); + // nullptr api supported - if (status == nullptr) - return AMDSMI_STATUS_INVAL; return rsmi_wrapper(rsmi_dev_power_profile_presets_get, processor_handle, sensor_ind, reinterpret_cast(status)); @@ -1228,15 +1223,16 @@ amdsmi_status_t reserved, static_cast(profile)); } + amdsmi_status_t amdsmi_get_gpu_perf_level(amdsmi_processor_handle processor_handle, amdsmi_dev_perf_level_t *perf) { AMDSMI_CHECK_INIT(); + // nullptr api supported - if (perf == nullptr) - return AMDSMI_STATUS_INVAL; return rsmi_wrapper(rsmi_dev_perf_level_get, processor_handle, reinterpret_cast(perf)); } + amdsmi_status_t amdsmi_set_gpu_perf_level(amdsmi_processor_handle processor_handle, amdsmi_dev_perf_level_t perf_lvl) { @@ -1260,37 +1256,44 @@ amdsmi_status_t amdsmi_get_gpu_pci_bandwidth(amdsmi_processor_handle processor_h amdsmi_status_t amdsmi_get_clk_freq(amdsmi_processor_handle processor_handle, amdsmi_clk_type_t clk_type, amdsmi_frequencies_t *f) { AMDSMI_CHECK_INIT(); - - if (f == nullptr) - return AMDSMI_STATUS_INVAL; + // nullptr api supported // Get from gpu_metrics if (clk_type == CLK_TYPE_VCLK0 || clk_type == CLK_TYPE_VCLK1 || clk_type == CLK_TYPE_DCLK0 || clk_type == CLK_TYPE_DCLK1 ) { + + // when f == nullptr -> check if metrics are supported amdsmi_gpu_metrics_t metric_info; + amdsmi_gpu_metrics_t * metric_info_p = nullptr; + + if (f != nullptr) { + metric_info_p = &metric_info; + } + + // when metric_info_p == nullptr - this will not return AMDSMI_STATUS_SUCCESS auto r_status = amdsmi_get_gpu_metrics_info( - processor_handle, &metric_info); + processor_handle, metric_info_p); if (r_status != AMDSMI_STATUS_SUCCESS) return r_status; f->num_supported = 1; if (clk_type == CLK_TYPE_VCLK0) { - f->current = metric_info.current_vclk0; - f->frequency[0] = metric_info.average_vclk0_frequency; + f->current = metric_info_p->current_vclk0; + f->frequency[0] = metric_info_p->average_vclk0_frequency; } if (clk_type == CLK_TYPE_VCLK1) { - f->current = metric_info.current_vclk1; - f->frequency[0] = metric_info.average_vclk1_frequency; + f->current = metric_info_p->current_vclk1; + f->frequency[0] = metric_info_p->average_vclk1_frequency; } if (clk_type == CLK_TYPE_DCLK0) { - f->current = metric_info.current_dclk0; - f->frequency[0] = metric_info.average_dclk0_frequency; + f->current = metric_info_p->current_dclk0; + f->frequency[0] = metric_info_p->average_dclk0_frequency; } if (clk_type == CLK_TYPE_DCLK1) { - f->current = metric_info.current_dclk1; - f->frequency[0] = metric_info.average_dclk1_frequency; + f->current = metric_info_p->current_dclk1; + f->frequency[0] = metric_info_p->average_dclk1_frequency; } return r_status; @@ -1305,7 +1308,7 @@ amdsmi_status_t amdsmi_set_clk_freq(amdsmi_processor_handle processor_handle, amdsmi_clk_type_t clk_type, uint64_t freq_bitmask) { AMDSMI_CHECK_INIT(); - // Not support the clock type read from gpu_metrics + // Not support the clock type write into gpu_metrics if (clk_type == CLK_TYPE_VCLK0 || clk_type == CLK_TYPE_VCLK1 || clk_type == CLK_TYPE_DCLK0 || diff --git a/projects/amdsmi/tests/amd_smi_test/functional/err_cnt_read.cc b/projects/amdsmi/tests/amd_smi_test/functional/err_cnt_read.cc index c63d561fa1..ab341b21a0 100755 --- a/projects/amdsmi/tests/amd_smi_test/functional/err_cnt_read.cc +++ b/projects/amdsmi/tests/amd_smi_test/functional/err_cnt_read.cc @@ -109,7 +109,7 @@ void TestErrCntRead::Run(void) { } // Verify api support checking functionality is working err = amdsmi_get_gpu_ecc_enabled(processor_handles_[i], nullptr); - ASSERT_EQ(err, AMDSMI_STATUS_INVAL); + ASSERT_EQ(err, AMDSMI_STATUS_NOT_SUPPORTED); continue; } else { @@ -150,7 +150,7 @@ void TestErrCntRead::Run(void) { // Verify api support checking functionality is working err = amdsmi_get_gpu_ecc_count(processor_handles_[i], static_cast(b), nullptr); - ASSERT_EQ(err, AMDSMI_STATUS_INVAL); + ASSERT_EQ(err, AMDSMI_STATUS_NOT_SUPPORTED); } else { CHK_ERR_ASRT(err) diff --git a/projects/amdsmi/tests/amd_smi_test/functional/fan_read.cc b/projects/amdsmi/tests/amd_smi_test/functional/fan_read.cc index 5829567ec7..78e257e895 100755 --- a/projects/amdsmi/tests/amd_smi_test/functional/fan_read.cc +++ b/projects/amdsmi/tests/amd_smi_test/functional/fan_read.cc @@ -107,6 +107,9 @@ void TestFanRead::Run(void) { std::cout << "\t**" << ": " << "Not supported on this machine" << std::endl; } + // Verify api support checking functionality is working + err = amdsmi_get_gpu_fan_speed(processor_handles_[i], 0, nullptr); + ASSERT_EQ(err, AMDSMI_STATUS_NOT_SUPPORTED); return; } else { CHK_ERR_ASRT(err) diff --git a/projects/amdsmi/tests/amd_smi_test/functional/frequencies_read.cc b/projects/amdsmi/tests/amd_smi_test/functional/frequencies_read.cc index 33d678e7da..98e310d64b 100755 --- a/projects/amdsmi/tests/amd_smi_test/functional/frequencies_read.cc +++ b/projects/amdsmi/tests/amd_smi_test/functional/frequencies_read.cc @@ -128,7 +128,7 @@ void TestFrequenciesRead::Run(void) { ": Not supported on this machine" << std::endl; // Verify api support checking functionality is working err = amdsmi_get_clk_freq(processor_handles_[i], t, nullptr); - ASSERT_EQ(err, AMDSMI_STATUS_INVAL); + ASSERT_EQ(err, AMDSMI_STATUS_NOT_SUPPORTED); return; }