Skip to content

Commit baf2d13

Browse files
committed
[mlir][GPUToROCDL] Lower arith.remf to GPU intrinsic.
Differential Revision: https://reviews.llvm.org/D159423
1 parent b1b6c06 commit baf2d13

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

mlir/lib/Conversion/GPUToROCDL/LowerGpuOpsToROCDLOps.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,9 @@ void mlir::configureGpuToROCDLConversionLegality(ConversionTarget &target) {
317317
target.addLegalDialect<ROCDL::ROCDLDialect>();
318318
target.addIllegalDialect<gpu::GPUDialect>();
319319
target.addIllegalOp<LLVM::CosOp, LLVM::ExpOp, LLVM::Exp2Op, LLVM::FAbsOp,
320-
LLVM::FCeilOp, LLVM::FFloorOp, LLVM::LogOp, LLVM::Log10Op,
321-
LLVM::Log2Op, LLVM::PowOp, LLVM::SinOp, LLVM::SqrtOp>();
320+
LLVM::FCeilOp, LLVM::FFloorOp, LLVM::FRemOp, LLVM::LogOp,
321+
LLVM::Log10Op, LLVM::Log2Op, LLVM::PowOp, LLVM::SinOp,
322+
LLVM::SqrtOp>();
322323

323324
// TODO: Remove once we support replacing non-root ops.
324325
target.addLegalOp<gpu::YieldOp, gpu::GPUModuleOp, gpu::ModuleEndOp>();
@@ -386,6 +387,8 @@ void mlir::populateGpuToROCDLConversionPatterns(
386387
"__ocml_expm1_f64");
387388
populateOpPatterns<math::FloorOp>(converter, patterns, "__ocml_floor_f32",
388389
"__ocml_floor_f64");
390+
populateOpPatterns<arith::RemFOp>(converter, patterns, "__ocml_fmod_f32",
391+
"__ocml_fmod_f64");
389392
populateOpPatterns<math::LogOp>(converter, patterns, "__ocml_log_f32",
390393
"__ocml_log_f64");
391394
populateOpPatterns<math::Log10Op>(converter, patterns, "__ocml_log10_f32",

mlir/test/Conversion/GPUToROCDL/gpu-to-rocdl.mlir

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,21 @@ gpu.module @test_module {
574574

575575
// -----
576576

577+
gpu.module @test_module {
578+
// CHECK: llvm.func @__ocml_fmod_f32(f32, f32) -> f32
579+
// CHECK: llvm.func @__ocml_fmod_f64(f64, f64) -> f64
580+
// CHECK-LABEL: func @gpu_fmod
581+
func.func @gpu_fmod(%arg_f32 : f32, %arg_f64 : f64) -> (f32, f64) {
582+
%result32 = arith.remf %arg_f32, %arg_f32 : f32
583+
// CHECK: llvm.call @__ocml_fmod_f32(%{{.*}}, %{{.*}}) : (f32, f32) -> f32
584+
%result64 = arith.remf %arg_f64, %arg_f64 : f64
585+
// CHECK: llvm.call @__ocml_fmod_f64(%{{.*}}, %{{.*}}) : (f64, f64) -> f64
586+
func.return %result32, %result64 : f32, f64
587+
}
588+
}
589+
590+
// -----
591+
577592
gpu.module @test_module {
578593
// CHECK-LABEL: func @gpu_shuffle()
579594
func.func @gpu_shuffle() -> (f32, f32) {
@@ -612,4 +627,4 @@ gpu.module @test_module {
612627
%shfli, %predi = gpu.shuffle idx %arg0, %arg1, %arg2 : f32
613628
func.return %shfl, %shfli : f32, f32
614629
}
615-
}
630+
}

0 commit comments

Comments
 (0)