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/C/GPUTuning/ManualPowerTuning

Code

Copied!

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


#include "SDK/ADLXHelper/Windows/C/ADLXHelper.h"
#include "SDK/Include/IGPUManualPowerTuning.h"
#include "SDK/Include/IGPUTuning.h"

// Main menu
void MainMenu();

// Menu action control
void MenuControl(IADLXManualPowerTuning* manualPowerTuning);

// Wait for exit with error message
int WaitAndExit(const char* msg, const int retCode,
                IADLXGPUTuningServices* gpuTuningService,
                IADLXGPUList* gpus,
                IADLXGPU* oneGPU,
                IADLXInterface* manualPowerTuni.gifc,
                IADLXManualPowerTuning* manualPowerTuning);

// Display power limit range
void ShowGetPowerLimitRange(IADLXManualPowerTuning* manualPowerTuning);

// Display current power limit
void ShowGetPowerLimit(IADLXManualPowerTuning* manualPowerTuning);

// Display default power limit
void ShowGetPowerLimitDefault(IADLXManualPowerTuning* manualPowerTuning);

// Set power limit
void ShowSetPowerLimit(IADLXManualPowerTuning* manualPowerTuning);

//Show to check TDC  limit is supported
void ShowTDCLimitSupported(IADLXManualPowerTuning* manualPowerTuning);

// Show how to get TDC limit range.
void ShowGetTDCLimitRange(IADLXManualPowerTuning* manualPowerTuning);

// Show how to get current TDC limit.
void ShowGetTDCLimit(IADLXManualPowerTuning* manualPowerTuning);

// Show how to get default TDC limit.
void ShowGetTDCLimitDefault(IADLXManualPowerTuning* manualPowerTuning);

// Show how to set TDC limit.
void ShowSetTDCLimit(IADLXManualPowerTuning* manualPowerTuning);


int main()
{
    ADLX_RESULT  res = ADLX_FAIL ;

    // Initialize ADLX
    res = ADLXHelper_Initialize();

    if (ADLX_SUCCEEDED (res))
    {
        IADLXSystem* sys = ADLXHelper_GetSystemServices();
        IADLXGPUTuningServices* gpuTuningService = NULL;
        IADLXGPUList* gpus = NULL;
        IADLXGPU* oneGPU = NULL;
        IADLXInterface* manualPowerTuni.gifc = NULL;
        IADLXManualPowerTuning* manualPowerTuning = NULL;

        res = sys->pVtbl->GetGPUTuningServices(sys, &gpuTuningService);
        if (ADLX_FAILED (res))
            return WaitAndExit("\\tGet GPU tuning services failed", 0, gpuTuningService, gpus, oneGPU, manualPowerTuni.gifc, manualPowerTuning);

        res = sys->pVtbl->GetGPUs(sys, &gpus);
        if (ADLX_FAILED (res))
            return WaitAndExit("\\tGet GPU list failed", 0, gpuTuningService, gpus, oneGPU, manualPowerTuni.gifc, manualPowerTuning);

        res = gpus->pVtbl->At_GPUList(gpus, 0, &oneGPU);
        if (ADLX_FAILED (res) || oneGPU == NULL)
            return WaitAndExit("\\tGet GPU failed", 0, gpuTuningService, gpus, oneGPU, manualPowerTuni.gifc, manualPowerTuning);

        adlx_bool supported = false;
        res = gpuTuningService->pVtbl->IsSupportedManualPowerTuning(gpuTuningService, oneGPU, &supported);
        if (ADLX_FAILED (res) || supported == false)
            return WaitAndExit("\\tThis GPU doesn't supported manual power tuning", 0, gpuTuningService, gpus, oneGPU, manualPowerTuni.gifc, manualPowerTuning);

        res = gpuTuningService->pVtbl->GetManualPowerTuning(gpuTuningService, oneGPU, &manualPowerTuni.gifc);
        if (ADLX_FAILED (res) || manualPowerTuni.gifc == NULL)
            return WaitAndExit("\\tGet manual power tuning interface failed", 0, gpuTuningService, gpus, oneGPU, manualPowerTuni.gifc, manualPowerTuning);

        res = manualPowerTuni.gifc->pVtbl->QueryInterface(manualPowerTuni.gifc, IID_IADLXManualPowerTuning(), (void**)&manualPowerTuning);
        if (manualPowerTuning == NULL)
            return WaitAndExit("\\tGet manual power tuning failed", 0, gpuTuningService, gpus, oneGPU, manualPowerTuni.gifc, manualPowerTuning);

        // Display main menu options
        MainMenu();

        // Get and execute the choice
        MenuControl(manualPowerTuning);

        // Release the manualPowerTuning interface
        if (manualPowerTuning != NULL)
        {
            manualPowerTuning->pVtbl->Release(manualPowerTuning);
            manualPowerTuning = NULL;
        }
        if (manualPowerTuni.gifc != NULL)
        {
            manualPowerTuni.gifc->pVtbl->Release(manualPowerTuni.gifc);
            manualPowerTuni.gifc = NULL;
        }
        if (oneGPU != NULL)
        {
            oneGPU->pVtbl->Release(oneGPU);
            oneGPU = NULL;
        }
        if (gpus != NULL)
        {
            gpus->pVtbl->Release(gpus);
            gpus = NULL;
        }
        if (gpuTuningService != NULL)
        {
            gpuTuningService->pVtbl->Release(gpuTuningService);
            gpuTuningService = NULL;
        }
    }
    else
    {
        printf("\\tg_ADLXHelp initialize failed\\n");
        system("pause");
        return 0;
    }

    // Destroy ADLX
    res = ADLXHelper_Terminate();
    printf("Destroy ADLX res: %d\\n", res);

    // Pause to see the print out
    system("pause");

    return 0;
}

