diff --git a/src/config_file.rs b/src/config_file.rs index efcb57a..d5f5a25 100644 --- a/src/config_file.rs +++ b/src/config_file.rs @@ -15,6 +15,7 @@ pub(crate) struct ConfigFile { pub p2pool_enabled: bool, pub http_server_enabled: bool, pub http_server_port: u16, + pub gpu_percentage: u8, } impl Default for ConfigFile { @@ -27,6 +28,7 @@ impl Default for ConfigFile { p2pool_enabled: false, http_server_enabled: true, http_server_port: 18000, + gpu_percentage: 100, } } } diff --git a/src/main.rs b/src/main.rs index 1f4c57b..12cf525 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,5 @@ -use std::fs; use std::str::FromStr; +use std::{cmp, fs}; use std::{convert::TryInto, env::current_dir, path::PathBuf, sync::Arc, thread, time::Instant}; use anyhow::{anyhow, Context as AnyContext, Error}; @@ -96,6 +96,10 @@ struct Cli { /// Port of HTTP server #[arg(long)] http_server_port: Option, + + /// GPU percentage + #[arg(long)] + gpu_percentage: Option, } async fn main_inner() -> Result<(), anyhow::Error> { @@ -139,6 +143,9 @@ async fn main_inner() -> Result<(), anyhow::Error> { if let Some(port) = cli.http_server_port { config.http_server_port = port; } + if let Some(percentage) = cli.gpu_percentage { + config.gpu_percentage = percentage; + } let submit = true; @@ -210,10 +217,12 @@ fn run_thread( let gpu_function = gpu_engine.get_main_function(&context)?; - let (grid_size, block_size) = gpu_function + let (mut grid_size, block_size) = gpu_function .suggested_launch_configuration() .context("get suggest config")?; // let (grid_size, block_size) = (23, 50); + grid_size = + (grid_size as f64 / 100f64 * cmp::max(cmp::min(100, config.gpu_percentage as usize), 1) as f64).round() as u32; let output = vec![0u64; 5]; // let mut output_buf = output.as_slice().as_dbuf()?;