Skip to content

Commit ab166d4

Browse files
fschlimbAntonLydikeDinistro
authored
[mlir][mpi] Lowering Mpi To LLVM (#127053)
* The first set of patterns to convert the MPI dialect to LLVM. * Further conversion pattern will be added in future PRs. * Supports MPICH compatible MPI implementations and openMPI, selectable through DLTI attribute on module --------- Co-authored-by: Anton Lydike <[email protected]> Co-authored-by: Christian Ulmann <[email protected]>
1 parent 506deb0 commit ab166d4

File tree

8 files changed

+726
-9
lines changed

8 files changed

+726
-9
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef MLIR_CONVERSION_MPITOLLVM_H
10+
#define MLIR_CONVERSION_MPITOLLVM_H
11+
12+
#include "mlir/IR/DialectRegistry.h"
13+
14+
namespace mlir {
15+
16+
class LLVMTypeConverter;
17+
class RewritePatternSet;
18+
19+
namespace mpi {
20+
21+
void populateMPIToLLVMConversionPatterns(LLVMTypeConverter &converter,
22+
RewritePatternSet &patterns);
23+
24+
void registerConvertMPIToLLVMInterface(DialectRegistry &registry);
25+
26+
} // namespace mpi
27+
} // namespace mlir
28+
29+
#endif // MLIR_CONVERSION_MPITOLLVM_H

mlir/include/mlir/Dialect/MPI/IR/MPIOps.td

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,13 @@ def MPI_SendOp : MPI_Op<"send", []> {
102102
let arguments = (
103103
ins AnyMemRef : $ref,
104104
I32 : $tag,
105-
I32 : $rank
105+
I32 : $dest
106106
);
107107

108108
let results = (outs Optional<MPI_Retval>:$retval);
109109

110-
let assemblyFormat = "`(` $ref `,` $tag `,` $rank `)` attr-dict `:` "
111-
"type($ref) `,` type($tag) `,` type($rank)"
110+
let assemblyFormat = "`(` $ref `,` $tag `,` $dest `)` attr-dict `:` "
111+
"type($ref) `,` type($tag) `,` type($dest)"
112112
"(`->` type($retval)^)?";
113113
let hasCanonicalizer = 1;
114114
}
@@ -154,11 +154,11 @@ def MPI_ISendOp : MPI_Op<"isend", []> {
154154
//===----------------------------------------------------------------------===//
155155

156156
def MPI_RecvOp : MPI_Op<"recv", []> {
157-
let summary = "Equivalent to `MPI_Recv(ptr, size, dtype, dest, tag, "
157+
let summary = "Equivalent to `MPI_Recv(ptr, size, dtype, source, tag, "
158158
"MPI_COMM_WORLD, MPI_STATUS_IGNORE)`";
159159
let description = [{
160160
MPI_Recv performs a blocking receive of `size` elements of type `dtype`
161-
from rank `dest`. The `tag` value and communicator enables the library to
161+
from rank `source`. The `tag` value and communicator enables the library to
162162
determine the matching of multiple sends and receives between the same
163163
ranks.
164164

@@ -172,13 +172,13 @@ def MPI_RecvOp : MPI_Op<"recv", []> {
172172

173173
let arguments = (
174174
ins AnyMemRef : $ref,
175-
I32 : $tag, I32 : $rank
175+
I32 : $tag, I32 : $source
176176
);
177177

178178
let results = (outs Optional<MPI_Retval>:$retval);
179179

180-
let assemblyFormat = "`(` $ref `,` $tag `,` $rank `)` attr-dict `:`"
181-
"type($ref) `,` type($tag) `,` type($rank)"
180+
let assemblyFormat = "`(` $ref `,` $tag `,` $source `)` attr-dict `:` "
181+
"type($ref) `,` type($tag) `,` type($source)"
182182
"(`->` type($retval)^)?";
183183
let hasCanonicalizer = 1;
184184
}

mlir/include/mlir/Dialect/MPI/IR/MPITypes.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class MPI_Type<string name, string typeMnemonic, list<Trait> traits = []>
3030
//===----------------------------------------------------------------------===//
3131

3232
def MPI_Retval : MPI_Type<"Retval", "retval"> {
33-
let summary = "MPI function call return value";
33+
let summary = "MPI function call return value (!mpi.retval)";
3434
let description = [{
3535
This type represents a return value from an MPI function call.
3636
This value can be MPI_SUCCESS, MPI_ERR_IN_STATUS, or any error code.

mlir/include/mlir/InitAllExtensions.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#ifndef MLIR_INITALLEXTENSIONS_H_
1515
#define MLIR_INITALLEXTENSIONS_H_
1616

17+
#include "Conversion/MPIToLLVM/MPIToLLVM.h"
1718
#include "mlir/Conversion/ArithToLLVM/ArithToLLVM.h"
1819
#include "mlir/Conversion/ComplexToLLVM/ComplexToLLVM.h"
1920
#include "mlir/Conversion/ControlFlowToLLVM/ControlFlowToLLVM.h"
@@ -70,6 +71,7 @@ inline void registerAllExtensions(DialectRegistry &registry) {
7071
registerConvertFuncToLLVMInterface(registry);
7172
index::registerConvertIndexToLLVMInterface(registry);
7273
registerConvertMathToLLVMInterface(registry);
74+
mpi::registerConvertMPIToLLVMInterface(registry);
7375
registerConvertMemRefToLLVMInterface(registry);
7476
registerConvertNVVMToLLVMInterface(registry);
7577
registerConvertOpenMPToLLVMInterface(registry);

mlir/lib/Conversion/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ add_subdirectory(MemRefToEmitC)
4242
add_subdirectory(MemRefToLLVM)
4343
add_subdirectory(MemRefToSPIRV)
4444
add_subdirectory(MeshToMPI)
45+
add_subdirectory(MPIToLLVM)
4546
add_subdirectory(NVGPUToNVVM)
4647
add_subdirectory(NVVMToLLVM)
4748
add_subdirectory(OpenACCToSCF)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
add_mlir_conversion_library(MLIRMPIToLLVM
2+
MPIToLLVM.cpp
3+
4+
ADDITIONAL_HEADER_DIRS
5+
${MLIR_MAIN_INCLUDE_DIR}/mlir/Conversion/MPIToLLVM
6+
7+
DEPENDS
8+
MLIRConversionPassIncGen
9+
10+
LINK_COMPONENTS
11+
Core
12+
13+
LINK_LIBS PUBLIC
14+
MLIRDLTIDialect
15+
MLIRLLVMCommonConversion
16+
MLIRLLVMDialect
17+
MLIRMPIDialect
18+
)

0 commit comments

Comments
 (0)