Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cublas return in reverse #1882

Merged
merged 2 commits into from
May 15, 2024
Merged
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
37 changes: 27 additions & 10 deletions enzyme/tools/enzyme-tblgen/blas-tblgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,20 +147,30 @@ void emit_handleBLAS(ArrayRef<TGPattern> blasPatterns, raw_ostream &os) {
<< " return false; \n"
<< " } \n"
<< " } else { \n"
<< " if (gutils->knownRecomputeHeuristic.find(&call) !=\n"
<< " gutils->knownRecomputeHeuristic.end()) {\n"
<< " if (!gutils->knownRecomputeHeuristic[&call]) {\n"
<< " auto found = gutils->knownRecomputeHeuristic.find(&call); \n"
<< " auto end = gutils->knownRecomputeHeuristic.end(); \n"
<< " bool shouldErase = true;\n"
<< " if (found != end) {\n"
<< " if (!found->second) { \n"
<< " auto newCall = gutils->getNewFromOriginal(&call);\n"
<< " llvm::IRBuilder<> BuilderZ(newCall);\n"
<< " gutils->cacheForReverse(BuilderZ, newCall,\n"
<< " getIndex(&call, CacheType::Self, BuilderZ));\n"
<< " shouldErase = false;\n"
<< " }\n"
<< " }\n"
<< " if (Mode == DerivativeMode::ReverseModeGradient) { \n"
<< " eraseIfUnused(call, /*erase*/ true, /*check*/ false); \n"
<< " } else { \n"
<< " eraseIfUnused(call); \n"
<< " } \n"
<< " if (shouldErase) {\n"
<< " if (Mode == DerivativeMode::ReverseModeGradient) { "
"\n"
<< " eraseIfUnused(call, /*erase*/ true, /*check*/ false); "
"\n"
<< " } else { "
"\n"
<< " eraseIfUnused(call); "
"\n"
<< " } "
"\n"
<< " }\n"
<< " }\n"
<< " return result; \n"
<< "} \n";
Expand Down Expand Up @@ -237,8 +247,15 @@ void emit_free_and_ending(const TGPattern &pattern, raw_ostream &os) {

os << " }\n"
<< " }\n"
<< " \n"
<< " if (gutils->knownRecomputeHeuristic.find(&call) !=\n"
<< " \n";

os << " if (cublas && Mode == DerivativeMode::ReverseModeGradient && "
"call.getType()->isIntegerTy()) { \n"
<< " gutils->replaceAWithB(gutils->getNewFromOriginal(&call), "
"Constant::getNullValue(call.getType()));\n"
<< " }\n";

os << " if (gutils->knownRecomputeHeuristic.find(&call) !=\n"
<< " gutils->knownRecomputeHeuristic.end()) {\n"
<< " if (!gutils->knownRecomputeHeuristic[&call]) {\n"
<< " auto cv = gutils->cacheForReverse(BuilderZ, newCall,\n"
Expand Down
Loading