ptx-90-parser is both an executable binary that can be run, and a library that can be used in Rust programs.
Installing the ptx-parser-bin executable
Assuming you have Rust/Cargo installed , run this command in a terminal:
cargo install ptx-90-parser
It will make the ptx-parser-bin command available in your PATH if you've allowed the PATH to be modified when installing Rust . cargo uninstall ptx-90-parser uninstalls.
Adding ptx_parser library as a dependency
Run this command in a terminal, in your project's directory:
cargo add ptx-90-parser
To add it manually, edit your project's Cargo.toml file and add to the [dependencies] section:
ptx-90-parser = "0.4.4"
The ptx_parser library will be automatically available globally.
Read the ptx_parser library documentation .
Back to the crate overview .
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.