#ptx #ir #structure #natural #module #execution #parallel

ptx-ir

Parallel Thread Execution (PTX) IR structure and parser

2 releases

Uses new Rust 2024

new 0.1.1 Mar 18, 2025
0.1.0 Mar 15, 2025

#411 in Data structures

Download history 178/week @ 2025-03-13

178 downloads per month

MIT license

2.5MB
2.5K SLoC

ptx-ir: PTX IR in natural Rust data structures

This crate provides a Rust representation of the PTX IR, the intermediate representation used by the NVIDIA CUDA compiler. The goal is to provide a more natural way to work with PTX code than the raw textual representation in Rust.

Nvidia does not provide a formal specification of the PTX IR, so the crate is based on the PTX ISA documentation and the PTX ISA reference manual. The crate is still in an early stage of development and is not yet feature complete. Feel free to make an issue or a pull request if you have any suggestions or improvements.

Getting Started

Add the following to your Cargo.toml:

[dependencies]
ptx-ir = "0.1.1"

Example

use ptx_ir::Module;
use std::path::PathBuf;
fn main() {
    let input = PathBuf::from("path/to/your/file.ptx");
    match Module::from_ptx_path(&input) {
        Ok(module) => {
            println!("{:#?}", module);
        }
        Err(diagnostic) => {
            println!("{}", diagnostic);
        }
    }
}

Dependencies

~2.9–9.5MB
~55K SLoC