Skip to main content

fauna_api/termite/
spec.rs

1use serde::{Deserialize, Serialize};
2use serde_json::Value;
3
4/// A machine's size. vCPUs and memory are the most a machine gets; tflops and GPU memory the
5/// least; storage at least the repository's disk.
6#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
7#[serde(rename_all = "camelCase")]
8pub struct Spec {
9    pub vcpus: u32,
10    pub memory_bytes: u64,
11    pub storage_bytes: u64,
12    /// Dense BF16. 0 asks for no GPU.
13    pub tflops: f64,
14    pub gpu_memory_bytes: u64,
15}
16
17impl Spec {
18    pub fn from_json(json: &Value) -> Spec {
19        Spec {
20            vcpus: json["vcpus"].as_f64().unwrap_or_default() as u32,
21            memory_bytes: json["memoryBytes"].as_f64().unwrap_or_default() as u64,
22            storage_bytes: json["storageBytes"].as_f64().unwrap_or_default() as u64,
23            tflops: json["tflops"].as_f64().unwrap_or_default(),
24            gpu_memory_bytes: json["gpuMemoryBytes"].as_f64().unwrap_or_default() as u64,
25        }
26    }
27}
28
29/// 2 vCPUs, 4 GiB of memory and 8 GiB of storage, with no GPU.
30pub const STANDARD_SPEC: Spec = Spec {
31    vcpus: 2,
32    memory_bytes: 4 << 30,
33    storage_bytes: 8 << 30,
34    tflops: 0.0,
35    gpu_memory_bytes: 0,
36};