ptx-90-parser

Crates.ioptx-90-parser
lib.rsptx-90-parser
version0.4.4
created_at2025-10-24 15:26:10.212091+00
updated_at2025-11-28 22:57:08.255951+00
descriptionParse NVIDIA PTX 9.0 assembly into a structured AST and explore modules via a CLI.
homepagehttps://github.com/jialunzhang-psu/ptx-90-parser
repositoryhttps://github.com/jialunzhang-psu/ptx-90-parser
max_upload_size
id1898597
size9,837,078
Jialun Zhang (jialunzhang-psu)

documentation

https://docs.rs/ptx-90-parser

README

ptx-90-parser

There is already a crate named ptx-parser on crates.io, but it has not been updated for 2 years and does not support PTX 9.0. This crate, ptx-90-parser, parses NVIDIA PTX 9.0 assembly source into a structured abstract syntax tree. It also ships with a small companion CLI that prints module summaries and optionally emits a tree representation of the parsed PTX.

TODO

  • Currently we have a heavy AST that lists every PTX instruction, for the purpose of comprehensive analysis and transformation. Later we will add a feature option to bring back the lightweight AST.

Features

  • Parses PTX source into rich Rust data types for downstream analysis or transformation.
  • The types and parsers for PTX instructions are generated from the PTX specification under crates/parser-gen/ptx_syntax.
  • Provides a CLI (ptx-parser-bin) that reports module statistics and outputs a tree view.

Library quick start

Add the crate to your project:

cargo add ptx-parser

Parse a PTX module from source text:

use ptx_parser::parse;

fn main() -> Result<(), ptx_parser::PtxParseError> {
    let module = parse(
        r#"
        .version 7.8
        .target sm_90
        .entry add(.param .u64 a) { ret; }
        "#,
    )?;
    println!("directives: {}", module.directives.len());
    Ok(())
}

Refer to the items exported from ptx_parser::type for the full AST shape.

CLI usage

cargo run --bin ptx-parser-bin -- --input ./examples/module.ptx

Options:

  • --input (-i): path to the PTX file to parse (required)
  • --output (-o): optional path for writing the textual tree representation

Example:

ptx-parser-bin --input kernel.ptx --output kernel.tree

License

This project is distributed under the terms of the MIT license. See LICENSE for details.

Commit count: 0

cargo fmt