Last active
February 8, 2024 19:07
-
-
Save divinity76/ef1e297fc4ec8d53f5d4d64aeac16e21 to your computer and use it in GitHub Desktop.
sets "compute mode" on AMD GPU's in linux
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env php | |
<?php | |
declare(strict_types = 1); | |
// this does NOT work on my ubuntu 20.04, look at the other files for a 20.04 version | |
if (posix_geteuid () !== 0) { | |
die ( "error: this script requires root privileges, re-run it as root." ); | |
} | |
$amdgpu_dir = '/sys/bus/pci/drivers/amdgpu'; | |
$dirs = array_filter ( array_map ( 'trim', glob ( $amdgpu_dir.DIRECTORY_SEPARATOR.'*', GLOB_NOSORT | GLOB_ONLYDIR | GLOB_MARK ) ), function (string $str) { | |
return (is_writable ( $str."power_dpm_force_performance_level" ) && is_writable ( $str.'pp_compute_power_profile' )); | |
} ); | |
$max = count ( $dirs ); | |
if ($max === 0) { | |
die ( "error: found 0 applicable devices in $amdgpu_dir\n" ); | |
} | |
echo "found $max applicable amdgpu devices\n"; | |
$i = 0; | |
foreach ( $dirs as $gpu ) { | |
++ $i; | |
echo "setting card {$i}/{$max}: {$gpu} .."; | |
my_write ( $gpu."power_dpm_force_performance_level", "auto" ); | |
my_write ( $gpu."pp_compute_power_profile", "set" ); | |
echo ". done\n"; | |
} | |
die ( "finished!\n" ); | |
function my_write(string $file, string $data, bool $append = false) { | |
if (! is_writable ( $file )) { | |
throw new \RuntimeException ( "$file is not writable!" ); | |
} | |
$len = strlen ( $data ); | |
$written = file_put_contents ( $file, $data, $append ? FILE_APPEND : 0 ); | |
if ($written !== $len) { | |
throw new \RuntimeException ( "tried to write $len bytes, but could only write $written bytes, file: $file" ); | |
} | |
return $written; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env php | |
<?php | |
declare(strict_types = 1); | |
// this does NOT work on ubuntu18.04, look at other files for an 18.04 version | |
if (posix_geteuid () !== 0) { | |
die ( "error: this script requires root privileges, re-run it as root." ); | |
} | |
$amdgpu_dir = '/sys/bus/pci/drivers/amdgpu'; | |
$dirs = array_filter ( array_map ( 'trim', glob ( $amdgpu_dir.DIRECTORY_SEPARATOR.'*', GLOB_NOSORT | GLOB_ONLYDIR | GLOB_MARK ) ), function (string $str) { | |
return (is_writable ( $str."power_dpm_force_performance_level" ) && is_writable ( $str.'pp_power_profile_mode' )); | |
} ); | |
$max = count ( $dirs ); | |
if ($max === 0) { | |
die ( "error: found 0 applicable devices in $amdgpu_dir\n" ); | |
} | |
echo "found $max applicable amdgpu devices\n"; | |
$i = 0; | |
foreach ( $dirs as $gpu ) { | |
++ $i; | |
echo "setting card {$i}/{$max}: {$gpu} .."; | |
my_write ( $gpu."power_dpm_force_performance_level", "manual" ); | |
my_write ( $gpu."pp_power_profile_mode", "5" ); | |
echo ". done\n"; | |
} | |
die ( "finished!\n" ); | |
function my_write(string $file, string $data, bool $append = false) { | |
if (! is_writable ( $file )) { | |
throw new \RuntimeException ( "$file is not writable!" ); | |
} | |
$len = strlen ( $data ); | |
$written = file_put_contents ( $file, $data, $append ? FILE_APPEND : 0 ); | |
if ($written !== $len) { | |
throw new \RuntimeException ( "tried to write $len bytes, but could only write $written bytes, file: $file" ); | |
} | |
return $written; | |
} |
Will it work on today latest drivers
Will it work on today latest drivers
kinda doubt it, on Ubuntu 16.04, the interface for activating "compute mode" was something like
set pp_power_profile_mode to the magic number 4
and around Ubuntu 18.04 the interface changed to like
activate pp_compute_power_profile
so it wouldn't surprise me if the correct way to set compute-mode has changed yet again by ubuntu 20.04...
in any case, i don't have any system to test on, so i don't know.
Will it work on today latest drivers
made a new ubuntu 20.04 version based on the link provided by liolok ^^ this version doesn't seem to work on 18.04 though.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this, much appreciated!