23 #include "../GPUCommon/GPUOpsLowering.h"
24 #include "../GPUCommon/IndexIntrinsicsOpLowering.h"
25 #include "../GPUCommon/OpToFuncCallLowering.h"
29 #define GEN_PASS_DEF_CONVERTMATHTOROCDL
30 #include "mlir/Conversion/Passes.h.inc"
35 #define DEBUG_TYPE "math-to-rocdl"
36 #define DBGS() (llvm::dbgs() << "[" DEBUG_TYPE "]: ")
38 template <
typename OpTy>
42 StringRef f32ApproxFunc =
"") {
65 populateOpPatterns<math::AcosOp>(converter, patterns,
"__ocml_acos_f32",
67 populateOpPatterns<math::AcoshOp>(converter, patterns,
"__ocml_acosh_f32",
69 populateOpPatterns<math::AsinOp>(converter, patterns,
"__ocml_asin_f32",
71 populateOpPatterns<math::AsinhOp>(converter, patterns,
"__ocml_asinh_f32",
73 populateOpPatterns<math::AtanOp>(converter, patterns,
"__ocml_atan_f32",
75 populateOpPatterns<math::AtanhOp>(converter, patterns,
"__ocml_atanh_f32",
77 populateOpPatterns<math::Atan2Op>(converter, patterns,
"__ocml_atan2_f32",
79 populateOpPatterns<math::CbrtOp>(converter, patterns,
"__ocml_cbrt_f32",
81 populateOpPatterns<math::CeilOp>(converter, patterns,
"__ocml_ceil_f32",
83 populateOpPatterns<math::CosOp>(converter, patterns,
"__ocml_cos_f32",
85 populateOpPatterns<math::CoshOp>(converter, patterns,
"__ocml_cosh_f32",
87 populateOpPatterns<math::SinhOp>(converter, patterns,
"__ocml_sinh_f32",
89 populateOpPatterns<math::ExpOp>(converter, patterns,
"",
"__ocml_exp_f64");
90 populateOpPatterns<math::Exp2Op>(converter, patterns,
"__ocml_exp2_f32",
92 populateOpPatterns<math::ExpM1Op>(converter, patterns,
"__ocml_expm1_f32",
94 populateOpPatterns<math::FloorOp>(converter, patterns,
"__ocml_floor_f32",
96 populateOpPatterns<math::LogOp>(converter, patterns,
"",
"__ocml_log_f64");
97 populateOpPatterns<math::Log10Op>(converter, patterns,
"__ocml_log10_f32",
99 populateOpPatterns<math::Log1pOp>(converter, patterns,
"__ocml_log1p_f32",
101 populateOpPatterns<math::Log2Op>(converter, patterns,
"__ocml_log2_f32",
103 populateOpPatterns<math::PowFOp>(converter, patterns,
"__ocml_pow_f32",
105 populateOpPatterns<math::RsqrtOp>(converter, patterns,
"__ocml_rsqrt_f32",
107 populateOpPatterns<math::SinOp>(converter, patterns,
"__ocml_sin_f32",
109 populateOpPatterns<math::TanhOp>(converter, patterns,
"__ocml_tanh_f32",
111 populateOpPatterns<math::TanOp>(converter, patterns,
"__ocml_tan_f32",
113 populateOpPatterns<math::ErfOp>(converter, patterns,
"__ocml_erf_f32",
117 populateOpPatterns<arith::RemFOp>(converter, patterns,
"__ocml_fmod_f32",
122 struct ConvertMathToROCDLPass
123 :
public impl::ConvertMathToROCDLBase<ConvertMathToROCDLPass> {
124 ConvertMathToROCDLPass() =
default;
125 void runOnOperation()
override;
129 void ConvertMathToROCDLPass::runOnOperation() {
130 auto m = getOperation();
138 target.addLegalDialect<BuiltinDialect, func::FuncDialect,
139 vector::VectorDialect, LLVM::LLVMDialect>();
140 target.addIllegalOp<LLVM::CosOp, LLVM::ExpOp, LLVM::Exp2Op, LLVM::FAbsOp,
141 LLVM::FCeilOp, LLVM::FFloorOp, LLVM::FRemOp, LLVM::LogOp,
142 LLVM::Log10Op, LLVM::Log2Op, LLVM::PowOp, LLVM::SinOp,
static MLIRContext * getContext(OpFoldResult val)
static void populateOpPatterns(LLVMTypeConverter &converter, RewritePatternSet &patterns, StringRef f32Func, StringRef f64Func, StringRef f32ApproxFunc="")
static llvm::ManagedStatic< PassManagerOptions > options
This class describes a specific conversion target.
The main mechanism for performing data layout queries.
Conversion from types to the LLVM IR dialect.
Options to control the LLVM lowering.
MLIRContext is the top-level object for a collection of MLIR operations.
RewritePatternSet & add(ConstructorArg &&arg, ConstructorArgs &&...args)
Add an instance of each of the pattern types 'Ts' to the pattern list with the given arguments.
Include the generated interface declarations.
void populateMathToROCDLConversionPatterns(LLVMTypeConverter &converter, RewritePatternSet &patterns)
Populate the given list with patterns that convert from Math to ROCDL calls.
LogicalResult applyPartialConversion(ArrayRef< Operation * > ops, const ConversionTarget &target, const FrozenRewritePatternSet &patterns, ConversionConfig config=ConversionConfig())
Below we define several entry points for operation conversion.
Rewriting that replace SourceOp with a CallOp to f32Func or f64Func or f32ApproxFunc depending on the...
Rewriting that unrolls SourceOp to scalars if it's operating on vectors.