From 1f89a60a1502586c0cb8c6ae608e39675c7a857c Mon Sep 17 00:00:00 2001 From: Manuel Drehwald Date: Sat, 30 Mar 2024 22:59:33 -0400 Subject: [PATCH 1/3] update enzyme --- src/tools/enzyme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/enzyme b/src/tools/enzyme index 7e3e90f428706..328332fe1c3c9 160000 --- a/src/tools/enzyme +++ b/src/tools/enzyme @@ -1 +1 @@ -Subproject commit 7e3e90f4287068a41d3fb5a99127ee2857353b04 +Subproject commit 328332fe1c3c99a60445c13feee566c61b724999 From 432e4f3b699d27421fb7e2be7bc7faf81ca862fb Mon Sep 17 00:00:00 2001 From: Manuel Drehwald Date: Sun, 31 Mar 2024 00:15:49 -0400 Subject: [PATCH 2/3] update enzyme --- src/tools/enzyme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/enzyme b/src/tools/enzyme index 328332fe1c3c9..0bf10624447d0 160000 --- a/src/tools/enzyme +++ b/src/tools/enzyme @@ -1 +1 @@ -Subproject commit 328332fe1c3c99a60445c13feee566c61b724999 +Subproject commit 0bf10624447d0f68eb537cc111a13f48f464f2e1 From 5668afae540e4b2693e4b8e1f05de8133f7085d4 Mon Sep 17 00:00:00 2001 From: Manuel Drehwald Date: Sun, 31 Mar 2024 11:08:58 -0400 Subject: [PATCH 3/3] move from dbg to trace --- .../rustc_ast/src/expand/autodiff_attrs.rs | 17 +++++++++---- compiler/rustc_codegen_llvm/src/back/write.rs | 20 ++++------------ compiler/rustc_codegen_llvm/src/builder.rs | 1 - compiler/rustc_codegen_llvm/src/llvm/ffi.rs | 24 +++++++++++++------ compiler/rustc_middle/src/ty/mod.rs | 9 +++---- .../rustc_monomorphize/src/partitioning.rs | 8 +++---- compiler/rustc_passes/src/check_attr.rs | 1 - 7 files changed, 41 insertions(+), 39 deletions(-) diff --git a/compiler/rustc_ast/src/expand/autodiff_attrs.rs b/compiler/rustc_ast/src/expand/autodiff_attrs.rs index 9cee364543af7..5855fc845520e 100644 --- a/compiler/rustc_ast/src/expand/autodiff_attrs.rs +++ b/compiler/rustc_ast/src/expand/autodiff_attrs.rs @@ -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}; @@ -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"), @@ -209,7 +209,6 @@ impl AutoDiffAttrs { DiffMode::Inactive => false, DiffMode::Source => false, _ => { - dbg!(&self); true } } @@ -222,7 +221,6 @@ impl AutoDiffAttrs { inputs: Vec, output: TypeTree, ) -> AutoDiffItem { - dbg!(&self); AutoDiffItem { source, target, inputs, output, attrs: self } } } @@ -235,3 +233,14 @@ pub struct AutoDiffItem { pub inputs: Vec, 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) + } +} + + diff --git a/compiler/rustc_codegen_llvm/src/back/write.rs b/compiler/rustc_codegen_llvm/src/back/write.rs index d916cfb7d8291..ec31d9dc0b7cd 100644 --- a/compiler/rustc_codegen_llvm/src/back/write.rs +++ b/compiler/rustc_codegen_llvm/src/back/write.rs @@ -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); @@ -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. @@ -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); @@ -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); } @@ -944,7 +932,9 @@ pub(crate) unsafe fn differentiate( _typetrees: FxHashMap, _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; diff --git a/compiler/rustc_codegen_llvm/src/builder.rs b/compiler/rustc_codegen_llvm/src/builder.rs index 3a82a40fa1035..f7afe9cbefb7a 100644 --- a/compiler/rustc_codegen_llvm/src/builder.rs +++ b/compiler/rustc_codegen_llvm/src/builder.rs @@ -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); } diff --git a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs index b490dd40302df..a3a89f7854f36 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs +++ b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs @@ -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); @@ -938,8 +937,6 @@ pub(crate) unsafe fn enzyme_rust_reverse_diff( let input_activity: Vec = input_activity.iter().map(|&x| cdiffe_from(x)).collect(); - dbg!(&fnc); - let mut args_tree = input_tts.iter().map(|x| x.inner).collect::>(); // We don't support volatile / extern / (global?) values. @@ -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(), @@ -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 } @@ -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, diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 3cfb7550b5a62..91f9b6846cff7 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -2741,7 +2741,6 @@ pub fn fnc_typetrees<'tcx>(tcx: TyCtxt<'tcx>, fn_ty: Ty<'tcx>, da: &mut Vec(tcx: TyCtxt<'tcx>, fn_ty: Ty<'tcx>, da: &mut Vec(tcx: TyCtxt<'tcx>, fn_ty: Ty<'tcx>, da: &mut Vec(ty: Ty<'a>, tcx: TyCtxt<'a>, depth: usize, safety: bool, visited: &mut Vec>) -> 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); @@ -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() { diff --git a/compiler/rustc_monomorphize/src/partitioning.rs b/compiler/rustc_monomorphize/src/partitioning.rs index 6ab79c969291a..0c3d8a64ea317 100644 --- a/compiler/rustc_monomorphize/src/partitioning.rs +++ b/compiler/rustc_monomorphize/src/partitioning.rs @@ -1174,8 +1174,7 @@ fn collect_and_partition_mono_items( let target_attrs: &AutoDiffAttrs = tcx.autodiff_attrs(target_id); let mut input_activities: Vec = 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; @@ -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); }; @@ -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); } } diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index 5e6c3ca9963d4..64243a4c438eb 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -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 => {} _ => {