GPUPresetTuning

Demonstrates how to control GPU preset tuning when programming with ADLX.

Command Prompts

Command Prompt Description
1 Get GPU tuning support states.
2 Get current GPU tuning states.
3 Set GPU states.
M/m Show this menu.
Q/q Quit.

Sample Path

/Samples/CPP/GPUTuning/GPUPresetTuning

Code

Copied!

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


#include "SDK/ADLXHelper/Windows/Cpp/ADLXHelper.h"
#include "SDK/Include/IGPUPresetTuning.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(IADLXGPUPresetTuningPtr gpuPresetTuning);

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

// Display GPU tuning support states
void ShowIsSupported(IADLXGPUPresetTuningPtr gpuPresetTuning);

// Display current GPU tuning states
void GetCurrentStates(IADLXGPUPresetTuningPtr gpuPresetTuning);

// Set GPU states
void SetGPUStates(IADLXGPUPresetTuningPtr gpuPresetTuning);

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_SUCCEEDED  (res))
        {
            IADLXGPUListPtr gpus;
            res = g_ADLXHelp.GetSystemServices()->GetGPUs(&gpus);
            if (ADLX_SUCCEEDED  (res))
            {
                IADLXGPUPtr oneGPU;
                res = gpus->At(0, &oneGPU);
                if (ADLX_SUCCEEDED  (res) && oneGPU != nullptr)
                {
                    adlx_bool supported = false;
                    res = gpuTuningService->IsSupportedPresetTuning(oneGPU, &supported);
                    if (ADLX_SUCCEEDED  (res) && supported)
                    {
                        IADLXInterfacePtr gpuPresetTuni.gifc;
                        res = gpuTuningService->GetPresetTuning(oneGPU, &gpuPresetTuni.gifc);
                        if (ADLX_SUCCEEDED  (res) && gpuPresetTuni.gifc != nullptr)
                        {
                            IADLXGPUPresetTuningPtr gpuPresetTuning(gpuPresetTuni.gifc);
                            if (gpuPresetTuning != nullptr)
                            {
                                // Display main menu options
                                MainMenu();

                                // Get and execute the choice
                                MenuControl(gpuPresetTuning);
                            }
                            else
                            {
                                std::cout << "\\tGet GPU preset tuning failed" << std::endl;
                            }
                        }
                        else
                        {
                            std::cout << "\\tGet GPU preset tuning interface failed" << std::endl;
                        }
                    }
                    else
                    {
                        std::cout << "\\tGPU preset tuning is not supported by this GPU" << std::endl;
                    }
                }
                else
                {
                    std::cout << "\\tGet GPU failed" << std::endl;
                }
            }
            else
            {
                std::cout << "\\tGet GPU list failed" << std::endl;
            }
        }
        else
        {
            std::cout << "\\tGet GPU tuning services failed" << std::endl;
        }
    }
    else
        return WaitAndExit("\\tg_ADLXHelp initialize failed", 0);

    // 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 display GPU tuning support states" << std::endl;
    std::cout << "\\t->Press 2 to display current GPU tuning states" << std::endl;
    std::cout << "\\t->Press 3 to set GPU states" << 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;
}

