Skip to content

Commit

Permalink
fixed printer
Browse files Browse the repository at this point in the history
  • Loading branch information
shiinamiyuki committed Sep 22, 2023
1 parent 7337b26 commit fefc3c7
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
12 changes: 6 additions & 6 deletions luisa_compute/examples/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ fn main() {
"cpu"
});
let printer = Printer::new(&device, 65536);
let kernel = device.create_kernel::<fn()>(&|| {
let kernel = device.create_kernel::<fn()>(track!(&|| {
let id = dispatch_id().xy();
if_!(id.x().cmpeq(id.y()), {
if id.x == id.y {
lc_info!(printer, "id = {:?}", id);
}, else {
lc_info!(printer, "not equal!, id = [{} {}]", id.x(), id.y());
});
});
} else {
lc_info!(printer, "not equal!, id = [{} {}]", id.x, id.y);
}
}));
device.default_stream().with_scope(|s| {
s.reset_printer(&printer);
s.submit([kernel.dispatch_async([4, 4, 1])]);
Expand Down
2 changes: 1 addition & 1 deletion luisa_compute/examples/ray_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ fn main() {
let t = Var::<f32>::zeroed();

for _ in 0..100 {
let dist = (o + d * t.load() - (sphere.center + translate.expr())).length()
let dist = (o + d * t - (sphere.center + translate.expr())).length()
- sphere.radius;
if dist < 0.001 {
if (px == Uint2::expr(400, 400)).all() {
Expand Down
7 changes: 7 additions & 0 deletions luisa_compute/src/lang/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ pub struct Expr<T: Value> {
proxy: *mut ExprProxyData<T>,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct TypeTag<T: Value>(PhantomData<T>);

/// A variable within a [`Kernel`](crate::runtime::Kernel) or
/// [`Callable`](crate::runtime::Callable). Created using [`Expr::var`]
/// and [`Value::var`].
Expand Down Expand Up @@ -294,6 +298,9 @@ impl<T: Value> Expr<T> {
let node = __current_scope(|s| s.bitcast(self.node(), ty));
Expr::<S>::from_node(node)
}
pub fn _type_tag(&self)->TypeTag<T> {
TypeTag(PhantomData)
}
}

impl<T: Value> Var<T> {
Expand Down
3 changes: 2 additions & 1 deletion luisa_compute/src/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub use log as _log;

use crate::internal_prelude::*;

use crate::lang::types::TypeTag;
use crate::lang::{pack_to, packed_size};

pub use crate::{lc_debug, lc_error, lc_info, lc_warn};
Expand Down Expand Up @@ -102,7 +103,7 @@ macro_rules! lc_error {
$crate::lc_log!($printer, log::Level::Error, $fmt, $($arg)*);
};
}
pub fn _unpack_from_expr<V: Value>(data: *const u32, _: Expr<V>) -> V {
pub fn _unpack_from_expr<V: Value>(data: *const u32, _: TypeTag<V>) -> V {
unsafe { std::ptr::read_unaligned(data as *const V) }
}
impl Printer {
Expand Down
5 changes: 4 additions & 1 deletion luisa_compute_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub fn _log(item: TokenStream) -> TokenStream {
quote! {
{
#(
let #arg_idents = #args;
let #arg_idents = #args._type_tag();
)*;
let mut __log_priv_i = 0;
let log_fn = Box::new(move |args: &[*const u32]| -> () {
Expand All @@ -81,6 +81,9 @@ pub fn _log(item: TokenStream) -> TokenStream {
}
), *);
});
#(
let #arg_idents = #args;
)*;
let mut printer_args = luisa_compute::printer::PrinterArgs::new();
#(
printer_args.append(#arg_idents);
Expand Down

0 comments on commit fefc3c7

Please sign in to comment.