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, and `CUBECL_ENVIRONMENT_RECORDS`
24/// (`off`, `basic` or `full`) the record level: a harness can record a build
25/// in full without editing the configuration the build reads.
26///
27/// `path` only exists where there is a file system to put environments on;
28/// elsewhere the name still selects one, it just isn't backed by a directory.
29#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
30pub struct EnvironmentConfig {
31    /// Name of the environment to activate when the configuration loads.
32    #[serde(default = "default_name")]
33    pub name: String,
34
35    /// Directory the environments live in.
36    #[cfg(std_io)]
37    #[serde(default)]
38    pub path: CacheConfig,
39
40    /// What the environment remembers of how it was built.
41    #[serde(default)]
42    pub records: cubecl_environment::records::RecordsConfig,
43}
44
45fn default_name() -> String {
46    cubecl_environment::environment::DEFAULT.to_string()
47}
48
49impl Default for EnvironmentConfig {
50    fn default() -> Self {
51        Self {
52            name: default_name(),
53            #[cfg(std_io)]
54            path: CacheConfig::default(),
55            records: Default::default(),
56        }
57    }
58}