Kronos Compute π
π¦ Release Candidate 6 (v0.2.0-rc6): Enhanced debug logging for buffer creation issues! π¬ Helps diagnose why create_buffer might not be loaded.
A high-performance, compute-only Vulkan implementation in Rust, featuring state-of-the-art GPU compute optimizations.
Overview
Kronos Compute is a streamlined Vulkan implementation that removes all graphics functionality to achieve maximum GPU compute performance. This Rust port not only provides memory-safe abstractions over the C API but also implements cutting-edge optimizations that deliver:
- Zero descriptor updates per dispatch
- β€0.5 barriers per dispatch (83% reduction)
- 30-50% reduction in CPU submit time
- Zero memory allocations in steady state
- 13.9% reduction in structure sizes
π― Key Features
1. Safe Unified API π
- Zero unsafe code required
- Automatic resource management (RAII)
- Builder patterns and fluent interfaces
- Type-safe abstractions
- All optimizations work transparently
2. Advanced Optimizations
Persistent Descriptors
- Set0 reserved for storage buffers with zero updates in hot path
- Parameters passed via push constants (β€128 bytes)
- Eliminates descriptor set allocation and update overhead
Intelligent Barrier Policy
- Smart tracking reduces barriers from 3 per dispatch to β€0.5
- Only three transition types: uploadβread, readβwrite, writeβread
- Vendor-specific optimizations for AMD, NVIDIA, and Intel GPUs
Timeline Semaphore Batching
- One timeline semaphore per queue
- Batch multiple submissions with a single fence
- 30-50% reduction in CPU overhead
Advanced Memory Allocator
- Three-pool system: DEVICE_LOCAL, HOST_VISIBLE|COHERENT, HOST_VISIBLE|CACHED
- Slab-based sub-allocation with 256MB slabs
- Power-of-2 block sizes for O(1) allocation/deallocation
3. Type-Safe Implementation
- Safe handles with phantom types
- Proper error handling with Result types
- Zero-cost abstractions
- Memory safety guarantees
4. Smart ICD Loader (Enhanced in v0.2.0)
- Automatically discovers all available Vulkan drivers
- Prioritizes hardware drivers (AMD, NVIDIA, Intel) over software renderers
- No manual
VK_ICD_FILENAMESconfiguration needed - Falls back to software rendering only when no hardware is available
- Clear logging of available and selected drivers
- Robust library resolution: resolves
library_pathas provided (via dynamic linker search) and relative to the manifest directory - Detailed discovery logs: search paths, discovered JSON files, load attempts, and per-candidate errors
5. Optimized Structures
VkPhysicalDeviceFeatures: 32 bytes (vs 220 in standard Vulkan)VkBufferCreateInfo: Reordered fields for better packingVkMemoryTypeCache: O(1) memory type lookups
π Project Structure
kronos/
βββ src/
β βββ lib.rs # Main library entry point
β βββ sys/ # Low-level FFI types
β βββ core/ # Core Kronos types
β βββ ffi/ # C-compatible function signatures
β βββ implementation/ # Kronos optimizations
βββ benches/ # Performance benchmarks
βββ examples/ # Usage examples
βββ tests/ # Integration and unit tests
βββ shaders/ # SPIR-V compute shaders
βββ scripts/ # Build and validation scripts
βββ docs/ # Documentation
βββ architecture/ # Design documents
β βββ OPTIMIZATION_SUMMARY.md
β βββ VULKAN_COMPARISON.md
β βββ ICD_SUCCESS.md
β βββ COMPATIBILITY.md
βββ benchmarks/ # Performance results
β βββ BENCHMARK_RESULTS.md
βββ qa/ # Quality assurance
β βββ QA_REPORT.md
β βββ MINI_REVIEW.md
β βββ TEST_RESULTS.md
βββ EPIC.md # Project epic and vision
βββ TODO.md # Development roadmap
π οΈ Installation
From crates.io
From Source
Prerequisites
- Rust 1.70 or later
- Vulkan SDK (for ICD loader and validation layers)
- A Vulkan-capable GPU with compute support
- Build tools (gcc/clang on Linux, Visual Studio on Windows, Xcode on macOS)
- (Optional) SPIR-V compiler (glslc or glslangValidator) for shader development
See Development Setup Guide for detailed installation instructions.
Build Steps
# Clone the repository
# Build SPIR-V shaders (optional, pre-built shaders included)
# Build with optimizations enabled
# Run tests
# Run benchmarks
# Run validation scripts
π Benchmarks
Kronos includes comprehensive benchmarks for common compute workloads:
- SAXPY: Vector multiply-add operations (c = a*x + b)
- Reduction: Parallel array summation
- Prefix Sum: Parallel scan algorithm
- GEMM: Dense matrix multiplication (C = A * B)
Each benchmark tests multiple configurations:
- Sizes: 64KB (small), 8MB (medium), 64MB (large)
- Batch sizes: 1, 16, 256 dispatches
- Metrics: descriptor updates, barriers, CPU time, memory allocations
# Run specific benchmark
# Run with custom parameters
π Usage Example
Safe Unified API (Recommended)
use ;
// No unsafe code needed!
let ctx = new?;
// Load shader and create pipeline
let shader = ctx.load_shader?;
let pipeline = ctx.create_pipeline?;
// Create buffers
let input = ctx.create_buffer?;
let output = ctx.create_buffer_uninit?;
// Dispatch compute work
ctx.dispatch
.bind_buffer
.bind_buffer
.workgroups
.execute?;
// Read results
let results: = output.read?;
All optimizations work transparently through the safe API!
Low-Level FFI (Advanced)
use *;
unsafe
π Performance
Based on Mini's optimization targets:
| Metric | Baseline Vulkan | Kronos | Improvement |
|---|---|---|---|
| Descriptor updates/dispatch | 3-5 | 0 | 100% β¬οΈ |
| Barriers/dispatch | 3 | β€0.5 | 83% β¬οΈ |
| CPU submit time | 100% | 50-70% | 30-50% β¬οΈ |
| Memory allocations | Continuous | 0* | 100% β¬οΈ |
| Structure size (avg) | 100% | 86.1% | 13.9% β¬οΈ |
*After initial warm-up
π§ Configuration
Kronos can be configured via environment variables:
KRONOS_ICD_SEARCH_PATHS: Custom Vulkan ICD search pathsVK_ICD_FILENAMES: Standard Vulkan ICD overrideRUST_LOG: Logging level (info, debug, trace)
ICD Discovery Logging
Enable detailed logs to debug ICD discovery and loading:
RUST_LOG=kronos_compute=info,kronos_compute::implementation::icd_loader=debug
Logs include:
- Search paths scanned
- Each discovered manifest JSON
- Each library load attempt (as-provided and manifest-relative)
- Errors per candidate and the selected ICD summary
ICD Selection
You can enumerate available ICDs and select one explicitly when creating a context.
- Enumerate programmatically:
use icd_loader;
let icds = available_icds;
for in icds.iter.enumerate
- Select via
ContextBuilder:
use api;
let ctx = builder
.prefer_icd_index // or .prefer_icd_path("/path/to/libvulkan_*.so")
.build?;
println!;
- Example CLI:
Aggregated Mode (Experimental)
Aggregated mode exposes physical devices from multiple ICDs in a single instance and routes calls to the correct ICD by handle provenance.
- Enable:
KRONOS_AGGREGATE_ICD=1 RUST_LOG=kronos_compute=info,kronos_compute::implementation::icd_loader=debug
-
Behavior:
vkCreateInstancecreates a meta-instance wrapping perβICD instances.vkEnumeratePhysicalDevicesreturns a combined list across all ICDs.vkCreateDeviceroutes by the physical deviceβs owning ICD.- Subsequent queue, pool, command buffer and all
vkCmd*calls route by handle.
-
Caveats:
- Experimental: Intended for orchestration and testing; API surface remains Vulkan-compatible, but behavior is meta-loader-like.
- Performance: Routing adds a small handleβICD lookup; negligible vs GPU work.
- Diagnostics: enable debug logs for provenance and routing visibility.
Windows CI / Headless Testing
- Linking: on Windows, linking to
vulkan-1is opt-in. SetKRONOS_LINK_VULKAN=1if the Vulkan runtime is installed. CI uses direct ICD loading by default. - Unit tests: run on
windows-latestvia.github/workflows/windows.ymlwithout a GPU. - Optional ICD tests: provide a software ICD (e.g., SwiftShader) and set:
VK_ICD_FILENAMESto the SwiftShader JSON pathKRONOS_ALLOW_UNTRUSTED_LIBS=1(if path is outside trusted prefixes)KRONOS_RUN_ICD_TESTS=1to enable ignored tests- (Optional)
KRONOS_AGGREGATE_ICD=1to test aggregated enumeration
Security Notes (ICD Loading)
- Paths from
VK_ICD_FILENAMESand discovery directories are canonicalized and validated. - Libraries must resolve to regular files under trusted prefixes (Linux defaults:
/usr/lib,/usr/lib64,/usr/local/lib,/lib,/lib64,/usr/lib/x86_64-linux-gnu). - For development on non-standard locations, set
KRONOS_ALLOW_UNTRUSTED_LIBS=1to override the trust policy (not recommended for production).
Runtime configuration through the API:
// Set timeline batch size
set_batch_size?;
// Configure memory pools
set_slab_size?;
β‘ How It Works
Persistent Descriptors
Traditional Vulkan requires updating descriptor sets for each dispatch. Kronos pre-allocates all storage buffer descriptors in Set0 and uses push constants for parameters:
// Traditional: 3-5 descriptor updates per dispatch
vkUpdateDescriptorSets;
vkCmdBindDescriptorSets;
// Kronos: 0 descriptor updates
vkCmdPushConstants;
vkCmdDispatch;
Smart Barriers
Kronos tracks buffer usage patterns and inserts only the minimum required barriers:
// Traditional: 3 barriers per dispatch
vkCmdPipelineBarrier; // uploadβcompute
vkCmdPipelineBarrier; // computeβcompute
vkCmdPipelineBarrier; // computeβdownload
// Kronos: β€0.5 barriers per dispatch (automatic)
Timeline Batching
Instead of submitting each command buffer individually:
// Traditional: N submits, N fences
for cmd in commands
// Kronos: 1 submit, 1 timeline semaphore
new
.add_command_buffer
.add_command_buffer
.submit?;
π Documentation
Comprehensive documentation is available in the docs/ directory:
-
API Documentation:
- Unified Safe API - π Safe, ergonomic Rust API (recommended)
-
Architecture: Design decisions, optimization details, and comparisons
- Optimization Summary - Mini's 4 optimizations explained
- Vulkan Comparison - Differences from standard Vulkan
- ICD Integration - How Kronos integrates with existing drivers
- Troubleshooting - Common issues and ICD loader diagnostics
-
Quality Assurance: Test results and validation reports
- QA Report - Comprehensive validation for Sporkle integration
- Test Results - Unit and integration test details
-
Benchmarks: Performance measurements and analysis
- Benchmark Results - Detailed performance metrics
π€ Contributing
Contributions are welcome! Areas of interest:
- SPIR-V shader integration for benchmarks
- Additional vendor-specific optimizations
- Performance profiling on different GPUs
- Safe wrapper API design
- Documentation improvements
Please read our Contributing Guide for details.
π Safety
This crate uses unsafe for FFI compatibility but provides safe abstractions where possible:
// Unsafe C-style API (required for compatibility)
let result = unsafe ;
// Safe Rust wrapper (future work)
let buffer = device.create_buffer?;
All unsafe functions include comprehensive safety documentation.
π¦ Features
implementation- Enable Kronos optimizations and ICD forwardingvalidation- Enable additional safety checks (default)compare-ash- Enable comparison benchmarks with ash
π Status
- β Core implementation complete
- β All optimizations integrated
- β ICD loader with Vulkan forwarding
- β Comprehensive benchmark suite
- β Basic examples working
- β Published to crates.io (v0.1.0)
- β C header generation
- β SPIR-V shader build scripts
- β Safe unified API (NEW!)
- β Compute correctness fixed (1024/1024 correct results)
- β Safety documentation complete (100% coverage)
- β CI/CD pipeline with multi-platform testing
- β Test suite expanded (46 tests passing)
- β³ Production testing
πΊοΈ Roadmap
v0.2.0 (Q1 2025)
- NVIDIA & Intel GPU optimizations
- Multi-queue concurrent dispatch support
- Dynamic memory pool resizing
- Vulkan validation layer support
v0.3.0 (Q2 2025)
- Enhanced Sporkle integration
- Advanced timeline semaphore patterns
- Ray query & cooperative matrix support
- Performance regression testing
v1.0.0 (Q3 2025)
- Production-ready status
- Full Vulkan 1.3 compute coverage
- Platform-specific optimizations
- Enterprise support
See TODO.md for the complete roadmap and contribution opportunities.
π Acknowledgments
- Mini (@notmini) for the groundbreaking optimization techniques
- The Vulkan community for driver support
- Contributors who helped port these optimizations to Rust
π License
This project is dual-licensed under MIT OR Apache-2.0. See LICENSE-MIT and LICENSE-APACHE for details.
Built with β€οΈ and π¦ for maximum GPU compute performance.
Citation
If you use Kronos in your research, please cite: