Skip to content

Commit

Permalink
update submod
Browse files Browse the repository at this point in the history
  • Loading branch information
shiinamiyuki committed Oct 13, 2023
1 parent 7afa417 commit 07ed711
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 15 deletions.
2 changes: 1 addition & 1 deletion luisa_compute/src/lang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::{env, unreachable};
use crate::internal_prelude::*;

use bumpalo::Bump;
use indexmap::{IndexMap, IndexSet};
use indexmap::IndexMap;

use crate::runtime::WeakDevice;

Expand Down
4 changes: 0 additions & 4 deletions luisa_compute/src/lang/types/core.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
use std::any::TypeId;

use serde_json::value::Index;

use crate::lang::soa::SoaBuffer;

use super::*;
Expand Down
9 changes: 6 additions & 3 deletions luisa_compute/src/resource.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::cell::{Cell, RefCell};
use std::cell::RefCell;
use std::collections::HashMap;
use std::fmt;
use std::ops::RangeBounds;
Expand Down Expand Up @@ -537,16 +537,18 @@ pub struct BufferHeap<T: Value> {
pub(crate) inner: BindlessArray,
pub(crate) _marker: PhantomData<T>,
}
#[allow(deprecated)]
impl<T: Value + fmt::Debug> fmt::Debug for BufferHeap<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "BufferHeap<{}>", std::any::type_name::<T>(),)
}
}

