diff --git a/Cargo.lock b/Cargo.lock index 84eb439..1bd3a34 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -238,7 +238,7 @@ checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "nvidia_oc" -version = "0.1.15" +version = "0.1.16" dependencies = [ "clap", "clap_complete", diff --git a/Cargo.toml b/Cargo.toml index a11ffc6..126d50d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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." diff --git a/README.md b/README.md index 77dc1b0..68a1f92 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/example_config.json b/example_config.json index 6d1657f..3f418be 100644 --- a/example_config.json +++ b/example_config.json @@ -3,7 +3,9 @@ "0": { "freqOffset": 200000, "memOffset": 160, - "powerLimit": 500 + "powerLimit": 500, + "minClock": 0, + "maxClock": 2000 } } } diff --git a/src/main.rs b/src/main.rs index 03d103b..8045cde 100644 --- a/src/main.rs +++ b/src/main.rs @@ -42,11 +42,17 @@ struct Sets { #[arg(short, long)] freq_offset: Option, /// GPU memory frequency offset - #[arg(short, long)] + #[arg(long = "mem-offset")] mem_offset: Option, /// GPU power limit in milliwatts #[arg(short, long)] power_limit: Option, + /// GPU min clock + #[arg(long = "min-clock")] + min_clock: Option, + /// GPU max clock + #[arg(long = "max-clock")] + max_clock: Option, } impl Sets { @@ -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"); + } } } @@ -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(gen: G) { let mut cmd = Cli::command(); let name = cmd.get_name().to_string();