Skip to content

Commit

Permalink
Test assert-less build
Browse files Browse the repository at this point in the history
  • Loading branch information
wsmoses committed Feb 19, 2024
1 parent cc7ef6f commit d00860f
Show file tree
Hide file tree
Showing 21 changed files with 84 additions and 18 deletions.
2 changes: 1 addition & 1 deletion enzyme/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ add_definitions(-DENZYME_VERSION_MINOR=${ENZYME_MINOR_VERSION})
add_definitions(-DENZYME_VERSION_PATCH=${ENZYME_PATCH_VERSION})

set(CMAKE_POSITION_INDEPENDENT_CODE ON)
SET(CMAKE_CXX_FLAGS "-Wall -fno-rtti ${CMAKE_CXX_FLAGS} -Werror=unused-variable -Werror=dangling-else")
SET(CMAKE_CXX_FLAGS "-Wall -fno-rtti ${CMAKE_CXX_FLAGS} -Werror=unused-variable -Werror=dangling-else -Werror=unused-but-set-variable -Werror=return-type -Werror=nonnull")
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g -ggdb")
SET(CMAKE_CXX_FLAGS_RELEASE "-O2")

Expand Down
7 changes: 5 additions & 2 deletions enzyme/Enzyme/ActivityAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1049,9 +1049,11 @@ bool ActivityAnalyzer::isConstantValue(TypeResults const &TR, Value *Val) {
}
assert(TR.getFunction() == I->getParent()->getParent());
}
#ifndef NDEBUG
if (auto Arg = dyn_cast<Argument>(Val)) {
assert(TR.getFunction() == Arg->getParent());
}
#endif

