Skip to main content

torsh_jit/graph/
metadata.rs

1//! Graph metadata and additional information structures
2
3use std::collections::HashMap;
4
5/// Graph metadata containing additional information about the computation graph
6#[derive(Debug, Clone, Default)]
7pub struct GraphMetadata {
8    /// Graph name
9    pub name: String,
10
11    /// Graph version
12    pub version: String,
13
14    /// Creator information
15    pub creator: String,
16
17    /// Compilation target
18    pub target: Option<String>,
19
20    /// Optimization level
21    pub optimization_level: OptimizationLevel,
22
23    /// Additional custom metadata
24    pub custom: HashMap<String, String>,
25}
26
27impl GraphMetadata {
28    /// Create new metadata with the given name
29    pub fn new(name: String) -> Self {
30        Self {
31            name,
32            version: "1.0.0".to_string(),
33            creator: "torsh-jit".to_string(),
34            target: None,
35            optimization_level: OptimizationLevel::Default,
36            custom: HashMap::new(),
37        }
38    }
39
40    /// Set version
41    pub fn with_version(mut self, version: String) -> Self {
42        self.version = version;
43        self
44    }
45
46    /// Set creator
47    pub fn with_creator(mut self, creator: String) -> Self {
48        self.creator = creator;
49        self
50    }
51
52    /// Set target
53    pub fn with_target(mut self, target: String) -> Self {
54        self.target = Some(target);
55        self
56    }
57
58    /// Set optimization level
59    pub fn with_optimization_level(mut self, level: OptimizationLevel) -> Self {
60        self.optimization_level = level;
61        self
62    }
63
64    /// Add custom metadata
65    pub fn with_custom(mut self, key: String, value: String) -> Self {
66        self.custom.insert(key, value);
67        self
68    }
69
70    /// Get custom metadata value
71    pub fn get_custom(&self, key: &str) -> Option<&String> {
72        self.custom.get(key)
73    }
74}
75
76/// Optimization levels for graph compilation
77#[derive(Debug, Clone, PartialEq, Eq)]
78pub enum OptimizationLevel {
79    None,       // No optimizations
80    Basic,      // Basic optimizations (constant folding, dead code elimination)
81    Default,    // Default optimization level
82    Aggressive, // Aggressive optimizations that may change semantics
83}
84
85impl Default for OptimizationLevel {
86    fn default() -> Self {
87        OptimizationLevel::Default
88    }
89}