Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions enzyme/Enzyme/DiffeGradientUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,26 @@

using namespace llvm;

namespace {
bool noAtomicsForContext(const Instruction *orig, const Value *origptr) {
if (orig) {
if (const Function *F = orig->getFunction()) {
if (F->hasFnAttribute("enzyme_noatomic")) {
return true;
}
}
}
const Value *base = getBaseObject(origptr);
if (auto *arg = dyn_cast<Argument>(base)) {
if (const Function *F = arg->getParent()) {
return F->getAttributes().hasParamAttr(arg->getArgNo(),
"enzyme_noatomic");
}
}
return false;
}
} // namespace

DiffeGradientUtils::DiffeGradientUtils(
EnzymeLogic &Logic, Function *newFunc_, Function *oldFunc_,
TargetLibraryInfo &TLI, TypeAnalysis &TA, TypeResults TR,
Expand Down Expand Up @@ -918,6 +938,8 @@ void DiffeGradientUtils::addToInvertedPtrDiffe(Instruction *orig,
// all additional parallelism in this function is outlined.
if (backwardsOnlyShadows.find(TmpOrig) != backwardsOnlyShadows.end())
Atomic = false;
if (Atomic && noAtomicsForContext(orig, origptr))
Atomic = false;

if (Atomic) {
// For amdgcn constant AS is 4 and if the primal is in it we need to cast
Expand Down
9 changes: 9 additions & 0 deletions enzyme/Enzyme/PreserveNVVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,15 @@ bool preserveNVVM(bool Begin, Module &M) {
continue;
}

if (AS == "enzyme_noatomic" && Func) {
Func->addAttribute(
AttributeList::FunctionIndex,
Attribute::get(Func->getContext(), "enzyme_noatomic"));
changed = true;
replacements.push_back(Constant::getNullValue(CAOp->getType()));
continue;
}

if (AS == "enzyme_shouldrecompute" && Func) {
Func->addAttribute(
AttributeList::FunctionIndex,
Expand Down