// Void values are definitionally inactive
if (Val->getType()->isVoidTy())
Expand Down Expand Up @@ -2305,6 +2307,9 @@ bool ActivityAnalyzer::isConstantValue(TypeResults const &TR, Value *Val) {
// this value is inactive, we are inactive Since we won't look at uses to
// prove, we can inductively assume this is inactive
if (directions & UP) {
if (!UpHypothesis)
UpHypothesis =
std::shared_ptr<ActivityAnalyzer>(new ActivityAnalyzer(*this, UP));
if (directions == UP && !isa<PHINode>(Val)) {
if (isInstructionInactiveFromOrigin(TR, Val, true)) {
InsertConstantValue(TR, Val);
Expand All @@ -2320,8 +2325,6 @@ bool ActivityAnalyzer::isConstantValue(TypeResults const &TR, Value *Val) {
}
}
} else {
UpHypothesis =
std::shared_ptr<ActivityAnalyzer>(new ActivityAnalyzer(*this, UP));
UpHypothesis->ConstantValues.insert(Val);
if (UpHypothesis->isInstructionInactiveFromOrigin(TR, Val, true)) {
insertConstantsFrom(TR, *UpHypothesis);
Expand Down
4 changes: 4 additions & 0 deletions enzyme/Enzyme/AdjointGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ class AdjointGenerator : public llvm::InstVisitor<AdjointGenerator> {
constantval |= gutils->isConstantValue(&I);

Type *type = gutils->getShadowType(I.getType());
(void)type;

auto *newi = dyn_cast<Instruction>(gutils->getNewFromOriginal(&I));

Expand Down Expand Up @@ -621,6 +622,7 @@ class AdjointGenerator : public llvm::InstVisitor<AdjointGenerator> {
if (primalNeededInReverse) {
inst = gutils->cacheForReverse(BuilderZ, newi,
getIndex(&I, CacheType::Self, BuilderZ));
(void)inst;
assert(inst->getType() == type);

if (Mode == DerivativeMode::ReverseModeGradient ||
Expand Down Expand Up @@ -3777,6 +3779,7 @@ class AdjointGenerator : public llvm::InstVisitor<AdjointGenerator> {
setDiffe(&I, Constant::getNullValue(gutils->getShadowType(I.getType())),
Builder2);
}
(void)vdiff;

switch (ID) {

Expand Down Expand Up @@ -5201,6 +5204,7 @@ class AdjointGenerator : public llvm::InstVisitor<AdjointGenerator> {

// Note sometimes whattype mistakenly says something should be
// constant [because composed of integer pointers alone]
(void)argType;
assert(whatType(argType, Mode) == DIFFE_TYPE::DUP_ARG ||
whatType(argType, Mode) == DIFFE_TYPE::CONSTANT);
} else {
Expand Down
2 changes: 2 additions & 0 deletions enzyme/Enzyme/CApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1184,6 +1184,7 @@ LLVMValueRef EnzymeCloneFunctionWithoutReturnOrArgs(LLVMValueRef FC,
for (auto s : sub) {
uint64_t ival;
bool b = s.getAsInteger(10, ival);
(void)b;
assert(!b);
previdx.push_back(ival);
}
Expand Down Expand Up @@ -1241,6 +1242,7 @@ LLVMValueRef EnzymeComputeByteOffsetOfGEP(LLVMBuilderRef B_r, LLVMValueRef V_r,
APInt Offset(width, 0);
bool success =
collectOffset(cast<GEPOperator>(gep), DL, width, VariableOffsets, Offset);
(void)success;
assert(success);
Value *start = ConstantInt::get(T, Offset);
for (auto &pair : VariableOffsets)
Expand Down
3 changes: 3 additions & 0 deletions enzyme/Enzyme/CacheUtility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ std::pair<PHINode *, Instruction *> FindCanonicalIV(Loop *L, Type *Ty) {
}
llvm::errs() << *Header << "\n";
assert(0 && "Could not find canonical IV");
return std::pair<PHINode *, Instruction *>(nullptr, nullptr);
}

// Attempt to rewrite all phinode's in the loop in terms of the
Expand Down Expand Up @@ -1330,8 +1331,10 @@ void CacheUtility::storeInstructionInCache(LimitContext ctx,
IRBuilder<> &BuilderM, Value *val,
AllocaInst *cache, MDNode *TBAA) {
assert(BuilderM.GetInsertBlock()->getParent() == newFunc);
#ifndef NDEBUG
if (auto inst = dyn_cast<Instruction>(val))
assert(inst->getParent()->getParent() == newFunc);
#endif
IRBuilder<> v(BuilderM.GetInsertBlock());
v.SetInsertPoint(BuilderM.GetInsertBlock(), BuilderM.GetInsertPoint());
v.setFastMathFlags(getFast());
Expand Down
1 change: 1 addition & 0 deletions enzyme/Enzyme/CallDerivatives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4047,6 +4047,7 @@ bool AdjointGenerator::handleKnownCallDerivatives(
return true;
}
assert(!unnecessaryValues.count(rmat.first));
(void)primalNeededInReverse;
assert(primalNeededInReverse);
}
}
Expand Down
4 changes: 2 additions & 2 deletions enzyme/Enzyme/Clang/EnzymeClang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@ class EnzymePlugin final : public clang::ASTConsumer {
using namespace clang;
DeclGroupRef::iterator it;

Visitor v(CI);
// Visitor v(CI);
// Forcibly require emission of all libdevice
for (it = dg.begin(); it != dg.end(); ++it) {
v.TraverseDecl(*it);
// v.TraverseDecl(*it);
if (auto FD = dyn_cast<FunctionDecl>(*it)) {
if (!FD->hasAttr<clang::CUDADeviceAttr>())
continue;
Expand Down
9 changes: 9 additions & 0 deletions enzyme/Enzyme/DiffeGradientUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,12 @@ DiffeGradientUtils *DiffeGradientUtils::CreateFromClone(

AllocaInst *DiffeGradientUtils::getDifferential(Value *val) {
assert(val);
#ifndef NDEBUG
if (auto arg = dyn_cast<Argument>(val))
assert(arg->getParent() == oldFunc);
if (auto inst = dyn_cast<Instruction>(val))
assert(inst->getParent()->getParent() == oldFunc);
#endif
assert(inversionAllocs);

Type *type = getShadowType(val->getType());
Expand Down Expand Up @@ -195,10 +197,12 @@ AllocaInst *DiffeGradientUtils::getDifferential(Value *val) {
}

Value *DiffeGradientUtils::diffe(Value *val, IRBuilder<> &BuilderM) {
#ifndef NDEBUG
if (auto arg = dyn_cast<Argument>(val))
assert(arg->getParent() == oldFunc);
if (auto inst = dyn_cast<Instruction>(val))
assert(inst->getParent()->getParent() == oldFunc);
#endif

if (isConstantValue(val)) {
llvm::errs() << *newFunc << "\n";
Expand Down Expand Up @@ -336,6 +340,7 @@ DiffeGradientUtils::addToDiffe(Value *val, Value *dif, IRBuilder<> &BuilderM,
llvm::errs() << "} start=" << start << " size=" << size
<< " storeSize=" << storeSize << " val=" << *val << "\n";
assert(0 && "unhandled accumulate with partial sizes");
return {};
}

SmallVector<SelectInst *, 4>
Expand All @@ -345,10 +350,12 @@ DiffeGradientUtils::addToDiffe(Value *val, Value *dif, IRBuilder<> &BuilderM,
assert(mode == DerivativeMode::ReverseModeGradient ||
mode == DerivativeMode::ReverseModeCombined);

#ifndef NDEBUG
if (auto arg = dyn_cast<Argument>(val))
assert(arg->getParent() == oldFunc);
if (auto inst = dyn_cast<Instruction>(val))
assert(inst->getParent()->getParent() == oldFunc);
#endif

SmallVector<SelectInst *, 4> addedSelects;

Expand Down Expand Up @@ -659,6 +666,7 @@ DiffeGradientUtils::addToDiffe(Value *val, Value *dif, IRBuilder<> &BuilderM,

void DiffeGradientUtils::setDiffe(Value *val, Value *toset,
IRBuilder<> &BuilderM) {
#ifndef NDEBUG
if (auto arg = dyn_cast<Argument>(val))
assert(arg->getParent() == oldFunc);
if (auto inst = dyn_cast<Instruction>(val))
Expand All @@ -668,6 +676,7 @@ void DiffeGradientUtils::setDiffe(Value *val, Value *toset,
llvm::errs() << *val << "\n";
}
assert(!isConstantValue(val));
#endif
toset = SanitizeDerivatives(val, toset, BuilderM);
if (mode == DerivativeMode::ForwardMode ||
mode == DerivativeMode::ForwardModeSplit) {
Expand Down
7 changes: 5 additions & 2 deletions enzyme/Enzyme/DifferentialUseAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ bool DifferentialUseAnalysis::is_use_directly_needed_in_reverse(
const SmallPtrSetImpl<BasicBlock *> &oldUnreachable, QueryType qtype,
bool *recursiveUse) {
TypeResults const &TR = gutils->TR;
#ifndef NDEBUG
if (auto ainst = dyn_cast<Instruction>(val)) {
assert(ainst->getParent()->getParent() == gutils->oldFunc);
}
#endif

bool shadow =
qtype == QueryType::Shadow || qtype == QueryType::ShadowByConstPrimal;
Expand All @@ -79,8 +81,7 @@ bool DifferentialUseAnalysis::is_use_directly_needed_in_reverse(

if (!user) {
if (EnzymePrintDiffUse)
llvm::errs() << " Need: of " << *val << " in reverse as unknown user "
<< *user << "\n";
llvm::errs() << " Need: of " << *val << " in reverse as nullptr user\n";
return true;
}

Expand Down Expand Up @@ -794,12 +795,14 @@ void DifferentialUseAnalysis::minCut(const DataLayout &DL, LoopInfo &OrigLI,
}
}
}
#ifndef NDEBUG
for (auto R : Required) {
assert(Intermediates.count(R));
}
for (auto R : Recomputes) {
assert(Intermediates.count(R));
}
#endif

Graph Orig = G;

Expand Down
2 changes: 2 additions & 0 deletions enzyme/Enzyme/EnzymeLogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3632,13 +3632,15 @@ Function *EnzymeLogic::CreatePrimalAndGradient(

if (hasMetadata(key.todiff, "enzyme_gradient")) {
std::set<llvm::Type *> seen;
#ifndef NDEBUG
DIFFE_TYPE subretType = whatType(key.todiff->getReturnType(),
DerivativeMode::ReverseModeGradient,
/*intAreConstant*/ false, seen);
if (key.todiff->getReturnType()->isVoidTy() ||
key.todiff->getReturnType()->isEmptyTy())
subretType = DIFFE_TYPE::CONSTANT;
assert(subretType == key.retType);
#endif

if (key.mode == DerivativeMode::ReverseModeCombined) {
auto res = getDefaultFunctionTypeForGradient(
Expand Down
2 changes: 2 additions & 0 deletions enzyme/Enzyme/FunctionUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6295,6 +6295,7 @@ class Constraints : public std::enable_shared_from_this<Constraints> {
assert(t != Type::None);
assert(c.size() != 0);
assert(c.size() != 1);
#ifndef NDEBUG
SmallVector<InnerTy, 1> tmp(c.begin(), c.end());
for (unsigned i = 0; i < tmp.size(); i++)
for (unsigned j = 0; j < i; j++)
Expand All @@ -6317,6 +6318,7 @@ class Constraints : public std::enable_shared_from_this<Constraints> {
if (auto s = dyn_cast<SCEVAddRecExpr>(tmp[j]->node))
assert(s->getLoop() != tmp[i]->Loop);
}
#endif
}

bool operator==(const Constraints &rhs) const {
Expand Down
Loading

0 comments on commit d00860f

Please sign in to comment.