1//===- MPIops.td - Message Passing Interface Ops -----------*- tablegen -*-===// 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 MPI_MLIR_IR_MPIOPS_TD 10#define MPI_MLIR_IR_MPIOPS_TD 11 12include "mlir/Dialect/MPI/IR/MPI.td" 13include "mlir/Dialect/MPI/IR/MPITypes.td" 14 15class MPI_Op<string mnemonic, list<Trait> traits = []> 16 : Op<MPI_Dialect, mnemonic, traits>; 17 18//===----------------------------------------------------------------------===// 19// InitOp 20//===----------------------------------------------------------------------===// 21 22def MPI_InitOp : MPI_Op<"init", []> { 23 let summary = 24 "Initialize the MPI library, equivalent to `MPI_Init(NULL, NULL)`"; 25 let description = [{ 26 This operation must preceed most MPI calls (except for very few exceptions, 27 please consult with the MPI specification on these). 28 29 Passing &argc, &argv is not supported currently. 30 31 This operation can optionally return an `!mpi.retval` value that can be used 32 to check for errors. 33 }]; 34 35 let results = (outs Optional<MPI_Retval>:$retval); 36 37 let assemblyFormat = "attr-dict (`:` type($retval)^)?"; 38} 39 40//===----------------------------------------------------------------------===// 41// CommRankOp 42//===----------------------------------------------------------------------===// 43 44def MPI_CommRankOp : MPI_Op<"comm_rank", []> { 45 let summary = "Get the current rank, equivalent to " 46 "`MPI_Comm_rank(MPI_COMM_WORLD, &rank)`"; 47 let description = [{ 48 Communicators other than `MPI_COMM_WORLD` are not supported for now. 49 50 This operation can optionally return an `!mpi.retval` value that can be used 51 to check for errors. 52 }]; 53 54 let results = ( 55 outs Optional<MPI_Retval> : $retval, 56 I32 : $rank 57 ); 58 59 let assemblyFormat = "attr-dict `:` type(results)"; 60} 61 62//===----------------------------------------------------------------------===// 63// SendOp 64//===----------------------------------------------------------------------===// 65 66def MPI_SendOp : MPI_Op<"send", []> { 67 let summary = 68 "Equivalent to `MPI_Send(ptr, size, dtype, dest, tag, MPI_COMM_WORLD)`"; 69 let description = [{ 70 MPI_Send performs a blocking send of `size` elements of type `dtype` to rank 71 `dest`. The `tag` value and communicator enables the library to determine 72 the matching of multiple sends and receives between the same ranks. 73 74 Communicators other than `MPI_COMM_WORLD` are not supprted for now. 75 76 This operation can optionally return an `!mpi.retval` value that can be used 77 to check for errors. 78 }]; 79 80 let arguments = (ins AnyMemRef : $ref, I32 : $tag, I32 : $rank); 81 82 let results = (outs Optional<MPI_Retval>:$retval); 83 84 let assemblyFormat = "`(` $ref `,` $tag `,` $rank `)` attr-dict `:` " 85 "type($ref) `,` type($tag) `,` type($rank)" 86 "(`->` type($retval)^)?"; 87 let hasCanonicalizer = 1; 88} 89 90//===----------------------------------------------------------------------===// 91// RecvOp 92//===----------------------------------------------------------------------===// 93 94def MPI_RecvOp : MPI_Op<"recv", []> { 95 let summary = "Equivalent to `MPI_Recv(ptr, size, dtype, dest, tag, " 96 "MPI_COMM_WORLD, MPI_STATUS_IGNORE)`"; 97 let description = [{ 98 MPI_Recv performs a blocking receive of `size` elements of type `dtype` 99 from rank `dest`. The `tag` value and communicator enables the library to 100 determine the matching of multiple sends and receives between the same 101 ranks. 102 103 Communicators other than `MPI_COMM_WORLD` are not supprted for now. 104 The MPI_Status is set to `MPI_STATUS_IGNORE`, as the status object 105 is not yet ported to MLIR. 106 107 This operation can optionally return an `!mpi.retval` value that can be used 108 to check for errors. 109 }]; 110 111 let arguments = (ins AnyMemRef : $ref, I32 : $tag, I32 : $rank); 112 113 let results = (outs Optional<MPI_Retval>:$retval); 114 115 let assemblyFormat = "`(` $ref `,` $tag `,` $rank `)` attr-dict `:` " 116 "type($ref) `,` type($tag) `,` type($rank)" 117 "(`->` type($retval)^)?"; 118 let hasCanonicalizer = 1; 119} 120 121 122//===----------------------------------------------------------------------===// 123// FinalizeOp 124//===----------------------------------------------------------------------===// 125 126def MPI_FinalizeOp : MPI_Op<"finalize", []> { 127 let summary = "Finalize the MPI library, equivalent to `MPI_Finalize()`"; 128 let description = [{ 129 This function cleans up the MPI state. Afterwards, no MPI methods may 130 be invoked (excpet for MPI_Get_version, MPI_Initialized, and MPI_Finalized). 131 Notably, MPI_Init cannot be called again in the same program. 132 133 This operation can optionally return an `!mpi.retval` value that can be used 134 to check for errors. 135 }]; 136 137 let results = (outs Optional<MPI_Retval>:$retval); 138 139 let assemblyFormat = "attr-dict (`:` type($retval)^)?"; 140} 141 142 143//===----------------------------------------------------------------------===// 144// RetvalCheckOp 145//===----------------------------------------------------------------------===// 146 147def MPI_RetvalCheckOp : MPI_Op<"retval_check", []> { 148 let summary = "Check an MPI return value against an error class"; 149 let description = [{ 150 This operation compares MPI status codes to known error class 151 constants such as `MPI_SUCCESS`, or `MPI_ERR_COMM`. 152 }]; 153 154 let arguments = ( 155 ins MPI_Retval:$val, 156 MPI_ErrorClassAttr:$errclass 157 ); 158 159 let results = ( 160 outs I1:$res 161 ); 162 163 let assemblyFormat = "$val `=` $errclass attr-dict `:` type($res)"; 164} 165 166 167 168//===----------------------------------------------------------------------===// 169// RetvalCheckOp 170//===----------------------------------------------------------------------===// 171 172def MPI_ErrorClassOp : MPI_Op<"error_class", []> { 173 let summary = "Get the error class from an error code, equivalent to " 174 "the `MPI_Error_class` function"; 175 let description = [{ 176 `MPI_Error_class` maps return values from MPI calls to a set of well-known 177 MPI error classes. 178 }]; 179 180 let arguments = ( 181 ins MPI_Retval:$val 182 ); 183 184 let results = ( 185 outs MPI_Retval:$errclass 186 ); 187 188 let assemblyFormat = "$val attr-dict `:` type($val)"; 189} 190 191#endif // MPI_MLIR_IR_MPIOPS_TD 192