[Mlir-commits] [mlir] [MLIR][MPI] Add LLVM lowering patterns for some MPI operations (PR #95524)
Markus Böck
llvmlistbot at llvm.org
Tue Aug 6 12:03:58 PDT 2024
================
@@ -0,0 +1,40 @@
+// RUN: mlir-opt -convert-to-llvm %s | FileCheck %s
+
+module {
+// CHECK: llvm.func @MPI_Finalize() -> i32
+// CHECK: llvm.func @MPI_Comm_rank(!llvm.ptr, !llvm.ptr) -> i32
+// CHECK: llvm.mlir.global external @MPI_COMM_WORLD() {addr_space = 0 : i32} : !llvm.struct<"MPI_ABI_Comm", opaque>
+// CHECK: llvm.func @MPI_Init(!llvm.ptr, !llvm.ptr) -> i32
+
+ func.func @mpi_test(%arg0: memref<100xf32>) {
+ %0 = mpi.init : !mpi.retval
+// CHECK: %7 = llvm.mlir.zero : !llvm.ptr
+// CHECK-NEXT: %8 = llvm.call @MPI_Init(%7, %7) : (!llvm.ptr, !llvm.ptr) -> i32
+// CHECK-NEXT: %9 = builtin.unrealized_conversion_cast %8 : i32 to !mpi.retval
+
+
+ %retval, %rank = mpi.comm_rank : !mpi.retval, i32
+// CHECK: %10 = llvm.mlir.constant(1 : i32) : i32
+// CHECK-NEXT: %11 = llvm.alloca %10 x i32 : (i32) -> !llvm.ptr
+// CHECK-NEXT: %12 = llvm.mlir.addressof @MPI_COMM_WORLD : !llvm.ptr
+// CHECK-NEXT: %13 = llvm.call @MPI_Comm_rank(%12, %11) : (!llvm.ptr, !llvm.ptr) -> i32
+// CHECK-NEXT: %14 = llvm.load %11 : !llvm.ptr -> i32
+// CHECK-NEXT: %15 = builtin.unrealized_conversion_cast %13 : i32 to !mpi.retval
----------------
zero9178 wrote:
These tests should be using filecheck variables for the SSA values. It is also convention that the `//` of the comments have the same indentation as the body.
You can also try (but don't see this as blocking) to slim down the tests a bit to not test the syntax of the LLVM operations so much, but rather just the lowering.
Just
```
%[[NULL_PTR:.*]] = llvm.mlir.zero
%[[INIT_RAW:.*]] = llvm.call @MPI_INIT(%[[NULL_PTR, %[[NULL_PTR]])
%[[INIT:.*]] = builtin.unrealized_conversion_cast %[[INIT_RAW]] : i32 to !mpi.retval
```
is fine (maybe splitting some of the type signatures with `// CHECK-SAME: ` on the next lines if you feel they are very relevant.
https://github.com/llvm/llvm-project/pull/95524
More information about the Mlir-commits
mailing list