- 
                Notifications
    
You must be signed in to change notification settings  - Fork 670
 
feat: kvbm v2 memory crate #4012
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Open
      
      
            ryanolson
  wants to merge
  16
  commits into
  main
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
ryan/kvbm_v2/memory
  
      
      
   
  
    
  
  
  
 
  
      
    base: main
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
      
        
          +3,175
        
        
          −0
        
        
          
        
      
    
  
  
     Open
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            16 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      5c90a41
              
                kvbm v2 memory
              
              
                ryanolson ef11ec0
              
                Update lib/memory/src/disk.rs
              
              
                ryanolson 5feaad6
              
                Update lib/memory/src/disk.rs
              
              
                ryanolson 3c66f02
              
                Update lib/memory/src/system.rs
              
              
                ryanolson 118c956
              
                Update lib/memory/src/pinned.rs
              
              
                ryanolson 8c3a8c9
              
                Update lib/memory/src/actions.rs
              
              
                ryanolson ece80d9
              
                copyright headers
              
              
                ryanolson e6fa60b
              
                fixed arena nixl descriptor offset
              
              
                ryanolson cb7d915
              
                adding nixl config and backends
              
              
                ryanolson 992af68
              
                copyright headers
              
              
                ryanolson 876a4aa
              
                Update lib/memory/src/nixl.rs
              
              
                ryanolson 73a6d49
              
                Update lib/memory/src/nixl.rs
              
              
                ryanolson 33a1fb6
              
                fixes from @coderabbitai
              
              
                ryanolson fcf523d
              
                typeo
              
              
                ryanolson b9e3f36
              
                Merge branch 'main' into ryan/kvbm_v2/memory
              
              
                ryanolson 0dcf35e
              
                Merge branch 'main' into ryan/kvbm_v2/memory
              
              
                ryanolson File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
      
      Oops, something went wrong.
      
    
  
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| 
     | 
||
| [package] | ||
| name = "dynamo-config" | ||
| version.workspace = true | ||
| edition.workspace = true | ||
| description.workspace = true | ||
| authors.workspace = true | ||
| license.workspace = true | ||
| homepage.workspace = true | ||
| repository.workspace = true | ||
| keywords.workspace = true | ||
| 
     | 
||
| [dependencies] | ||
| anyhow = { workspace = true } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,202 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| 
     | 
||
| //! Configuration utilities and trait re-exports. | ||
| //! | ||
| //! This module provides utility functions for parsing configuration values | ||
| //! and re-exports the core configuration traits from the integrations module. | ||
| 
     | 
||
| // ===== Environment Variable Utilities ===== | ||
| 
     | 
||
| /// Check if a string is truthy. | ||
| /// | ||
| /// This will be used to evaluate environment variables or any other subjective | ||
| /// configuration parameters that can be set by the user that should be evaluated | ||
| /// as a boolean value. | ||
| /// | ||
| /// Truthy values: "1", "true", "on", "yes" (case-insensitive) | ||
| /// | ||
| /// Returns `false` for invalid values. Use [`parse_bool`] if you need to error on invalid values. | ||
| pub fn is_truthy(val: &str) -> bool { | ||
| matches!(val.to_lowercase().as_str(), "1" | "true" | "on" | "yes") | ||
| } | ||
| 
     | 
||
| /// Check if a string is falsey. | ||
| /// | ||
| /// This will be used to evaluate environment variables or any other subjective | ||
| /// configuration parameters that can be set by the user that should be evaluated | ||
| /// as a boolean value (opposite of is_truthy). | ||
| /// | ||
| /// Falsey values: "0", "false", "off", "no" (case-insensitive) | ||
| /// | ||
| /// Returns `false` for invalid values. Use [`parse_bool`] if you need to error on invalid values. | ||
| pub fn is_falsey(val: &str) -> bool { | ||
| matches!(val.to_lowercase().as_str(), "0" | "false" | "off" | "no") | ||
| } | ||
| 
     | 
