mirror of
https://github.com/vosen/ZLUDA.git
synced 2025-04-20 00:14:45 +00:00
Continue working on a better addressable support
This commit is contained in:
parent
952ed5d504
commit
bcb749cdd9
5 changed files with 862 additions and 623 deletions
|
@ -164,8 +164,8 @@ pub enum MethodDecl<'a, P: ArgParams> {
|
|||
Kernel(&'a str, Vec<KernelArgument<P>>),
|
||||
}
|
||||
|
||||
pub type FnArgument<P: ArgParams> = Variable<FnArgumentType, P>;
|
||||
pub type KernelArgument<P: ArgParams> = Variable<VariableParamType, P>;
|
||||
pub type FnArgument<P> = Variable<FnArgumentType, P>;
|
||||
pub type KernelArgument<P> = Variable<VariableParamType, P>;
|
||||
|
||||
pub struct Function<'a, P: ArgParams, S> {
|
||||
pub func_directive: MethodDecl<'a, P>,
|
||||
|
@ -316,7 +316,7 @@ pub struct PredAt<ID> {
|
|||
|
||||
pub enum Instruction<P: ArgParams> {
|
||||
Ld(LdData, Arg2<P>),
|
||||
Mov(MovType, Arg2<P>),
|
||||
Mov(MovType, Arg2Mov<P>),
|
||||
MovVector(MovVectorDetails, Arg2Vec<P>),
|
||||
Mul(MulDetails, Arg3<P>),
|
||||
Add(AddDetails, Arg3<P>),
|
||||
|
@ -354,7 +354,7 @@ pub struct CallInst<P: ArgParams> {
|
|||
pub trait ArgParams {
|
||||
type ID;
|
||||
type Operand;
|
||||
type MemoryOperand;
|
||||
type MovOperand;
|
||||
type CallOperand;
|
||||
type VecOperand;
|
||||
}
|
||||
|
@ -366,7 +366,7 @@ pub struct ParsedArgParams<'a> {
|
|||
impl<'a> ArgParams for ParsedArgParams<'a> {
|
||||
type ID = &'a str;
|
||||
type Operand = Operand<&'a str>;
|
||||
type MemoryOperand = Operand<&'a str>;
|
||||
type MovOperand = MovOperand<&'a str>;
|
||||
type CallOperand = CallOperand<&'a str>;
|
||||
type VecOperand = (&'a str, u8);
|
||||
}
|
||||
|
@ -380,13 +380,27 @@ pub struct Arg2<P: ArgParams> {
|
|||
pub src: P::Operand,
|
||||
}
|
||||
|
||||
pub struct Arg2Ld<P: ArgParams> {
|
||||
pub struct Arg2Mov<P: ArgParams> {
|
||||
pub dst: P::ID,
|
||||
pub src: P::MemoryOperand,
|
||||
pub src: P::MovOperand,
|
||||
}
|
||||
|
||||
impl<'input> From<Arg2<ParsedArgParams<'input>>> for Arg2Mov<ParsedArgParams<'input>> {
|
||||
fn from(a: Arg2<ParsedArgParams<'input>>) -> Arg2Mov<ParsedArgParams<'input>> {
|
||||
let new_src = match a.src {
|
||||
Operand::Reg(r) => MovOperand::Reg(r),
|
||||
Operand::RegOffset(r, imm) => MovOperand::RegOffset(r, imm),
|
||||
Operand::Imm(x) => MovOperand::Imm(x),
|
||||
};
|
||||
Arg2Mov {
|
||||
dst: a.dst,
|
||||
src: new_src,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Arg2St<P: ArgParams> {
|
||||
pub src1: P::MemoryOperand,
|
||||
pub src1: P::Operand,
|
||||
pub src2: P::Operand,
|
||||
}
|
||||
|
||||
|
@ -419,6 +433,14 @@ pub struct Arg5<P: ArgParams> {
|
|||
pub src3: P::Operand,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
pub enum MovOperand<ID> {
|
||||
Reg(ID),
|
||||
Address(ID),
|
||||
RegOffset(ID, i32),
|
||||
AddressOffset(ID, i32),
|
||||
Imm(u32),
|
||||
}
|
||||
#[derive(Copy, Clone)]
|
||||
pub enum Operand<ID> {
|
||||
Reg(ID),
|
||||
|
|
|
@ -31,6 +31,7 @@ pub use crate::ptx::ModuleParser;
|
|||
pub use lalrpop_util::lexer::Token;
|
||||
pub use lalrpop_util::ParseError;
|
||||
pub use rspirv::dr::Error as SpirvError;
|
||||
pub use translate::TranslateError as TranslateError;
|
||||
pub use translate::to_spirv;
|
||||
|
||||
pub(crate) fn without_none<T>(x: Vec<Option<T>>) -> Vec<T> {
|
||||
|
|
|
@ -496,7 +496,7 @@ LdCacheOperator: ast::LdCacheOperator = {
|
|||
// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#data-movement-and-conversion-instructions-mov
|
||||
InstMov: ast::Instruction<ast::ParsedArgParams<'input>> = {
|
||||
"mov" <t:MovType> <a:Arg2> => {
|
||||
ast::Instruction::Mov(t, a)
|
||||
ast::Instruction::Mov(t, a.into())
|
||||
},
|
||||
"mov" <t:MovVectorType> <a:Arg2Vec> => {
|
||||
ast::Instruction::MovVector(ast::MovVectorDetails{typ: t, length: 0}, a)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use super::ptx;
|
||||
use super::TranslateError;
|
||||
|
||||
mod spirv_run;
|
||||
|
||||
|
@ -8,7 +9,7 @@ fn parse_and_assert(s: &str) {
|
|||
assert!(errors.len() == 0);
|
||||
}
|
||||
|
||||
fn compile_and_assert(s: &str) -> Result<(), rspirv::dr::Error> {
|
||||
fn compile_and_assert(s: &str) -> Result<(), TranslateError> {
|
||||
let mut errors = Vec::new();
|
||||
let ast = ptx::ModuleParser::new().parse(&mut errors, s).unwrap();
|
||||
crate::to_spirv(ast)?;
|
||||
|
@ -28,14 +29,14 @@ fn operands_ptx() {
|
|||
|
||||
#[test]
|
||||
#[allow(non_snake_case)]
|
||||
fn vectorAdd_kernel64_ptx() -> Result<(), rspirv::dr::Error> {
|
||||
fn vectorAdd_kernel64_ptx() -> Result<(), TranslateError> {
|
||||
let vector_add = include_str!("vectorAdd_kernel64.ptx");
|
||||
compile_and_assert(vector_add)
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[allow(non_snake_case)]
|
||||
fn _Z9vectorAddPKfS0_Pfi_ptx() -> Result<(), rspirv::dr::Error> {
|
||||
fn _Z9vectorAddPKfS0_Pfi_ptx() -> Result<(), TranslateError> {
|
||||
let vector_add = include_str!("_Z9vectorAddPKfS0_Pfi.ptx");
|
||||
compile_and_assert(vector_add)
|
||||
}
|
||||
|
|
1437
ptx/src/translate.rs
1437
ptx/src/translate.rs
File diff suppressed because it is too large
Load diff
Loading…
Add table
Reference in a new issue