From 1d6b8d942252e3322936d397c03ee1be9eb46a99 Mon Sep 17 00:00:00 2001 From: "Kanangot Balakrishnan, Bindhiya" Date: Wed, 5 Mar 2025 23:46:17 -0600 Subject: [PATCH] SWDEV-510419: Restore compute partition after memory partition test (#15) Memory partition test was changing original compute partiton based on default compute mode. Corrected this to set back to original compute partition. Signed-off-by: Bindhiya Kanangot Balakrishnan --- .../functional/memorypartition_read_write.cc | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/tests/rocm_smi_test/functional/memorypartition_read_write.cc b/tests/rocm_smi_test/functional/memorypartition_read_write.cc index 81b7161b3e..7ca8b637e4 100755 --- a/tests/rocm_smi_test/functional/memorypartition_read_write.cc +++ b/tests/rocm_smi_test/functional/memorypartition_read_write.cc @@ -110,6 +110,15 @@ mapStringToRSMIMemoryPartitionTypes { {"NPS8", RSMI_MEMORY_PARTITION_NPS8} }; +static const std::map +mapStringToRSMIComputePartitionTypes { + {"DPX", RSMI_COMPUTE_PARTITION_DPX}, + {"TPX", RSMI_COMPUTE_PARTITION_TPX}, + {"QPX", RSMI_COMPUTE_PARTITION_QPX}, + {"CPX", RSMI_COMPUTE_PARTITION_CPX}, + {"SPX", RSMI_COMPUTE_PARTITION_SPX} +}; + void TestMemoryPartitionReadWrite::Run(void) { rsmi_status_t ret, err, ret_set; char orig_memory_partition[255]; @@ -125,6 +134,41 @@ void TestMemoryPartitionReadWrite::Run(void) { return; } + // initial_num_devices - keep this value static, due to parition changes + // fluctuating # of devices. We should end up with same # of devices at + // end of test. + uint32_t initial_num_devices = num_monitor_devs(); + char orig_char_computePartition[initial_num_devices][255]; + char current_char_computePartition[255]; + + for (uint32_t dv_ind = 0; dv_ind < num_monitor_devs(); ++dv_ind) { + // Run and get compute_partition, so we can reset to later + ret = rsmi_dev_compute_partition_get(dv_ind, orig_char_computePartition[dv_ind], + 255); + if(ret == RSMI_STATUS_SETTING_UNAVAILABLE + || ret== RSMI_STATUS_PERMISSION + || ret == RSMI_STATUS_BUSY + || ret == RSMI_STATUS_NOT_SUPPORTED + || ret == RSMI_STATUS_INVALID_ARGS) { + IF_VERB(STANDARD) { + std::cout << "\t**rsmi_dev_compute_partition_get(): " + << "Not supported on this device" + << std::endl; + } + continue; + } + + std::cout << "\t**rsmi_dev_compute_partition_get(" << dv_ind + << ", " << orig_char_computePartition[dv_ind] << ")\n"; + + ret = rsmi_dev_compute_partition_get(dv_ind, orig_char_computePartition[dv_ind], 255); + IF_VERB(STANDARD) { + std::cout << std::endl << "\t**" + << "Original compute partition: " + << orig_char_computePartition[dv_ind] << std::endl; + } + } + for (uint32_t dv_ind = 0; dv_ind < num_monitor_devs(); ++dv_ind) { bool wasSetSuccess = false; if (dv_ind != 0) { @@ -408,4 +452,28 @@ void TestMemoryPartitionReadWrite::Run(void) { << current_memory_partition << ")" << std::endl; } } + + // Return to original compute_partition + for (uint32_t dv_ind = 0; dv_ind < num_monitor_devs(); ++dv_ind) { + ret = rsmi_dev_compute_partition_get(dv_ind, current_char_computePartition, 255); + if(ret == RSMI_STATUS_SETTING_UNAVAILABLE + || ret== RSMI_STATUS_PERMISSION + || ret == RSMI_STATUS_BUSY + || ret == RSMI_STATUS_NOT_SUPPORTED + || ret == RSMI_STATUS_INVALID_ARGS) + continue; + + if (strcmp(orig_char_computePartition[dv_ind], current_char_computePartition) != 0) { + rsmi_compute_partition_type_t newPartition + = mapStringToRSMIComputePartitionTypes.at( + std::string(orig_char_computePartition[dv_ind])); + ret = rsmi_dev_compute_partition_set(dv_ind, newPartition); + + IF_VERB(STANDARD) { + std::cout << "\t**" + << "Returning compute partition to: " + << std::string(orig_char_computePartition[dv_ind]) << std::endl; + } + } + } }