Ensure that `gpu.func` is only used within the dedicated `gpu.module`.
Implement the constraint to the GPU dialect and adopt test cases.
Differential Revision: https://reviews.llvm.org/D78541
/// functions.
static StringRef getKernelFuncAttrName() { return "gpu.kernel"; }
- /// Get the name of the attribute used to annotate kernel modules.
- static StringRef getKernelModuleAttrName() { return "gpu.kernel_module"; }
-
/// Returns whether the given function is a kernel function, i.e., has the
/// 'gpu.kernel' attribute.
static bool isKernel(Operation *op);
}];
}
-def GPU_GPUFuncOp : GPU_Op<"func", [AutomaticAllocationScope, FunctionLike,
+def GPU_GPUFuncOp : GPU_Op<"func", [HasParent<"GPUModuleOp">,
+ AutomaticAllocationScope, FunctionLike,
IsolatedFromAbove, Symbol]> {
let summary = "Function executable on a GPU";
// RUN: mlir-opt -test-all-reduce-lowering %s | FileCheck %s
// NOTE: Assertions have been autogenerated by utils/generate-test-checks.py
-// CHECK: module @kernels attributes {gpu.kernel_module} {
-module @kernels attributes {gpu.kernel_module} {
+// CHECK: gpu.module @kernels {
+gpu.module @kernels {
// CHECK-LABEL: gpu.func @kernel(
// CHECK-SAME: [[VAL_0:%.*]]: f32) workgroup([[VAL_1:%.*]] : memref<32xf32, 3>) kernel {
// RUN: mlir-opt -test-all-reduce-lowering %s | FileCheck %s
// NOTE: Assertions have been autogenerated by utils/generate-test-checks.py
-// CHECK: module @kernels attributes {gpu.kernel_module} {
-module @kernels attributes {gpu.kernel_module} {
+// CHECK: gpu.module @kernels {
+gpu.module @kernels {
// CHECK-LABEL: gpu.func @kernel(
// CHECK-SAME: [[VAL_0:%.*]]: f32) workgroup([[VAL_1:%.*]] : memref<32xf32, 3>) kernel {
module attributes {gpu.container_module} {
module @kernels {
+ // expected-error@+1 {{'gpu.func' op expects parent op 'gpu.module'}}
+ gpu.func @kernel_1(%arg1 : !llvm<"float*">) {
+ gpu.return
+ }
+ }
+}
+
+// -----
+
+module attributes {gpu.container_module} {
+ module @kernels {
}
func @launch_func_missing_module_attribute(%sz : index) {
// -----
module {
- module @gpu_funcs attributes {gpu.kernel_module} {
+ gpu.module @gpu_funcs {
// expected-error @+1 {{requires 'type' attribute of function type}}
"gpu.func"() ({
gpu.return
// -----
module {
- module @gpu_funcs attributes {gpu.kernel_module} {
+ gpu.module @gpu_funcs {
// expected-error @+1 {{expected memref type in attribution}}
gpu.func @kernel() workgroup(%0: i32) {
gpu.return
// -----
module {
- module @gpu_funcs attributes {gpu.kernel_module} {
+ gpu.module @gpu_funcs {
// expected-error @+1 {{expected memory space 3 in attribution}}
gpu.func @kernel() workgroup(%0: memref<4xf32>) {
gpu.return
// -----
module {
- module @gpu_funcs attributes {gpu.kernel_module} {
+ gpu.module @gpu_funcs {
// expected-error @+1 {{expected memory space 5 in attribution}}
gpu.func @kernel() private(%0: memref<4xf32>) {
gpu.return
// -----
module {
- module @gpu_funcs attributes {gpu.kernel_module} {
+ gpu.module @gpu_funcs {
// expected-error @+1 {{expected memory space 5 in attribution}}
gpu.func @kernel() private(%0: memref<4xf32>) {
gpu.return
return
}
- module @gpu_funcs attributes {gpu.kernel_module} {
+ gpu.module @gpu_funcs {
// CHECK-LABEL: gpu.func @kernel_1({{.*}}: f32)
// CHECK: workgroup
// CHECK: private
-// RUN: mlir-opt -allow-unregistered-dialect -test-gpu-memory-promotion -split-input-file %s | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect -test-gpu-memory-promotion -pass-pipeline='gpu.module(gpu.func(test-gpu-memory-promotion))' -split-input-file %s | FileCheck %s
+
+gpu.module @foo {
-module @foo attributes {gpu.kernel_module} {
// Verify that the attribution was indeed introduced
// CHECK-LABEL: @memref3d
// CHECK-SAME: (%[[arg:.*]]: memref<5x4xf32>
// -----
-module @foo attributes {gpu.kernel_module} {
+gpu.module @foo {
+
// Verify that the attribution was indeed introduced
// CHECK-LABEL: @memref5d
// CHECK-SAME: (%[[arg:.*]]: memref<8x7x6x5x4xf32>
// -----
-module @foo attributes {gpu.kernel_module} {
+gpu.module @foo {
+
// Check that attribution insertion works fine.
// CHECK-LABEL: @insert
// CHECK-SAME: (%{{.*}}: memref<4xf32>