1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502
|
/*
* =============================================================================
* ROC Runtime Conformance Release License
* =============================================================================
* The University of Illinois/NCSA
* Open Source License (NCSA)
*
* Copyright (c) 2017-2023, Advanced Micro Devices, Inc.
* All rights reserved.
*
* Developed by:
*
* AMD Research and AMD ROC Software Development
*
* Advanced Micro Devices, Inc.
*
* www.amd.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal with the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimers.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimers in
* the documentation and/or other materials provided with the distribution.
* - Neither the names of <Name of Development Group, Name of Institution>,
* nor the names of its contributors may be used to endorse or promote
* products derived from this Software without specific prior written
* permission.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS WITH THE SOFTWARE.
*
*/
#include <stdint.h>
#include <stddef.h>
#include <iostream>
#include <string>
#include <map>
#include "gtest/gtest.h"
#include "rocm_smi/rocm_smi.h"
#include "rocm_smi_test/functional/memorypartition_read_write.h"
#include "rocm_smi/rocm_smi_utils.h"
#include "rocm_smi_test/test_common.h"
TestMemoryPartitionReadWrite::TestMemoryPartitionReadWrite() : TestBase() {
set_title("RSMI Memory Partition Read Test");
set_description("The memory partition tests verifies that the memory "
"partition settings can be read and updated properly.");
}
TestMemoryPartitionReadWrite::~TestMemoryPartitionReadWrite(void) {
}
void TestMemoryPartitionReadWrite::SetUp(void) {
TestBase::SetUp();
return;
}
void TestMemoryPartitionReadWrite::DisplayTestInfo(void) {
TestBase::DisplayTestInfo();
}
void TestMemoryPartitionReadWrite::DisplayResults(void) const {
TestBase::DisplayResults();
return;
}
void TestMemoryPartitionReadWrite::Close() {
// This will close handles opened within rsmitst utility calls and call
// rsmi_shut_down(), so it should be done after other hsa cleanup
TestBase::Close();
}
static const std::string
memoryPartitionString(rsmi_memory_partition_type memoryPartitionType) {
switch (memoryPartitionType) {
case RSMI_MEMORY_PARTITION_NPS1:
return "NPS1";
case RSMI_MEMORY_PARTITION_NPS2:
return "NPS2";
case RSMI_MEMORY_PARTITION_NPS4:
return "NPS4";
case RSMI_MEMORY_PARTITION_NPS8:
return "NPS8";
default:
return "UNKNOWN";
}
}
static const std::map<std::string, rsmi_memory_partition_type_t>
mapStringToRSMIMemoryPartitionTypes {
{"NPS1", RSMI_MEMORY_PARTITION_NPS1},
{"NPS2", RSMI_MEMORY_PARTITION_NPS2},
{"NPS4", RSMI_MEMORY_PARTITION_NPS4},
{"NPS8", RSMI_MEMORY_PARTITION_NPS8}
};
static const std::map<std::string, rsmi_compute_partition_type_t>
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];
char current_memory_partition[255];
char current_memory_capabilities[255];
orig_memory_partition[0] = '\0';
current_memory_partition[0] = '\0';
current_memory_capabilities[0] = '\0';
TestBase::Run();
if (setup_failed_) {
std::cout << "** SetUp Failed for this test. Skipping.**" << std::endl;
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) {
IF_VERB(STANDARD) {
std::cout << std::endl;
}
}
PrintDeviceHeader(dv_ind);
// Standard checks to see if API is supported, before running full tests
ret = rsmi_dev_memory_partition_get(dv_ind, orig_memory_partition, 255);
if (ret == RSMI_STATUS_NOT_SUPPORTED) {
IF_VERB(STANDARD) {
std::cout << "\t**" << ": "
<< "Not supported on this machine" << std::endl;
}
continue;
} else {
CHK_ERR_ASRT(ret)
}
IF_VERB(STANDARD) {
std::cout << std::endl << "\t**Current Memory Partition: "
<< orig_memory_partition << std::endl;
}
if ((orig_memory_partition == nullptr) ||
(orig_memory_partition[0] == '\0')) {
std::cout << "***System memory partition value is not defined or received"
" unexpected data. Skip memory partition test." << std::endl;
continue;
}
ASSERT_TRUE(ret == RSMI_STATUS_SUCCESS);
// Verify api support checking functionality is working
uint32_t kLen = 2;
char smallBuffer[kLen];
err = rsmi_dev_memory_partition_get(dv_ind, smallBuffer, kLen);
size_t size = sizeof(smallBuffer)/sizeof(*smallBuffer);
ASSERT_EQ(err, RSMI_STATUS_INSUFFICIENT_SIZE);
ASSERT_EQ((size_t)kLen, size);
if (err == RSMI_STATUS_INSUFFICIENT_SIZE) {
IF_VERB(STANDARD) {
std::cout << "\t**"
<< "Confirmed RSMI_STATUS_INSUFFICIENT_SIZE was returned "
<< "and size matches kLen requested." << std::endl;
}
}
// Verify api support checking functionality is working
err = rsmi_dev_memory_partition_get(dv_ind, nullptr, 255);
ASSERT_EQ(err, RSMI_STATUS_INVALID_ARGS);
if (err == RSMI_STATUS_INVALID_ARGS) {
IF_VERB(STANDARD) {
std::cout << "\t**rsmi_dev_memory_partition_get(dv_ind, nullptr, 255): "
<< "Confirmed RSMI_STATUS_INVALID_ARGS was returned."
<< std::endl;
}
}
err = rsmi_dev_memory_partition_capabilities_get(dv_ind, nullptr, 255);
ASSERT_EQ(err, RSMI_STATUS_INVALID_ARGS);
if (err == RSMI_STATUS_INVALID_ARGS) {
IF_VERB(STANDARD) {
std::cout << "\t**rsmi_dev_memory_partition_capabilities_get(dv_ind, nullptr, 255): "
<< "Confirmed RSMI_STATUS_INVALID_ARGS was returned."
<< std::endl;
}
}
// Verify api support checking functionality is working
err = rsmi_dev_memory_partition_get(dv_ind, orig_memory_partition, 0);
ASSERT_TRUE((err == RSMI_STATUS_INVALID_ARGS) ||
(err == RSMI_STATUS_NOT_SUPPORTED));
if (err == RSMI_STATUS_INVALID_ARGS) {
IF_VERB(STANDARD) {
std::cout << "\t**rsmi_dev_memory_partition_get(dv_ind, orig_memory_partition, 0): "
<< "Confirmed RSMI_STATUS_INVALID_ARGS was returned."
<< std::endl;
}
}
err = rsmi_dev_memory_partition_capabilities_get(dv_ind, current_memory_capabilities, 0);
ASSERT_TRUE((err == RSMI_STATUS_INVALID_ARGS) ||
(err == RSMI_STATUS_NOT_SUPPORTED));
if (err == RSMI_STATUS_INVALID_ARGS) {
IF_VERB(STANDARD) {
std::cout << "\t**"
<< "rsmi_dev_memory_partition_capabilities_get(dv_ind, "
<< "current_memory_capabilities, 0): "
<< "Confirmed RSMI_STATUS_INVALID_ARGS was returned."
<< std::endl;
}
}
/******************************/
/* rsmi_dev_memory_partition_set(...) */
/******************************/
// Verify api support checking functionality is working
rsmi_memory_partition_type new_memory_partition = {};
err = rsmi_dev_memory_partition_set(dv_ind, new_memory_partition);
std::cout << "\t**rsmi_dev_memory_partition_set(null ptr): "
<< amd::smi::getRSMIStatusString(err, false) << "\n";
// Note: new_memory_partition is not set
ASSERT_TRUE((err == RSMI_STATUS_INVALID_ARGS) ||
(err == RSMI_STATUS_NOT_SUPPORTED));
if (err == RSMI_STATUS_INVALID_ARGS) {
IF_VERB(STANDARD) {
std::cout << "\t**"
<< "Confirmed RSMI_STATUS_INVALID_ARGS was returned."
<< std::endl;
}
} else if (err == RSMI_STATUS_NOT_SUPPORTED) {
IF_VERB(STANDARD) {
std::cout << "\t**" << ": "
<< "rsmi_dev_memory_partition_set not supported on this "
<< "device\n\t (if rsmi_dev_memory_partition_get works, "
<< "then likely need to set in bios)"
<< std::endl;
}
continue;
} else {
DISPLAY_RSMI_ERR(err)
}
ASSERT_FALSE(err == RSMI_STATUS_PERMISSION);
// Verify api support checking functionality is working
new_memory_partition =
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) ||
(err == RSMI_STATUS_NOT_SUPPORTED) ||
(err == RSMI_STATUS_PERMISSION));
if (err == RSMI_STATUS_INVALID_ARGS) {
IF_VERB(STANDARD) {
std::cout << "\t**"
<< "Confirmed RSMI_STATUS_INVALID_ARGS was returned."
<< std::endl;
} else if (err == RSMI_STATUS_PERMISSION) {
DISPLAY_RSMI_ERR(err)
// tests should not continue if err is a permission issue
ASSERT_FALSE(err == RSMI_STATUS_PERMISSION);
} else {
DISPLAY_RSMI_ERR(err)
}
}
// Re-run original get, so we can reset to later
ret = rsmi_dev_memory_partition_get(dv_ind, orig_memory_partition, 255);
ASSERT_EQ(RSMI_STATUS_SUCCESS, ret);
for (int partition = RSMI_MEMORY_PARTITION_NPS1;
partition <= RSMI_MEMORY_PARTITION_NPS8;
partition++) {
ret_set = RSMI_STATUS_NOT_SUPPORTED;
wasSetSuccess = false;
new_memory_partition = static_cast<rsmi_memory_partition_type>(partition);
IF_VERB(STANDARD) {
std::cout << std::endl;
std::cout << "\t**"
<< "======== TEST RSMI_MEMORY_PARTITION_"
<< memoryPartitionString(new_memory_partition)
<< " ===============" << std::endl;
}
IF_VERB(STANDARD) {
std::cout << "\t**"
<< "Attempting to set memory partition to: "
<< memoryPartitionString(new_memory_partition) << std::endl;
}
rsmi_status_t ret_caps = rsmi_dev_memory_partition_capabilities_get(dv_ind,
current_memory_capabilities, 255);
IF_VERB(STANDARD) {
std::cout << "\t**"
<< "rsmi_dev_memory_partition_capabilities_get(" << dv_ind
<< ", current_memory_capabilities, 255): "
<< amd::smi::getRSMIStatusString(ret_caps, false) << std::endl;
std::cout << "\t**"
<< "current_memory_capabilities: " << current_memory_capabilities
<< std::endl;
}
ASSERT_TRUE((ret_caps == RSMI_STATUS_NOT_SUPPORTED) ||
(ret_caps == RSMI_STATUS_SUCCESS));
ret_set = rsmi_dev_memory_partition_set(dv_ind, new_memory_partition);
IF_VERB(STANDARD) {
std::cout << "\t**" << "rsmi_dev_memory_partition_set("
<< dv_ind << " , " << memoryPartitionString(new_memory_partition) << "): "
<< amd::smi::getRSMIStatusString(ret_set, false) << "\n";
}
if (ret_set == RSMI_STATUS_NOT_SUPPORTED) {
IF_VERB(STANDARD) {
std::cout << "\t**" << ": "
<< "Not supported on this machine" << std::endl;
}
break;
} else {
ASSERT_TRUE((ret_set == RSMI_STATUS_SUCCESS)
|| (ret_set == RSMI_STATUS_BUSY)
|| (ret_set == RSMI_STATUS_AMDGPU_RESTART_ERR)
|| (ret_set == RSMI_STATUS_INVALID_ARGS)
|| (ret_set == RSMI_STATUS_NOT_SUPPORTED));
}
IF_VERB(STANDARD) {
std::cout << "\t**" << "rsmi_dev_memory_partition_set("
<< dv_ind << " , " << memoryPartitionString(new_memory_partition) << "): "
<< amd::smi::getRSMIStatusString(ret_set, false) << "\n";
}
if (ret_set == RSMI_STATUS_SUCCESS) { // do not continue trying to reset
wasSetSuccess = true;
}
ret = rsmi_dev_memory_partition_get(dv_ind, current_memory_partition,
255);
CHK_ERR_ASRT(ret)
IF_VERB(STANDARD) {
std::cout << "\t**"
<< "Current memory partition: " << current_memory_partition
<< std::endl;
}
if (wasSetSuccess) {
ASSERT_EQ(RSMI_STATUS_SUCCESS, ret_set);
ASSERT_STREQ(memoryPartitionString(new_memory_partition).c_str(),
current_memory_partition);
CHK_ERR_ASRT(ret_set)
} else {
ASSERT_NE(RSMI_STATUS_SUCCESS, ret_set);
ASSERT_STRNE(memoryPartitionString(new_memory_partition).c_str(),
current_memory_partition);
}
}
/* TEST RETURN TO ORIGINAL MEMORY PARTITION SETTING */
IF_VERB(STANDARD) {
std::cout << std::endl;
std::cout << "\t**"
<< "=========== TEST RETURN TO ORIGINAL MEMORY PARTITION "
<< "SETTING ( " << orig_memory_partition
<< " ) ========" << std::endl;
}
std::string oldMode = current_memory_partition;
bool wasResetSuccess = false;
ret = rsmi_dev_memory_partition_reset(dv_ind);
ASSERT_TRUE((ret == RSMI_STATUS_SUCCESS) ||
(ret == RSMI_STATUS_NOT_SUPPORTED));
if (ret == RSMI_STATUS_SUCCESS) {
wasResetSuccess = true;
}
ret = rsmi_dev_memory_partition_get(dv_ind, current_memory_partition, 255);
CHK_ERR_ASRT(ret)
IF_VERB(STANDARD) {
std::cout << "\t**"
<< "Current memory partition: " << current_memory_partition
<< std::endl;
}
if (wasResetSuccess && wasSetSuccess) {
ASSERT_STRNE(oldMode.c_str(), current_memory_partition);
IF_VERB(STANDARD) {
std::cout << "\t**"
<< "Confirmed prior memory partition (" << oldMode << ") is "
<< "not equal to current memory partition ("
<< current_memory_partition << ")" << std::endl;
}
} else {
ASSERT_STREQ(oldMode.c_str(), current_memory_partition);
IF_VERB(STANDARD) {
std::cout << "\t**"
<< "Confirmed prior memory partition (" << oldMode << ") is "
<< "equal to current memory partition ("
<< current_memory_partition << ")" << std::endl;
}
}
new_memory_partition
= mapStringToRSMIMemoryPartitionTypes.at(orig_memory_partition);
IF_VERB(STANDARD) {
std::cout << "\t**" << "Returning memory partition to: "
<< memoryPartitionString(new_memory_partition) << std::endl;
}
ret = rsmi_dev_memory_partition_set(dv_ind, new_memory_partition);
IF_VERB(STANDARD) {
std::cout << "\t**"
<< "rsmi_dev_memory_partition_set(" << dv_ind
<< ", " << orig_memory_partition << "): "
<< amd::smi::getRSMIStatusString(ret, false) << std::endl;
}
CHK_ERR_ASRT(ret)
ret = rsmi_dev_memory_partition_get(dv_ind, current_memory_partition, 255);
CHK_ERR_ASRT(ret)
IF_VERB(STANDARD) {
std::cout << "\t**" << "Attempted to set memory partition: "
<< memoryPartitionString(new_memory_partition) << std::endl
<< "\t**" << "Current memory partition: "
<< current_memory_partition
<< std::endl;
}
ASSERT_EQ(RSMI_STATUS_SUCCESS, ret);
ASSERT_STREQ(orig_memory_partition, current_memory_partition);
IF_VERB(STANDARD) {
std::cout << "\t**"
<< "Confirmed prior memory partition (" << orig_memory_partition
<< ") is equal to current memory partition ("
<< 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;
}
}
}
}
|