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 MPI Reduce bug #1025

Merged
merged 2 commits into from
Mar 11, 2023
Merged
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
2 changes: 1 addition & 1 deletion enzyme/Enzyme/AdjointGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -7725,7 +7725,7 @@ class AdjointGenerator
if (!forwardMode)
root = lookup(root, Builder2);

Value *comm = lookup(gutils->getNewFromOriginal(orig_comm), Builder2);
Value *comm = gutils->getNewFromOriginal(orig_comm);
if (!forwardMode)
comm = lookup(comm, Builder2);

Expand Down
68 changes: 60 additions & 8 deletions enzyme/Enzyme/TypeAnalysis/TypeAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3822,6 +3822,13 @@ void TypeAnalyzer::visitCallInst(CallInst &call) {
} else if (GV->getName() == "ompi_mpi_float") {
buf.insert({0}, Type::getFloatTy(C->getContext()));
}
} else if (auto CI = dyn_cast<ConstantInt>(C)) {
// MPICH
if (CI->getValue() == 1275070475) {
buf.insert({0}, Type::getDoubleTy(C->getContext()));
} else if (CI->getValue() == 1275069450) {
buf.insert({0}, Type::getFloatTy(C->getContext()));
}
}
}
updateAnalysis(call.getOperand(0), buf.Only(-1, &call), &call);
Expand All @@ -3847,6 +3854,13 @@ void TypeAnalyzer::visitCallInst(CallInst &call) {
} else if (GV->getName() == "ompi_mpi_float") {
buf.insert({0}, Type::getFloatTy(C->getContext()));
}
} else if (auto CI = dyn_cast<ConstantInt>(C)) {
// MPICH
if (CI->getValue() == 1275070475) {
buf.insert({0}, Type::getDoubleTy(C->getContext()));
} else if (CI->getValue() == 1275069450) {
buf.insert({0}, Type::getFloatTy(C->getContext()));
}
}
}
updateAnalysis(call.getOperand(0), buf.Only(-1, &call), &call);
Expand Down Expand Up @@ -3902,15 +3916,34 @@ void TypeAnalyzer::visitCallInst(CallInst &call) {
return;
}
if (funcName == "MPI_Reduce" || funcName == "PMPI_Reduce") {
TypeTree buf = TypeTree(BaseType::Pointer);

if (Constant *C = dyn_cast<Constant>(call.getOperand(3))) {
while (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
C = CE->getOperand(0);
}
if (auto GV = dyn_cast<GlobalVariable>(C)) {
if (GV->getName() == "ompi_mpi_double") {
buf.insert({0}, Type::getDoubleTy(C->getContext()));
} else if (GV->getName() == "ompi_mpi_float") {
buf.insert({0}, Type::getFloatTy(C->getContext()));
}
} else if (auto CI = dyn_cast<ConstantInt>(C)) {
// MPICH
if (CI->getValue() == 1275070475) {
buf.insert({0}, Type::getDoubleTy(C->getContext()));
} else if (CI->getValue() == 1275069450) {
buf.insert({0}, Type::getFloatTy(C->getContext()));
}
}
}
// int MPI_Reduce(const void *sendbuf, void *recvbuf, int count,
// MPI_Datatype datatype,
// MPI_Op op, int root, MPI_Comm comm)
// sendbuf
updateAnalysis(call.getOperand(0),
TypeTree(BaseType::Pointer).Only(-1, &call), &call);
updateAnalysis(call.getOperand(0), buf.Only(-1, &call), &call);
// recvbuf
updateAnalysis(call.getOperand(1),
TypeTree(BaseType::Pointer).Only(-1, &call), &call);
updateAnalysis(call.getOperand(1), buf.Only(-1, &call), &call);
// count
updateAnalysis(call.getOperand(2),
TypeTree(BaseType::Integer).Only(-1, &call), &call);
Expand All @@ -3922,14 +3955,33 @@ void TypeAnalyzer::visitCallInst(CallInst &call) {
return;
}
if (funcName == "MPI_Allreduce") {
TypeTree buf = TypeTree(BaseType::Pointer);

if (Constant *C = dyn_cast<Constant>(call.getOperand(3))) {
while (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
C = CE->getOperand(0);
}
if (auto GV = dyn_cast<GlobalVariable>(C)) {
if (GV->getName() == "ompi_mpi_double") {
buf.insert({0}, Type::getDoubleTy(C->getContext()));
} else if (GV->getName() == "ompi_mpi_float") {
buf.insert({0}, Type::getFloatTy(C->getContext()));
}
} else if (auto CI = dyn_cast<ConstantInt>(C)) {
// MPICH
if (CI->getValue() == 1275070475) {
buf.insert({0}, Type::getDoubleTy(C->getContext()));
} else if (CI->getValue() == 1275069450) {
buf.insert({0}, Type::getFloatTy(C->getContext()));
}
}
}
// int MPI_Allreduce(const void *sendbuf, void *recvbuf, int count,
// MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
// sendbuf
updateAnalysis(call.getOperand(0),
TypeTree(BaseType::Pointer).Only(-1, &call), &call);
updateAnalysis(call.getOperand(0), buf.Only(-1, &call), &call);
// recvbuf
updateAnalysis(call.getOperand(1),
TypeTree(BaseType::Pointer).Only(-1, &call), &call);
updateAnalysis(call.getOperand(1), buf.Only(-1, &call), &call);
// count
updateAnalysis(call.getOperand(2),
TypeTree(BaseType::Integer).Only(-1, &call), &call);
Expand Down