sc_neurocore_engine/bindings/
runtime_control.rs1use pyo3::exceptions::PyValueError;
12use pyo3::prelude::*;
13
14pub(crate) fn register(module: &Bound<'_, PyModule>) -> PyResult<()> {
16 module.add_function(wrap_pyfunction!(simd_tier, module)?)?;
17 module.add_function(wrap_pyfunction!(set_num_threads, module)?)?;
18 Ok(())
19}
20
21#[pyfunction]
23fn simd_tier() -> &'static str {
24 #[cfg(target_arch = "x86_64")]
25 {
26 if is_x86_feature_detected!("avx512vpopcntdq") {
27 return "avx512-vpopcntdq";
28 }
29 if is_x86_feature_detected!("avx512bw") {
30 return "avx512bw";
31 }
32 if is_x86_feature_detected!("avx512f") {
33 return "avx512f";
34 }
35 if is_x86_feature_detected!("avx2") {
36 return "avx2";
37 }
38 if is_x86_feature_detected!("popcnt") {
39 return "popcnt";
40 }
41 }
42 #[cfg(target_arch = "aarch64")]
43 {
44 return "neon";
45 }
46 "portable"
47}
48
49#[pyfunction]
54fn set_num_threads(n: usize) -> PyResult<()> {
55 if n == 0 {
56 return Ok(());
57 }
58 rayon::ThreadPoolBuilder::new()
59 .num_threads(n)
60 .build_global()
61 .map_err(|e| PyValueError::new_err(format!("Cannot set thread pool: {e}")))
62}