// Main menu
void MainMenu()
{
    printf("\\tChoose from the following options:\\n");
    printf("\\t->Press 1 to display power limit range\\n");
    printf("\\t->Press 2 to display current power limit\\n");
    printf("\\t->Press 3 to set power limit\\n");
    printf("\\t->Press 4 to check if TDC Limit is supported\\n");
    printf("\\t->Press 5 to display TDC limit range\\n");
    printf("\\t->Press 6 to display current TDC limit\\n");
    printf("\\t->Press 7 to set TDC limit\\n");
    printf("\\t->Press 8 to display default power limit\\n");
    printf("\\t->Press 9 to display default TDC limit\\n");
    printf("\\t->Press Q/q to terminate the application\\n");
    printf("\\t->Press M/m to display main menu options\\n");
}

// Menu action control
void MenuControl(IADLXManualPowerTuning* 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 how to check TDC limit 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,
                IADLXGPUTuningServices* gpuTuningService,
                IADLXGPUList* gpus,
                IADLXGPU* oneGPU,
                IADLXInterface* manualPowerTuni.gifc,
                IADLXManualPowerTuning* manualPowerTuning)
{
    // Printout the message and pause to see it before returning the desired code
    if (NULL != msg)
        printf("%s\\n", msg);

    // Release the manualPowerTuning interface
    if (manualPowerTuning != NULL)
    {
        manualPowerTuning->pVtbl->Release(manualPowerTuning);
        manualPowerTuning = NULL;
    }
    if (manualPowerTuni.gifc != NULL)
    {
        manualPowerTuni.gifc->pVtbl->Release(manualPowerTuni.gifc);
        manualPowerTuni.gifc = NULL;
    }
    if (oneGPU != NULL)
    {
        oneGPU->pVtbl->Release(oneGPU);
        oneGPU = NULL;
    }
    if (gpus != NULL)
    {
        gpus->pVtbl->Release(gpus);
        gpus = NULL;
    }
    if (gpuTuningService != NULL)
    {
        gpuTuningService->pVtbl->Release(gpuTuningService);
        gpuTuningService = NULL;
    }

    // Destroy ADLX
    ADLX_RESULT  res = ADLXHelper_Terminate();
    printf("Destroy ADLX res: %d\\n", res);

    system("pause");
    return retCode;
}

// Display power limit range
void ShowGetPowerLimitRange(IADLXManualPowerTuning* manualPowerTuning)
{
    ADLX_IntRange  powerRange;
    ADLX_RESULT  res = manualPowerTuning->pVtbl->GetPowerLimitRange(manualPowerTuning, &powerRange);
    printf("\\tPower limit range: (%d, %d), return code is: %d(0 means success)\\n", powerRange.minValue , powerRange.maxValue , res);
}

// Display current power limit
void ShowGetPowerLimit(IADLXManualPowerTuning* manualPowerTuning)
{
    adlx_int powerLimit;
    ADLX_RESULT  res = manualPowerTuning->pVtbl->GetPowerLimit(manualPowerTuning, &powerLimit);
    printf("\\tCurrent power limit: %d, return code is: %d(0 means success)\\n", powerLimit, res);
}

