Skip to content

Commit

Permalink
add Enzyme timings to -ftime-trace reports (#1892)
Browse files Browse the repository at this point in the history
* Move preservenvvm to modulepass

* sprinkle some scoped timers around

* two more timers

* remove test trace in NVVM, respond to comments

* clang-format

* fix fmt

* Update ActivityAnalysis.cpp

---------

Co-authored-by: William S. Moses <gh@wsmoses.com>
Co-authored-by: Manuel Drehwald <git@manuel.drehwald.info>
  • Loading branch information
3 people authored May 24, 2024
1 parent 4ee5eb7 commit e99c01e
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 0 deletions.
7 changes: 7 additions & 0 deletions enzyme/Enzyme/ActivityAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

#include "llvm/IR/InstIterator.h"

#include "llvm/Support/TimeProfiler.h"
#include "llvm/Support/raw_ostream.h"

#include "llvm/IR/InlineAsm.h"
Expand Down Expand Up @@ -730,6 +731,10 @@ bool isPossibleFloat(const TypeResults &TR, Value *I, const DataLayout &DL) {
/// do not propagate adjoints themselves
bool ActivityAnalyzer::isConstantInstruction(TypeResults const &TR,
Instruction *I) {

TimeTraceScope timeScope("isConstantInstruction",
I->getParent()->getParent()->getName());

// This analysis may only be called by instructions corresponding to
// the function analyzed by TypeInfo
assert(I);
Expand Down Expand Up @@ -1044,6 +1049,8 @@ bool ActivityAnalyzer::isConstantValue(TypeResults const &TR, Value *Val) {
// This analysis may only be called by instructions corresponding to
// the function analyzed by TypeInfo -- however if the Value
// was created outside a function (e.g. global, constant), that is allowed
TimeTraceScope timeScope("isConstantValue");

assert(Val);
if (auto I = dyn_cast<Instruction>(Val)) {
if (TR.getFunction() != I->getParent()->getParent()) {
Expand Down
2 changes: 2 additions & 0 deletions enzyme/Enzyme/Enzyme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3198,6 +3198,8 @@ class EnzymeBase {
Logic.clear();

if (changed && Logic.PostOpt) {
TimeTraceScope timeScope("Enzyme PostOpt", M.getName());

PassBuilder PB;
LoopAnalysisManager LAM;
FunctionAnalysisManager FAM;
Expand Down
9 changes: 9 additions & 0 deletions enzyme/Enzyme/EnzymeLogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
#include "llvm/Analysis/GlobalsModRef.h"

#include "llvm/Support/AMDGPUMetadata.h"
#include "llvm/Support/TimeProfiler.h"

#include "llvm/ADT/StringSet.h"

Expand Down Expand Up @@ -1976,6 +1977,9 @@ const AugmentedReturn &EnzymeLogic::CreateAugmentedPrimal(
bool shadowReturnUsed, const FnTypeInfo &oldTypeInfo_,
const std::vector<bool> _overwritten_args, bool forceAnonymousTape,
unsigned width, bool AtomicAdd, bool omp) {

TimeTraceScope timeScope("CreateAugmentedPrimal", todiff->getName());

if (returnUsed)
assert(!todiff->getReturnType()->isEmptyTy() &&
!todiff->getReturnType()->isVoidTy());
Expand Down Expand Up @@ -3677,6 +3681,8 @@ Function *EnzymeLogic::CreatePrimalAndGradient(
RequestContext context, const ReverseCacheKey &&key, TypeAnalysis &TA,
const AugmentedReturn *augmenteddata, bool omp) {

TimeTraceScope timeScope("CreatePrimalAndGradient", key.todiff->getName());

assert(key.mode == DerivativeMode::ReverseModeCombined ||
key.mode == DerivativeMode::ReverseModeGradient);

Expand Down Expand Up @@ -4557,6 +4563,9 @@ Function *EnzymeLogic::CreateForwardDiff(
llvm::Type *additionalArg, const FnTypeInfo &oldTypeInfo_,
const std::vector<bool> _overwritten_args,
const AugmentedReturn *augmenteddata, bool omp) {

TimeTraceScope timeScope("CreateForwardDiff", todiff->getName());

assert(retType != DIFFE_TYPE::OUT_DIFF);

assert(mode == DerivativeMode::ForwardMode ||
Expand Down
4 changes: 4 additions & 0 deletions enzyme/Enzyme/FunctionUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@
#include "llvm/Analysis/ScopedNoAliasAA.h"
#include "llvm/Analysis/TargetTransformInfo.h"

#include "llvm/Support/TimeProfiler.h"

#include "llvm/Transforms/IPO/FunctionAttrs.h"
#include "llvm/Transforms/Utils/Mem2Reg.h"

Expand Down Expand Up @@ -1416,6 +1418,8 @@ void SplitPHIs(llvm::Function &F) {
Function *PreProcessCache::preprocessForClone(Function *F,
DerivativeMode mode) {

TimeTraceScope timeScope("preprocessForClone", F->getName());

if (mode == DerivativeMode::ReverseModeGradient)
mode = DerivativeMode::ReverseModePrimal;
if (mode == DerivativeMode::ForwardModeSplit)
Expand Down
3 changes: 3 additions & 0 deletions enzyme/Enzyme/GradientUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8242,6 +8242,9 @@ void GradientUtils::eraseFictiousPHIs() {
}

void GradientUtils::forceActiveDetection() {

TimeTraceScope timeScope("Activity Analysis", oldFunc->getName());

for (auto &Arg : oldFunc->args()) {
ATA->isConstantValue(TR, &Arg);
}
Expand Down
2 changes: 2 additions & 0 deletions enzyme/Enzyme/PreserveNVVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#include "llvm/IR/Module.h"
#include "llvm/Support/raw_ostream.h"

#include "llvm/Support/TimeProfiler.h"

#include "llvm/Pass.h"

#include "llvm/Transforms/Utils.h"
Expand Down
4 changes: 4 additions & 0 deletions enzyme/Enzyme/TypeAnalysis/TypeAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "llvm/IR/InstIterator.h"

#include "llvm/Support/CommandLine.h"
#include "llvm/Support/TimeProfiler.h"
#include "llvm/Support/raw_ostream.h"

#include "llvm/ADT/SmallSet.h"
Expand Down Expand Up @@ -1538,6 +1539,9 @@ void TypeAnalyzer::runPHIHypotheses() {
}

void TypeAnalyzer::run() {

TimeTraceScope timeScope("Type Analysis", fntypeinfo.Function->getName());

// This function runs a full round of type analysis.
// This works by doing two stages of analysis,
// with a "deduced integer types for unused" values
Expand Down

0 comments on commit e99c01e

Please sign in to comment.