#[deprecated]
pub struct BufferHeapVar<T: Value> {
inner: BindlessArrayVar,
_marker: PhantomData<T>,
}
#[allow(deprecated)]
impl<T: Value> BufferHeap<T> {
#[inline]
pub fn var(&self) -> BufferHeapVar<T> {
Expand Down Expand Up @@ -593,6 +595,7 @@ impl<T: Value> BufferHeap<T> {
self.inner.buffer(index)
}
}
#[allow(deprecated)]
impl<T: Value> BufferHeapVar<T> {
#[inline]
pub fn buffer(&self, index: impl AsExpr<Value = u32>) -> BindlessBufferVar<T> {
Expand Down Expand Up @@ -838,7 +841,7 @@ impl BindlessArray {
self.lock();
let mut rt = ResourceTracker::new();
let mut modifications = self.modifications.borrow_mut();
let modifications = Arc::new(modifications.drain().map(|(k, v)| v).collect::<Vec<_>>());
let modifications = Arc::new(modifications.drain().map(|(_k, v)| v).collect::<Vec<_>>());
rt.add(modifications.clone());
let lock = self.lock.clone();
Command {
Expand Down
4 changes: 1 addition & 3 deletions luisa_compute/src/rtx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ use crate::internal_prelude::*;

use crate::runtime::*;
use crate::{ResourceTracker, *};
use luisa_compute_ir::ir::{
AccelBinding, Binding, Func, Instruction, IrBuilder, Node, NodeRef, Type,
};
use luisa_compute_ir::ir::{AccelBinding, Binding, Func, Instruction, IrBuilder, Node, Type};
use parking_lot::RwLock;
use std::ops::Deref;

Expand Down
15 changes: 15 additions & 0 deletions luisa_compute/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,10 @@ impl Device {
buffer.view(..).fill_fn(f);
buffer
}
#[deprecated(
note = "Spamming BufferHeap can cause serious performance issue on CUDA backend. Use BindlessArray instead."
)]
#[allow(deprecated)]
pub fn create_buffer_heap<T: Value>(&self, slots: usize) -> BufferHeap<T> {
let array = self.create_bindless_array(slots);
BufferHeap {
Expand Down Expand Up @@ -1222,6 +1226,7 @@ impl RawKernel {
rt.add(self.clone());
let args = args.args;
let args = Arc::new(args);
assert_eq!(args.len(), self.module.args.len());
rt.add(args.clone());
Command {
inner: api::Command::ShaderDispatch(api::ShaderDispatchCommand {
Expand Down Expand Up @@ -1421,6 +1426,16 @@ impl<T: KernelSignature> Kernel<T> {
pub fn dump(&self) -> String {
ir::debug::dump_ir_human_readable(&self.inner.module.module)
}
pub fn num_arguments(&self) -> usize {
self.inner.module.args.len()
}
pub fn num_capture_arguments(&self) -> usize {
let mut unique_bindings = HashSet::new();
for c in self.inner.module.captures.iter() {
unique_bindings.insert(c.binding);
}
unique_bindings.len()
}
#[doc(hidden)]
pub fn raw(&self) -> &RawKernel {
&self.inner
Expand Down
2 changes: 0 additions & 2 deletions luisa_compute/src/runtime/kernel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,15 +338,13 @@ impl KernelBuilder {
let callables: Vec<CallableModuleRef> = r.callables.values().cloned().collect();
let mut captured_set = HashSet::<Capture>::new();
let mut cpu_custom_ops_set = HashSet::<u64>::new();
let mut callable_set = HashSet::<u64>::new();
for capture in captured.iter() {
captured_set.insert(*capture);
}
for op in &cpu_custom_ops {
cpu_custom_ops_set.insert(CArc::as_ptr(op) as u64);
}
for c in &callables {
callable_set.insert(CArc::as_ptr(&c.0) as u64);
for capture in c.0.captures.as_ref() {
if !captured_set.contains(capture) {
captured_set.insert(*capture);
Expand Down
1 change: 0 additions & 1 deletion luisa_compute/tests/autodiff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::ops::Range;

use alias::*;
use luisa::lang::autodiff::*;
use luisa::lang::types::core::*;
use luisa::lang::types::vector::*;
use luisa::prelude::*;
use luisa_compute as luisa;
Expand Down
38 changes: 38 additions & 0 deletions luisa_compute/tests/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,44 @@ fn nested_callable_capture_by_value() {
assert_eq!(z_data[i], (i as f32 + 1000.0 * i as f32));
}
}

// this is broken on dx!!!
#[test]
fn nested_callable_capture_by_ref_alias() {
let device = get_device();

let x = device.create_buffer::<f32>(1024);
let y = device.create_buffer::<f32>(1024);
let z = device.create_buffer::<f32>(1024);
z.view(..).fill(0.0);
x.view(..).fill_fn(|i| i as f32);
y.view(..).fill_fn(|i| 1000.0 * i as f32);
let kernel = Kernel::<fn(Buffer<f32>)>::new(
&device,
&track!(|buf_z| {
let tid = dispatch_id().x;
let v = Var::<Float2>::zeroed();
*v.x = 0.0;
let u = Var::<Float2>::zeroed();
let acc = |x: Expr<f32>| {
outline(|| {
*v.x += x;
*u = Float2::expr(v.x, v.x);
buf_z.write(tid, v.load().x);
})
};
acc(x.read(tid));
acc(y.read(tid));
acc(1.23f32.expr());
}),
);
kernel.dispatch([1024, 1, 1], &z);
let z_data = z.view(..).copy_to_vec();
for i in 0..x.len() {
assert!((z_data[i] - (i as f32 + 1000.0 * i as f32 + 1.23f32)).abs() < 1e-6);
}
}

#[test]
fn nested_callable_capture_by_ref() {
let device = get_device();
Expand Down
2 changes: 1 addition & 1 deletion luisa_compute_sys/LuisaCompute
Submodule LuisaCompute updated 40 files
+2 −0 include/luisa/ast/external_function.h
+12 −2 include/luisa/ast/function_builder.h
+51 −37 include/luisa/backends/ext/dx_cuda_interop.h
+1 −1 include/luisa/core/logging.h
+0 −2,969 include/luisa/ir/ir.h
+1 −0 include/luisa/runtime/buffer.h
+1 −0 include/luisa/runtime/image.h
+1 −0 include/luisa/runtime/volume.h
+39 −0 include/luisa/rust/api_types.hpp
+1 −0 src/ast/CMakeLists.txt
+352 −0 src/ast/function_duplicator.cpp
+19 −3 src/backends/cuda/cuda_buffer.cpp
+2 −2 src/backends/cuda/cuda_buffer.h
+3 −2 src/backends/cuda/cuda_codegen_ast.cpp
+64 −20 src/backends/dx/DXApi/cuda_interop.cpp
+10 −11 src/backends/dx/DXApi/ext.h
+5 −3 src/backends/dx/Resource/DefaultBuffer.cpp
+2 −1 src/backends/dx/Resource/DefaultBuffer.h
+8 −5 src/backends/dx/Resource/GpuAllocator.cpp
+4 −2 src/backends/dx/Resource/GpuAllocator.h
+6 −3 src/backends/dx/Resource/RenderTexture.cpp
+2 −1 src/backends/dx/Resource/RenderTexture.h
+0 −1 src/ir/CMakeLists.txt
+0 −197 src/ir/ir.cpp
+0 −1 src/ir/ir2ast.cpp
+0 −8 src/rust/Cargo.lock
+1 −2 src/rust/Cargo.toml
+0 −10 src/rust/cppbindgen/Cargo.toml
+0 −27 src/rust/cppbindgen/data/BasicBlock.h
+0 −54 src/rust/cppbindgen/data/IrBuilder.cpp
+0 −22 src/rust/cppbindgen/data/IrBuilder.h
+0 −24 src/rust/cppbindgen/data/NodeRef.cpp
+0 −14 src/rust/cppbindgen/data/NodeRef.h
+0 −544 src/rust/cppbindgen/src/main.rs
+15 −3 src/rust/luisa_compute_api_types/build.rs
+7 −11 src/rust/luisa_compute_ir/build.rs
+2 −4 src/rust/luisa_compute_ir/src/ast2ir.rs
+8 −6 src/rust/luisa_compute_ir/src/transform/autodiff.rs
+9 −8 src/rust/luisa_compute_ir/src/transform/fwd_autodiff.rs
+21 −0 src/rust/write_if_different.rs

0 comments on commit 07ed711

Please sign in to comment.