void MenuControl(IADLXGPUPresetTuningPtr gpuPresetTuning)
{
    char num = 0;
    while ((num = getchar()) != 'q' && num != 'Q')
    {
        switch (num)
        {
        // Display GPU tuning support states
        case '1':
            ShowIsSupported(gpuPresetTuning);
            break;

        // Display current GPU tuning states
        case '2':
            GetCurrentStates(gpuPresetTuning);
            break;

        // Set GPU states
        case '3':
            SetGPUStates(gpuPresetTuning);
            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 GPU tuning support states
void ShowIsSupported(IADLXGPUPresetTuningPtr gpuPresetTuning)
{
    adlx_bool supported = false;
    ADLX_RESULT  res = gpuPresetTuning->IsSupportedPowerSaver(&supported);
    std::cout << "\\tIs Power Saver supported by the GPU: " << supported << ", return code is: " << res << "(0 means success)" << std::endl;
    supported = false;
    res = gpuPresetTuning->IsSupportedQuiet(&supported);
    std::cout << "\\tIs Quiet supported by the GPU: " << supported << ", return code is: " << res << "(0 means success)" << std::endl;
    supported = false;
    res = gpuPresetTuning->IsSupportedBalanced(&supported);
    std::cout << "\\tIs Balanced supported by the GPU: " << supported << ", return code is: " << res << "(0 means success)" << std::endl;
    supported = false;
    res = gpuPresetTuning->IsSupportedTurbo(&supported);
    std::cout << "\\tIs Turbo supported by the GPU: " << supported << ", return code is: " << res << "(0 means success)" << std::endl;
    supported = false;
    res = gpuPresetTuning->IsSupportedRage(&supported);
    std::cout << "\\tIs Rage supported by the GPU: " << supported << ", return code is: " << res << "(0 means success)" << std::endl;
}

// Display current GPU tuning states
void GetCurrentStates(IADLXGPUPresetTuningPtr gpuPresetTuning)
{
    adlx_bool applied = false;
    ADLX_RESULT  res = gpuPresetTuning->IsCurrentPowerSaver(&applied);
    std::cout << "\\tIs Power Saver applied: " << applied << ", return code is: " << res << "(0 means success)" << std::endl;
    applied = false;
    res = gpuPresetTuning->IsCurrentQuiet(&applied);
    std::cout << "\\tIs Quiet applied: " << applied << ", return code is: " << res << "(0 means success)" << std::endl;
    applied = false;
    res = gpuPresetTuning->IsCurrentBalanced(&applied);
    std::cout << "\\tIs Balanced applied: " << applied << ", return code is: " << res << "(0 means success)" << std::endl;
    applied = false;
    res = gpuPresetTuning->IsCurrentTurbo(&applied);
    std::cout << "\\tIs Turbo applied: " << applied << ", return code is: " << res << "(0 means success)" << std::endl;
    applied = false;
    res = gpuPresetTuning->IsCurrentRage(&applied);
    std::cout << "\\tIs Rage applied: " << applied << ", return code is: " << res << "(0 means success)" << std::endl;
}

// Set GPU states
void SetGPUStates(IADLXGPUPresetTuningPtr gpuPresetTuning)
{
    adlx_bool applied = false;
    ADLX_RESULT  res = gpuPresetTuning->SetPowerSaver();
    res = gpuPresetTuning->IsCurrentPowerSaver(&applied);
    std::cout << "\\tSet Power Saver preset tuning " << (applied ? "Successful" : "failed") << ", return code is: " << res << "(0 means success)" << std::endl;
    applied = false;
    res = gpuPresetTuning->SetQuiet();
    res = gpuPresetTuning->IsCurrentQuiet(&applied);
    std::cout << "\\tSet Quiet preset tuning " << (applied ? "Successful" : "failed") << ", return code is: " << res << "(0 means success)" << std::endl;
    applied = false;
    res = gpuPresetTuning->SetBalanced();
    res = gpuPresetTuning->IsCurrentBalanced(&applied);
    std::cout << "\\tSet Balanced preset tuning " << (applied ? "Successful" : "failed") << ", return code is: " << res << "(0 means success)" << std::endl;
    applied = false;
    res = gpuPresetTuning->SetTurbo();
    res = gpuPresetTuning->IsCurrentTurbo(&applied);
    std::cout << "\\tSet Turbo preset tuning " << (applied ? "Successful" : "failed") << ", return code is: " << res << "(0 means success)" << std::endl;
    applied = false;
    res = gpuPresetTuning->SetRage();
    res = gpuPresetTuning->IsCurrentRage(&applied);
    std::cout << "\\tSet Rage preset tuning " << (applied ? "Successful" : "failed") << ", return code is: " << res << "(0 means success)" << 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!