Skip to main content

diffsol_la/context/
faer.rs

1use faer::{get_global_parallelism, Par};
2
3use crate::LaError;
4
5/// Context for the faer backend.
6///
7/// Carries the faer parallelism configuration.  Batching (`nbatch > 1`) is
8/// not supported by this backend; use the CUDA backend instead.
9#[derive(Copy, Clone, Debug, PartialEq)]
10pub struct FaerContext {
11    pub par: Par,
12}
13
14impl FaerContext {
15    pub fn new() -> Self {
16        Self {
17            par: get_global_parallelism(),
18        }
19    }
20}
21
22impl Default for FaerContext {
23    fn default() -> Self {
24        Self::new()
25    }
26}
27
28impl crate::Context for FaerContext {
29    fn clone_with_nbatch(&self, nbatch: usize) -> Result<Self, LaError> {
30        if nbatch != 1 {
31            Err(LaError::Other(
32                "FaerContext does not support batching (nbatch > 1). Use the CUDA backend instead."
33                    .to_string(),
34            ))
35        } else {
36            Ok(Self { par: self.par })
37        }
38    }
39}