Modular GPU Programming with Typed Perspectives

Manya Bansal, Daniel Sainati, Joseph W. Cutler, Saman P. Amarasinghe, Jonathan Ragan-KelleyarXiv 2025 · DOI · arXiv

Abstract

Prism is a domain-specific language for GPU programming that introduces "typed perspectives" to reconcile the tension between single-thread programming models and collective hardware execution. By embedding the GPU's compute hierarchy into its type system, Prism enables the development of modular, reusable, and high-performance kernels. This paper describes the design of Prism, its core calculus Bundl, and demonstrates that it achieves performance parity with hand-tuned CUDA libraries like cuBLAS and CUB while providing static safety guarantees.

Introduction

Writing high-performance GPU code is notoriously difficult due to a fundamental conceptual clash. While GPU programs (like CUDA) are written from the perspective of a single thread, the hardware achieves peak performance through collective operations—where groups of threads, such as warps or blocks, must act in perfect synchronization to utilize features like Tensor Cores or shared memory.

Currently, if a programmer calls a collective function inside a divergent code path, the result is often a deadlock or undefined behavior. This makes modularity nearly impossible; libraries like NVIDIA's CUB must rely on extensive documentation and naming conventions to warn users about hidden requirements. Prism addresses this by materializing the programmer's mental model of the GPU hierarchy into the type system using Typed Perspectives.

Methods

Prism introduces a formal way to track the granularity at which a programmer is controlling threads.

  • Perspectives: These describe execution scopes (e.g., grid[1], block[1], or thread[32]).
  • The @ Syntax: Prism tracks the "frequency" of variables. A variable marked @ thread[1] can hold different values for every thread, while one marked @ block[1] must be uniform across the entire block. This ensures that collective operations receive the uniform data they require.
Figure 1: Illustration of legal and illegal thread frequencies. A variable at a specific frequency must be uniform across that group of threads to be considered legal.
  • Core Constructs: The language uses group to replicate code across broader perspectives and split to shard perspectives into unequal groups (enabling warp-specialization). Operations like partition and claim allow threads to safely "narrow" their view of memory, enabling independent writes without race conditions.
  • Automatic Synchronization: The Prism compiler constructs a data-control-flow graph to automatically insert synchronization barriers (like __syncthreads()) exactly where memory views diverge or reconverge.

Evaluation and Results

The authors evaluated Prism by implementing several "speed-of-light" GPU kernels and comparing them against industry-standard baselines like cuBLAS and CUB on both consumer-grade (RTX 4070 Ti Super) and server-grade (H100) hardware.

Prism demonstrates that safety does not have to come at the cost of performance:

  • Matrix Multiplication (HGEMM): On the H100, Prism's implementation came within 15% of cuBLAS, an impressive feat for a high-level language.
  • Parallel Prefix Scan: Prism achieved bandwidth within 7% of the CUB library, proving it can handle complex, memory-bound algorithms.
  • Productivity: The authors successfully implemented complex features like the H100's new wgmma (warpgroup-level matrix multiply) and TMA (Tensor Memory Accelerator) using these perspective-based abstractions.

Key Insights

Prism enforces a strict "Read Up, Write Down" rule: code can read data from a broader (more global) perspective but can only write to data at its current or a narrower perspective. This prevents threads from accidentally clobbering shared data without proper coordination. Furthermore, Prism’s type system tracks thread alignment statically, ensuring that collective operations—which often require threads to be aligned to specific boundaries (e.g., multiples of 32)—are called correctly.

Discussion and Future Work

While Prism offers "fearless composition" by making perspectives part of function signatures, some limitations remain. Pipeline ergonomics currently require manual unrolling for overlapping data movement, and the system does not yet provide a full formal guarantee of data-race freedom or liveness. Future directions include extending Prism to support newer architectures like Blackwell and exploring its application in distributed systems. Overall, Prism provides a robust framework for building safe, modular, and high-performance GPU software.

Summary updated

Abstract

To achieve peak performance on modern GPUs, one must balance two frames of mind: issuing instructions to individual threads to control their behavior, while simultaneously tracking the convergence of many threads acting in concert to perform collective operations like Tensor Core instructions. The tension between these two mindsets makes modular programming error prone. Functions that encapsulate collective operations, despite being called per-thread, must be executed cooperatively by groups of threads. In this work, we introduce Prism, a new GPU language that restores modularity while still giving programmers the low-level control over collective operations necessary for high performance. Our core idea is typed perspectives, which materialize, at the type level, the granularity at which the programmer is controlling the behavior of threads. We describe the design of Prism, implement a compiler for it, and lay its theoretical foundations in a core calculus called Bundl. We implement state-of-the-art GPU kernels in Prism and find that it offers programmers the safety guarantees needed to confidently write modular code without sacrificing performance.
BibTeX
@misc{bansal2025modular,
  author = {Manya Bansal and Daniel Sainati and Joseph W. Cutler and Saman P. Amarasinghe and Jonathan Ragan-Kelley},
  title = {{Modular GPU Programming with Typed Perspectives}},
  year = {2025},
  eprint = {2511.11939},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2511.11939},
}
Figure