||
| /// Parse a string as a boolean value, returning an error if invalid. | ||
| /// | ||
| /// This function strictly validates that the input is a valid boolean representation. | ||
| /// | ||
| /// # Arguments | ||
| /// * `val` - The string value to parse | ||
| /// | ||
| /// # Returns | ||
| /// * `Ok(true)` - For truthy values: "1", "true", "on", "yes" (case-insensitive) | ||
| /// * `Ok(false)` - For falsey values: "0", "false", "off", "no" (case-insensitive) | ||
| /// * `Err(_)` - For any other value | ||
| /// | ||
| /// # Example | ||
| /// ```ignore | ||
| /// assert_eq!(parse_bool("true")?, true); | ||
| /// assert_eq!(parse_bool("0")?, false); | ||
| /// assert!(parse_bool("maybe").is_err()); | ||
| /// ``` | ||
| pub fn parse_bool(val: &str) -> anyhow::Result<bool> { | ||
| if is_truthy(val) { | ||
| Ok(true) | ||
| } else if is_falsey(val) { | ||
| Ok(false) | ||
| } else { | ||
| anyhow::bail!( | ||
| "Invalid boolean value: '{}'. Expected one of: true/false, 1/0, on/off, yes/no", | ||
| val | ||
| ) | ||
| } | ||
| } | ||
| 
     | 
||
| /// Check if an environment variable is truthy. | ||
| /// | ||
| /// Returns `false` if the environment variable is not set or is invalid. | ||
| /// Use [`env_parse_bool`] if you need to distinguish between unset, valid, and invalid values. | ||
| pub fn env_is_truthy(env: &str) -> bool { | ||
| match std::env::var(env) { | ||
| Ok(val) => is_truthy(val.as_str()), | ||
| Err(_) => false, | ||
| } | ||
| } | ||
| 
     | 
||
| /// Check if an environment variable is falsey. | ||
| /// | ||
| /// Returns `false` if the environment variable is not set or is invalid. | ||
| /// Use [`env_parse_bool`] if you need to distinguish between unset, valid, and invalid values. | ||
| pub fn env_is_falsey(env: &str) -> bool { | ||
| match std::env::var(env) { | ||
| Ok(val) => is_falsey(val.as_str()), | ||
| Err(_) => false, | ||
| } | ||
| } | ||
| 
     | 
||
| /// Parse an environment variable as a boolean, returning an error if invalid. | ||
| /// | ||
| /// # Arguments | ||
| /// * `env` - The environment variable name | ||
| /// | ||
| /// # Returns | ||
| /// * `Ok(Some(true))` - If the env var is set to a truthy value | ||
| /// * `Ok(Some(false))` - If the env var is set to a falsey value | ||
| /// * `Ok(None)` - If the env var is not set | ||
| /// * `Err(_)` - If the env var is set to an invalid value | ||
| /// | ||
| /// # Example | ||
| /// ```ignore | ||
| /// match env_parse_bool("MY_FLAG")? { | ||
| /// Some(true) => println!("enabled"), | ||
| /// Some(false) => println!("disabled"), | ||
| /// None => println!("not configured"), | ||
| /// } | ||
| /// ``` | ||
| pub fn env_parse_bool(env: &str) -> anyhow::Result<Option<bool>> { | ||
| match std::env::var(env) { | ||
| Ok(val) => parse_bool(&val).map(Some), | ||
| Err(std::env::VarError::NotPresent) => Ok(None), | ||
| Err(e) => anyhow::bail!("Failed to read environment variable {}: {}", env, e), | ||
| } | ||
| } | ||
| 
     | 
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
| 
     | 
||
| #[test] | ||
| fn test_is_truthy() { | ||
| assert!(is_truthy("1")); | ||
| assert!(is_truthy("true")); | ||
| assert!(is_truthy("True")); | ||
| assert!(is_truthy("TRUE")); | ||
| assert!(is_truthy("on")); | ||
| assert!(is_truthy("ON")); | ||
| assert!(is_truthy("yes")); | ||
| assert!(is_truthy("YES")); | ||
| 
     | 
||
| assert!(!is_truthy("0")); | ||
| assert!(!is_truthy("false")); | ||
| assert!(!is_truthy("off")); | ||
| assert!(!is_truthy("no")); | ||
| assert!(!is_truthy("")); | ||
| assert!(!is_truthy("random")); | ||
| } | ||
| 
     | 
