Skip to content

Commit

Permalink
PTX parser rewrite (#267)
Browse files Browse the repository at this point in the history
Replaces traditional LALRPOP-based parser with winnow-based parser to handle out-of-order instruction modifer. Generate instruction type and instruction visitor from a macro instead of writing by hand. Add separate compilation path using the new parser that only works in tests for now
  • Loading branch information
vosen authored Sep 4, 2024
1 parent 872054a commit 193eb29
Show file tree
Hide file tree
Showing 34 changed files with 14,776 additions and 55 deletions.
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
[workspace]

resolver = "2"

members = [
"cuda_base",
"cuda_types",
Expand All @@ -15,6 +17,9 @@ members = [
"zluda_redirect",
"zluda_ml",
"ptx",
"ptx_parser",
"ptx_parser_macros",
"ptx_parser_macros_impl",
]

default-members = ["zluda_lib", "zluda_ml", "zluda_inject", "zluda_redirect"]
Expand Down
8 changes: 6 additions & 2 deletions ptx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2018"
[lib]

[dependencies]
lalrpop-util = "0.19"
ptx_parser = { path = "../ptx_parser" }
regex = "1"
rspirv = "0.7"
spirv_headers = "1.5"
Expand All @@ -17,8 +17,12 @@ bit-vec = "0.6"
half ="1.6"
bitflags = "1.2"

[dependencies.lalrpop-util]
version = "0.19.12"
features = ["lexer"]

[build-dependencies.lalrpop]
version = "0.19"
version = "0.19.12"
features = ["lexer"]

[dev-dependencies]
Expand Down
28 changes: 16 additions & 12 deletions ptx/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ pub enum PtxError {
source: ParseFloatError,
},
#[error("")]
Unsupported32Bit,
#[error("")]
SyntaxError,
#[error("")]
NonF32Ftz,
Expand All @@ -32,15 +34,9 @@ pub enum PtxError {
#[error("")]
NonExternPointer,
#[error("{start}:{end}")]
UnrecognizedStatement {
start: usize,
end: usize,
},
UnrecognizedStatement { start: usize, end: usize },
#[error("{start}:{end}")]
UnrecognizedDirective {
start: usize,
end: usize,
},
UnrecognizedDirective { start: usize, end: usize },
}

// For some weird reson this is illegal:
Expand Down Expand Up @@ -576,11 +572,15 @@ impl CvtDetails {
if saturate {
if src.kind() == ScalarKind::Signed {
if dst.kind() == ScalarKind::Signed && dst.size_of() >= src.size_of() {
err.push(ParseError::from(PtxError::SyntaxError));
err.push(ParseError::User {
error: PtxError::SyntaxError,
});
}
} else {
if dst == src || dst.size_of() >= src.size_of() {
err.push(ParseError::from(PtxError::SyntaxError));
err.push(ParseError::User {
error: PtxError::SyntaxError,
});
}
}
}
Expand All @@ -596,7 +596,9 @@ impl CvtDetails {
err: &'err mut Vec<ParseError<usize, Token<'input>, PtxError>>,
) -> Self {
if flush_to_zero && dst != ScalarType::F32 {
err.push(ParseError::from(PtxError::NonF32Ftz));
err.push(ParseError::from(lalrpop_util::ParseError::User {
error: PtxError::NonF32Ftz,
}));
}
CvtDetails::FloatFromInt(CvtDesc {
dst,
Expand All @@ -616,7 +618,9 @@ impl CvtDetails {
err: &'err mut Vec<ParseError<usize, Token<'input>, PtxError>>,
) -> Self {
if flush_to_zero && src != ScalarType::F32 {
err.push(ParseError::from(PtxError::NonF32Ftz));
err.push(ParseError::from(lalrpop_util::ParseError::User {
error: PtxError::NonF32Ftz,
}));
}
CvtDetails::IntFromFloat(CvtDesc {
dst,
Expand Down
1 change: 1 addition & 0 deletions ptx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ lalrpop_mod!(
);

pub mod ast;
pub(crate) mod pass;
#[cfg(test)]
mod test;
mod translate;
Expand Down
Loading

0 comments on commit 193eb29

Please sign in to comment.