Skip to content

Commit 4b01190

Browse files
committed
[mlir][openacc] Introduce acc.enter_data operation
This patch introduces the acc.enter_data operation that represents an OpenACC Enter Data directive. Operands and attributes are dervied from clauses in the spec 2.6.6. Reviewed By: kiranchandramohan Differential Revision: https://reviews.llvm.org/D88941
1 parent 849c605 commit 4b01190

File tree

4 files changed

+127
-2
lines changed

4 files changed

+127
-2
lines changed

mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,48 @@ def OpenACC_TerminatorOp : OpenACC_Op<"terminator", [Terminator]> {
229229
let assemblyFormat = "attr-dict";
230230
}
231231

232+
//===----------------------------------------------------------------------===//
233+
// 2.6.6 Enter Data Directive
234+
//===----------------------------------------------------------------------===//
235+
236+
def OpenACC_EnterDataOp : OpenACC_Op<"enter_data", [AttrSizedOperandSegments]> {
237+
let summary = "enter data operation";
238+
239+
let description = [{
240+
The "acc.enter_data" operation represents the OpenACC enter data directive.
241+
242+
Example:
243+
244+
```mlir
245+
acc.enter_data create(%d1 : memref<10xf32>) attributes {async}
246+
```
247+
}];
248+
249+
let arguments = (ins Optional<I1>:$ifCond,
250+
Optional<IntOrIndex>:$asyncOperand,
251+
UnitAttr:$async,
252+
Optional<IntOrIndex>:$waitDevnum,
253+
Variadic<IntOrIndex>:$waitOperands,
254+
UnitAttr:$wait,
255+
Variadic<AnyType>:$copyinOperands,
256+
Variadic<AnyType>:$createOperands,
257+
Variadic<AnyType>:$createZeroOperands,
258+
Variadic<AnyType>:$attachOperands);
259+
260+
let assemblyFormat = [{
261+
( `if` `(` $ifCond^ `)` )?
262+
( `async` `(` $asyncOperand^ `:` type($asyncOperand) `)` )?
263+
( `wait_devnum` `(` $waitDevnum^ `:` type($waitDevnum) `)` )?
264+
( `wait` `(` $waitOperands^ `:` type($waitOperands) `)` )?
265+
( `copyin` `(` $copyinOperands^ `:` type($copyinOperands) `)` )?
266+
( `create` `(` $createOperands^ `:` type($createOperands) `)` )?
267+
( `create_zero` `(` $createZeroOperands^ `:`
268+
type($createZeroOperands) `)` )?
269+
( `attach` `(` $attachOperands^ `:` type($attachOperands) `)` )?
270+
attr-dict-with-keyword
271+
}];
272+
}
273+
232274
//===----------------------------------------------------------------------===//
233275
// 2.6.6 Exit Data Directive
234276
//===----------------------------------------------------------------------===//

mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,36 @@ static LogicalResult verify(acc::ExitDataOp op) {
682682
return success();
683683
}
684684

685+
//===----------------------------------------------------------------------===//
686+
// DataEnterOp
687+
//===----------------------------------------------------------------------===//
688+
689+
static LogicalResult verify(acc::EnterDataOp op) {
690+
// 2.6.6. Data Enter Directive restriction
691+
// At least one copyin, create, or attach clause must appear on an enter data
692+
// directive.
693+
if (op.copyinOperands().empty() && op.createOperands().empty() &&
694+
op.createZeroOperands().empty() && op.attachOperands().empty())
695+
return op.emitError(
696+
"at least one operand in copyin, create, "
697+
"create_zero or attach must appear on the enter data operation");
698+
699+
// The async attribute represent the async clause without value. Therefore the
700+
// attribute and operand cannot appear at the same time.
701+
if (op.asyncOperand() && op.async())
702+
return op.emitError("async attribute cannot appear with asyncOperand");
703+
704+
// The wait attribute represent the wait clause without values. Therefore the
705+
// attribute and operands cannot appear at the same time.
706+
if (!op.waitOperands().empty() && op.wait())
707+
return op.emitError("wait attribute cannot appear with waitOperands");
708+
709+
if (op.waitDevnum() && op.waitOperands().empty())
710+
return op.emitError("wait_devnum cannot appear without waitOperands");
711+
712+
return success();
713+
}
714+
685715
//===----------------------------------------------------------------------===//
686716
// InitOp
687717
//===----------------------------------------------------------------------===//

