Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PTX parser rewrite #267

Merged
merged 47 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
a05bee9
Start rewriting PTX parser
vosen Aug 14, 2024
8d7c88c
Fully parse operands
vosen Aug 15, 2024
dbd37f9
Clean up and improve ident parsing
vosen Aug 15, 2024
ba17906
Pass parser state to instruction callbacks
vosen Aug 15, 2024
0da45ea
Add parsing of st, allow associating type with a non-alternative modi…
vosen Aug 15, 2024
0112880
Parse ld, add, ret
vosen Aug 16, 2024
91dbbb3
Move all types to a separate module
vosen Aug 16, 2024
77de5c7
Parse simplest vector add kernel
vosen Aug 18, 2024
522541d
Support simple module variables
vosen Aug 18, 2024
cb64b04
Add mul
vosen Aug 18, 2024
c08e6a6
Implement setp
vosen Aug 19, 2024
22492ec
Implement not, or, and, bra
vosen Aug 19, 2024
34b0a67
Add types for call instruction
vosen Aug 20, 2024
c21c55d
Parse call instruction
vosen Aug 20, 2024
bc1074e
Add cvt
vosen Aug 20, 2024
47f8314
Add shr, shl
vosen Aug 20, 2024
588d66b
Add cvta
vosen Aug 20, 2024
6cd18bf
Add abs, mad
vosen Aug 21, 2024
798bbf0
Add fma and sub
vosen Aug 21, 2024
fc713f2
Add min, max
vosen Aug 21, 2024
c16bae3
Add rcp, sqrt, rsqrt
vosen Aug 21, 2024
39faaa7
Add atom and atom.cas
vosen Aug 21, 2024
0760c3d
Map remaining instructions
vosen Aug 21, 2024
71e0258
Rename new crates
vosen Aug 21, 2024
1ec1ca0
Attempt #2
vosen Aug 23, 2024
12ef8db
Port first pass
vosen Aug 23, 2024
7ea990e
Work on more passes
vosen Aug 23, 2024
69175d2
Add relaxed type check information to visitors
vosen Aug 24, 2024
4e6dc07
Implement third pass
vosen Aug 24, 2024
107f1eb
Port sreg fix pass
vosen Aug 26, 2024
3e0a15a
Add stateless-to-stateful conversion
vosen Aug 26, 2024
cccd37f
Port ssa conversion
vosen Aug 26, 2024
c088cc2
Port expand_arguments
vosen Aug 26, 2024
144f8bd
Port remaining two passes
vosen Aug 27, 2024
790fe18
Emit most of SPIR-V
vosen Aug 30, 2024
2e5ad8e
Wire new parser into spvtxt tests
vosen Aug 30, 2024
32b6262
Fix PtrAdd
vosen Aug 30, 2024
16fafe5
Parse comments and vector members correctly
vosen Aug 30, 2024
aebf06a
Improve implicit conversion and handling of vectors
vosen Aug 30, 2024
0c93393
Correctly report dst in call instructions
vosen Aug 31, 2024
8d15499
More fixes
vosen Sep 3, 2024
340ad86
Emit correct float add
vosen Sep 3, 2024
7a45b44
Fix more failing tests
vosen Sep 3, 2024
6a7c871
Fix array initializers
vosen Sep 3, 2024
3f31069
Allow ftz and saturated conversions
vosen Sep 3, 2024
aa98ab9
Fix all remaining problems
vosen Sep 3, 2024
061312c
Document wtf is going on with parsing macros
vosen Sep 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading