mirror of
https://github.com/Chaoscaot/schemsearch.git
synced 2025-11-05 05:54:02 +01:00
Enable lazy initialization for OpenCL availability check
This commit is contained in:
@ -1,4 +1,4 @@
|
|||||||
use std::sync::OnceLock;
|
use lazy_static::lazy_static;
|
||||||
use math::round::ceil;
|
use math::round::ceil;
|
||||||
use schemsearch_common::Match;
|
use schemsearch_common::Match;
|
||||||
use schemsearch_files::SpongeSchematic;
|
use schemsearch_files::SpongeSchematic;
|
||||||
@ -6,7 +6,11 @@ use schemsearch_ocl_matcher::{ocl_available, ocl_search};
|
|||||||
use crate::{SearchBehavior};
|
use crate::{SearchBehavior};
|
||||||
use crate::pattern_mapper::{match_palette, match_palette_adapt};
|
use crate::pattern_mapper::{match_palette, match_palette_adapt};
|
||||||
|
|
||||||
const OPENCL_AVAILABLE: OnceLock<bool> = OnceLock::new();
|
lazy_static! {
|
||||||
|
static ref OPENCL_AVAILABLE: bool = {
|
||||||
|
ocl_available()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
pub fn search(
|
pub fn search(
|
||||||
schem: SpongeSchematic,
|
schem: SpongeSchematic,
|
||||||
@ -44,7 +48,7 @@ pub fn search(
|
|||||||
let schem_height = schem.height as usize;
|
let schem_height = schem.height as usize;
|
||||||
let schem_length = schem.length as usize;
|
let schem_length = schem.length as usize;
|
||||||
|
|
||||||
if !search_behavior.use_cpu && *OPENCL_AVAILABLE.get_or_init(|| ocl_available()) {
|
if !search_behavior.use_cpu && *OPENCL_AVAILABLE {
|
||||||
return ocl_search(schem_data.as_slice(), [schem_width, schem_height, schem_length], pattern_schem.block_data.as_slice(), [pattern_width, pattern_height, pattern_length], *air_id, search_behavior).unwrap()
|
return ocl_search(schem_data.as_slice(), [schem_width, schem_height, schem_length], pattern_schem.block_data.as_slice(), [pattern_width, pattern_height, pattern_length], *air_id, search_behavior).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user