Skip to content

Commit

Permalink
device debug print (wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
shiinamiyuki committed Oct 27, 2023
1 parent d0a48ad commit ecb4f83
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
1 change: 1 addition & 0 deletions luisa_compute/src/lang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub mod functions;
pub mod index;
pub mod ops;
pub mod poly;
pub mod print;
pub mod soa;
pub mod types;

Expand Down
55 changes: 55 additions & 0 deletions luisa_compute/src/lang/print.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use crate::internal_prelude::*;

use super::types::core::Primitive;

pub struct DebugFormatter {
pub(crate) fmt: String,
pub(crate) args: Vec<NodeRef>,
}
impl DebugFormatter {
pub fn new() -> Self {
Self {
fmt: String::new(),
args: Vec::new(),
}
}
pub fn push_str(&mut self, s: &str) {
assert!(
s.find("{}").is_none(),
"DebugFormatter::push_str cannot contain {{}}"
);
self.fmt.push_str(s);
}
pub fn push_arg(&mut self, node: NodeRef) {
assert!(
node.type_().is_primitive(),
"DebugFormatter::push_arg must be primitive"
);
self.fmt.push_str("{}");
self.args.push(node);
}
}
pub trait DebugPrintValue: Value {
fn fmt_args(e: Expr<Self>, fmt: &mut DebugFormatter);
}

impl<T: DebugPrintValue + Primitive> DebugPrintValue for T {
fn fmt_args(e: Expr<Self>, fmt: &mut DebugFormatter) {
fmt.push_arg(e.node().get());
}
}

pub trait DebugPrint {
fn fmt_args(&self, fmt: &mut DebugFormatter);
}

impl<T: DebugPrintValue> DebugPrint for Expr<T> {
fn fmt_args(&self, fmt: &mut DebugFormatter) {
T::fmt_args(*self, fmt);
}
}
impl<T: DebugPrintValue> DebugPrint for Var<T> {
fn fmt_args(&self, fmt: &mut DebugFormatter) {
T::fmt_args(self.load(), fmt);
}
}
2 changes: 1 addition & 1 deletion luisa_compute_sys/LuisaCompute
Submodule LuisaCompute updated 39 files
+2 −0 include/luisa/ast/function.h
+5 −0 include/luisa/ast/function_builder.h
+3 −0 include/luisa/ast/op.h
+44 −13 include/luisa/ast/statement.h
+8 −0 include/luisa/dsl/stmt.h
+1 −0 include/luisa/ir/ir2ast.h
+12 −0 src/ast/ast2json.cpp
+28 −0 src/ast/callable_library.cpp
+4 −0 src/ast/function.cpp
+16 −0 src/ast/function_builder.cpp
+8 −0 src/ast/function_duplicator.cpp
+14 −1 src/ast/statement.cpp
+1 −0 src/backends/cuda/CMakeLists.txt
+7 −1 src/backends/cuda/cuda_buffer.cpp
+26 −0 src/backends/cuda/cuda_builtin/cuda_device_resource.h
+45 −2 src/backends/cuda/cuda_builtin_embedded.cpp
+1 −1 src/backends/cuda/cuda_builtin_embedded.h
+94 −2 src/backends/cuda/cuda_codegen_ast.cpp
+8 −1 src/backends/cuda/cuda_codegen_ast.h
+0 −1 src/backends/cuda/cuda_command_encoder.cpp
+17 −5 src/backends/cuda/cuda_device.cpp
+8 −3 src/backends/cuda/cuda_shader.cpp
+6 −2 src/backends/cuda/cuda_shader.h
+99 −16 src/backends/cuda/cuda_shader_metadata.cpp
+6 −2 src/backends/cuda/cuda_shader_metadata.h
+14 −4 src/backends/cuda/cuda_shader_native.cpp
+2 −2 src/backends/cuda/cuda_shader_native.h
+14 −1 src/backends/cuda/cuda_shader_optix.cpp
+239 −0 src/backends/cuda/cuda_shader_printer.cpp
+45 −0 src/backends/cuda/cuda_shader_printer.h
+26 −6 src/core/logging.cpp
+55 −14 src/ir/ir2ast.cpp
+4 −0 src/rust/Cargo.toml
+156 −6 src/rust/luisa_compute_backend_impl/src/cpu/codegen/cpp.rs
+3 −2 src/rust/luisa_compute_backend_impl/src/cpu/codegen/cpu_prelude.h
+1 −0 src/rust/luisa_compute_backend_impl/src/cpu/llvm.rs
+2 −2 src/rust/luisa_compute_backend_impl/src/cpu/mod.rs
+2 −4 src/rust/luisa_compute_ir/Cargo.toml
+9 −0 src/rust/luisa_compute_ir/src/ast2ir.rs

0 comments on commit ecb4f83

Please sign in to comment.