mumugpu/
debug.rs

1#[cfg(debug_assertions)]
2use lazy_static::lazy_static;
3#[cfg(debug_assertions)]
4use std::sync::Mutex;
5#[cfg(debug_assertions)]
6use core_mumu::parser::interpreter::Interpreter;
7#[cfg(debug_assertions)]
8use core_mumu::parser::types::{Value};
9#[cfg(debug_assertions)]
10use indexmap::IndexMap;
11
12#[cfg(debug_assertions)]
13#[derive(Clone)]
14pub struct GpuCallInfo {
15    pub op: String,
16    pub used_gpu: bool,
17}
18
19#[cfg(debug_assertions)]
20lazy_static! {
21    pub static ref LAST_CALL: Mutex<GpuCallInfo> = Mutex::new(GpuCallInfo {
22        op: "none".to_string(),
23        used_gpu: false,
24    });
25}
26
27#[cfg(debug_assertions)]
28pub fn set_last_call_info(op: &str, used_gpu: bool) {
29    let mut lock = LAST_CALL.lock().unwrap();
30    lock.op = op.to_string();
31    lock.used_gpu = used_gpu;
32}
33
34#[cfg(debug_assertions)]
35pub fn gpu_last_call_bridge(
36    _interp: &mut Interpreter,
37    _args: Vec<Value>
38) -> Result<Value, String> {
39    let info = LAST_CALL.lock().unwrap().clone();
40    let mut map = IndexMap::new();
41    map.insert("op".to_string(), Value::SingleString(info.op));
42    map.insert("used_gpu".to_string(), Value::Bool(info.used_gpu));
43    Ok(Value::KeyedArray(map))
44}