11 unstable releases (3 breaking)
Uses new Rust 2024
| 0.4.4 | Nov 28, 2025 |
|---|---|
| 0.4.3 | Nov 27, 2025 |
| 0.3.0 | Nov 11, 2025 |
| 0.2.3 | Nov 9, 2025 |
| 0.1.0 | Oct 24, 2025 |
#1392 in Parser implementations
4.5MB
105K
SLoC
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.
Dependencies
~1–13MB
~106K SLoC