mirror of
https://github.com/Chaoscaot/schemsearch.git
synced 2025-11-05 05:54:02 +01:00
**Optimize ProQue initialization with OnceLock**
Replaced repeated ProQue initialization with a static OnceLock to ensure efficient and thread-safe reuse. This minimizes the overhead of recreating the ProQue instance while maintaining correct behavior by dynamically updating its dimensions.
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
use std::sync::OnceLock;
|
||||
use ocl::{Buffer, MemFlags, ProQue, Platform};
|
||||
use ocl::SpatialDims::Three;
|
||||
use schemsearch_common::{Match, SearchBehavior};
|
||||
@ -5,6 +6,8 @@ use math::round::ceil;
|
||||
|
||||
const KERNEL: &str = include_str!("kernel.cl");
|
||||
|
||||
static PRO_QUEU_CELL: OnceLock<ProQue> = OnceLock::new();
|
||||
|
||||
pub fn ocl_available() -> bool {
|
||||
!Platform::list().is_empty()
|
||||
}
|
||||
@ -40,10 +43,15 @@ fn search_ocl(
|
||||
|
||||
let skip_amount = ceil((pattern_blocks * (1.0 - search_behavior.threshold)) as f64, 0) as i32;
|
||||
|
||||
let pro_que = ProQue::builder()
|
||||
.src(KERNEL)
|
||||
.dims(Three(schem_width, schem_height, schem_length))
|
||||
.build()?;
|
||||
let cell = &PRO_QUEU_CELL;
|
||||
let mut pro_que = cell.get_or_init(|| {
|
||||
ProQue::builder()
|
||||
.src(KERNEL)
|
||||
.build().unwrap()
|
||||
}).clone();
|
||||
|
||||
|
||||
pro_que.set_dims(Three(schem_width, schem_height, schem_length));
|
||||
|
||||
let buffer = Buffer::builder()
|
||||
.queue(pro_que.queue().clone())
|
||||
|
||||
Reference in New Issue
Block a user