Skip to content

Commit

Permalink
Merge pull request #3024 from autonomys/gpu-plotting-improvements
Browse files Browse the repository at this point in the history
GPU plotting improvements
  • Loading branch information
nazar-pc committed Sep 15, 2024
2 parents 92340f8 + 0b5dc74 commit 70c266b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ struct CpuPlottingOptions {
/// `--cpu-sector-downloading-concurrency` and setting this option higher than
/// `--cpu-sector-downloading-concurrency` will have no effect.
///
/// CPU plotting is disabled by default if GPU plotting is detected.
///
/// Increase will result in higher memory usage, setting to 0 will disable CPU plotting.
#[arg(long)]
cpu_sector_encoding_concurrency: Option<usize>,
Expand Down Expand Up @@ -151,34 +153,42 @@ where
let mut legacy_plotters = Vec::<Box<dyn Plotter + Send + Sync>>::new();
let mut modern_plotters = Vec::<Box<dyn Plotter + Send + Sync>>::new();

#[cfg(feature = "cuda")]
{
let maybe_cpu_plotters = init_cpu_plotters::<_, PosTableLegacy, PosTable>(
cpu_plotting_options,
let maybe_cuda_plotter = init_cuda_plotter(
cuda_plotting_options,
piece_getter.clone(),
Arc::clone(&global_mutex),
kzg.clone(),
erasure_coding.clone(),
registry,
)?;

if let Some((legacy_cpu_plotter, modern_cpu_plotter)) = maybe_cpu_plotters {
legacy_plotters.push(Box::new(legacy_cpu_plotter));
modern_plotters.push(Box::new(modern_cpu_plotter));
if let Some(cuda_plotter) = maybe_cuda_plotter {
modern_plotters.push(Box::new(cuda_plotter));
}
}
#[cfg(feature = "cuda")]
{
let maybe_cuda_plotter = init_cuda_plotter(
cuda_plotting_options,
let cpu_sector_encoding_concurrency = cpu_plotting_options.cpu_sector_encoding_concurrency;
let maybe_cpu_plotters = init_cpu_plotters::<_, PosTableLegacy, PosTable>(
cpu_plotting_options,
piece_getter,
global_mutex,
kzg,
erasure_coding,
registry,
)?;

if let Some(cuda_plotter) = maybe_cuda_plotter {
modern_plotters.push(Box::new(cuda_plotter));
if let Some((legacy_cpu_plotter, modern_cpu_plotter)) = maybe_cpu_plotters {
legacy_plotters.push(Box::new(legacy_cpu_plotter));
if !modern_plotters.is_empty() && cpu_sector_encoding_concurrency.is_none() {
info!(
"CPU plotting for v1 farms was disabled due to detected faster plotting with \
GPU"
);
} else {
modern_plotters.push(Box::new(modern_cpu_plotter));
}
}
}
let legacy_plotter = Arc::new(PoolPlotter::new(legacy_plotters, PLOTTING_RETRY_INTERVAL));
Expand Down
30 changes: 20 additions & 10 deletions crates/subspace-farmer/src/bin/subspace-farmer/commands/farm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ struct CpuPlottingOptions {
/// `--cpu-sector-downloading-concurrency` and setting this option higher than
/// `--cpu-sector-downloading-concurrency` will have no effect.
///
/// CPU plotting is disabled by default if GPU plotting is detected.
///
/// Increase will result in higher memory usage, setting to 0 will disable CPU plotting.
#[arg(long)]
cpu_sector_encoding_concurrency: Option<usize>,
Expand Down Expand Up @@ -469,34 +471,42 @@ where
let mut legacy_plotters = Vec::<Box<dyn Plotter + Send + Sync>>::new();
let mut modern_plotters = Vec::<Box<dyn Plotter + Send + Sync>>::new();

#[cfg(feature = "cuda")]
{
let maybe_cpu_plotters = init_cpu_plotters::<_, PosTableLegacy, PosTable>(
cpu_plotting_options,
let maybe_cuda_plotter = init_cuda_plotter(
cuda_plotting_options,
piece_getter.clone(),
Arc::clone(&global_mutex),
kzg.clone(),
erasure_coding.clone(),
&mut registry,
)?;

if let Some((legacy_cpu_plotter, modern_cpu_plotter)) = maybe_cpu_plotters {
legacy_plotters.push(Box::new(legacy_cpu_plotter));
modern_plotters.push(Box::new(modern_cpu_plotter));
if let Some(cuda_plotter) = maybe_cuda_plotter {
modern_plotters.push(Box::new(cuda_plotter));
}
}
#[cfg(feature = "cuda")]
{
let maybe_cuda_plotter = init_cuda_plotter(
cuda_plotting_options,
let cpu_sector_encoding_concurrency = cpu_plotting_options.cpu_sector_encoding_concurrency;
let maybe_cpu_plotters = init_cpu_plotters::<_, PosTableLegacy, PosTable>(
cpu_plotting_options,
piece_getter.clone(),
Arc::clone(&global_mutex),
kzg.clone(),
erasure_coding.clone(),
&mut registry,
)?;

if let Some(cuda_plotter) = maybe_cuda_plotter {
modern_plotters.push(Box::new(cuda_plotter));
if let Some((legacy_cpu_plotter, modern_cpu_plotter)) = maybe_cpu_plotters {
legacy_plotters.push(Box::new(legacy_cpu_plotter));
if !modern_plotters.is_empty() && cpu_sector_encoding_concurrency.is_none() {
info!(
"CPU plotting for v1 farms was disabled due to detected faster plotting with \
GPU"
);
} else {
modern_plotters.push(Box::new(modern_cpu_plotter));
}
}
}
let legacy_plotter = Arc::new(PoolPlotter::new(legacy_plotters, PLOTTING_RETRY_INTERVAL));
Expand Down
13 changes: 10 additions & 3 deletions shared/subspace-proof-of-space-gpu/src/cuda.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl CudaDevice {
let mut challenge_index_gpu = Vec::<u32>::with_capacity(challenge_len);
let mut parity_record_chunks = Vec::<Scalar>::with_capacity(Record::NUM_CHUNKS);

let err = unsafe {
let error = unsafe {
generate_and_encode_pospace_dispatch(
u32::from(PosProof::K),
&**seed,
Expand All @@ -126,8 +126,15 @@ impl CudaDevice {
)
};

if err.code != 0 {
return Err(String::from(err));
if error.code != 0 {
let error = error.to_string();
if error.contains("the provided PTX was compiled with an unsupported toolchain.") {
return Err(format!(
"Nvidia driver is likely too old, make sure install version 550 or newer: \
{error}"
));
}
return Err(error);
}

let proof_count = proof_count as usize;
Expand Down

0 comments on commit 70c266b

Please sign in to comment.