ManualPowerTuning
Navigation: Programming with ADLX → ADLX Samples → C++ Samples → GPU Tuning
Demonstrates how to control manual power tuning when programming with ADLX.
Command Prompts
Command Prompt | Description |
---|---|
1 | Get power limit range. |
2 | Get current power limit. |
3 | Set power limit. |
4 | Check TDC limit supported. |
5 | Get TDC limit range. |
6 | Get current TDC limit. |
7 | Set TDC limit. |
8 | Get default power limit. |
9 | Get default TDC limit. |
M/m | Show this menu. |
Q/q | Quit. |
Sample Path
/Samples/CPP/GPUTuning/ManualPowerTuning
C++
Code
C++
//// Copyright Advanced Micro Devices, Inc. All rights reserved.////-------------------------------------------------------------------------------------------------
/// \file mainManualPowerTuning.cpp/// \brief Demonstrates how to control manual power tuning when programming with ADLX.
#include "SDK/ADLXHelper/Windows/Cpp/ADLXHelper.h"#include "SDK/Include/IGPUManualPowerTuning.h"#include "SDK/Include/IGPUTuning.h"#include <iostream>
// Use ADLX namespaceusing namespace adlx;
// ADLXHelper instance// No outstanding interfaces from ADLX must exist when ADLX is destroyed.// Use global variables to ensure validity of the interface.static ADLXHelper g_ADLXHelp;
// Main menuvoid MainMenu();
// Menu action controlvoid MenuControl(IADLXManualPowerTuningPtr manualPowerTuning, IADLXGPUTuningServicesPtr gpuTuningService, IADLXGPUPtr oneGPU);
// Wait for exit with error messageint WaitAndExit(const char* msg, const int retCode);
// Display power limit rangevoid ShowGetPowerLimitRange(IADLXManualPowerTuningPtr manualPowerTuning);
// Display current power limitvoid ShowGetPowerLimit(IADLXManualPowerTuningPtr manualPowerTuning);
// Display default power limitvoid ShowGetPowerLimitDefault(IADLXManualPowerTuningPtr manualPowerTuning);
// Set power limitvoid ShowSetPowerLimit(IADLXManualPowerTuningPtr manualPowerTuning, IADLXGPUTuningServicesPtr gpuTuningService, IADLXGPUPtr oneGPU);
//Show to check TDC limit is supportedvoid ShowTDCLimitSupported(IADLXManualPowerTuningPtr manualPowerTuning);
// Show how to get TDC limit range.void ShowGetTDCLimitRange(IADLXManualPowerTuningPtr manualPowerTuning);
// Show how to get current TDC limit.void ShowGetTDCLimit(IADLXManualPowerTuningPtr manualPowerTuning);
// Show how to get default TDC limit.void ShowGetTDCLimitDefault(IADLXManualPowerTuningPtr manualPowerTuning);
// Show how to set TDC limit.void ShowSetTDCLimit(IADLXManualPowerTuningPtr manualPowerTuning, IADLXGPUTuningServicesPtr gpuTuningService, IADLXGPUPtr oneGPU);
int main(){ ADLX_RESULT res = ADLX_FAIL;
// Initialize ADLX res = g_ADLXHelp.Initialize();
if (ADLX_SUCCEEDED(res)) { IADLXGPUTuningServicesPtr gpuTuningService; res = g_ADLXHelp.GetSystemServices()->GetGPUTuningServices(&gpuTuningService); if (ADLX_FAILED (res)) { std::cout << "\tGet GPU tuning services failed " << std::endl; goto EXIT; } IADLXGPUListPtr gpus; res = g_ADLXHelp.GetSystemServices()->GetGPUs(&gpus); if (ADLX_FAILED (res)) { std::cout << "\tGet GPU list failed " << std::endl; goto EXIT; } IADLXGPUPtr oneGPU; res = gpus->At(0, &oneGPU); if (ADLX_FAILED (res) || oneGPU == nullptr) { std::cout << "\tGet GPU failed " << std::endl; goto EXIT; } adlx_bool supported = false; res = gpuTuningService->IsSupportedManualPowerTuning(oneGPU, &supported); if (ADLX_FAILED (res) || supported == false) { std::cout << "\tThis GPU does not support manual power tuning " << std::endl; goto EXIT; } IADLXInterfacePtr manualPowerTuningIfc; res = gpuTuningService->GetManualPowerTuning(oneGPU, &manualPowerTuningIfc); if (ADLX_FAILED (res) || manualPowerTuningIfc == nullptr) { std::cout << "\tGet manual power tuning interface failed " << std::endl; goto EXIT; } IADLXManualPowerTuningPtr manualPowerTuning(manualPowerTuningIfc); if (manualPowerTuning == nullptr) { std::cout << "\tGet manual power tuning failed " << std::endl; goto EXIT; } // Display main menu options MainMenu();
// Get and execute the choice MenuControl(manualPowerTuning, gpuTuningService,oneGPU); } else return WaitAndExit("\tg_ADLXHelp initialize failed", 0); EXIT: // Destroy ADLX res = g_ADLXHelp.Terminate(); std::cout << "Destroy ADLX res: " << res << std::endl;
// Pause to see the print out system("pause");
return 0;}
// Main menuvoid MainMenu(){ std::cout << "\tChoose from the following options:" << std::endl;
std::cout << "\t->Press 1 to show how to get power limit range" << std::endl; std::cout << "\t->Press 2 to show how to get current power limit" << std::endl; std::cout << "\t->Press 3 to show how to set power limit" << std::endl; std::cout << "\t->Press 4 to show TDC Limit is supported" << std::endl; std::cout << "\t->Press 5 to show how to get TDC limit range" << std::endl; std::cout << "\t->Press 6 to show how to get current TDC limit" << std::endl; std::cout << "\t->Press 7 to show how to set TDC limit" << std::endl; std::cout << "\t->Press 8 to show how to get default power limit" << std::endl; std::cout << "\t->Press 9 to show how to get default TDC limit" << std::endl;
std::cout << "\t->Press Q/q to terminate the application" << std::endl; std::cout << "\t->Press M/m to display main menu options" << std::endl;}
// Menu action controlvoid MenuControl(IADLXManualPowerTuningPtr manualPowerTuning, IADLXGPUTuningServicesPtr gpuTuningService, IADLXGPUPtr oneGPU){ int num = 0; while ((num = getchar()) != 'q' && num != 'Q') { switch (num) { // Display power limit range case '1': ShowGetPowerLimitRange(manualPowerTuning); break;
// Display current power limit case '2': ShowGetPowerLimit(manualPowerTuning); break;
// Set power limit case '3': ShowSetPowerLimit(manualPowerTuning, gpuTuningService, oneGPU); break; // Show to check if TDCLimit is supported case '4': ShowTDCLimitSupported(manualPowerTuning); break; // Show how to get TDC limit range. case '5': ShowGetTDCLimitRange(manualPowerTuning); break;
// Show how to get current TDC limit. case '6': ShowGetTDCLimit(manualPowerTuning); break;
// Show how to set TDC limit. case '7': ShowSetTDCLimit(manualPowerTuning, gpuTuningService, oneGPU); break;
// Display default power limit case '8': ShowGetPowerLimitDefault(manualPowerTuning); break; // Show how to get default TDC limit. case '9': ShowGetTDCLimitDefault(manualPowerTuning); break;
// Display menu options case 'm': case 'M': MainMenu(); break; default: break; } }}
// Wait for exit with error messageint WaitAndExit(const char* msg, const int retCode){ // Printout the message and pause to see it before returning the desired code if (nullptr != msg) std::cout << msg << std::endl;
system("pause"); return retCode;}
// Display power limit rangevoid ShowGetPowerLimitRange(IADLXManualPowerTuningPtr manualPowerTuning){ ADLX_IntRange powerRange; ADLX_RESULT res = manualPowerTuning->GetPowerLimitRange(&powerRange); std::cout << "\tPower limit range: (" << powerRange.minValue << ", " << powerRange.maxValue << ")" << ", return code is: "<< res << "(0 means success)" << std::endl;}
// Display current power limitvoid ShowGetPowerLimit(IADLXManualPowerTuningPtr manualPowerTuning){ adlx_int powerLimit; ADLX_RESULT res = manualPowerTuning->GetPowerLimit(&powerLimit); std::cout << "\tCurrent power limit: " << powerLimit << ", return code is: "<< res << "(0 means success)" << std::endl;}
// Display default power limitvoid ShowGetPowerLimitDefault(IADLXManualPowerTuningPtr manualPowerTuning){ IADLXManualPowerTuning1Ptr manualGFXTuning1(manualPowerTuning); if (manualGFXTuning1 == nullptr) { std::cout << "\tGet IADLXManualPowerTuning1Ptr failed" << std::endl; return; }
adlx_int powerLimit; ADLX_RESULT res = manualGFXTuning1->GetPowerLimitDefault(&powerLimit); std::cout << "\tDefault power limit: " << powerLimit << ", return code is: " << res << "(0 means success)" << std::endl;}
// Set power limitvoid ShowSetPowerLimit(IADLXManualPowerTuningPtr manualPowerTuning, IADLXGPUTuningServicesPtr gpuTuningService, IADLXGPUPtr oneGPU){ ADLX_IntRange powerRange; ADLX_RESULT res = manualPowerTuning->GetPowerLimitRange(&powerRange); res = manualPowerTuning->SetPowerLimit(powerRange.step + powerRange.minValue + (powerRange.maxValue - powerRange.minValue) / 2); if (ADLX_RESET_NEEDED == res) { res = gpuTuningService->ResetToFactory(oneGPU); if (ADLX_SUCCEEDED(res)) { res = manualPowerTuning->SetPowerLimit(powerRange.step + powerRange.minValue + (powerRange.maxValue - powerRange.minValue) / 2); } }
std::cout << "\tSet power limit " << (ADLX_SUCCEEDED (res) ? "succeeded" : "failed") << std::endl; adlx_int powerLimit; res = manualPowerTuning->GetPowerLimit(&powerLimit); std::cout << "\tSet current power limit to: " << powerLimit << ", return code is: "<< res << "(0 means success)" << std::endl;}
// Show TDCLimit is supported.void ShowTDCLimitSupported(IADLXManualPowerTuningPtr manualPowerTuning){ adlx_bool supportedTDC; ADLX_RESULT res = manualPowerTuning->IsSupportedTDCLimit(&supportedTDC); std::cout << "\tTDC limit is supported: " << supportedTDC << ", return code is: "<< res << "(0 means success)" << std::endl;}
// Show how to get tdc limit range.void ShowGetTDCLimitRange(IADLXManualPowerTuningPtr manualPowerTuning){ ADLX_IntRange tdcRange; ADLX_RESULT res = manualPowerTuning->GetTDCLimitRange(&tdcRange); std::cout << "\tGet TDC limit range is: (" << tdcRange.minValue << ", " << tdcRange.maxValue << "), return code (0 is Success) is: " << res << std::endl;}
// Show how to get current TDC limit.void ShowGetTDCLimit(IADLXManualPowerTuningPtr manualPowerTuning){ adlx_int tdcLimit; ADLX_RESULT res = manualPowerTuning->GetTDCLimit(&tdcLimit); std::cout << "\tThe current TDC limit is: " << tdcLimit << ", return code (0 is Success) is: " << res << std::endl;}
// Show how to get current TDC limit.void ShowGetTDCLimitDefault(IADLXManualPowerTuningPtr manualPowerTuning){ IADLXManualPowerTuning1Ptr manualGFXTuning1(manualPowerTuning); if (manualGFXTuning1 == nullptr) { std::cout << "\tGet IADLXManualPowerTuning1Ptr failed" << std::endl; return; } adlx_int tdcLimit; ADLX_RESULT res = manualGFXTuning1->GetTDCLimitDefault(&tdcLimit); std::cout << "\tThe default TDC limit is: " << tdcLimit << ", return code (0 is Success) is: " << res << std::endl;}
// Show how to set TDC limit.void ShowSetTDCLimit(IADLXManualPowerTuningPtr manualPowerTuning, IADLXGPUTuningServicesPtr gpuTuningService, IADLXGPUPtr oneGPU){ ADLX_IntRange tdcRange; ADLX_RESULT res = manualPowerTuning->GetTDCLimitRange(&tdcRange);
res = manualPowerTuning->SetTDCLimit(tdcRange.step + tdcRange.minValue + (tdcRange.maxValue - tdcRange.minValue) / 2); if (ADLX_RESET_NEEDED == res) { res = gpuTuningService->ResetToFactory(oneGPU); if (ADLX_SUCCEEDED(res)) { res = manualPowerTuning->SetTDCLimit(tdcRange.step + tdcRange.minValue + (tdcRange.maxValue - tdcRange.minValue) / 2); } } adlx_int tdcLimit; res = manualPowerTuning->GetTDCLimit (&tdcLimit); std::cout << "\tSet current TDC limit to: " << tdcLimit << ", return code (0 is Success) is: " << res << std::endl;}