Skip to content

Commit e29cf8e

Browse files
authored
[MLIR][MathToXeVM] Remove requirement for ModuleOp op type for MathToXeVM (llvm#163619)
This dependency is not needed. This PR removes it and checks that MathToXeVM works and respects pass pipelines specified by the user.
1 parent 56ee43a commit e29cf8e

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

mlir/include/mlir/Conversion/Passes.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,7 @@ def ConvertMathToSPIRVPass : Pass<"convert-math-to-spirv"> {
807807
// MathToXeVM
808808
//===----------------------------------------------------------------------===//
809809

810-
def ConvertMathToXeVM : Pass<"convert-math-to-xevm", "ModuleOp"> {
810+
def ConvertMathToXeVM : Pass<"convert-math-to-xevm"> {
811811
let summary =
812812
"Convert (fast) math operations to native XeVM/SPIRV equivalents";
813813
let description = [{

mlir/test/Conversion/MathToXeVM/math-to-xevm.mlir

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@
33
// RUN: mlir-opt %s -convert-math-to-xevm='convert-arith=false' \
44
// RUN: | FileCheck %s -check-prefixes='CHECK,CHECK-NO-ARITH'
55

6+
// RUN: mlir-opt --pass-pipeline="builtin.module(convert-math-to-xevm)" %s \
7+
// RUN: | FileCheck %s -check-prefixes='CHECK-MODULE,CHECK-ENTIRE-MODULE'
8+
// RUN: mlir-opt --pass-pipeline="builtin.module(gpu.module(convert-math-to-xevm))" %s \
9+
// RUN: | FileCheck %s -check-prefixes='CHECK-MODULE,CHECK-ONLY-GPU'
10+
11+
// This test:
12+
// - check that MathToXeVM converts fastmath math/arith ops properly;
13+
// - check that MathToXeVM handles nested modules while respecting pass manager.
14+
615
module @test_module {
716
// CHECK-DAG: llvm.func @_Z22__spirv_ocl_native_expDh(f16) -> f16
817
// CHECK-DAG: llvm.func @_Z22__spirv_ocl_native_expf(f32) -> f32
@@ -152,4 +161,39 @@ module @test_module {
152161

153162
return
154163
}
164+
165+
// Check that MathToXeVM handles nested modules while respecting pass manager:
166+
167+
// CHECK-ENTIRE-MODULE: llvm.func @_Z22__spirv_ocl_native_expf(f32) -> f32
168+
// CHECK-ONLY-GPU-NOT: llvm.func @_Z22__spirv_ocl_native_expf(f32) -> f32
169+
170+
// CHECK-MODULE-LABEL: @test_gpu
171+
gpu.module @test_gpu {
172+
// CHECK-MODULE: llvm.func @_Z22__spirv_ocl_native_expf(f32) -> f32
173+
gpu.func @exp_gpu() {
174+
%c1_f32 = arith.constant 1. : f32
175+
176+
// CHECK-MODULE: math.exp
177+
%exp_normal_f32 = math.exp %c1_f32 : f32
178+
179+
// CHECK-MODULE: llvm.call @_Z22__spirv_ocl_native_expf(%{{.*}}) {fastmathFlags = #llvm.fastmath<afn>} : (f32) -> f32
180+
%exp_fast_f32 = math.exp %c1_f32 fastmath<afn> : f32
181+
182+
gpu.return
183+
}
184+
}
185+
186+
// CHECK-MODULE-LABEL: @exp_func
187+
func.func @exp_func() {
188+
%c1_f32 = arith.constant 1. : f32
189+
190+
// CHECK-MODULE: math.exp
191+
%exp_normal_f32 = math.exp %c1_f32 : f32
192+
193+
// CHECK-ENTIRE-MODULE: llvm.call @_Z22__spirv_ocl_native_expf(%{{.*}}) {fastmathFlags = #llvm.fastmath<afn>} : (f32) -> f32
194+
// CHECK-ONLY-GPU: math.exp
195+
%exp_fast_f32 = math.exp %c1_f32 fastmath<afn> : f32
196+
197+
return
198+
}
155199
}

0 commit comments

Comments
 (0)