Skip to content

Commit 500996f

Browse files
committed
[mlir][gpu] Update attribute definitions in gpu::LaunchOp
This PR makes two updates to `gpu.launch`: - Change the attribute type for kernel function and module from `SymbolRefAttr` to `FlatSymbolRefAttr` to avoid nested symbol references. - Rename variables from camel case (kernelFunc, kernelModule) to lower case (function, module).
1 parent 0d7c869 commit 500996f

File tree

4 files changed

+28
-17
lines changed

4 files changed

+28
-17
lines changed

mlir/include/mlir/Dialect/GPU/IR/GPUOps.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -804,8 +804,8 @@ def GPU_LaunchOp : GPU_Op<"launch", [
804804
Optional<Index>:$clusterSizeY,
805805
Optional<Index>:$clusterSizeZ,
806806
Optional<I32>:$dynamicSharedMemorySize,
807-
OptionalAttr<SymbolRefAttr>:$kernelFunc,
808-
OptionalAttr<SymbolRefAttr>:$kernelModule)>,
807+
OptionalAttr<FlatSymbolRefAttr>:$function,
808+
OptionalAttr<FlatSymbolRefAttr>:$module)>,
809809
Results<(outs Optional<GPU_AsyncToken>:$asyncToken)> {
810810
let summary = "GPU kernel launch operation";
811811

@@ -839,7 +839,7 @@ def GPU_LaunchOp : GPU_Op<"launch", [
839839
- a variadic number of Workgroup memory attributions.
840840
- a variadic number of Private memory attributions.
841841

842-
The `kernelFunc` and `kernelModule` attributes are optional and specifies
842+
The `function` and `module` attributes are optional and specifies
843843
the kernel name and a module in which the kernel should be outlined.
844844

845845
Syntax:

mlir/lib/Dialect/GPU/Transforms/KernelOutlining.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,8 @@ class GpuKernelOutliningPass
356356
auto funcWalkResult = func.walk([&](gpu::LaunchOp op) {
357357
SetVector<Value> operands;
358358
std::string kernelFnName;
359-
if (op.getKernelFunc()) {
360-
kernelFnName = op.getKernelFunc()->getRootReference().str();
359+
if (op.getFunction()) {
360+
kernelFnName = op.getFunction()->str();
361361
} else {
362362
kernelFnName =
363363
Twine(op->getParentOfType<SymbolOpInterface>().getName(),
@@ -403,9 +403,8 @@ class GpuKernelOutliningPass
403403
OpBuilder builder(context);
404404
std::string kernelModuleName;
405405
gpu::GPUModuleOp kernelModule;
406-
if (gpuLaunchOp.getKernelModule()) {
407-
kernelModuleName =
408-
gpuLaunchOp.getKernelModule()->getRootReference().str();
406+
if (gpuLaunchOp.getModule()) {
407+
kernelModuleName = gpuLaunchOp.getModule()->str();
409408
kernelModule =
410409
parentSymbolTable.lookup<gpu::GPUModuleOp>(kernelModuleName);
411410
} else {

mlir/test/Dialect/GPU/ops.mlir

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@ module attributes {gpu.container_module} {
1717
return
1818
}
1919

20+
// CHECK-LABEL:func @launch_with_module_func_attr(%{{.*}}: index)
21+
func.func @launch_with_module_func_attr(%sz : index) {
22+
// CHECK: gpu.launch blocks(%{{.*}}, %{{.*}}, %{{.*}}) in (%{{.*}} = %{{.*}}, %{{.*}} = %{{.*}}, %{{.*}} = %{{.*}}) threads(%{{.*}}, %{{.*}}, %{{.*}}) in (%{{.*}} = %{{.*}}, %{{.*}} = %{{.*}}, %{{.*}} = %{{.*}})
23+
gpu.launch blocks(%bx, %by, %bz) in (%grid_x = %sz, %grid_y = %sz, %grid_z = %sz)
24+
threads(%tx, %ty, %tz) in (%block_x = %sz, %block_y = %sz, %block_z = %sz) {
25+
// CHECK: gpu.terminator
26+
gpu.terminator
27+
// CHECK: {function = @test_kernel_func, module = @existing_module}
28+
} {function = @test_kernel_func, module = @existing_module}
29+
return
30+
}
31+
2032
// CHECK-LABEL:func @args(%{{.*}}: index, %{{.*}}: index, %{{.*}}: f32, %{{.*}}: memref<?xf32, 1>) {
2133
func.func @args(%blk : index, %thrd : index, %float : f32, %data : memref<?xf32,1>) {
2234
// CHECK: gpu.launch blocks(%{{.*}}, %{{.*}}, %{{.*}}) in (%{{.*}} = %{{.*}}, %{{.*}} = %{{.*}}, %{{.*}} = %{{.*}}) threads(%{{.*}}, %{{.*}}, %{{.*}}) in (%{{.*}} = %{{.*}}, %{{.*}} = %{{.*}}, %{{.*}} = %{{.*}})

mlir/test/Dialect/GPU/outlining.mlir

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ func.func @launch_cluster() {
509509
// CHECK-NEXT: = memref.load %[[KERNEL_ARG1]][%[[TID]]] : memref<?xf32, 1>
510510

511511
// -----
512-
// This test tests the two optional attributes kernelModule and kernelFunc for gpu.launch
512+
// This test tests the two optional attributes `module` and `function` for gpu.launch
513513
// CHECK-LABEL: func.func @testKernelAttributes()
514514
// CHECK: gpu.launch_func @test_module::@test_kernel_func blocks in (%[[GRID_X:.*]], %[[GRID_Y:.*]], %[[GRID_Z:.*]]) threads in (%[[BLOCK_X:.*]], %[[BLOCK_Y:.*]], %[[BLOCK_Z:.*]])
515515
// CHECK: gpu.module @test_module
@@ -526,12 +526,12 @@ func.func @testKernelAttributes() {
526526
threads(%tx, %ty, %tz) in (%block_x = %bDimX, %block_y = %bDimY, %block_z = %bDimZ) {
527527
"some_op"(%bx, %tx) : (index, index) -> ()
528528
gpu.terminator
529-
} {kernelModule = @test_module, kernelFunc = @test_kernel_func}
529+
} {module = @test_module, function = @test_kernel_func}
530530
return
531531
}
532532

533533
// -----
534-
// This test tests the two optional attributes kernelModule and kernelFunc for gpu.launch, when kernelModule already exists.
534+
// This test tests the two optional attributes `module` and `function` for gpu.launch, when kernelModule already exists.
535535

536536
// CHECK-LABEL: gpu.module @existing_module
537537
// CHECK: gpu.func @test_kernel_func()
@@ -559,12 +559,12 @@ func.func @testExistingModule() {
559559
threads(%tx, %ty, %tz) in (%block_x = %bDimX, %block_y = %bDimY, %block_z = %bDimZ) {
560560
"some_op"(%bx, %tx) : (index, index) -> ()
561561
gpu.terminator
562-
} {kernelModule = @existing_module, kernelFunc = @test_kernel_func}
562+
} {module = @existing_module, function = @test_kernel_func}
563563
return
564564
}
565565

566566
// -----
567-
// This test tests the optional attribute kernelModule for gpu.launch.
567+
// This test tests the optional attribute `module` for gpu.launch.
568568
// CHECK-LABEL: func.func @testKernelModuleOnly()
569569
// CHECK: gpu.launch_func @test_module::@testKernelModuleOnly_kernel blocks in (%[[GRID_X:.*]], %[[GRID_Y:.*]], %[[GRID_Z:.*]]) threads in (%[[BLOCK_X:.*]], %[[BLOCK_Y:.*]], %[[BLOCK_Z:.*]])
570570
// CHECK: gpu.module @test_module
@@ -581,12 +581,12 @@ func.func @testKernelModuleOnly() {
581581
threads(%tx, %ty, %tz) in (%block_x = %bDimX, %block_y = %bDimY, %block_z = %bDimZ) {
582582
"some_op"(%bx, %tx) : (index, index) -> ()
583583
gpu.terminator
584-
} {kernelModule = @test_module}
584+
} {module = @test_module}
585585
return
586586
}
587587

588588
// -----
589-
// This test tests the optional attribute kernelFunc for gpu.launch.
589+
// This test tests the optional attribute `function` for gpu.launch.
590590
// CHECK-LABEL: func.func @testKernelFuncOnly()
591591
// CHECK: gpu.launch_func @test_kernel_func::@test_kernel_func blocks in (%[[GRID_X:.*]], %[[GRID_Y:.*]], %[[GRID_Z:.*]]) threads in (%[[BLOCK_X:.*]], %[[BLOCK_Y:.*]], %[[BLOCK_Z:.*]])
592592

@@ -604,12 +604,12 @@ func.func @testKernelFuncOnly() {
604604
threads(%tx, %ty, %tz) in (%block_x = %bDimX, %block_y = %bDimY, %block_z = %bDimZ) {
605605
"some_op"(%bx, %tx) : (index, index) -> ()
606606
gpu.terminator
607-
} {kernelFunc = @test_kernel_func}
607+
} {function = @test_kernel_func}
608608
return
609609
}
610610

611611
// -----
612-
// This test tests gpu.launch when optional attributes kernelModule and kernelFunc are not specified.
612+
// This test tests gpu.launch when optional attributes `module` and `function` are not specified.
613613
// CHECK-LABEL: func.func @testNoAttributes()
614614
// CHECK: gpu.launch_func @testNoAttributes_kernel::@testNoAttributes_kernel blocks in (%[[GRID_X:.*]], %[[GRID_Y:.*]], %[[GRID_Z:.*]]) threads in (%[[BLOCK_X:.*]], %[[BLOCK_Y:.*]], %[[BLOCK_Z:.*]])
615615

0 commit comments

Comments
 (0)