mlir/test/Dialect/OpenACC/invalid.mlir

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,14 +168,33 @@ acc.exit_data async(%cst: index) delete(%value : memref<10xf32>) attributes {asy
168168

169169
// -----
170170

171+
%cst = constant 1 : index
172+
%value = alloc() : memref<10xf32>
173+
// expected-error@+1 {{wait_devnum cannot appear without waitOperands}}
174+
acc.exit_data wait_devnum(%cst: index) delete(%value : memref<10xf32>)
175+
176+
// -----
177+
178+
// expected-error@+1 {{at least one operand in copyin, create, create_zero or attach must appear on the enter data operation}}
179+
acc.enter_data attributes {async}
180+
181+
// -----
182+
183+
%cst = constant 1 : index
184+
%value = alloc() : memref<10xf32>
185+
// expected-error@+1 {{async attribute cannot appear with asyncOperand}}
186+
acc.enter_data async(%cst: index) create(%value : memref<10xf32>) attributes {async}
187+
188+
// -----
189+
171190
%cst = constant 1 : index
172191
%value = alloc() : memref<10xf32>
173192
// expected-error@+1 {{wait attribute cannot appear with waitOperands}}
174-
acc.exit_data wait(%cst: index) delete(%value : memref<10xf32>) attributes {wait}
193+
acc.enter_data wait(%cst: index) create(%value : memref<10xf32>) attributes {wait}
175194

176195
// -----
177196

178197
%cst = constant 1 : index
179198
%value = alloc() : memref<10xf32>
180199
// expected-error@+1 {{wait_devnum cannot appear without waitOperands}}
181-
acc.exit_data wait_devnum(%cst: index) delete(%value : memref<10xf32>)
200+
acc.enter_data wait_devnum(%cst: index) create(%value : memref<10xf32>)

mlir/test/Dialect/OpenACC/ops.mlir

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,3 +684,37 @@ func @testexitdataop(%a: memref<10xf32>, %b: memref<10xf32>, %c: memref<10x10xf3
684684
// CHECK: acc.exit_data async([[I64VALUE]] : i64) copyout([[ARGA]] : memref<10xf32>)
685685
// CHECK: acc.exit_data if([[IFCOND]]) copyout([[ARGA]] : memref<10xf32>)
686686
// CHECK: acc.exit_data wait_devnum([[I64VALUE]] : i64) wait([[I32VALUE]], [[IDXVALUE]] : i32, index) copyout([[ARGA]] : memref<10xf32>)
687+
// -----
688+
689+
690+
func @testenterdataop(%a: memref<10xf32>, %b: memref<10xf32>, %c: memref<10x10xf32>) -> () {
691+
%ifCond = constant true
692+
%i64Value = constant 1 : i64
693+
%i32Value = constant 1 : i32
694+
%idxValue = constant 1 : index
695+
696+
acc.enter_data copyin(%a : memref<10xf32>)
697+
acc.enter_data create(%a : memref<10xf32>) create_zero(%b, %c : memref<10xf32>, memref<10x10xf32>)
698+
acc.enter_data attach(%a : memref<10xf32>)
699+
acc.enter_data copyin(%a : memref<10xf32>) attributes {async}
700+
acc.enter_data create(%a : memref<10xf32>) attributes {wait}
701+
acc.enter_data async(%i64Value : i64) copyin(%a : memref<10xf32>)
702+
acc.enter_data if(%ifCond) copyin(%a : memref<10xf32>)
703+
acc.enter_data wait_devnum(%i64Value: i64) wait(%i32Value, %idxValue : i32, index) copyin(%a : memref<10xf32>)
704+
705+
return
706+
}
707+
708+
// CHECK: func @testenterdataop([[ARGA:%.*]]: memref<10xf32>, [[ARGB:%.*]]: memref<10xf32>, [[ARGC:%.*]]: memref<10x10xf32>) {
709+
// CHECK: [[IFCOND1:%.*]] = constant true
710+
// CHECK: [[I64VALUE:%.*]] = constant 1 : i64
711+
// CHECK: [[I32VALUE:%.*]] = constant 1 : i32
712+
// CHECK: [[IDXVALUE:%.*]] = constant 1 : index
713+
// CHECK: acc.enter_data copyin([[ARGA]] : memref<10xf32>)
714+
// CHECK: acc.enter_data create([[ARGA]] : memref<10xf32>) create_zero([[ARGB]], [[ARGC]] : memref<10xf32>, memref<10x10xf32>)
715+
// CHECK: acc.enter_data attach([[ARGA]] : memref<10xf32>)
716+
// CHECK: acc.enter_data copyin([[ARGA]] : memref<10xf32>) attributes {async}
717+
// CHECK: acc.enter_data create([[ARGA]] : memref<10xf32>) attributes {wait}
718+
// CHECK: acc.enter_data async([[I64VALUE]] : i64) copyin([[ARGA]] : memref<10xf32>)
719+
// CHECK: acc.enter_data if([[IFCOND]]) copyin([[ARGA]] : memref<10xf32>)
720+
// CHECK: acc.enter_data wait_devnum([[I64VALUE]] : i64) wait([[I32VALUE]], [[IDXVALUE]] : i32, index) copyin([[ARGA]] : memref<10xf32>)

0 commit comments

Comments
 (0)