use std::convert::From; use std::num::ParseIntError; quick_error! { #[derive(Debug)] pub enum PtxError { ParseInt (err: ParseIntError) { from() display("{}", err) cause(err) } } } pub trait UnwrapWithVec { fn unwrap_with(self, errs: &mut Vec) -> To; } impl, EInto> UnwrapWithVec for Result { fn unwrap_with(self, errs: &mut Vec) -> R { self.unwrap_or_else(|e| { errs.push(e.into()); R::default() }) } } impl< R1: Default, EFrom1: std::convert::Into, R2: Default, EFrom2: std::convert::Into, EInto, > UnwrapWithVec for (Result, Result) { fn unwrap_with(self, errs: &mut Vec) -> (R1, R2) { let (x, y) = self; let r1 = x.unwrap_with(errs); let r2 = y.unwrap_with(errs); (r1, r2) } } pub struct Module<'a> { pub version: (u8, u8), pub functions: Vec>, } pub struct Function<'a> { pub kernel: bool, pub name: &'a str, pub args: Vec>, pub body: Vec>, } #[derive(Default)] pub struct Argument<'a> { pub name: &'a str, pub a_type: ScalarType, pub length: u32, } #[derive(PartialEq, Eq, Hash, Clone, Copy)] pub enum Type { Scalar(ScalarType), ExtendedScalar(ExtendedScalarType), } #[derive(PartialEq, Eq, Hash, Clone, Copy)] pub enum ScalarType { B8, B16, B32, B64, U8, U16, U32, U64, S8, S16, S32, S64, F16, F32, F64, } #[derive(PartialEq, Eq, Hash, Clone, Copy)] pub enum ExtendedScalarType { F16x2, Pred, } impl Default for ScalarType { fn default() -> Self { ScalarType::B8 } } pub enum Statement { Label(ID), Variable(Variable), Instruction(Option>, Instruction), } pub struct Variable { pub space: StateSpace, pub v_type: Type, pub name: ID, pub count: Option, } pub enum StateSpace { Reg, Sreg, Const, Global, Local, Shared, } pub struct PredAt { pub not: bool, pub label: ID, } pub enum Instruction { Ld(LdData, Arg2), Mov(MovData, Arg2Mov), Mul(MulData, Arg3), Add(AddData, Arg3), Setp(SetpData, Arg4), SetpBool(SetpBoolData, Arg5), Not(NotData, Arg2), Bra(BraData, Arg1), Cvt(CvtData, Arg2), Shl(ShlData, Arg3), St(StData, Arg2), Ret(RetData), } pub struct Arg1 { pub src: ID, // it is a jump destination, but in terms of operands it is a source operand } pub struct Arg2 { pub dst: ID, pub src: Operand, } pub struct Arg2Mov { pub dst: ID, pub src: MovOperand, } pub struct Arg3 { pub dst: ID, pub src1: Operand, pub src2: Operand, } pub struct Arg4 { pub dst1: ID, pub dst2: Option, pub src1: Operand, pub src2: Operand, } pub struct Arg5 { pub dst1: ID, pub dst2: Option, pub src1: Operand, pub src2: Operand, pub src3: Operand, } pub enum Operand { Reg(ID), RegOffset(ID, i32), Imm(i128), } pub enum MovOperand { Op(Operand), Vec(String, String), } pub enum VectorPrefix { V2, V4, } pub struct LdData { pub qualifier: LdStQualifier, pub state_space: LdStateSpace, pub caching: LdCacheOperator, pub vector: Option, pub typ: ScalarType, } #[derive(Copy, Clone, PartialEq, Eq)] pub enum LdStQualifier { Weak, Volatile, Relaxed(LdScope), Acquire(LdScope), } #[derive(Copy, Clone, PartialEq, Eq)] pub enum LdScope { Cta, Gpu, Sys, } #[derive(Copy, Clone, PartialEq, Eq)] pub enum LdStateSpace { Generic, Const, Global, Local, Param, Shared, } #[derive(Copy, Clone, PartialEq, Eq)] pub enum LdCacheOperator { Cached, L2Only, Streaming, LastUse, Uncached, } pub struct MovData {} pub struct MulData {} pub struct AddData { pub typ: ScalarType, } pub struct SetpData {} pub struct SetpBoolData {} pub struct NotData {} pub struct BraData { pub uniform: bool, } pub struct CvtData {} pub struct ShlData {} pub struct StData { pub qualifier: LdStQualifier, pub state_space: StStateSpace, pub caching: StCacheOperator, pub vector: Option, pub typ: ScalarType, } #[derive(PartialEq, Eq)] pub enum StStateSpace { Generic, Global, Local, Param, Shared, } #[derive(PartialEq, Eq)] pub enum StCacheOperator { Writeback, L2Only, Streaming, Writethrough, } pub struct RetData { pub uniform: bool, }