||
| #[test] | ||
| fn test_is_falsey() { | ||
| assert!(is_falsey("0")); | ||
| assert!(is_falsey("false")); | ||
| assert!(is_falsey("False")); | ||
| assert!(is_falsey("FALSE")); | ||
| assert!(is_falsey("off")); | ||
| assert!(is_falsey("OFF")); | ||
| assert!(is_falsey("no")); | ||
| assert!(is_falsey("NO")); | ||
| 
     | 
||
| assert!(!is_falsey("1")); | ||
| assert!(!is_falsey("true")); | ||
| assert!(!is_falsey("on")); | ||
| assert!(!is_falsey("yes")); | ||
| assert!(!is_falsey("")); | ||
| assert!(!is_falsey("random")); | ||
| } | ||
| 
     | 
||
| #[test] | ||
| fn test_env_is_truthy_not_set() { | ||
| // Test with a variable that definitely doesn't exist | ||
| assert!(!env_is_truthy("DEFINITELY_NOT_SET_VAR_12345")); | ||
| } | ||
| 
     | 
||
| #[test] | ||
| fn test_env_is_falsey_not_set() { | ||
| // Test with a variable that definitely doesn't exist | ||
| assert!(!env_is_falsey("DEFINITELY_NOT_SET_VAR_12345")); | ||
| } | ||
| 
     | 
||
| #[test] | ||
| fn test_parse_bool() { | ||
| // Truthy values | ||
| assert!(parse_bool("1").unwrap()); | ||
| assert!(parse_bool("true").unwrap()); | ||
| assert!(parse_bool("TRUE").unwrap()); | ||
| assert!(parse_bool("on").unwrap()); | ||
| assert!(parse_bool("yes").unwrap()); | ||
| 
     | 
||
| // Falsey values | ||
| assert!(!parse_bool("0").unwrap()); | ||
| assert!(!parse_bool("false").unwrap()); | ||
| assert!(!parse_bool("FALSE").unwrap()); | ||
| assert!(!parse_bool("off").unwrap()); | ||
| assert!(!parse_bool("no").unwrap()); | ||
| 
     | 
||
| // Invalid values | ||
| assert!(parse_bool("").is_err()); | ||
| assert!(parse_bool("maybe").is_err()); | ||
| assert!(parse_bool("2").is_err()); | ||
| assert!(parse_bool("random").is_err()); | ||
| } | ||
| 
     | 
||
| #[test] | ||
| fn test_env_parse_bool_not_set() { | ||
| // Test with a variable that definitely doesn't exist | ||
| assert_eq!( | ||
| env_parse_bool("DEFINITELY_NOT_SET_VAR_12345").unwrap(), | ||
| None | ||
| ); | ||
| } | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| 
     | 
||
| [package] | ||
| name = "dynamo-memory" | ||
| version.workspace = true | ||
| edition.workspace = true | ||
| authors.workspace = true | ||
| license.workspace = true | ||
| repository.workspace = true | ||
| 
     | 
||
| [features] | ||
| default = ["testing-all"] | ||
| 
     | 
||
| # feature to enable unsafe slices of memory descriptors | ||
| # for advanced testing in other crates | ||
| unsafe-slices = [] | ||
| 
     | 
||
| # test features for hardware-specific tests | ||
| testing-cuda = [] | ||
| testing-nixl = [] | ||
| testing-all = ["testing-cuda", "testing-nixl"] | ||
| 
     | 
||
| [dependencies] | ||
| dynamo-config = { workspace = true } | ||
| 
     | 
||
| anyhow = { workspace = true } | ||
| cudarc = { workspace = true } | ||
| nixl-sys = { version = "0.7" } | ||
| serde = { workspace = true} | ||
| thiserror = { workspace = true } | ||
| tracing = { workspace = true } | ||
| 
     | 
||
| libc = { version = "0.2" } | ||
| nix = { version = "0.30", features = ["fs"] } | ||
| offset-allocator = "0.2" | ||
| 
     | 
||
| [dev-dependencies] | ||
| tempfile = "3" | ||
      
      Oops, something went wrong.
        
    
  
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.