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

Extend mpi support #1292

Draft
wants to merge 26 commits into
base: main
Choose a base branch
from
Draft

Extend mpi support #1292

wants to merge 26 commits into from

Conversation

l90lpa
Copy link
Collaborator

@l90lpa l90lpa commented Jun 20, 2023

No description provided.

@l90lpa l90lpa linked an issue Jun 20, 2023 that may be closed by this pull request
@l90lpa l90lpa force-pushed the extend-mpi_support branch from 888445a to ddb792d Compare June 20, 2023 17:55
@@ -136,7 +136,7 @@ const StringSet<> InactiveGlobals = {
"_ZTVN10__cxxabiv121__vmi_class_type_infoE"
};

const llvm::StringMap<size_t> MPIInactiveCommAllocators = {
const llvm::StringMap<size_t> MPIInactiveAllocators = {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed the name because I've added some non-comm allocator routines.

@@ -147,7 +147,8 @@ class AdjointGenerator
}

llvm::Value *MPI_TYPE_SIZE(llvm::Value *DT, llvm::IRBuilder<> &B,
llvm::Type *intType) {
llvm::Type *intType,
llvm::BasicBlock *allocBlock = nullptr) {
Copy link
Collaborator Author

@l90lpa l90lpa Jun 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When handling MPI_Allreduce using min/max op, I replace the call in the primal code with an MPI_Allreduce using the minloc/maxloc (+ some loops for copying data, and mallocs for temporary arrays). I'm not sure if it is the best strategy, but I construct this replacement code inside a function, similar to getOInsertCheckedFree. Because I'm constructing the replacement code in a function I added the extra parameter allocaBlock to MPI_TYPE_SIZE etc so that I could use them in this case.

BuilderZ.setFastMathFlags(getFast());

enum class MPI_Op_Kind { SUM, MIN, MAX, MINLOC, MAXLOC, UNKNOWN };
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a few helper functions and maps at the start of handleMPI that I extracted from MPI_Allreduce handling, and extended.

// op in the primal code
CallInst *newNewCall;
Value *recvlocbuf;
if (opKind == MPI_Op_Kind::MIN || opKind == MPI_Op_Kind::MAX) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the block where I construct the replacement code for MPI_Allreduce when the op is min/max, and then replace the primal call. The replacement code is constructed in a function (I took a similar approach as getOrInsertCheckedFree. Is this the best approach? Or is it better to generate the code in-place?

BuilderZ.CreateCall(mpi_allreduce_comploc_fp->getFunctionType(),
mpi_allreduce_comploc_fp, args);

gutils->replaceAWithB(newCall, newNewCall);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the best way to replace the primal code?

@l90lpa l90lpa force-pushed the extend-mpi_support branch from 6616fbb to 8bc9729 Compare June 21, 2023 14:09
@l90lpa l90lpa requested a review from wsmoses June 21, 2023 14:29
MilesCranmer pushed a commit to MilesCranmer/Enzyme that referenced this pull request Jul 24, 2024
* Support complex knownops

* Update Project.toml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handle more MPI functions
1 participant