You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
GlassBoxAI-RandomForest/
│
├── random_forest.cu # C++ CUDA Random Forest implementation
├── random_forest_opencl.cpp # C++ OpenCL Random Forest implementation
├── facaded_random_forest.cu # C++ CUDA Random Forest with Facade pattern
├── facaded_random_forest_opencl.cpp # C++ OpenCL Random Forest with Facade pattern
│
├── rust_cuda/ # Rust CUDA Random Forest implementation
│ ├── Cargo.toml
│ └── src/
│ └── main.rs
│
├── facaded_rust_cuda/ # Rust CUDA Random Forest with Facade pattern
│ ├── Cargo.toml
│ └── src/
│ ├── main.rs
│ └── kani/ # Kani proof harnesses
│
├── random_forest_cpp_tests.sh # C++ test suite
├── random_forest_opencl_tests.sh # OpenCL test suite
│
├── license.md # MIT License
└── README.md # This file
Prerequisites
Required
Dependency
Version
Purpose
GCC/G++
11+
C++ compilation
CUDA Toolkit
12.0+
CUDA compilation
Rust
1.75+
Rust compilation
Optional
Dependency
Version
Purpose
OpenCL SDK
3.0
OpenCL compilation
Kani
0.67+
Formal verification
Installation & Compilation
C++ CUDA Implementation
# Standard Random Forest
nvcc -O2 -o forest_cuda random_forest.cu
# Facade Random Forest
nvcc -O2 -o forest_facade_cuda facaded_random_forest.cu
C++ OpenCL Implementation
# Standard Random Forest
g++ -O2 -std=c++14 -o forest_opencl random_forest_opencl.cpp -lOpenCL
# Facade Random Forest
g++ -O2 -std=c++14 -o forest_facade_opencl facaded_random_forest_opencl.cpp -lOpenCL
Rust CUDA Implementation
# Standard Random Forestcd rust_cuda
cargo build --release
# Facade Random Forestcd facaded_rust_cuda
cargo build --release
# Create a new model
forest_cuda create --trees=50 --max-depth=15 --save=model.bin
# Train the model
forest_cuda train --model=model.bin --data=train.csv --save=model_trained.bin
# Make predictions
forest_cuda predict --model=model_trained.bin --data=test.csv --output=predictions.csv
# Get model information
forest_cuda info --model=model_trained.bin
Facade Random Forest Commands
The facade implementations provide deep introspection and tree manipulation capabilities.
# Run C++ tests
./random_forest_cpp_tests.sh
# Run OpenCL tests
./random_forest_opencl_tests.sh
# Run Rust testscd rust_cuda && cargo testcd facaded_rust_cuda && cargo test
Test Categories
Each test suite covers:
Category
Tests
Help & Usage
Command-line interface verification
Model Creation
Various hyperparameter configurations
Hyperparameters
Trees, depth, split criteria, task types
Model Info
Metadata retrieval
Save & Load
Model persistence
Introspection
Tree, node, feature inspection
Error Handling
Invalid input handling
Cross-Implementation
API compatibility
Train & Predict
End-to-end workflows
Test Output Example
=========================================
Random Forest Test Suite
=========================================
Group: Help & Usage
Test 1: Help command... PASS
Test 2: --help flag... PASS
Test 3: -h flag... PASS
...
=========================================
Test Summary
=========================================
Total tests: 50
Passed: 50
Failed: 0
All tests passed!
Formal Verification with Kani
Overview
The Rust Facade implementation includes Kani formal verification proofs that mathematically prove the absence of certain classes of bugs. This goes beyond traditional testing to provide mathematical guarantees about code correctness.
Verification Categories
Category
Description
Strict Bound Checks
Array/collection indexing safety
Pointer Validity
Slice-to-pointer conversion safety
No-Panic Guarantee
Enum and command handling safety
Integer Overflow Prevention
Tree size, dimension calculations
Division-by-Zero Exclusion
Bootstrap sampling, feature selection
Global State Consistency
Training mode state tracking
Input Sanitization Bounds
Loop iteration limits
Memory Leak Prevention
Vector allocation bounds
Floating-Point Sanity
NaN/Infinity prevention
Key Kani Proofs
Bound Checking Proofs
verify_tree_indexing ✓
verify_node_indexing ✓
verify_feature_indexing ✓
Overflow Prevention Proofs
verify_tree_size_no_overflow ✓
verify_bootstrap_no_overflow ✓
verify_feature_selection_no_overflow ✓
Safety Proofs
verify_criterion_type_no_panic ✓
verify_task_type_no_panic ✓
verify_command_parsing_no_panic ✓
verify_gini_no_nan ✓
Running Kani Verification
# CLI Versioncd facaded_rust_cuda
cargo kani
# Run specific proof
cargo kani --harness verify_tree_indexing
Why Formal Verification Matters
Traditional testing can only verify specific test cases. Formal verification with Kani:
Exhaustively checks all possible inputs within defined bounds
Mathematically proves absence of panics, buffer overflows, and undefined behavior
Catches edge cases that random testing might miss
Provides cryptographic-level assurance for safety-critical code
CISA/NSA Compliance
Secure by Design
This project follows CISA (Cybersecurity and Infrastructure Security Agency) and NSA (National Security Agency) Secure by Design principles:
Principle
Implementation
Memory Safety
Rust ownership model eliminates buffer overflows, use-after-free, and data races
Formal Verification
Kani proofs mathematically verify absence of critical bugs
Input Validation
All CLI inputs validated before processing
Defense in Depth
Multiple layers of safety (language, compiler, runtime checks)
This codebase has been developed following secure software development lifecycle (SSDLC) practices and demonstrates:
Formal verification proofs passed (Kani proofs)
Zero warnings compilation across all implementations
Consistent API across all language/backend combinations
Production-ready code quality
License
MIT License
Copyright (c) 2025 Matthew Abbott
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.