Skip to content

Commit

Permalink
No dbg call (#88)
Browse files Browse the repository at this point in the history
* move from dbg to trace
  • Loading branch information
ZuseZ4 authored Mar 31, 2024
1 parent 1f65049 commit ca1aa97
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 39 deletions.
17 changes: 13 additions & 4 deletions compiler/rustc_ast/src/expand/autodiff_attrs.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::expand::typetree::TypeTree;
use std::str::FromStr;
use std::fmt::{Display, Formatter};
use std::fmt::{self, Display, Formatter};
use crate::ptr::P;
use crate::{Ty, TyKind};

Expand All @@ -14,7 +14,7 @@ pub enum DiffMode {
}

impl Display for DiffMode {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
DiffMode::Inactive => write!(f, "Inactive"),
DiffMode::Source => write!(f, "Source"),
Expand Down Expand Up @@ -209,7 +209,6 @@ impl AutoDiffAttrs {
DiffMode::Inactive => false,
DiffMode::Source => false,
_ => {
dbg!(&self);
true
}
}
Expand All @@ -222,7 +221,6 @@ impl AutoDiffAttrs {
inputs: Vec<TypeTree>,
output: TypeTree,
) -> AutoDiffItem {
dbg!(&self);
AutoDiffItem { source, target, inputs, output, attrs: self }
}
}
Expand All @@ -235,3 +233,14 @@ pub struct AutoDiffItem {
pub inputs: Vec<TypeTree>,
pub output: TypeTree,
}

impl fmt::Display for AutoDiffItem {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Differentiating {} -> {}", self.source, self.target)?;
write!(f, " with attributes: {:?}", self.attrs)?;
write!(f, " with inputs: {:?}", self.inputs)?;
write!(f, " with output: {:?}", self.output)
}
}


20 changes: 5 additions & 15 deletions compiler/rustc_codegen_llvm/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,6 @@ fn get_params(fnc: &Value) -> Vec<&Value> {

unsafe fn create_call<'a>(tgt: &'a Value, src: &'a Value, rev_mode: bool,
llmod: &'a llvm::Module, llcx: &llvm::Context) {
dbg!(&tgt);
// first, remove all calls from fnc
let bb = LLVMGetFirstBasicBlock(tgt);
let br = LLVMRustGetTerminator(bb);
Expand All @@ -711,7 +710,7 @@ unsafe fn create_call<'a>(tgt: &'a Value, src: &'a Value, rev_mode: bool,
if inner_param_num == outer_param_num {
call_args = outer_args;
} else {
dbg!("Different number of args, adjusting");
trace!("Different number of args, adjusting");
let mut outer_pos: usize = 0;
let mut inner_pos: usize = 0;
// copy over if they are identical.
Expand Down Expand Up @@ -784,16 +783,9 @@ unsafe fn create_call<'a>(tgt: &'a Value, src: &'a Value, rev_mode: bool,
let md_val = LLVMMetadataAsValue(llcx, md);
let md2 = llvm::LLVMSetMetadata(struct_ret, md_ty, md_val);
} else {
dbg!("No dbg info");
dbg!(&inst);
trace!("No dbg info");
}

// Our placeholder originally ended with `loop {}`, and therefore got the noreturn fnc attr.
// This is not true anymore, so we remove it.
//LLVMRustRemoveFncAttr(tgt, AttributeKind::NoReturn);

dbg!(&tgt);

// Now clean up placeholder code.
LLVMRustEraseInstBefore(bb, last_inst);

Expand All @@ -809,15 +801,11 @@ unsafe fn create_call<'a>(tgt: &'a Value, src: &'a Value, rev_mode: bool,
}
}
if f_return_type != void_type {
dbg!("Returning struct");
let _ret = LLVMBuildRet(builder, struct_ret);
} else {
dbg!("Returning void");
let _ret = LLVMBuildRetVoid(builder);
}
LLVMDisposeBuilder(builder);

dbg!(&tgt);
let _fnc_ok =
LLVMVerifyFunction(tgt, llvm::LLVMVerifierFailureAction::LLVMAbortProcessAction);
}
Expand Down Expand Up @@ -944,7 +932,9 @@ pub(crate) unsafe fn differentiate(
_typetrees: FxHashMap<String, DiffTypeTree>,
_config: &ModuleConfig,
) -> Result<(), FatalError> {
dbg!(&diff_items);
for item in &diff_items {
trace!("{}", item);
}

let llmod = module.module_llvm.llmod();
let llcx = &module.module_llvm.llcx;
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_codegen_llvm/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ fn add_tt<'ll>(llmod: &'ll llvm::Module, llcx: &'ll llvm::Context,val: &'ll Valu
}
unsafe { llvm::EnzymeTypeTreeToStringFree(c_str.as_ptr()) };
}
dbg!(&val);
}


