Skip to content

Commit

Permalink
Support batching scalar types (#2175) (#2180)
Browse files Browse the repository at this point in the history
* support batching scalar types

* formatting

Co-authored-by: jumerckx <[email protected]>
  • Loading branch information
wsmoses and jumerckx authored Nov 28, 2024
1 parent b59ab66 commit 095ee7e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions enzyme/Enzyme/CallDerivatives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3312,6 +3312,10 @@ bool AdjointGenerator::handleKnownCallDerivatives(
}
#endif
Value *replacement = B.CreateAlloca(elTy, Size);
for (auto MD : {"enzyme_active", "enzyme_inactive", "enzyme_type",
"enzymejl_allocart"})
if (auto M = call.getMetadata(MD))
cast<AllocaInst>(replacement)->setMetadata(MD, M);
if (I)
replacement->takeName(I);
else
Expand Down
3 changes: 2 additions & 1 deletion enzyme/Enzyme/FunctionUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,8 @@ UpgradeAllocasToMallocs(Function *NewF, DerivativeMode mode,
{ConstantAsMetadata::get(ConstantInt::get(
IntegerType::get(AI->getContext(), 64), align))}));

for (auto MD : {"enzyme_active", "enzyme_inactive", "enzyme_type"})
for (auto MD : {"enzyme_active", "enzyme_inactive", "enzyme_type",
"enzymejl_allocart"})
if (auto M = AI->getMetadata(MD))
CI->setMetadata(MD, M);

Expand Down
8 changes: 8 additions & 0 deletions enzyme/Enzyme/GradientUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3280,6 +3280,10 @@ BasicBlock *GradientUtils::prepRematerializedLoopEntry(LoopContext &lc) {
auto replacement = NB.CreateAlloca(
Type::getInt8Ty(I.getContext()),
lookupM(getNewFromOriginal(I.getOperand(0)), NB, available));
for (auto MD : {"enzyme_active", "enzyme_inactive", "enzyme_type",
"enzymejl_allocart"})
if (auto M = I.getMetadata(MD))
replacement->setMetadata(MD, M);
auto Alignment =
cast<ConstantInt>(
cast<ConstantAsMetadata>(MD->getOperand(0))->getValue())
Expand Down Expand Up @@ -3524,6 +3528,10 @@ BasicBlock *GradientUtils::prepRematerializedLoopEntry(LoopContext &lc) {
auto rule = [&](Value *anti) {
AllocaInst *replacement = NB.CreateAlloca(
Type::getInt8Ty(orig->getContext()), args[0]);
for (auto MD : {"enzyme_active", "enzyme_inactive",
"enzyme_type", "enzymejl_allocart"})
if (auto M = I.getMetadata(MD))
replacement->setMetadata(MD, M);
replacement->takeName(anti);
auto Alignment = cast<ConstantInt>(cast<ConstantAsMetadata>(
MD->getOperand(0))
Expand Down

0 comments on commit 095ee7e

Please sign in to comment.