[Mlir-commits] [mlir] 9c77350 - [mlir][openacc] Add shutdown operation

llvmlistbot at llvm.org llvmlistbot at llvm.org
Tue Sep 29 10:13:17 PDT 2020


Author: Valentin Clement
Date: 2020-09-29T13:13:09-04:00
New Revision: 9c77350b0c737f44732ee26b558b5f4868864a38

URL: https://github.com/llvm/llvm-project/commit/9c77350b0c737f44732ee26b558b5f4868864a38
DIFF: https://github.com/llvm/llvm-project/commit/9c77350b0c737f44732ee26b558b5f4868864a38.diff

LOG: [mlir][openacc] Add shutdown operation

This patch introduces the acc.shutdown operation that represents an OpenACC shutdown directive.
Clauses are derived from the spec 2.14.2

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D88272

Added: 
    

Modified: 
    mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td
    mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp
    mlir/test/Dialect/OpenACC/invalid.mlir
    mlir/test/Dialect/OpenACC/ops.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td b/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td
index 0d8efcc456b4..779f588cf5b1 100644
--- a/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td
+++ b/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td
@@ -348,6 +348,36 @@ def OpenACC_InitOp : OpenACC_Op<"init", [AttrSizedOperandSegments]> {
   }];
 }
 
+//===----------------------------------------------------------------------===//
+// 2.14.2. Shutdown
+//===----------------------------------------------------------------------===//
+
+def OpenACC_ShutdownOp : OpenACC_Op<"shutdown", [AttrSizedOperandSegments]> {
+  let summary = "shutdown operation";
+
+  let description = [{
+    The "acc.shutdown" operation represents the OpenACC shutdown executable
+    directive.
+
+    Example:
+
+    ```mlir
+    acc.shutdown
+    acc.shutdown device_num(%dev1 : i32)
+    ```
+  }];
+
+  let arguments = (ins Variadic<AnyInteger>:$deviceTypeOperands,
+                       Optional<IntOrIndex>:$deviceNumOperand,
+                       Optional<I1>:$ifCond);
+
+  let assemblyFormat = [{
+    ( `device_type` `(` $deviceTypeOperands^ `:` type($deviceTypeOperands) `)` )?
+    ( `device_num` `(` $deviceNumOperand^ `:` type($deviceNumOperand) `)` )?
+    ( `if` `(` $ifCond^ `)` )? attr-dict-with-keyword
+  }];
+}
+
 //===----------------------------------------------------------------------===//
 // 2.14.4. Update Directive
 //===----------------------------------------------------------------------===//

diff  --git a/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp b/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp
index 515f5a9e28e8..7ebba75389d3 100644
--- a/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp
+++ b/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp
@@ -149,6 +149,10 @@ static OptionalParseResult parserOptionalOperandAndTypeWithPrefix(
   return llvm::None;
 }
 
+static bool isComputeOperation(Operation *op) {
+  return isa<acc::ParallelOp>(op) || isa<acc::LoopOp>(op);
+}
+
 //===----------------------------------------------------------------------===//
 // ParallelOp
 //===----------------------------------------------------------------------===//
@@ -655,12 +659,25 @@ static LogicalResult verify(acc::DataOp dataOp) {
 static LogicalResult verify(acc::InitOp initOp) {
   Operation *currOp = initOp;
   while ((currOp = currOp->getParentOp())) {
-    if (isa<acc::ParallelOp>(currOp) || isa<acc::LoopOp>(currOp))
+    if (isComputeOperation(currOp))
       return initOp.emitOpError("cannot be nested in a compute operation");
   }
   return success();
 }
 
+//===----------------------------------------------------------------------===//
+// ShutdownOp
+//===----------------------------------------------------------------------===//
+
+static LogicalResult verify(acc::ShutdownOp op) {
+  Operation *currOp = op;
+  while ((currOp = currOp->getParentOp())) {
+    if (isComputeOperation(currOp))
+      return op.emitOpError("cannot be nested in a compute operation");
+  }
+  return success();
+}
+
 //===----------------------------------------------------------------------===//
 // UpdateOp
 //===----------------------------------------------------------------------===//

diff  --git a/mlir/test/Dialect/OpenACC/invalid.mlir b/mlir/test/Dialect/OpenACC/invalid.mlir
index 7a8a07f78f9a..c56ccdb186f9 100644
--- a/mlir/test/Dialect/OpenACC/invalid.mlir
+++ b/mlir/test/Dialect/OpenACC/invalid.mlir
@@ -1,4 +1,4 @@
-// RUN: mlir-opt -split-input-file -verify-diagnostics %s
+// RUN: mlir-opt -allow-unregistered-dialect -split-input-file -verify-diagnostics %s
 
 // expected-error at +1 {{gang, worker or vector cannot appear with the seq attr}}
 acc.loop gang {
@@ -127,3 +127,29 @@ acc.loop {
   acc.init
   acc.yield
 }
+
+// -----
+
+acc.parallel {
+// expected-error at +1 {{'acc.shutdown' op cannot be nested in a compute operation}}
+  acc.shutdown
+  acc.yield
+}
+
+// -----
+
+acc.loop {
+// expected-error at +1 {{'acc.shutdown' op cannot be nested in a compute operation}}
+  acc.shutdown
+  acc.yield
+}
+
+// -----
+
+acc.loop {
+  "some.op"() ({
+    // expected-error at +1 {{'acc.shutdown' op cannot be nested in a compute operation}}
+    acc.shutdown
+  }) : () -> ()
+  acc.yield
+}

diff  --git a/mlir/test/Dialect/OpenACC/ops.mlir b/mlir/test/Dialect/OpenACC/ops.mlir
index a4dec5dcf480..7ed4340fa308 100644
--- a/mlir/test/Dialect/OpenACC/ops.mlir
+++ b/mlir/test/Dialect/OpenACC/ops.mlir
@@ -620,3 +620,31 @@ acc.init if(%ifCond)
 // CHECK: acc.init device_num([[I32VALUE]] : i32)
 // CHECK: acc.init device_num([[IDXVALUE]] : index)
 // CHECK: acc.init if([[IFCOND]])
+
+// -----
+
+%i64Value = constant 1 : i64
+%i32Value = constant 1 : i32
+%i32Value2 = constant 2 : i32
+%idxValue = constant 1 : index
+%ifCond = constant true
+acc.shutdown
+acc.shutdown device_type(%i32Value : i32)
+acc.shutdown device_type(%i32Value, %i32Value2 : i32, i32)
+acc.shutdown device_num(%i64Value : i64)
+acc.shutdown device_num(%i32Value : i32)
+acc.shutdown device_num(%idxValue : index)
+acc.shutdown if(%ifCond)
+
+// CHECK: [[I64VALUE:%.*]] = constant 1 : i64
+// CHECK: [[I32VALUE:%.*]] = constant 1 : i32
+// CHECK: [[I32VALUE2:%.*]] = constant 2 : i32
+// CHECK: [[IDXVALUE:%.*]] = constant 1 : index
+// CHECK: [[IFCOND:%.*]] = constant true
+// CHECK: acc.shutdown
+// CHECK: acc.shutdown device_type([[I32VALUE]] : i32)
+// CHECK: acc.shutdown device_type([[I32VALUE]], [[I32VALUE2]] : i32, i32)
+// CHECK: acc.shutdown device_num([[I64VALUE]] : i64)
+// CHECK: acc.shutdown device_num([[I32VALUE]] : i32)
+// CHECK: acc.shutdown device_num([[IDXVALUE]] : index)
+// CHECK: acc.shutdown if([[IFCOND]])


        


More information about the Mlir-commits mailing list