Index: mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp =================================================================== --- mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp +++ mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp @@ -712,6 +712,9 @@ populateGpuToNVVMConversionPatterns(converter, patterns); ConversionTarget target(getContext()); target.addIllegalDialect(); + target.addIllegalOp(); + target.addIllegalOp(); + target.addIllegalOp(); target.addIllegalOp(); target.addIllegalOp(); target.addLegalDialect(); @@ -739,6 +742,12 @@ NVVM::GridDimYOp, NVVM::GridDimZOp>, GPUAllReduceOpLowering, GPUShuffleOpLowering, GPUFuncOpLowering, GPUReturnOpLowering>(converter); + patterns.insert>(converter, "__nv_fabsf", + "__nv_fabs"); + patterns.insert>(converter, "__nv_ceilf", + "__nv_ceil"); + patterns.insert>(converter, "__nv_cosf", + "__nv_cos"); patterns.insert>(converter, "__nv_expf", "__nv_exp"); } Index: mlir/lib/Conversion/GPUToROCDL/LowerGpuOpsToROCDLOps.cpp =================================================================== --- mlir/lib/Conversion/GPUToROCDL/LowerGpuOpsToROCDLOps.cpp +++ mlir/lib/Conversion/GPUToROCDL/LowerGpuOpsToROCDLOps.cpp @@ -51,11 +51,20 @@ GPUIndexIntrinsicOpLowering>( converter); + patterns.insert>(converter, "_ocml_fabs_f32", + "_ocml_fabs_f64"); + patterns.insert>(converter, "_ocml_ceil_f32", + "_ocml_ceil_f64"); + patterns.insert>(converter, "_ocml_cos_f32", + "_ocml_cos_f64"); patterns.insert>(converter, "_ocml_exp_f32", "_ocml_exp_f64"); ConversionTarget target(getContext()); target.addLegalDialect(); + target.addIllegalOp(); + target.addIllegalOp(); + target.addIllegalOp(); target.addIllegalOp(); target.addDynamicallyLegalOp( [&](FuncOp op) { return converter.isSignatureLegal(op.getType()); }); Index: mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm.mlir =================================================================== --- mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm.mlir +++ mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm.mlir @@ -111,6 +111,57 @@ // ----- +module attributes {gpu.kernel_module} { + // CHECK: llvm.func @__nv_fabsf(!llvm.float) -> !llvm.float + // CHECK: llvm.func @__nv_fabs(!llvm.double) -> !llvm.double + // CHECK-LABEL: func @gpu_fabs + func @gpu_fabs(%arg_f32 : f32, %arg_f64 : f64) { + %fabs_f32 = std.absf %arg_f32 : f32 + // CHECK: llvm.call @__nv_fabsf(%{{.*}}) : (!llvm.float) -> !llvm.float + %result_f32 = std.absf %fabs_f32 : f32 + // CHECK: llvm.call @__nv_fabsf(%{{.*}}) : (!llvm.float) -> !llvm.float + %result64 = std.absf %arg_f64 : f64 + // CHECK: llvm.call @__nv_fabs(%{{.*}}) : (!llvm.double) -> !llvm.double + std.return + } +} + +// ----- + +module attributes {gpu.kernel_module} { + // CHECK: llvm.func @__nv_ceilf(!llvm.float) -> !llvm.float + // CHECK: llvm.func @__nv_ceil(!llvm.double) -> !llvm.double + // CHECK-LABEL: func @gpu_ceil + func @gpu_ceil(%arg_f32 : f32, %arg_f64 : f64) { + %ceil_f32 = std.ceilf %arg_f32 : f32 + // CHECK: llvm.call @__nv_ceilf(%{{.*}}) : (!llvm.float) -> !llvm.float + %result_f32 = std.ceilf %ceil_f32 : f32 + // CHECK: llvm.call @__nv_ceilf(%{{.*}}) : (!llvm.float) -> !llvm.float + %result64 = std.ceilf %arg_f64 : f64 + // CHECK: llvm.call @__nv_ceil(%{{.*}}) : (!llvm.double) -> !llvm.double + std.return + } +} + +// ----- + +module attributes {gpu.kernel_module} { + // CHECK: llvm.func @__nv_cosf(!llvm.float) -> !llvm.float + // CHECK: llvm.func @__nv_cos(!llvm.double) -> !llvm.double + // CHECK-LABEL: func @gpu_cos + func @gpu_cos(%arg_f32 : f32, %arg_f64 : f64) { + %cos_f32 = std.cos %arg_f32 : f32 + // CHECK: llvm.call @__nv_cosf(%{{.*}}) : (!llvm.float) -> !llvm.float + %result_f32 = std.cos %cos_f32 : f32 + // CHECK: llvm.call @__nv_cosf(%{{.*}}) : (!llvm.float) -> !llvm.float + %result64 = std.cos %arg_f64 : f64 + // CHECK: llvm.call @__nv_cos(%{{.*}}) : (!llvm.double) -> !llvm.double + std.return + } +} + +// ----- + module attributes {gpu.kernel_module} { // CHECK: llvm.func @__nv_expf(!llvm.float) -> !llvm.float // CHECK: llvm.func @__nv_exp(!llvm.double) -> !llvm.double Index: mlir/test/Conversion/GPUToROCDL/gpu-to-rocdl.mlir =================================================================== --- mlir/test/Conversion/GPUToROCDL/gpu-to-rocdl.mlir +++ mlir/test/Conversion/GPUToROCDL/gpu-to-rocdl.mlir @@ -38,6 +38,57 @@ // ----- +module attributes {gpu.kernel_module} { + // CHECK: llvm.func @_ocml_fabs_f32(!llvm.float) -> !llvm.float + // CHECK: llvm.func @_ocml_fabs_f64(!llvm.double) -> !llvm.double + // CHECK-LABEL: func @gpu_fabs + func @gpu_fabs(%arg_f32 : f32, %arg_f64 : f64) { + %fabs_f32 = std.absf %arg_f32 : f32 + // CHECK: llvm.call @_ocml_fabs_f32(%{{.*}}) : (!llvm.float) -> !llvm.float + %result_f32 = std.absf %fabs_f32 : f32 + // CHECK: llvm.call @_ocml_fabs_f32(%{{.*}}) : (!llvm.float) -> !llvm.float + %result64 = std.absf %arg_f64 : f64 + // CHECK: llvm.call @_ocml_fabs_f64(%{{.*}}) : (!llvm.double) -> !llvm.double + std.return + } +} + +// ----- + +module attributes {gpu.kernel_module} { + // CHECK: llvm.func @_ocml_ceil_f32(!llvm.float) -> !llvm.float + // CHECK: llvm.func @_ocml_ceil_f64(!llvm.double) -> !llvm.double + // CHECK-LABEL: func @gpu_ceil + func @gpu_ceil(%arg_f32 : f32, %arg_f64 : f64) { + %ceil_f32 = std.ceilf %arg_f32 : f32 + // CHECK: llvm.call @_ocml_ceil_f32(%{{.*}}) : (!llvm.float) -> !llvm.float + %result_f32 = std.ceilf %ceil_f32 : f32 + // CHECK: llvm.call @_ocml_ceil_f32(%{{.*}}) : (!llvm.float) -> !llvm.float + %result64 = std.ceilf %arg_f64 : f64 + // CHECK: llvm.call @_ocml_ceil_f64(%{{.*}}) : (!llvm.double) -> !llvm.double + std.return + } +} + +// ----- + +module attributes {gpu.kernel_module} { + // CHECK: llvm.func @_ocml_cos_f32(!llvm.float) -> !llvm.float + // CHECK: llvm.func @_ocml_cos_f64(!llvm.double) -> !llvm.double + // CHECK-LABEL: func @gpu_cos + func @gpu_cos(%arg_f32 : f32, %arg_f64 : f64) { + %cos_f32 = std.cos %arg_f32 : f32 + // CHECK: llvm.call @_ocml_cos_f32(%{{.*}}) : (!llvm.float) -> !llvm.float + %result_f32 = std.cos %cos_f32 : f32 + // CHECK: llvm.call @_ocml_cos_f32(%{{.*}}) : (!llvm.float) -> !llvm.float + %result64 = std.cos %arg_f64 : f64 + // CHECK: llvm.call @_ocml_cos_f64(%{{.*}}) : (!llvm.double) -> !llvm.double + std.return + } +} + +// ----- + module attributes {gpu.kernel_module} { // CHECK: llvm.func @_ocml_exp_f32(!llvm.float) -> !llvm.float // CHECK: llvm.func @_ocml_exp_f64(!llvm.double) -> !llvm.double