Skip to content

Commit

Permalink
Fix julia build
Browse files Browse the repository at this point in the history
  • Loading branch information
wsmoses committed Nov 9, 2019
1 parent 8ccc64b commit ddf496e
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 19 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/julia.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,5 @@ jobs:
ENZYME_PATH: "../Enzyme/build/Enzyme"
- name: "Check Enzyme"
run: |
cd build
make check-enzyme
#cd build
#make check-enzyme
26 changes: 17 additions & 9 deletions enzyme/Enzyme/EnzymeLogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ cl::opt<bool> cache_reads_never(
"enzyme_never_cache_reads", cl::init(false), cl::Hidden,
cl::desc("Force never caching of all reads"));

cl::opt<bool> nonmarkedglobals_inactiveloads(
"enzyme_nonmarkedglobals_inactiveloads", cl::init(true), cl::Hidden,
cl::desc("Consider loads of nonmarked globals to be inactive"));


// Computes a map of LoadInst -> boolean for a function indicating whether that load is "uncacheable".
Expand Down Expand Up @@ -200,7 +203,7 @@ std::set<unsigned> compute_uncacheable_args_for_one_callsite(Instruction* callsi
// "inst" happens before "callsite_inst". If "inst" modifies an argument of the call,
// then that call needs to consider the argument uncacheable.
// To correctly handle case where inst == callsite_inst, we need to look at next instruction after callsite_inst.
if (!gutils->DT.dominates(inst, callsite_inst->getNextNonDebugInstruction())) {
if (!gutils->DT.dominates(inst, callsite_inst->getNextNode())) {
//llvm::errs() << "Instruction " << *inst << " DOES NOT dominates " << *callsite_inst << "\n";
// Consider Store Instructions.
if (auto op = dyn_cast<StoreInst>(inst)) {
Expand Down Expand Up @@ -2386,6 +2389,7 @@ Function* CreatePrimalAndGradient(Function* todiff, const std::set<unsigned>& co

auto op_operand = op->getPointerOperand();
auto op_type = op->getType();


if (can_modref_map[inst]) {
IRBuilder<> BuilderZ(op->getNextNode());
Expand All @@ -2400,19 +2404,23 @@ Function* CreatePrimalAndGradient(Function* todiff, const std::set<unsigned>& co
}
}

// TODO IF OP IS POINTER
if (nonmarkedglobals_inactiveloads) {
//Assume that non enzyme_shadow globals are inactive
// If we ever store to a global variable, we will error if it doesn't have a shadow
// This allows functions who only read global memory to have their derivative computed
// Note that this is too aggressive for general programs as if the global aliases with an argument something that is written to, then we will have a logical error
if (auto arg = dyn_cast<GlobalVariable>(op_operand)) {
if (!hasMetadata(arg, "enzyme_shadow")) {
continue;
}
}
}

if (!op_type->isPointerTy()) {
auto prediff = diffe(inst);
setDiffe(inst, Constant::getNullValue(op_type));
gutils->addToPtrDiffe(op_operand, prediff, Builder2);
} else {
//Builder2.CreateStore(diffe(inst), invertPointer(op->getOperand(0)));//, op->getName()+"'psweird");
//addToNPtrDiffe(op->getOperand(0), diffe(inst));
//assert(0 && "cannot handle non const pointer load inversion");
//assert(op);
//llvm::errs() << "ignoring load bc pointer of " << *op << "\n";
}

} else if(auto op = dyn_cast<StoreInst>(inst)) {
if (gutils->isConstantInstruction(inst)) continue;

Expand Down
9 changes: 7 additions & 2 deletions enzyme/Enzyme/FunctionUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,12 +466,17 @@ Function* preprocessForClone(Function *F, AAResults &AA, TargetLibraryInfo &TLI)
AssumptionCache* AC = new AssumptionCache(*NewF);
TargetLibraryInfo* TLI = new TargetLibraryInfo(AM.getResult<TargetLibraryAnalysis>(*NewF));
auto baa = new BasicAAResult(NewF->getParent()->getDataLayout(),
#if LLVM_VERSION_MAJOR > 6
*NewF,
#endif
*TLI,
*AC,
&AM.getResult<DominatorTreeAnalysis>(*NewF),
AM.getCachedResult<LoopAnalysis>(*NewF),
AM.getCachedResult<PhiValuesAnalysis>(*NewF));
AM.getCachedResult<LoopAnalysis>(*NewF)
#if LLVM_VERSION_MAJOR > 6
,AM.getCachedResult<PhiValuesAnalysis>(*NewF)
#endif
);
cache_AA[F] = baa;
AA.addAAResult(*baa);
//ScopedNoAliasAA sa;
Expand Down
2 changes: 2 additions & 0 deletions enzyme/Enzyme/GradientUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,12 +336,14 @@ Value* GradientUtils::invertPointerM(Value* val, IRBuilder<>& BuilderM) {
if (auto arg = dyn_cast<GlobalVariable>(val)) {
if (!hasMetadata(arg, "enzyme_shadow")) {
llvm::errs() << *arg << "\n";
assert(0 && "cannot compute with global variable that doesn't have marked shadow global");
report_fatal_error("cannot compute with global variable that doesn't have marked shadow global");
}
auto md = arg->getMetadata("enzyme_shadow");
if (!isa<MDTuple>(md)) {
llvm::errs() << *arg << "\n";
llvm::errs() << *md << "\n";
assert(0 && "cannot compute with global variable that doesn't have marked shadow global");
report_fatal_error("cannot compute with global variable that doesn't have marked shadow global (metadata incorrect type)");
}
auto md2 = cast<MDTuple>(md);
Expand Down
6 changes: 0 additions & 6 deletions enzyme/Enzyme/GradientUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,6 @@ class GradientUtils {
IRBuilder<> entryBuilder(inversionAllocs);
entryBuilder.setFastMathFlags(getFast());
AllocaInst* alloc = entryBuilder.CreateAlloca(types.back(), nullptr, name+"_cache");
llvm::errs() << "alloc: "<< *alloc << "\n";

Type *BPTy = Type::getInt8PtrTy(ctx->getContext());
auto realloc = newFunc->getParent()->getOrInsertFunction("realloc", BPTy, BPTy, Type::getInt64Ty(ctx->getContext()));
Expand Down Expand Up @@ -1027,8 +1026,6 @@ class GradientUtils {
//cast<Instruction>(firstallocation)->moveBefore(allocationBuilder.GetInsertBlock()->getTerminator());
//mallocs.push_back(firstallocation);
} else {
llvm::errs() << "storeInto: " << *storeInto << "\n";
llvm::errs() << "myType: " << *myType << "\n";
allocationBuilder.CreateStore(ConstantPointerNull::get(PointerType::getUnqual(myType)), storeInto);

IRBuilder <> build(containedloops.back().first.header->getFirstNonPHI());
Expand Down Expand Up @@ -1112,7 +1109,6 @@ class GradientUtils {
indices.push_back(idx.var);
available[idx.var] = idx.var;
}
llvm::errs() << "W sl idx=" << i << " " << *idx.var << " header=" << idx.header->getName() << "\n";

Value* lim = unwrapM(riter->second, BuilderM, available, /*lookupIfAble*/true);
assert(lim);
Expand All @@ -1124,10 +1120,8 @@ class GradientUtils {
}

if (indices.size() > 0) {
llvm::errs() << "sl idx=" << i << " " << *indices[0] << "\n";
Value* idx = indices[0];
for(unsigned ind=1; ind<indices.size(); ind++) {
llvm::errs() << "sl idx=" << i << " " << *indices[ind] << "\n";
idx = BuilderM.CreateNUWAdd(idx, BuilderM.CreateNUWMul(indices[ind], limits[ind-1]));
}
next = BuilderM.CreateGEP(next, {idx});
Expand Down

0 comments on commit ddf496e

Please sign in to comment.