ManualPowerTuning

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

Code

Copied!

//
// Copyright (c) 2021 - 2025 Advanced Micro Devices, Inc. All rights reserved.
//
//-------------------------------------------------------------------------------------------------


#include "SDK/ADLXHelper/Windows/Cpp/ADLXHelper.h"
#include "SDK/Include/IGPUManualPowerTuning.h"
#include "SDK/Include/IGPUTuning.h"
#include <iostream>

// Use ADLX namespace
using 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 menu
void MainMenu();

// Menu action control
void MenuControl(IADLXManualPowerTuningPtr manualPowerTuning);

// Wait for exit with error message
int WaitAndExit(const char* msg, const int retCode);

// Display power limit range
void ShowGetPowerLimitRange(IADLXManualPowerTuningPtr manualPowerTuning);

// Display current power limit
void ShowGetPowerLimit(IADLXManualPowerTuningPtr manualPowerTuning);

// Display default power limit
void ShowGetPowerLimitDefault(IADLXManualPowerTuningPtr manualPowerTuning);

// Set power limit
void ShowSetPowerLimit(IADLXManualPowerTuningPtr manualPowerTuning);

//Show to check TDC  limit is supported
void 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);

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 manualPowerTuni.gifc;
        res = gpuTuningService->GetManualPowerTuning(oneGPU, &manualPowerTuni.gifc);
        if (ADLX_FAILED  (res) || manualPowerTuni.gifc == nullptr)
        {
            std::cout << "\\tGet manual power tuning interface failed " << std::endl;
            goto EXIT;
        }
        IADLXManualPowerTuningPtr manualPowerTuning(manualPowerTuni.gifc);
        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);
    }
    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 menu
void 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 control
void MenuControl(IADLXManualPowerTuningPtr manualPowerTuning)
{
    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);
            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);
            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 message
int 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 range
void 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 limit
void 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 limit
void 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 limit
void ShowSetPowerLimit(IADLXManualPowerTuningPtr manualPowerTuning)
{
    ADLX_IntRange  powerRange;
    ADLX_RESULT  res = manualPowerTuning->GetPowerLimitRange(&powerRange);
    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)
{
    ADLX_IntRange  tdcRange;
    ADLX_RESULT  res = manualPowerTuning->GetTDCLimitRange(&tdcRange);

    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;
}

Related pages

  • Visit the Adlx product page for download links and more information.

Looking for more documentation on GPUOpen?

AMD GPUOpen software blogs

Our handy software release blogs will help you make good use of our tools, SDKs, and effects, as well as sharing the latest features with new releases.

GPUOpen Manuals

Don’t miss our manual documentation! And if slide decks are what you’re after, you’ll find 100+ of our finest presentations here.

AMD GPUOpen Performance Guides

The home of great performance and optimization advice for AMD RDNA™ 2 GPUs, AMD Ryzen™ CPUs, and so much more.

Getting started: AMD GPUOpen software

New or fairly new to AMD’s tools, libraries, and effects? This is the best place to get started on GPUOpen!

AMD GPUOpen Getting Started Development and Performance

Looking for tips on getting started with developing and/or optimizing your game, whether on AMD hardware or generally? We’ve got you covered!

AMD GPUOpen Technical blogs

Browse our technical blogs, and find valuable advice on developing with AMD hardware, ray tracing, Vulkan®, DirectX®, Unreal Engine, and lots more.

Find out more about our software!

AMD GPUOpen Effects - AMD FidelityFX technologies

Create wonder. No black boxes. Meet the AMD FidelityFX SDK!

AMD GPUOpen Samples

Browse all our useful samples. Perfect for when you’re needing to get started, want to integrate one of our libraries, and much more.

AMD GPUOpen developer SDKs

Discover what our SDK technologies can offer you. Query hardware or software, manage memory, create rendering applications or machine learning, and much more!

AMD GPUOpen Developer Tools

Analyze, Optimize, Profile, Benchmark. We provide you with the developer tools you need to make sure your game is the best it can be!