Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions src/gpu/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

use super::{GpuConfig, GpuContext};
use anyhow::Result;
use std::sync::Arc;
use std::collections::HashMap;
use std::sync::{Arc, Mutex, OnceLock};
use tracing::info;
use wgpu::{BindGroupLayout, ComputePipeline};

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub enum WorkgroupVariant {
Wg64,
Wg128,
Expand All @@ -31,6 +32,21 @@ pub struct KangarooPipeline {

impl KangarooPipeline {
pub fn new(ctx: &GpuContext, variant: WorkgroupVariant) -> Result<Self> {
static PIPELINE_CACHE: OnceLock<
Mutex<HashMap<(usize, WorkgroupVariant), KangarooPipeline>>,
> = OnceLock::new();
Comment thread
oritwoen marked this conversation as resolved.

let device_key = Arc::as_ptr(&ctx.device) as usize;
let cache = PIPELINE_CACHE.get_or_init(|| Mutex::new(HashMap::new()));
if let Some(pipeline) = cache
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Outdated
.lock()
.expect("pipeline cache poisoned")
.get(&(device_key, variant))
.cloned()
{
return Ok(pipeline);
Comment thread
oritwoen marked this conversation as resolved.
}

info!("Loading shader sources...");

let field = crate::gpu_crypto::shaders::FIELD_WGSL;
Expand Down Expand Up @@ -148,10 +164,17 @@ impl KangarooPipeline {
});
info!("Compute pipeline created");

Ok(Self {
let pipeline = Self {
pipeline: Arc::new(pipeline),
bind_group_layout: Arc::new(bind_group_layout),
variant,
})
};

cache
.lock()
.expect("pipeline cache poisoned")
.insert((device_key, variant), pipeline.clone());

Ok(pipeline)
}
}
Loading