-
Notifications
You must be signed in to change notification settings - Fork 260
Added LLVM ops and lowering phases from standard dialect. #300
Conversation
@@ -793,12 +790,33 @@ struct SubFOpLowering : public BinaryOpLLVMOpLowering<SubFOp, LLVM::FSubOp> { | |||
struct MulFOpLowering : public BinaryOpLLVMOpLowering<MulFOp, LLVM::FMulOp> { | |||
using Super::Super; | |||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe have unary ops defs before binary ops sorted and also sort them?
}]; | ||
} | ||
|
||
def LLVM_TanhOp : LLVM_Op<"tanh", [NoSideEffect]>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@River707, @ftynse, @joker-eph
What would be the right way to test values of Tanh? It is quite easy to introduce a bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need a more detailed explanation of where these values come from and what is computed in the end.
}]; | ||
} | ||
|
||
def LLVM_CosOp : LLVM_Op<"intr.cos", [NoSideEffect]>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: sort defs (CosOp should be after Copysign)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LLVM dialect should only contain LLVM instructions or intrinsics. There's no tanh in LLVM IR, so it should not be in the dialect. Consider implementing what you did in the builder as a conversion pattern from tanh to a combination of LLVM dialect operations.
Arguments<(ins LLVM_Type:$in)>, | ||
Results<(outs LLVM_Type:$res)> { | ||
let llvmBuilder = [{ | ||
llvm::Module *module = builder.GetInsertBlock()->getModule(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we keep adding more intrinsics, I am more and more interesting in generalizing these. Have you considered it?
}]; | ||
} | ||
|
||
def LLVM_FCeilOp : LLVM_Op<"intr.ceil", [NoSideEffect]>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a mismatch between op name (fceil) and intrinsic name (ceil), please fix.
def LLVM_TanhOp : LLVM_Op<"tanh", [NoSideEffect]>, | ||
Arguments<(ins LLVM_Type:$in)>, | ||
Results<(outs LLVM_Type:$res)> { | ||
let llvmBuilder = [{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is way too long to be inline code in Tablegen. Please extract into a function and just call it here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dfki-jugr Let's remove Tanh from the current PR. This logic be added to legalization from STD TanhOp to LLVM dialect, not from LLVM dialect to LLVM IR.
llvm::Module *module = builder.GetInsertBlock()->getModule(); | ||
|
||
llvm::Type *type = $in->getType(); | ||
llvm::Value *max_value = llvm::ConstantFP::get(type, 20.0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MLIR uses camelBack for variable names (see https://github.com/tensorflow/mlir/blob/master/g3doc/DeveloperGuide.md).
llvm::Value *input_clamped = | ||
builder.CreateSelect(cmp_lower_bound, clamp_min, select_res); | ||
|
||
static constexpr std::array<float, 7> numerator_coeffs{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The must be accompanied by a detailed comment of what you are doing here and why it should work.
}]; | ||
} | ||
|
||
def LLVM_TanhOp : LLVM_Op<"tanh", [NoSideEffect]>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there is no tanh
op in LLVM, it must not be an LLVM Op. Create it in some dialect and implement a lowering from that dialect to the LLVM dialect instead, so the translation from the LLVM dialect to LLVM IR is as simple as possible. Having magic constants in the translation wouldn't cut it.
If you implement your non-trivial conversion in as a conversion pattern, it is significantly easier to replace.
please do not merge this until the concerns on translation are addressed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can submit this CL, after the TanhOp lowering is excluded and the comments are addressed.
def LLVM_CosOp : LLVM_UnaryIntrinsicOp<"cos">; | ||
|
||
def LLVM_CopySignOp : LLVM_BinaryIntrinsicOp<"copysign">; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: remove empty line
…eil, Cos, FNeg, CopySign and Tanh. Added test cases for the newly added LLVM operations and lowering features.
7792dd7
to
da6168b
Compare
…eil, Cos, FNeg, CopySign. Added test cases for the newly added LLVM operations and lowering features. Closes #300 COPYBARA_INTEGRATE_REVIEW=tensorflow/mlir#300 from dfki-jugr:std_to_llvm da6168bbc1a369ae2e99ad3881fdddd82f075dd4 PiperOrigin-RevId: 286231169 Change-Id: I364bda2adad4054052a3a53b4cb1c3de1102864f
…eil, Cos, FNeg, CopySign. Added test cases for the newly added LLVM operations and lowering features. Closes tensorflow/mlir#300 COPYBARA_INTEGRATE_REVIEW=tensorflow/mlir#300 from dfki-jugr:std_to_llvm da6168bbc1a369ae2e99ad3881fdddd82f075dd4 PiperOrigin-RevId: 286231169
Added LLVM ops and lowering phases from standard dialect for FAbs, FCeil, Cos, FNeg, CopySign and Tanh.
Added test cases for the newly added LLVM operations and lowering features.