This commit is contained in:
Andrzej Janik 2024-08-20 19:50:09 +02:00
parent 47f8314a5d
commit 588d66b236
3 changed files with 60 additions and 5 deletions

View file

@ -16,6 +16,8 @@ pub enum PtxError {
source: ParseFloatError,
},
#[error("")]
Unsupported32Bit,
#[error("")]
SyntaxError,
#[error("")]
NonF32Ftz,

View file

@ -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 { }
}
);
@ -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 {
@ -977,3 +985,13 @@ pub enum RightShiftKind {
Arithmetic,
Logical,
}
pub struct CvtaDetails {
pub state_space: StateSpace,
pub direction: CvtaDirection,
}
pub enum CvtaDirection {
GenericToExplicit,
ExplicitToGeneric,
}

View file

@ -814,6 +814,8 @@ pub enum PtxError {
#[error("")]
NonF32Ftz,
#[error("")]
Unsupported32Bit,
#[error("")]
WrongType,
#[error("")]
UnknownFunction,
@ -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 };
@ -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 } }