[Mlir-commits] [mlir] ffe6a58 - [mlir][nvvm]: Add math::Exp2Op lowering to NVVM.
Adrian Kuegel
llvmlistbot at llvm.org
Thu Jul 15 04:06:45 PDT 2021
Author: Adrian Kuegel
Date: 2021-07-15T13:06:30+02:00
New Revision: ffe6a5832533e71e1edc4fe0eebda421f24fb61a
URL: https://github.com/llvm/llvm-project/commit/ffe6a5832533e71e1edc4fe0eebda421f24fb61a
DIFF: https://github.com/llvm/llvm-project/commit/ffe6a5832533e71e1edc4fe0eebda421f24fb61a.diff
LOG: [mlir][nvvm]: Add math::Exp2Op lowering to NVVM.
Differential Revision: https://reviews.llvm.org/D106050
Added:
Modified:
mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp
mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp b/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp
index 243ed6c334d3..4c8ad15b098b 100644
--- a/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp
+++ b/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp
@@ -188,9 +188,9 @@ void mlir::configureGpuToNVVMConversionLegality(ConversionTarget &target) {
target.addLegalDialect<::mlir::LLVM::LLVMDialect>();
target.addLegalDialect<::mlir::NVVM::NVVMDialect>();
target.addIllegalDialect<gpu::GPUDialect>();
- target.addIllegalOp<LLVM::CosOp, LLVM::ExpOp, LLVM::FAbsOp, LLVM::FCeilOp,
- LLVM::FFloorOp, LLVM::LogOp, LLVM::Log10Op, LLVM::Log2Op,
- LLVM::PowOp, LLVM::SinOp, LLVM::SqrtOp>();
+ target.addIllegalOp<LLVM::CosOp, LLVM::ExpOp, LLVM::Exp2Op, LLVM::FAbsOp,
+ LLVM::FCeilOp, LLVM::FFloorOp, LLVM::LogOp, LLVM::Log10Op,
+ LLVM::Log2Op, LLVM::PowOp, LLVM::SinOp, LLVM::SqrtOp>();
// TODO: Remove once we support replacing non-root ops.
target.addLegalOp<gpu::YieldOp, gpu::GPUModuleOp, gpu::ModuleEndOp>();
@@ -230,6 +230,8 @@ void mlir::populateGpuToNVVMConversionPatterns(LLVMTypeConverter &converter,
"__nv_cos");
patterns.add<OpToFuncCallLowering<math::ExpOp>>(converter, "__nv_expf",
"__nv_exp");
+ patterns.add<OpToFuncCallLowering<math::Exp2Op>>(converter, "__nv_exp2f",
+ "__nv_exp2");
patterns.add<OpToFuncCallLowering<math::ExpM1Op>>(converter, "__nv_expm1f",
"__nv_expm1");
patterns.add<OpToFuncCallLowering<FloorFOp>>(converter, "__nv_floorf",
diff --git a/mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm.mlir b/mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm.mlir
index 1aaa4cd2399b..415090ee68c2 100644
--- a/mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm.mlir
+++ b/mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm.mlir
@@ -214,6 +214,20 @@ gpu.module @test_module {
}
}
+// -----
+gpu.module @test_module {
+ // CHECK: llvm.func @__nv_exp2f(f32) -> f32
+ // CHECK: llvm.func @__nv_exp2(f64) -> f64
+ // CHECK-LABEL: func @gpu_exp2
+ func @gpu_exp2(%arg_f32 : f32, %arg_f64 : f64) -> (f32, f64) {
+ %result32 = math.exp2 %arg_f32 : f32
+ // CHECK: llvm.call @__nv_exp2f(%{{.*}}) : (f32) -> f32
+ %result64 = math.exp2 %arg_f64 : f64
+ // CHECK: llvm.call @__nv_exp2(%{{.*}}) : (f64) -> f64
+ std.return %result32, %result64 : f32, f64
+ }
+}
+
// -----
gpu.module @test_module {
More information about the Mlir-commits
mailing list