mirror of
https://github.com/Chaoscaot/schemsearch.git
synced 2025-11-23 04:17:05 +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::{Buffer, MemFlags, ProQue, Platform};
|
||||||
use ocl::SpatialDims::Three;
|
use ocl::SpatialDims::Three;
|
||||||
use schemsearch_common::{Match, SearchBehavior};
|
use schemsearch_common::{Match, SearchBehavior};
|
||||||
@@ -5,6 +6,8 @@ use math::round::ceil;
|
|||||||
|
|
||||||
const KERNEL: &str = include_str!("kernel.cl");
|
const KERNEL: &str = include_str!("kernel.cl");
|
||||||
|
|
||||||
|
static PRO_QUEU_CELL: OnceLock<ProQue> = OnceLock::new();
|
||||||
|
|
||||||
pub fn ocl_available() -> bool {
|
pub fn ocl_available() -> bool {
|
||||||
!Platform::list().is_empty()
|
!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 skip_amount = ceil((pattern_blocks * (1.0 - search_behavior.threshold)) as f64, 0) as i32;
|
||||||
|
|
||||||
let pro_que = ProQue::builder()
|
let cell = &PRO_QUEU_CELL;
|
||||||
.src(KERNEL)
|
let mut pro_que = cell.get_or_init(|| {
|
||||||
.dims(Three(schem_width, schem_height, schem_length))
|
ProQue::builder()
|
||||||
.build()?;
|
.src(KERNEL)
|
||||||
|
.build().unwrap()
|
||||||
|
}).clone();
|
||||||
|
|
||||||
|
|
||||||
|
pro_que.set_dims(Three(schem_width, schem_height, schem_length));
|
||||||
|
|
||||||
let buffer = Buffer::builder()
|
let buffer = Buffer::builder()
|
||||||
.queue(pro_que.queue().clone())
|
.queue(pro_que.queue().clone())
|
||||||
|
|||||||
Reference in New Issue
Block a user