Skip to content

Commit

Permalink
Added function to set GPU min and max clocks (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielBliem authored Dec 18, 2024
1 parent dc97c98 commit f6feecc
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "nvidia_oc"
version = "0.1.15"
version = "0.1.16"
edition = "2021"
license = "MIT"
description = "A simple command line tool to overclock Nvidia GPUs using the NVML library on Linux. This supports both X11 and Wayland."
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ NVIDIA_OC is a simple Rust CLI tool designed to overclock NVIDIA GPUs on Linux.
To set the overclock parameters for your NVIDIA GPU, use the following command:

```bash
./nvidia_oc set --index 0 --power-limit 200000 --freq-offset 160 --mem-offset 850
./nvidia_oc set --index 0 --power-limit 200000 --freq-offset 160 --mem-offset 850 --min-clock 0 --max-clock 2000
```

## Run on Startup
Expand All @@ -24,7 +24,7 @@ Description=NVIDIA Overclocking Service
After=network.target
[Service]
ExecStart=[path_to_binary]/nvidia_oc set --index 0 --power-limit 200000 --freq-offset 160 --mem-offset 850
ExecStart=[path_to_binary]/nvidia_oc set --index 0 --power-limit 200000 --freq-offset 160 --mem-offset 850 --min-clock 0 --max-clock 2000
User=root
Restart=on-failure
Expand Down
4 changes: 3 additions & 1 deletion example_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"0": {
"freqOffset": 200000,
"memOffset": 160,
"powerLimit": 500
"powerLimit": 500,
"minClock": 0,
"maxClock": 2000
}
}
}
27 changes: 26 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,17 @@ struct Sets {
#[arg(short, long)]
freq_offset: Option<i32>,
/// GPU memory frequency offset
#[arg(short, long)]
#[arg(long = "mem-offset")]
mem_offset: Option<i32>,
/// GPU power limit in milliwatts
#[arg(short, long)]
power_limit: Option<u32>,
/// GPU min clock
#[arg(long = "min-clock")]
min_clock: Option<u32>,
/// GPU max clock
#[arg(long = "max-clock")]
max_clock: Option<u32>,
}

impl Sets {
Expand All @@ -64,6 +70,11 @@ impl Sets {
if let Some(limit) = self.power_limit {
set_gpu_power_limit(&nvml, device, limit).expect("Failed to set GPU power limit");
}

if let (Some(min_clock), Some(max_clock)) = (self.min_clock, self.max_clock) {
set_gpu_min_max_clock(&nvml, device, min_clock, max_clock)
.expect("Failed to set GPU min and max clocks");
}
}
}

Expand Down Expand Up @@ -179,6 +190,20 @@ fn set_gpu_power_limit(nvml_lib: &NvmlLib, handle: nvmlDevice_t, limit: u32) ->
}
}

fn set_gpu_min_max_clock(
nvml_lib: &NvmlLib,
handle: nvmlDevice_t,
minclock: u32,
maxclock: u32,
) -> Result<(), String> {
let result = unsafe { nvml_lib.nvmlDeviceSetGpuLockedClocks(handle, minclock, maxclock) };
if result != 0 {
Err(format!("Error code: {}", result))
} else {
Ok(())
}
}

fn generate_completion_script<G: Generator>(gen: G) {
let mut cmd = Cli::command();
let name = cmd.get_name().to_string();
Expand Down

0 comments on commit f6feecc

Please sign in to comment.