Skip to main content

cubecl_runtime/config/
environment.rs

1use alloc::string::{String, ToString};
2
3#[cfg(std_io)]
4use super::cache::CacheConfig;
5
6/// Which named environment the process warms into, and where environments are
7/// kept.
8///
9/// An environment is one local store holding every cached namespace: autotune
10/// results, compiled kernels, throughput measurements. Exactly one is active
11/// at a time, so naming them lets a single checkout keep several side by side.
12///
13/// ```toml
14/// [environment]
15/// name = "h100"
16/// path = "target"
17///
18/// [environment.records]
19/// level = "basic"
20/// keep_sessions = 8
21/// ```
22///
23/// `CUBECL_ENVIRONMENT` overrides the name.
24///
25/// `path` only exists where there is a file system to put environments on;
26/// elsewhere the name still selects one, it just isn't backed by a directory.
27#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
28pub struct EnvironmentConfig {
29    /// Name of the environment to activate when the configuration loads.
30    #[serde(default = "default_name")]
31    pub name: String,
32
33    /// Directory the environments live in.
34    #[cfg(std_io)]
35    #[serde(default)]
36    pub path: CacheConfig,
37
38    /// What the environment remembers of how it was built.
39    #[serde(default)]
40    pub records: cubecl_environment::records::RecordsConfig,
41}
42
43fn default_name() -> String {
44    cubecl_environment::environment::DEFAULT.to_string()
45}
46
47impl Default for EnvironmentConfig {
48    fn default() -> Self {
49        Self {
50            name: default_name(),
51            #[cfg(std_io)]
52            path: CacheConfig::default(),
53            records: Default::default(),
54        }
55    }
56}