From b5d6ea22691feeec62e28a64ac6d634209ab76d7 Mon Sep 17 00:00:00 2001 From: ReversedGravity Date: Sat, 23 Sep 2023 17:54:57 +0100 Subject: [PATCH 1/2] Added Deref on VarProxy. --- luisa_compute/src/lang/ops.rs | 4 +--- luisa_compute/src/lang/types.rs | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/luisa_compute/src/lang/ops.rs b/luisa_compute/src/lang/ops.rs index 287e9855..d9af8b10 100644 --- a/luisa_compute/src/lang/ops.rs +++ b/luisa_compute/src/lang/ops.rs @@ -4,10 +4,10 @@ use std::ops::*; use super::types::core::{Floating, Integral, Numeric, Primitive, Signed}; use super::types::vector::{VectorAlign, VectorElement}; +mod cast_impls; mod impls; mod spread; mod traits; -mod cast_impls; pub use spread::*; pub use traits::*; @@ -24,8 +24,6 @@ pub trait Linear: Value { const N: usize; type Scalar: VectorElement; type WithScalar: Linear; - // We don't actually know that the vector has equivalent vectors of every - // primitive type. } impl Linear for T { const N: usize = 1; diff --git a/luisa_compute/src/lang/types.rs b/luisa_compute/src/lang/types.rs index 45f5abcc..11bad6b0 100644 --- a/luisa_compute/src/lang/types.rs +++ b/luisa_compute/src/lang/types.rs @@ -62,7 +62,7 @@ pub trait ExprProxy: Copy + 'static { /// For example, `Var<[f32; 4]>` dereferences to `ArrayVar`, which /// exposes [`Index`](std::ops::Index) and [`IndexMut`](std::ops::IndexMut) /// impls. -pub trait VarProxy: Copy + 'static { +pub trait VarProxy: Copy + 'static + Deref> { type Value: Value; fn as_var_from_proxy(&self) -> &Var; From 898009a0c46650478660cb30817ddb4e6203a844 Mon Sep 17 00:00:00 2001 From: ReversedGravity Date: Sat, 23 Sep 2023 17:55:13 +0100 Subject: [PATCH 2/2] Kernel dispatch fix. --- luisa_compute/src/runtime.rs | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/luisa_compute/src/runtime.rs b/luisa_compute/src/runtime.rs index 6c1fb73f..6d1ae634 100644 --- a/luisa_compute/src/runtime.rs +++ b/luisa_compute/src/runtime.rs @@ -401,12 +401,14 @@ impl Device { } } - /// Compile a [`KernelDef`] into a [`Kernel`]. See [`Kernel`] for more details on kernel creation + /// Compile a [`KernelDef`] into a [`Kernel`]. See [`Kernel`] for more + /// details on kernel creation pub fn compile_kernel(&self, k: &KernelDef) -> Kernel { self.compile_kernel_with_options(k, KernelBuildOptions::default()) } - /// Compile a [`KernelDef`] into a [`Kernel`] asynchronously. See [`Kernel`] for more details on kernel creation + /// Compile a [`KernelDef`] into a [`Kernel`] asynchronously. See [`Kernel`] + /// for more details on kernel creation pub fn compile_kernel_async(&self, k: &KernelDef) -> Kernel { self.compile_kernel_with_options( k, @@ -417,7 +419,8 @@ impl Device { ) } - /// Compile a [`KernelDef`] into a [`Kernel`] with options. See [`Kernel`] for more details on kernel creation + /// Compile a [`KernelDef`] into a [`Kernel`] with options. See [`Kernel`] + /// for more details on kernel creation pub fn compile_kernel_with_options( &self, k: &KernelDef, @@ -1084,7 +1087,11 @@ impl RawKernel { } } - pub fn dispatch_async(&self, args: KernelArgEncoder, dispatch_size: [u32; 3]) -> Command { + pub fn dispatch_async( + &self, + args: KernelArgEncoder, + dispatch_size: [u32; 3], + ) -> Command<'static> { let mut rt = ResourceTracker::new(); rt.add(Arc::new(args.uniform_data)); let args = args.args; @@ -1218,8 +1225,8 @@ pub struct KernelDef { /// use luisa_compute::prelude::*; /// let ctx = Context::new(std::env::current_exe().unwrap()); /// let device = ctx.create_device("cpu"); -/// let kernel = KernelDef::, Buffer, Buffer)>::new(&device, track!(|a,b,c|{ })); -/// // Compilation: +/// let kernel = KernelDef::, Buffer, +/// Buffer)>::new(&device, track!(|a,b,c|{ })); // Compilation: /// let kernel = device.compile_kernel(&kernel); /// ``` /// - Recording and compilation in one step: @@ -1227,11 +1234,10 @@ pub struct KernelDef { /// use luisa_compute::prelude::*; /// let ctx = Context::new(std::env::current_exe().unwrap()); /// let device = ctx.create_device("cpu"); -/// let kernel = Kernel::, Buffer, Buffer)>::new(&device, track!(|a,b,c|{ })); -/// ``` +/// let kernel = Kernel::, Buffer, +/// Buffer)>::new(&device, track!(|a,b,c|{ })); ``` /// - Asynchronous compilation use [`Kernel::::new_async`] /// - Custom build options using [`Kernel::::new_with_options`] -/// pub struct Kernel { pub(crate) inner: RawKernel, pub(crate) _marker: PhantomData, @@ -1335,10 +1341,10 @@ macro_rules! impl_dispatch_for_kernel { } #[allow(non_snake_case)] #[allow(unused_mut)] - pub fn dispatch_async<'a>( - &'a self, + pub fn dispatch_async( + &self, dispatch_size: [u32; 3], $($Ts:&impl AsKernelArg<$Ts>),* - ) -> Command<'a> { + ) -> Command<'static> { let mut encoder = KernelArgEncoder::new(); $($Ts.encode(&mut encoder);)* self.inner.dispatch_async(encoder, dispatch_size)