mirror of
https://github.com/vosen/ZLUDA.git
synced 2025-07-18 09:46:21 +03:00
Continue working on a better addressable support
This commit is contained in:
@ -164,8 +164,8 @@ pub enum MethodDecl<'a, P: ArgParams> {
|
|||||||
Kernel(&'a str, Vec<KernelArgument<P>>),
|
Kernel(&'a str, Vec<KernelArgument<P>>),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type FnArgument<P: ArgParams> = Variable<FnArgumentType, P>;
|
pub type FnArgument<P> = Variable<FnArgumentType, P>;
|
||||||
pub type KernelArgument<P: ArgParams> = Variable<VariableParamType, P>;
|
pub type KernelArgument<P> = Variable<VariableParamType, P>;
|
||||||
|
|
||||||
pub struct Function<'a, P: ArgParams, S> {
|
pub struct Function<'a, P: ArgParams, S> {
|
||||||
pub func_directive: MethodDecl<'a, P>,
|
pub func_directive: MethodDecl<'a, P>,
|
||||||
@ -316,7 +316,7 @@ pub struct PredAt<ID> {
|
|||||||
|
|
||||||
pub enum Instruction<P: ArgParams> {
|
pub enum Instruction<P: ArgParams> {
|
||||||
Ld(LdData, Arg2<P>),
|
Ld(LdData, Arg2<P>),
|
||||||
Mov(MovType, Arg2<P>),
|
Mov(MovType, Arg2Mov<P>),
|
||||||
MovVector(MovVectorDetails, Arg2Vec<P>),
|
MovVector(MovVectorDetails, Arg2Vec<P>),
|
||||||
Mul(MulDetails, Arg3<P>),
|
Mul(MulDetails, Arg3<P>),
|
||||||
Add(AddDetails, Arg3<P>),
|
Add(AddDetails, Arg3<P>),
|
||||||
@ -354,7 +354,7 @@ pub struct CallInst<P: ArgParams> {
|
|||||||
pub trait ArgParams {
|
pub trait ArgParams {
|
||||||
type ID;
|
type ID;
|
||||||
type Operand;
|
type Operand;
|
||||||
type MemoryOperand;
|
type MovOperand;
|
||||||
type CallOperand;
|
type CallOperand;
|
||||||
type VecOperand;
|
type VecOperand;
|
||||||
}
|
}
|
||||||
@ -366,7 +366,7 @@ pub struct ParsedArgParams<'a> {
|
|||||||
impl<'a> ArgParams for ParsedArgParams<'a> {
|
impl<'a> ArgParams for ParsedArgParams<'a> {
|
||||||
type ID = &'a str;
|
type ID = &'a str;
|
||||||
type Operand = Operand<&'a str>;
|
type Operand = Operand<&'a str>;
|
||||||
type MemoryOperand = Operand<&'a str>;
|
type MovOperand = MovOperand<&'a str>;
|
||||||
type CallOperand = CallOperand<&'a str>;
|
type CallOperand = CallOperand<&'a str>;
|
||||||
type VecOperand = (&'a str, u8);
|
type VecOperand = (&'a str, u8);
|
||||||
}
|
}
|
||||||
@ -380,13 +380,27 @@ pub struct Arg2<P: ArgParams> {
|
|||||||
pub src: P::Operand,
|
pub src: P::Operand,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Arg2Ld<P: ArgParams> {
|
pub struct Arg2Mov<P: ArgParams> {
|
||||||
pub dst: P::ID,
|
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 struct Arg2St<P: ArgParams> {
|
||||||
pub src1: P::MemoryOperand,
|
pub src1: P::Operand,
|
||||||
pub src2: P::Operand,
|
pub src2: P::Operand,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -419,6 +433,14 @@ pub struct Arg5<P: ArgParams> {
|
|||||||
pub src3: P::Operand,
|
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)]
|
#[derive(Copy, Clone)]
|
||||||
pub enum Operand<ID> {
|
pub enum Operand<ID> {
|
||||||
Reg(ID),
|
Reg(ID),
|
||||||
|
@ -31,6 +31,7 @@ pub use crate::ptx::ModuleParser;
|
|||||||
pub use lalrpop_util::lexer::Token;
|
pub use lalrpop_util::lexer::Token;
|
||||||
pub use lalrpop_util::ParseError;
|
pub use lalrpop_util::ParseError;
|
||||||
pub use rspirv::dr::Error as SpirvError;
|
pub use rspirv::dr::Error as SpirvError;
|
||||||
|
pub use translate::TranslateError as TranslateError;
|
||||||
pub use translate::to_spirv;
|
pub use translate::to_spirv;
|
||||||
|
|
||||||
pub(crate) fn without_none<T>(x: Vec<Option<T>>) -> Vec<T> {
|
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
|
// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#data-movement-and-conversion-instructions-mov
|
||||||
InstMov: ast::Instruction<ast::ParsedArgParams<'input>> = {
|
InstMov: ast::Instruction<ast::ParsedArgParams<'input>> = {
|
||||||
"mov" <t:MovType> <a:Arg2> => {
|
"mov" <t:MovType> <a:Arg2> => {
|
||||||
ast::Instruction::Mov(t, a)
|
ast::Instruction::Mov(t, a.into())
|
||||||
},
|
},
|
||||||
"mov" <t:MovVectorType> <a:Arg2Vec> => {
|
"mov" <t:MovVectorType> <a:Arg2Vec> => {
|
||||||
ast::Instruction::MovVector(ast::MovVectorDetails{typ: t, length: 0}, a)
|
ast::Instruction::MovVector(ast::MovVectorDetails{typ: t, length: 0}, a)
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
use super::ptx;
|
use super::ptx;
|
||||||
|
use super::TranslateError;
|
||||||
|
|
||||||
mod spirv_run;
|
mod spirv_run;
|
||||||
|
|
||||||
@ -8,7 +9,7 @@ fn parse_and_assert(s: &str) {
|
|||||||
assert!(errors.len() == 0);
|
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 mut errors = Vec::new();
|
||||||
let ast = ptx::ModuleParser::new().parse(&mut errors, s).unwrap();
|
let ast = ptx::ModuleParser::new().parse(&mut errors, s).unwrap();
|
||||||
crate::to_spirv(ast)?;
|
crate::to_spirv(ast)?;
|
||||||
@ -28,14 +29,14 @@ fn operands_ptx() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[allow(non_snake_case)]
|
#[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");
|
let vector_add = include_str!("vectorAdd_kernel64.ptx");
|
||||||
compile_and_assert(vector_add)
|
compile_and_assert(vector_add)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[allow(non_snake_case)]
|
#[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");
|
let vector_add = include_str!("_Z9vectorAddPKfS0_Pfi.ptx");
|
||||||
compile_and_assert(vector_add)
|
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
Reference in New Issue
Block a user