Skip to content

Commit

Permalink
Add cvta
Browse files Browse the repository at this point in the history
  • Loading branch information
vosen committed Aug 20, 2024
1 parent 47f8314 commit 588d66b
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 5 deletions.
2 changes: 2 additions & 0 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 Down
24 changes: 21 additions & 3 deletions ptx_parser/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,14 @@ gen::generate_instruction_type!(
Ret {
data: RetData
},
Cvta {
data: CvtaDetails,
type: { Type::Scalar(ScalarType::B64) },
arguments<T>: {
dst: T,
src: T,
}
},
Trap { }
}
);
Expand Down Expand Up @@ -824,9 +832,9 @@ impl<T: Operand> CallArgs<T> {
}

pub struct CvtDetails {
from: ScalarType,
to: ScalarType,
mode: CvtMode,
pub from: ScalarType,
pub to: ScalarType,
pub mode: CvtMode,
}

pub enum CvtMode {
Expand Down Expand Up @@ -977,3 +985,13 @@ pub enum RightShiftKind {
Arithmetic,
Logical,
}

pub struct CvtaDetails {
pub state_space: StateSpace,
pub direction: CvtaDirection,
}

pub enum CvtaDirection {
GenericToExplicit,
ExplicitToGeneric,
}
39 changes: 37 additions & 2 deletions ptx_parser/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,8 @@ pub enum PtxError {
#[error("")]
NonF32Ftz,
#[error("")]
Unsupported32Bit,
#[error("")]
WrongType,
#[error("")]
UnknownFunction,
Expand Down Expand Up @@ -1653,7 +1655,7 @@ derive_parser!(
.s8, .s16, .s32, .s64,
.bf16, .f16, .f32, .f64 };
// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#logic-and-shift-instructions-shl
shl.type d, a, b => {
shl.type d, a, b => {
ast::Instruction::Shl { data: type_, arguments: ShlArgs { dst: d, src1: a, src2: b } }
}
.type: ScalarType = { .b16, .b32, .b64 };
Expand All @@ -1666,11 +1668,44 @@ derive_parser!(
arguments: ShrArgs { dst: d, src1: a, src2: b }
}
}

.type: ScalarType = { .b16, .b32, .b64,
.u16, .u32, .u64,
.s16, .s32, .s64 };

// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#data-movement-and-conversion-instructions-cvta
cvta.space.size p, a => {
if size != ScalarType::U64 {
state.errors.push(PtxError::Unsupported32Bit);
}
let data = ast::CvtaDetails {
state_space: space,
direction: ast::CvtaDirection::ExplicitToGeneric
};
let arguments = ast::CvtaArgs {
dst: p, src: a
};
ast::Instruction::Cvta {
data, arguments
}
}
cvta.to.space.size p, a => {
if size != ScalarType::U64 {
state.errors.push(PtxError::Unsupported32Bit);
}
let data = ast::CvtaDetails {
state_space: space,
direction: ast::CvtaDirection::GenericToExplicit
};
let arguments = ast::CvtaArgs {
dst: p, src: a
};
ast::Instruction::Cvta {
data, arguments
}
}
.space: StateSpace = { .const, .global, .local, .shared{::cta, ::cluster}, .param{::entry} };
.size: ScalarType = { .u32, .u64 };

// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#control-flow-instructions-ret
ret{.uni} => {
Instruction::Ret { data: RetData { uniform: uni } }
Expand Down

0 comments on commit 588d66b

Please sign in to comment.