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

Mark mpi functions of booleans as inactive #1464

Merged
merged 1 commit into from
Oct 6, 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
37 changes: 37 additions & 0 deletions enzyme/Enzyme/Enzyme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,43 @@ void attributeKnownFunctions(llvm::Function &F) {
F.addParamAttr(2, Attribute::WriteOnly);
F.addParamAttr(2, Attribute::NoCapture);
}
// Map of MPI function name to the arg index of its type argument
std::map<std::string, int> MPI_TYPE_ARGS = {
{"MPI_Send", 2}, {"MPI_Ssend", 2}, {"MPI_Bsend", 2},
{"MPI_Recv", 2}, {"MPI_Brecv", 2}, {"PMPI_Send", 2},
{"PMPI_Ssend", 2}, {"PMPI_Bsend", 2}, {"PMPI_Recv", 2},
{"PMPI_Brecv", 2},

{"MPI_Isend", 2}, {"MPI_Irecv", 2}, {"PMPI_Isend", 2},
{"PMPI_Irecv", 2},

{"MPI_Reduce", 3}, {"PMPI_Reduce", 3},

{"MPI_Allreduce", 3}, {"PMPI_Allreduce", 3}};
{
auto found = MPI_TYPE_ARGS.find(F.getName().str());
if (found != MPI_TYPE_ARGS.end()) {
for (auto user : F.users()) {
if (auto CI = dyn_cast<CallBase>(user))
if (CI->getCalledFunction() == &F) {
if (Constant *C =
dyn_cast<Constant>(CI->getArgOperand(found->second))) {
while (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
C = CE->getOperand(0);
}
if (auto GV = dyn_cast<GlobalVariable>(C)) {
if (GV->getName() == "ompi_mpi_cxx_bool") {
CI->addAttribute(
AttributeList::FunctionIndex,
Attribute::get(CI->getContext(), "enzyme_inactive"));
}
}
}
}
}
}
}

if (F.getName() == "omp_get_max_threads" ||
F.getName() == "omp_get_thread_num") {
#if LLVM_VERSION_MAJOR >= 16
Expand Down
13 changes: 11 additions & 2 deletions enzyme/Enzyme/TypeAnalysis/TypeAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4031,6 +4031,8 @@ void TypeAnalyzer::visitCallBase(CallBase &call) {
buf.insert({0}, Type::getDoubleTy(C->getContext()));
} else if (GV->getName() == "ompi_mpi_float") {
buf.insert({0}, Type::getFloatTy(C->getContext()));
} else if (GV->getName() == "ompi_mpi_cxx_bool") {
buf.insert({0}, BaseType::Integer);
}
} else if (auto CI = dyn_cast<ConstantInt>(C)) {
// MPICH
Expand All @@ -4051,7 +4053,8 @@ void TypeAnalyzer::visitCallBase(CallBase &call) {
updateAnalysis(&call, TypeTree(BaseType::Integer).Only(-1, &call), &call);
return;
}
if (funcName == "MPI_Isend" || funcName == "MPI_Irecv") {
if (funcName == "MPI_Isend" || funcName == "MPI_Irecv" ||
funcName == "PMPI_Isend" || funcName == "PMPI_Irecv") {
TypeTree buf = TypeTree(BaseType::Pointer);

if (Constant *C = dyn_cast<Constant>(call.getOperand(2))) {
Expand All @@ -4063,6 +4066,8 @@ void TypeAnalyzer::visitCallBase(CallBase &call) {
buf.insert({0}, Type::getDoubleTy(C->getContext()));
} else if (GV->getName() == "ompi_mpi_float") {
buf.insert({0}, Type::getFloatTy(C->getContext()));
} else if (GV->getName() == "ompi_mpi_cxx_bool") {
buf.insert({0}, BaseType::Integer);
}
} else if (auto CI = dyn_cast<ConstantInt>(C)) {
// MPICH
Expand Down Expand Up @@ -4137,6 +4142,8 @@ void TypeAnalyzer::visitCallBase(CallBase &call) {
buf.insert({0}, Type::getDoubleTy(C->getContext()));
} else if (GV->getName() == "ompi_mpi_float") {
buf.insert({0}, Type::getFloatTy(C->getContext()));
} else if (GV->getName() == "ompi_mpi_cxx_bool") {
buf.insert({0}, BaseType::Integer);
}
} else if (auto CI = dyn_cast<ConstantInt>(C)) {
// MPICH
Expand Down Expand Up @@ -4164,7 +4171,7 @@ void TypeAnalyzer::visitCallBase(CallBase &call) {
updateAnalysis(&call, TypeTree(BaseType::Integer).Only(-1, &call), &call);
return;
}
if (funcName == "MPI_Allreduce") {
if (funcName == "MPI_Allreduce" || funcName == "PMPI_Allreduce") {
TypeTree buf = TypeTree(BaseType::Pointer);

if (Constant *C = dyn_cast<Constant>(call.getOperand(3))) {
Expand All @@ -4176,6 +4183,8 @@ void TypeAnalyzer::visitCallBase(CallBase &call) {
buf.insert({0}, Type::getDoubleTy(C->getContext()));
} else if (GV->getName() == "ompi_mpi_float") {
buf.insert({0}, Type::getFloatTy(C->getContext()));
} else if (GV->getName() == "ompi_mpi_cxx_bool") {
buf.insert({0}, BaseType::Integer);
}
} else if (auto CI = dyn_cast<ConstantInt>(C)) {
// MPICH
Expand Down
Loading