Skip to content

Commit f2fd80a

Browse files
committed
Add xevm-attach-target transform pass.
Co-authored-by: Artem Kroviakov artem.kroviakov@intel.com
1 parent dc8e89b commit f2fd80a

File tree

4 files changed

+44
-4
lines changed

4 files changed

+44
-4
lines changed

mlir/include/mlir/Dialect/GPU/Transforms/Passes.td

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,4 +258,38 @@ def GpuSPIRVAttachTarget: Pass<"spirv-attach-target", ""> {
258258
];
259259
}
260260

261+
def GpuXeVMAttachTarget : Pass<"xevm-attach-target", "mlir::gpu::GPUModuleOp"> {
262+
let summary = "Attaches a XeVM target attribute to a GPU Module.";
263+
let description = [{
264+
This pass searches for all GPU Modules in the immediate regions and attaches
265+
a XeVM target if the module matches the name specified by the `module` argument.
266+
267+
Example:
268+
```
269+
// File: in.mlir:
270+
gpu.module @nvvm_module_1 {...}
271+
gpu.module @rocdl_module_2 {...}
272+
gpu.module @xevm_module_3 {...}
273+
// mlir-opt --xevm-attach-target="module=xevm.* chip=pvc" in.mlir
274+
gpu.module @nvvm_module_1 {...}
275+
gpu.module @rocdl_module_2 {...}
276+
gpu.module @xevm_module_3 [#xevm.target<chip = "pvc">] {...}
277+
```
278+
}];
279+
let options =
280+
[Option<"moduleMatcher", "module", "std::string",
281+
/*default=*/[{""}],
282+
"Regex used to identify the modules to attach the target to.">,
283+
Option<"triple", "triple", "std::string",
284+
/*default=*/"\"spirv64-unknown-unknown\"", "Target triple.">,
285+
Option<"chip", "chip", "std::string",
286+
/*default=*/"\"bmg\"", "Target chip.">,
287+
Option<"optLevel", "O", "unsigned",
288+
/*default=*/"2", "Optimization level.">,
289+
ListOption<"linkLibs", "l", "std::string",
290+
"Extra bitcode libraries paths to link to.">,
291+
Option<"cmdOptions", "cmd-options", "std::string",
292+
/*default=*/[{""}],
293+
"Command line options passed to downstream compiler">];
294+
}
261295
#endif // MLIR_DIALECT_GPU_PASSES

mlir/lib/Dialect/GPU/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ add_mlir_dialect_library(MLIRGPUTransforms
4444
Transforms/ShuffleRewriter.cpp
4545
Transforms/SubgroupIdRewriter.cpp
4646
Transforms/SubgroupReduceLowering.cpp
47+
Transforms/XeVMAttachTarget.cpp
4748

4849
OBJECT
4950

mlir/test/Dialect/LLVMIR/attach-targets.mlir

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// RUN: mlir-opt %s --nvvm-attach-target='module=nvvm.* O=3 chip=sm_90' --rocdl-attach-target='module=rocdl.* O=3 chip=gfx90a' | FileCheck %s
2-
// RUN: mlir-opt %s --nvvm-attach-target='module=options.* O=1 chip=sm_70 fast=true ftz=true' --rocdl-attach-target='module=options.* l=file1.bc,file2.bc wave64=false finite-only=true' | FileCheck %s --check-prefix=CHECK_OPTS
1+
// RUN: mlir-opt %s --nvvm-attach-target='module=nvvm.* O=3 chip=sm_90' --rocdl-attach-target='module=rocdl.* O=3 chip=gfx90a' --xevm-attach-target='module=xevm.* O=3 chip=pvc' | FileCheck %s
2+
// RUN: mlir-opt %s --nvvm-attach-target='module=options.* O=1 chip=sm_70 fast=true ftz=true' --rocdl-attach-target='module=options.* l=file1.bc,file2.bc wave64=false finite-only=true' --xevm-attach-target='module=options.* O=1 chip=pvc' | FileCheck %s --check-prefix=CHECK_OPTS
33

44
module attributes {gpu.container_module} {
55
// Verify the target is appended.
@@ -18,12 +18,16 @@ gpu.module @nvvm_module_3 [#nvvm.target<O = 3, chip = "sm_90">] {
1818
// CHECK: @rocdl_module [#rocdl.target<O = 3, chip = "gfx90a">] {
1919
gpu.module @rocdl_module {
2020
}
21+
// Verify that other targets are not added as they fail to match the regex, but XeVM does get appended.
22+
// CHECK: @xevm_module [#xevm.target<O = 3, chip = "pvc">] {
23+
gpu.module @xevm_module {
24+
}
2125
// Check the options were added.
22-
// CHECK_OPTS: @options_module_1 [#nvvm.target<O = 1, chip = "sm_70", flags = {fast, ftz}>, #rocdl.target<flags = {finite_only, no_wave64}, link = ["file1.bc", "file2.bc"]>] {
26+
// CHECK_OPTS: @options_module_1 [#nvvm.target<O = 1, chip = "sm_70", flags = {fast, ftz}>, #rocdl.target<flags = {finite_only, no_wave64}, link = ["file1.bc", "file2.bc"]>, #xevm.target<O = 1, chip = "pvc">] {
2327
gpu.module @options_module_1 {
2428
}
2529
// Check the options were added and that the first target was preserved.
26-
// CHECK_OPTS: @options_module_2 [#nvvm.target<O = 3, chip = "sm_90">, #nvvm.target<O = 1, chip = "sm_70", flags = {fast, ftz}>, #rocdl.target<flags = {finite_only, no_wave64}, link = ["file1.bc", "file2.bc"]>] {
30+
// CHECK_OPTS: @options_module_2 [#nvvm.target<O = 3, chip = "sm_90">, #nvvm.target<O = 1, chip = "sm_70", flags = {fast, ftz}>, #rocdl.target<flags = {finite_only, no_wave64}, link = ["file1.bc", "file2.bc"]>, #xevm.target<O = 1, chip = "pvc">] {
2731
gpu.module @options_module_2 [#nvvm.target<O = 3, chip = "sm_90">] {
2832
}
2933
}

mlir/test/lib/Dialect/GPU/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ set(LIBS
2929
MLIRTranslateLib
3030
MLIRVectorDialect
3131
MLIRVectorToLLVMPass
32+
MLIRXeVMDialect
3233
)
3334

3435
add_mlir_library(MLIRGPUTestPasses

0 commit comments

Comments
 (0)