Expand Down
24 changes: 17 additions & 7 deletions compiler/rustc_codegen_llvm/src/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,6 @@ pub(crate) unsafe fn enzyme_rust_forward_diff(

// We don't support volatile / extern / (global?) values.
// Just because I didn't had time to test them, and it seems less urgent.
dbg!(&fnc);
let args_uncacheable = vec![0; input_tts.len()];
assert!(args_uncacheable.len() == input_activity.len());
let num_fnc_args = LLVMCountParams(fnc);
Expand Down Expand Up @@ -938,8 +937,6 @@ pub(crate) unsafe fn enzyme_rust_reverse_diff(

let input_activity: Vec<CDIFFE_TYPE> = input_activity.iter().map(|&x| cdiffe_from(x)).collect();

dbg!(&fnc);

let mut args_tree = input_tts.iter().map(|x| x.inner).collect::<Vec<_>>();

// We don't support volatile / extern / (global?) values.
Expand All @@ -964,9 +961,11 @@ pub(crate) unsafe fn enzyme_rust_reverse_diff(
KnownValues: known_values.as_mut_ptr(),
};

dbg!(&primary_ret);
dbg!(&ret_activity);
dbg!(&input_activity);
trace!("{}", &primary_ret);
trace!("{}", &ret_activity);
for i in &input_activity {
trace!("{}", &i);
}
let res = EnzymeCreatePrimalAndGradient(
logic_ref, // Logic
std::ptr::null(),
Expand All @@ -989,7 +988,6 @@ pub(crate) unsafe fn enzyme_rust_reverse_diff(
std::ptr::null_mut(), // write augmented function to this
0,
);
dbg!(&res);
res
}

Expand Down Expand Up @@ -2790,6 +2788,18 @@ pub mod Shared_AD {
DFT_DUP_NONEED = 3,
}

impl fmt::Display for CDIFFE_TYPE {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let value = match self {
CDIFFE_TYPE::DFT_OUT_DIFF => "DFT_OUT_DIFF",
CDIFFE_TYPE::DFT_DUP_ARG => "DFT_DUP_ARG",
CDIFFE_TYPE::DFT_CONSTANT => "DFT_CONSTANT",
CDIFFE_TYPE::DFT_DUP_NONEED => "DFT_DUP_NONEED",
};
write!(f, "{}", value)
}
}

pub fn cdiffe_from(act: DiffActivity) -> CDIFFE_TYPE {
return match act {
DiffActivity::None => CDIFFE_TYPE::DFT_CONSTANT,
Expand Down
9 changes: 3 additions & 6 deletions compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2741,7 +2741,6 @@ pub fn fnc_typetrees<'tcx>(tcx: TyCtxt<'tcx>, fn_ty: Ty<'tcx>, da: &mut Vec<Diff
// Recommended by compiler-errors:
// https://discord.com/channels/273534239310479360/957720175619215380/1223454360676208751
let x = tcx.instantiate_bound_regions_with_erased(fnc_binder);
dbg!("creating fncTree");

let mut offset = 0;
let mut visited = vec![];
Expand All @@ -2766,7 +2765,7 @@ pub fn fnc_typetrees<'tcx>(tcx: TyCtxt<'tcx>, fn_ty: Ty<'tcx>, da: &mut Vec<Diff
da.insert(i + 1 + offset, DiffActivity::Const);
offset += 1;
}
dbg!("ABI MATCHING\n\n\n");
trace!("ABI MATCHING!");
continue;
}
}
Expand All @@ -2782,12 +2781,11 @@ pub fn fnc_typetrees<'tcx>(tcx: TyCtxt<'tcx>, fn_ty: Ty<'tcx>, da: &mut Vec<Diff

pub fn typetree_from_ty<'a>(ty: Ty<'a>, tcx: TyCtxt<'a>, depth: usize, safety: bool, visited: &mut Vec<Ty<'a>>) -> TypeTree {
if depth > 20 {
dbg!(&ty);
trace!("depth > 20 for ty: {}", &ty);
}
if visited.contains(&ty) {
// recursive type
dbg!("recursive type");
dbg!(&ty);
trace!("recursive type: {}", &ty);
return TypeTree::new();
}
visited.push(ty);
Expand Down Expand Up @@ -2847,7 +2845,6 @@ pub fn typetree_from_ty<'a>(ty: Ty<'a>, tcx: TyCtxt<'a>, depth: usize, safety: b
FieldsShape::Array { .. } => {return TypeTree::new();}, //e.g. core::arch::x86_64::__m128i, TODO: later
FieldsShape::Union(_) => {return TypeTree::new();},
FieldsShape::Primitive => {return TypeTree::new();},
//_ => {dbg!(&adt_def); panic!("")},
};

let substs = match ty.kind() {
Expand Down
8 changes: 3 additions & 5 deletions compiler/rustc_monomorphize/src/partitioning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1174,8 +1174,7 @@ fn collect_and_partition_mono_items(
let target_attrs: &AutoDiffAttrs = tcx.autodiff_attrs(target_id);
let mut input_activities: Vec<DiffActivity> = target_attrs.input_activity.clone();
if target_attrs.is_source() {
dbg!("source");
dbg!(&target_attrs);
trace!("source found: {:?}", target_id);
}
if !target_attrs.apply_autodiff() {
continue;
Expand Down Expand Up @@ -1211,7 +1210,6 @@ fn collect_and_partition_mono_items(
let mut new_target_attrs = target_attrs.clone();
new_target_attrs.input_activity = input_activities;
let itm = new_target_attrs.into_item(symb, target_symbol, inputs, output);
dbg!(&itm);
autodiff_items.push(itm);
};

Expand Down Expand Up @@ -1277,9 +1275,9 @@ fn collect_and_partition_mono_items(
}
}
if autodiff_items.len() > 0 {
println!("AUTODIFF ITEMS EXIST");
trace!("AUTODIFF ITEMS EXIST");
for item in &mut *autodiff_items {
dbg!(&item);
trace!("{}", &item);
}
}

Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2386,7 +2386,6 @@ impl CheckAttrVisitor<'_> {

/// Checks if `#[autodiff]` is applied to an item other than a function item.
fn check_autodiff(&self, _hir_id: HirId, _attr: &Attribute, span: Span, target: Target) {
dbg!("check_autodiff");
match target {
Target::Fn => {}
_ => {
Expand Down

0 comments on commit ca1aa97

Please sign in to comment.