clean up autodiff code/comments
This commit is contained in:
parent
fe90883ef7
commit
f4e2218b13
3 changed files with 6 additions and 12 deletions
|
@ -17,7 +17,6 @@ use crate::{Ty, TyKind};
|
||||||
/// functions. The proper solution is to recognize and resolve this DAG of autodiff invocations,
|
/// functions. The proper solution is to recognize and resolve this DAG of autodiff invocations,
|
||||||
/// as it's already done in the C++ and Julia frontend of Enzyme.
|
/// as it's already done in the C++ and Julia frontend of Enzyme.
|
||||||
///
|
///
|
||||||
/// (FIXME) remove *First variants.
|
|
||||||
/// Documentation for using [reverse](https://enzyme.mit.edu/rust/rev.html) and
|
/// Documentation for using [reverse](https://enzyme.mit.edu/rust/rev.html) and
|
||||||
/// [forward](https://enzyme.mit.edu/rust/fwd.html) mode is available online.
|
/// [forward](https://enzyme.mit.edu/rust/fwd.html) mode is available online.
|
||||||
#[derive(Clone, Copy, Eq, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)]
|
#[derive(Clone, Copy, Eq, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)]
|
||||||
|
|
|
@ -564,19 +564,16 @@ pub(crate) unsafe fn llvm_optimize(
|
||||||
// FIXME(ZuseZ4): In a future update we could figure out how to only optimize individual functions getting
|
// FIXME(ZuseZ4): In a future update we could figure out how to only optimize individual functions getting
|
||||||
// differentiated.
|
// differentiated.
|
||||||
|
|
||||||
|
let consider_ad = cfg!(llvm_enzyme) && config.autodiff.contains(&config::AutoDiff::Enable);
|
||||||
|
let run_enzyme = autodiff_stage == AutodiffStage::DuringAD;
|
||||||
let unroll_loops;
|
let unroll_loops;
|
||||||
let vectorize_slp;
|
let vectorize_slp;
|
||||||
let vectorize_loop;
|
let vectorize_loop;
|
||||||
let run_enzyme = cfg!(llvm_enzyme) && autodiff_stage == AutodiffStage::DuringAD;
|
|
||||||
|
|
||||||
// When we build rustc with enzyme/autodiff support, we want to postpone size-increasing
|
// When we build rustc with enzyme/autodiff support, we want to postpone size-increasing
|
||||||
// optimizations until after differentiation. Our pipeline is thus: (opt + enzyme), (full opt).
|
// optimizations until after differentiation. Our pipeline is thus: (opt + enzyme), (full opt).
|
||||||
// We therefore have two calls to llvm_optimize, if autodiff is used.
|
// We therefore have two calls to llvm_optimize, if autodiff is used.
|
||||||
//
|
if consider_ad && autodiff_stage != AutodiffStage::PostAD {
|
||||||
// FIXME(ZuseZ4): Before shipping on nightly,
|
|
||||||
// we should make this more granular, or at least check that the user has at least one autodiff
|
|
||||||
// call in their code, to justify altering the compilation pipeline.
|
|
||||||
if cfg!(llvm_enzyme) && autodiff_stage != AutodiffStage::PostAD {
|
|
||||||
unroll_loops = false;
|
unroll_loops = false;
|
||||||
vectorize_slp = false;
|
vectorize_slp = false;
|
||||||
vectorize_loop = false;
|
vectorize_loop = false;
|
||||||
|
@ -706,10 +703,8 @@ pub(crate) unsafe fn optimize(
|
||||||
|
|
||||||
// If we know that we will later run AD, then we disable vectorization and loop unrolling.
|
// If we know that we will later run AD, then we disable vectorization and loop unrolling.
|
||||||
// Otherwise we pretend AD is already done and run the normal opt pipeline (=PostAD).
|
// Otherwise we pretend AD is already done and run the normal opt pipeline (=PostAD).
|
||||||
// FIXME(ZuseZ4): Make this more granular, only set PreAD if we actually have autodiff
|
let consider_ad = cfg!(llvm_enzyme) && config.autodiff.contains(&config::AutoDiff::Enable);
|
||||||
// usages, not just if we build rustc with autodiff support.
|
let autodiff_stage = if consider_ad { AutodiffStage::PreAD } else { AutodiffStage::PostAD };
|
||||||
let autodiff_stage =
|
|
||||||
if cfg!(llvm_enzyme) { AutodiffStage::PreAD } else { AutodiffStage::PostAD };
|
|
||||||
return unsafe {
|
return unsafe {
|
||||||
llvm_optimize(cgcx, dcx, module, config, opt_level, opt_stage, autodiff_stage)
|
llvm_optimize(cgcx, dcx, module, config, opt_level, opt_stage, autodiff_stage)
|
||||||
};
|
};
|
||||||
|
|
|
@ -66,7 +66,7 @@ pub(crate) fn find_autodiff_source_functions<'tcx>(
|
||||||
let mut autodiff_items: Vec<AutoDiffItem> = vec![];
|
let mut autodiff_items: Vec<AutoDiffItem> = vec![];
|
||||||
for (item, instance) in autodiff_mono_items {
|
for (item, instance) in autodiff_mono_items {
|
||||||
let target_id = instance.def_id();
|
let target_id = instance.def_id();
|
||||||
let cg_fn_attr = tcx.codegen_fn_attrs(target_id).autodiff_item.clone();
|
let cg_fn_attr = &tcx.codegen_fn_attrs(target_id).autodiff_item;
|
||||||
let Some(target_attrs) = cg_fn_attr else {
|
let Some(target_attrs) = cg_fn_attr else {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue