A Practical Guide to High-Performance GPU Computing from Rust
Introduction
Chapter 1: Why GPU Computing, Why Rust
- The Parallel Computing Revolution
- Where GPUs Excel and Where They Do Not
- The State of GPU Programming in 2025
- Why Rust for GPU Development
- How This Book Is Organized
Chapter 2: GPU Architecture and Execution Model
- From CPU to GPU: A Hardware Perspective
- Streaming Multiprocessors and Execution Units
- The Thread Block and Grid Execution Model
- Warp Execution and SIMT
- Memory Hierarchies on the GPU
- How a Kernel Launch Traverses the Hardware
Chapter 3: CUDA Fundamentals: The C++ Reference Model
- The CUDA C++ Kernel Syntax
- Host Code Versus Device Code
- Launch Configuration and Execution Dimensions
- Device Memory Allocation and Data Transfer
- A Complete CUDA C++ Example Walked Through
- What CUDA Rust Will Build Upon
Chapter 4: Introducing CUDA Rust: History and Vision
- The Road to GPU Programming in Rust
- NVIDIA’s CUDA Rust Initiative
- The Two Tracks: Native and C Bindings
- Design Goals and Philosophy
- Current Status, Stability and Versioning
- What CUDA Rust Is Not
Chapter 5: Toolchain Setup and Project Configuration
- Prerequisites: Hardware, CUDA Toolkit and Drivers
- Installing the CUDA Rust Compiler and Dependencies
- Project Layout with cargo-cuda
- Build Configuration and Environment Variables
- Your First CUDA Rust Project
- Troubleshooting Common Setup Issues
Chapter 6: The CUDA-Rust API Surface
- The core_cuda and cuda-rs Crates
- Device Pointer Types and Abstractions
- The Kernel Trait and Launch Mechanics
- Memory Allocation and Transfer APIs
- Utility Types: Dimensions, Streams, Events
- How the API Maps to CUDA C++ Concepts
Chapter 7: Device Code Fundamentals
- Marking Code as Device Code
- Computing Thread and Block Indices
- Your First Kernel: Vector Addition
- Understanding the Launch Dimensions
- Compilation: How Device Code Becomes PTX and SASS
- Safety Considerations in Device Code
Chapter 8: Memory Management: Allocation and Transfer
- Device Memory Allocation Patterns
- Host-to-Device and Device-to-Host Transfers
- Pinned Memory and Asynchronous Transfers
- The Cost Model of Data Movement
- Memory Safety at Host and Device Boundaries
- Complete Example: Matrix Initialization and Transfer
Chapter 9: Kernel Launch Patterns
- Launch Configuration and Grid Size Calculations
- Occupancy and Heuristics for Block Size
- Streams and Concurrent Execution
- Synchronous Versus Asynchronous Launches
- Kernel Chaining and Dependencies
- Example: Multi-Kernel Pipeline
Chapter 10: Shared Memory and Block-Level Optimization
- Shared Memory: Purpose and Performance
- Declaring and Using Shared Memory in Kernels
- The Matrix Transpose Optimization
- Warp Coalescing and Memory Access Patterns
- A Reduction Kernel with Shared Memory
- Barriers and Synchronization Within a Block
Chapter 11: Global Memory and Data Access Patterns
- Global Memory Architecture and Caching
- Coalesced Versus Uncoalesced Access
- Bank Conflicts and Shared Memory Layout
- Texture and Constant Memory
- Designing Kernels for Memory-Bound Workloads
- Example: Image Filter Kernel
Chapter 12: Synchronization and Coordination
- Thread-Level Synchronization: __syncthreads
- Warp-Level Primitives
- Cross-Block Synchronization Limitations
- Stream-Based Synchronization
- Host-Device Synchronization and Events
- Deadlock and Starvation Pitfalls
Chapter 13: Ownership, Lifetimes and GPU Safety
- Ownership Semantics for Device Resources
- Lifetimes at the Host-Device Boundary
- RAII for CUDA Handles
- Aliasing and the Device Pointer Model
- Avoiding Use-After-Free on the GPU
- Safe Abstractions Over Unsafe CUDA Operations
Chapter 14: Error Handling and Robust GPU Code
- CUDA Error Types and Categories
- Propagating Errors in Host Code
- Detecting Kernel Launch Errors
- Runtime Versus Compile-Time Errors
- Defensive Patterns for Production Kernels
- Logging and Diagnostic Infrastructure
Chapter 15: Numerical Computing on the GPU
- Float32, Float64 and Mixed Precision
- GPU Floating Point Semantics
- Denormals, NaN and Infinity
- Atomic Operations and Race Conditions
- Numerical Stability in Parallel Algorithms
Chapter 16: Interoperability: CUDA Rust and the Wider World
- Calling CUDA C++ Libraries from Rust
- FFI Patterns and Safety
- Interfacing with cuBLAS and Linear Algebra
- cuFFT and Transform Libraries
- CUDA Graphs and Advanced APIs
- Building Hybrid CUDA C++ and CUDA Rust Projects
Chapter 17: Integration with Rust Application Ecosystems
- Multi-Threaded Hosts and CUDA Contexts
- CUDA with Rust Async Runtimes
- CPU-GPU Hybrid Algorithms
- Designing a GPU-Accelerated Rust Library
- Example: Async GPU Processing Pipeline
Chapter 18: Debugging GPU Kernels
- Common GPU Kernel Bugs
- Using cuda-memcheck and Sanitizers
- Debug Builds and GDB for CUDA
- Print-Based and Trace-Based Debugging
- Debugging Deadlocks and Timing Issues
- Systematic Approaches to Bug Isolation
Chapter 19: Profiling and Performance Analysis
- NVIDIA Nsight Systems and Compute Profilers
- Occupancy Metrics and Utilization
- Memory Bandwidth Analysis
- Identifying Kernel Bottlenecks
- Roofline Model and Performance Reasoning
- Iterative Optimization Case Study
Chapter 20: Performance Optimization Patterns
- Register Pressure and Spilling
- Instruction-Level Parallelism
- Loop Unrolling and Predicate Elimination
- Warp Divergence and Control Flow
- Using Specialized Instructions
- Example: Optimizing a Convolution Kernel
Chapter 21: Production Deployment and Best Practices
- Testing GPU Kernels
- Continuous Integration for CUDA Rust
- API Design for Reusable Kernels
- Documentation and Team Conventions
- Portability and Hardware Targeting
- When Not to Use CUDA Rust
Conclusion
- The CUDA Rust Journey So Far
- Where the Ecosystem Is Heading
- Complementary Technologies
- A Final Word on GPU Computing with Rust
