diff --git a/src-tauri/src/gpu_miner_adapter.rs b/src-tauri/src/gpu_miner_adapter.rs index 7ec95579f..9e010c676 100644 --- a/src-tauri/src/gpu_miner_adapter.rs +++ b/src-tauri/src/gpu_miner_adapter.rs @@ -9,6 +9,8 @@ use async_trait::async_trait; use log::{info, warn}; use serde::{Deserialize, Serialize}; use std::collections::HashMap; +use std::ops::Div; +use std::ops::Mul; use std::path::PathBuf; use std::time::Instant; use tari_common::configuration::Network; @@ -22,9 +24,6 @@ use crate::{ const LOG_TARGET: &str = "tari::universe::gpu_miner_adapter"; -pub const ECO_MODE_GPU_GRID_SIZE: u32 = 2; -pub const LUDICROUS_MODE_GPU_GRID_SIZE: u32 = 900; // TODO: In future will allow user to configure this, but for now let's not burn the gpu too much - pub enum GpuNodeSource { BaseNode { port: u16 }, P2Pool { port: u16 }, @@ -64,9 +63,9 @@ impl GpuMinerAdapter { self.gpu_grid_size = self .gpu_devices .iter() - .map(|x| GpuThreads { - gpu_name: x.device_name.clone(), - max_gpu_threads: ECO_MODE_GPU_GRID_SIZE, + .map(|device| GpuThreads { + gpu_name: device.device_name.clone(), + max_gpu_threads: device.max_grid_size.mul(100).div(333), }) .collect() } @@ -74,9 +73,10 @@ impl GpuMinerAdapter { self.gpu_grid_size = self .gpu_devices .iter() - .map(|x| GpuThreads { - gpu_name: x.device_name.clone(), - max_gpu_threads: LUDICROUS_MODE_GPU_GRID_SIZE, + .map(|device| GpuThreads { + gpu_name: device.device_name.clone(), + // get 90% of max grid size + max_gpu_threads: device.max_grid_size.mul(100).div(111), }) .collect() } diff --git a/src/containers/main/SideBar/Miner/components/CustomPowerLevels/CustomPowerLevelsDialog.tsx b/src/containers/main/SideBar/Miner/components/CustomPowerLevels/CustomPowerLevelsDialog.tsx index 0305e28b5..40f941603 100644 --- a/src/containers/main/SideBar/Miner/components/CustomPowerLevels/CustomPowerLevelsDialog.tsx +++ b/src/containers/main/SideBar/Miner/components/CustomPowerLevels/CustomPowerLevelsDialog.tsx @@ -19,10 +19,6 @@ import { Controller, useFieldArray, useForm } from 'react-hook-form'; import { modeType } from '@app/store/types.ts'; import { Button } from '@app/components/elements/buttons/Button.tsx'; -// took from gpu_miner_adapter.rs -const ECO_MODE_GPU_GRID_SIZE = 2; -const LUDICROUS_MODE_GPU_GRID_SIZE = 900; - enum FormFields { CPU = 'cpu', GPUS = 'gpus', @@ -33,12 +29,16 @@ interface FormValues { [FormFields.GPUS]: GpuThreads[]; } -const resolveCpuInitialThreads = (configCpuLevels: number | undefined, mode: modeType | undefined) => { +const resolveCpuInitialThreads = ( + configCpuLevels: number | undefined, + mode: modeType | undefined, + maxAvailableThreads: MaxConsumptionLevels +) => { switch (mode) { case 'Eco': - return configCpuLevels || ECO_MODE_GPU_GRID_SIZE; + return configCpuLevels || Math.round(maxAvailableThreads.max_cpu_threads * 0.3); case 'Ludicrous': - return configCpuLevels || LUDICROUS_MODE_GPU_GRID_SIZE; + return configCpuLevels || Math.round(maxAvailableThreads.max_cpu_threads * 0.9); default: return 0; } @@ -56,12 +56,12 @@ const resolveGpuInitialThreads = ( case 'Eco': return maxAvailableThreads.max_gpus_threads.map((gpu) => ({ gpu_name: gpu.gpu_name, - max_gpu_threads: ECO_MODE_GPU_GRID_SIZE, + max_gpu_threads: Math.round(gpu.max_gpu_threads * 0.3), })); case 'Ludicrous': return maxAvailableThreads.max_gpus_threads.map((gpu) => ({ gpu_name: gpu.gpu_name, - max_gpu_threads: LUDICROUS_MODE_GPU_GRID_SIZE, + max_gpu_threads: Math.round(gpu.max_gpu_threads * 0.9), })); default: return []; @@ -88,7 +88,7 @@ export function CustomPowerLevelsDialog({ const { control, handleSubmit, setValue, getValues } = useForm({ defaultValues: { - [FormFields.CPU]: resolveCpuInitialThreads(configCpuLevels, mode), + [FormFields.CPU]: resolveCpuInitialThreads(configCpuLevels, mode, maxAvailableThreads), [FormFields.GPUS]: resolveGpuInitialThreads(configGpuLevels, mode, maxAvailableThreads), }, });