Skip to content

Commit

Permalink
feat: add gpu percentage hint
Browse files Browse the repository at this point in the history
  • Loading branch information
stringhandler committed Sep 3, 2024
1 parent 4d49d06 commit c5cf134
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/config_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -27,6 +28,7 @@ impl Default for ConfigFile {
p2pool_enabled: false,
http_server_enabled: true,
http_server_port: 18000,
gpu_percentage: 100,
}
}
}
Expand Down
13 changes: 11 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -96,6 +96,10 @@ struct Cli {
/// Port of HTTP server
#[arg(long)]
http_server_port: Option<u16>,

/// GPU percentage
#[arg(long)]
gpu_percentage: Option<u8>,
}

async fn main_inner() -> Result<(), anyhow::Error> {
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -210,10 +217,12 @@ fn run_thread<T: EngineImpl>(

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()?;
Expand Down

0 comments on commit c5cf134

Please sign in to comment.