Skip to content

Commit

Permalink
update submod
Browse files Browse the repository at this point in the history
  • Loading branch information
shiinamiyuki committed Dec 29, 2023
1 parent 4db529c commit 3638d4a
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
6 changes: 6 additions & 0 deletions luisa_compute/src/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1358,6 +1358,9 @@ impl<T: IoTexel> Tex2d<T> {
pub fn format(&self) -> PixelFormat {
self.handle.format
}
pub fn storage(&self) -> PixelStorage {
self.handle.storage
}
// pub fn read(&self, uv: impl AsExpr<Value = Uint2>) -> Expr<T> {
// self.var().read(uv)
// }
Expand All @@ -1384,6 +1387,9 @@ impl<T: IoTexel> Tex3d<T> {
pub fn format(&self) -> PixelFormat {
self.handle.format
}
pub fn storage(&self) -> PixelStorage {
self.handle.storage
}
// pub fn read(&self, uv: impl AsExpr<Value = Uint3>) -> Expr<T> {
// self.var().read(uv)
// }
Expand Down
54 changes: 53 additions & 1 deletion luisa_compute/tests/autodiff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,59 @@ fn autodiff_if_phi() {
}
}
}

#[test]
fn autodiff_if_phi_outer_no_else() {
let device = get_device();
let x: Buffer<f32> = device.create_buffer(1024);
let y: Buffer<f32> = device.create_buffer(1024);
let dx: Buffer<f32> = device.create_buffer(1024);
let dy: Buffer<f32> = device.create_buffer(1024);
let mut rng = rand::thread_rng();
x.view(..).fill_fn(|_| rng.gen());
y.view(..).fill_fn(|_| rng.gen());
let kernel = Kernel::<fn()>::new(
&device,
&track!(|| {
let buf_x = x.var();
let buf_y = y.var();
let buf_dx = dx.var();
let buf_dy = dy.var();
let tid = dispatch_id().x;
let x = buf_x.read(tid);
let y = buf_y.read(tid);
let z = 0.0f32.var();
if true.expr() {
autodiff(|| {
requires_grad(x);
requires_grad(y);
if x > y {
let tmp = 0.0f32.var();
*tmp = x * 4.0;
*z = tmp;
};
backward(**z);
buf_dx.write(tid, gradient(x));
buf_dy.write(tid, gradient(y));
});
}
}),
);
kernel.dispatch([1024, 1, 1]);
let dx = dx.view(..).copy_to_vec();
let dy = dy.view(..).copy_to_vec();
let x = x.view(..).copy_to_vec();
let y = y.view(..).copy_to_vec();
let cache_dir = kernel.cache_dir();
for i in 0..1024 {
if x[i] > y[i] {
assert_eq!(dx[i], 4.0, "{} cache_dir: {:?}", dx[i], cache_dir);
assert_eq!(dy[i], 0.0, "{} cache_dir: {:?}", dy[i], cache_dir);
} else {
assert_eq!(dx[i], 0.0, "{} cache_dir: {:?}", dx[i], cache_dir);
assert_eq!(dy[i], 0.0, "{} cache_dir: {:?}", dy[i], cache_dir);
}
}
}
#[test]
fn autodiff_if_phi2() {
let device = get_device();
Expand Down
2 changes: 1 addition & 1 deletion luisa_compute_sys/LuisaCompute
Submodule LuisaCompute updated 54 files
+4 −1 include/luisa/core/basic_traits.h
+7 −4 include/luisa/core/basic_types.h
+27 −5 include/luisa/runtime/rhi/device_interface.h
+2 −2 include/luisa/vstl/functional.h
+13 −5 include/luisa/vstl/meta_lib.h
+285 −467 include/luisa/vstl/ranges.h
+0 −3 scripts/xmake_func.lua
+5 −1 src/ast/type.cpp
+1 −0 src/backends/CMakeLists.txt
+17 −4 src/backends/common/hlsl/hlsl_codegen.h
+5 −5 src/backends/common/hlsl/hlsl_codegen_util.cpp
+3 −4 src/backends/common/hlsl/struct_generator.cpp
+1 −0 src/backends/common/hlsl/struct_generator.h
+1 −0 src/backends/cuda/CMakeLists.txt
+1 −1 src/backends/cuda/cuda_bindless_array.cpp
+35 −24 src/backends/cuda/cuda_buffer.cpp
+15 −5 src/backends/cuda/cuda_buffer.h
+16 −6 src/backends/cuda/cuda_builtin/cuda_device_math.h
+14 −14 src/backends/cuda/cuda_builtin/cuda_device_resource.h
+6,481 −6,453 src/backends/cuda/cuda_builtin_embedded.cpp
+2 −2 src/backends/cuda/cuda_builtin_embedded.h
+2 −1 src/backends/cuda/cuda_codegen_ast.cpp
+8 −8 src/backends/cuda/cuda_command_encoder.cpp
+1 −0 src/backends/cuda/cuda_compiler.cpp
+4 −4 src/backends/cuda/cuda_curve.cpp
+6 −4 src/backends/cuda/cuda_device.cpp
+2 −0 src/backends/cuda/cuda_device.h
+4 −4 src/backends/cuda/cuda_mesh.cpp
+2 −3 src/backends/cuda/cuda_procedural_primitive.cpp
+3 −3 src/backends/cuda/cuda_shader_optix.cpp
+13 −12 src/backends/cuda/extensions/cuda_denoiser.cpp
+87 −0 src/backends/cuda/extensions/cuda_pinned_memory.cpp
+31 −0 src/backends/cuda/extensions/cuda_pinned_memory.h
+1 −1 src/backends/cuda/extensions/cuda_texture_compression.cpp
+10 −2 src/backends/cuda/generate_device_library.py
+3 −1 src/backends/cuda/xmake.lua
+4 −2 src/backends/dx/DXApi/LCDevice.cpp
+6 −4 src/backends/dx/DXRuntime/Device.cpp
+1 −0 src/backends/dx/DXRuntime/Device.h
+2 −2 src/backends/dx/Resource/GpuAllocator.cpp
+2 −2 src/backends/dx/Resource/GpuAllocator.h
+3 −0 src/backends/dx/Shader/BuiltinKernel.cpp
+30 −1 src/backends/dx/Shader/ComputeShader.cpp
+6 −3 src/backends/dx/Shader/ComputeShader.h
+12 −9 src/backends/dx/Shader/RasterShader.cpp
+38 −2 src/backends/dx/Shader/ShaderSerializer.cpp
+1 −0 src/backends/dx/Shader/ShaderSerializer.h
+6 −3 src/backends/validation/CMakeLists.txt
+1 −1 src/ext/magic_enum
+1 −1 src/ext/spdlog
+6 −0 src/ir/ir2ast.cpp
+16 −6 src/rust/luisa_compute_backend_impl/src/cpu/codegen/device_math.h
+1 −1 src/tests/test_pinned_mem.cpp
+6 −1 src/vstl/vstl.cpp

0 comments on commit 3638d4a

Please sign in to comment.