// Display default power limit
void ShowGetPowerLimitDefault(IADLXManualPowerTuning* manualPowerTuning)
{
    IADLXManualPowerTuning1* manualPowerTuning1;
    manualPowerTuning->pVtbl->QueryInterface(manualPowerTuning, IID_IADLXManualPowerTuning1(), (void**)&manualPowerTuning1);
    if (manualPowerTuning1)
    {
        adlx_int powerLimit;
        ADLX_RESULT  res = manualPowerTuning1->pVtbl->GetPowerLimitDefault(manualPowerTuning1, &powerLimit);
        printf("\\tDefault power limit: %d, return code is: %d(0 means success)\\n", powerLimit, res);
        // release manualPowerTuning1
        manualPowerTuning1->pVtbl->Release(manualPowerTuning1);
        manualPowerTuning1 = NULL;
    }
}

// Set power limit
void ShowSetPowerLimit(IADLXManualPowerTuning* manualPowerTuning)
{
    ADLX_IntRange  powerRange;
    ADLX_RESULT  res = manualPowerTuning->pVtbl->GetPowerLimitRange(manualPowerTuning, &powerRange);
    res = manualPowerTuning->pVtbl->SetPowerLimit(manualPowerTuning, powerRange.minValue  + (powerRange.maxValue  - powerRange.minValue ) / 2);
    printf("\\tSet power limit %s\\n", (ADLX_SUCCEEDED  (res) ? "succeeded" : "failed"));
    adlx_int powerLimit;
    res = manualPowerTuning->pVtbl->GetPowerLimit(manualPowerTuning, &powerLimit);
    printf("\\tSet current power limit to: %d, return code is: %d(0 means success)\\n", powerLimit, res);
}


// Show how to check TDCLimit is supported.
void ShowTDCLimitSupported(IADLXManualPowerTuning* manualPowerTuning)
{
    adlx_bool tdcSupported;
    ADLX_RESULT  res = manualPowerTuning->pVtbl->IsSupportedTDCLimit(manualPowerTuning, &tdcSupported);
    printf("\\tIs TDC Limit supported: %d, return code is: %d(0 means success)\\n", tdcSupported, res);
}

// Show how to get TDC limit range.
void ShowGetTDCLimitRange(IADLXManualPowerTuning* manualPowerTuning)
{
    ADLX_IntRange  tdcRange;
    ADLX_RESULT  res = manualPowerTuning->pVtbl->GetTDCLimitRange(manualPowerTuning, &tdcRange);
    printf("\\tGet TDC limit range is: (%d, %d), return code is: %d (0 means success)\\n", tdcRange.minValue , tdcRange.maxValue , res);
}

// Show how to get current TDC limit.
void ShowGetTDCLimit(IADLXManualPowerTuning* manualPowerTuning)
{
    adlx_int tdcLimit;
    ADLX_RESULT  res = manualPowerTuning->pVtbl->GetTDCLimit(manualPowerTuning, &tdcLimit);
    printf("\\tThe current TDC limit is: %d, return code is: %d (0 means success)\\n", tdcLimit, res);
}

// Show how to get default TDC limit.
void ShowGetTDCLimitDefault(IADLXManualPowerTuning* manualPowerTuning)
{
    IADLXManualPowerTuning1* manualPowerTuning1;
    manualPowerTuning->pVtbl->QueryInterface(manualPowerTuning, IID_IADLXManualPowerTuning1(), (void**)&manualPowerTuning1);
    if (manualPowerTuning1)
    {
        adlx_int tdcLimit;
        ADLX_RESULT  res = manualPowerTuning1->pVtbl->GetTDCLimitDefault(manualPowerTuning1, &tdcLimit);
        printf("\\tThe default TDC limit is: %d, return code is: %d(0 means success)\\n", tdcLimit, res);
        // release manualPowerTuning1
        manualPowerTuning1->pVtbl->Release(manualPowerTuning1);
        manualPowerTuning1 = NULL;
    }
}

// Show how to set TDC limit.
void ShowSetTDCLimit(IADLXManualPowerTuning* manualPowerTuning)
{
    ADLX_IntRange  tdcRange;
    ADLX_RESULT  res = manualPowerTuning->pVtbl->GetTDCLimitRange(manualPowerTuning, &tdcRange);
    res = manualPowerTuning->pVtbl->SetTDCLimit(manualPowerTuning, tdcRange.minValue  + (tdcRange.maxValue  - tdcRange.minValue ) / 2);
    adlx_int tdcLimit;
    res = manualPowerTuning->pVtbl->GetTDCLimit(manualPowerTuning, &tdcLimit);
    printf("\\tSet current TDC limit to: %d, return code is: %d (0 means success)\\n", tdcLimit, res);
}

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!