Skip to content

Implicit broadcast of scalar values to vector values in the MathBuilder constructor #2900

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/Conversion/ONNXToKrnl/Math/Elementwise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ Value emitPostProcessingFor(ConversionPatternRewriter &rewriter, Location loc,

template <typename Op>
static void CheckIfCustomScalarOpIsSupported(Type elementType) {
Type actualElementType = MathBuilder::elementTypeWithVector(elementType);
Type actualElementType =
MathBuilder::elementTypeOfScalarOrVector(elementType);
if (mlir::isa<mlir::IntegerType>(actualElementType)) {
if constexpr (std::is_same<ScalarIOp<Op>, CustomScalarOp>::value)
return;
Expand Down Expand Up @@ -914,7 +915,7 @@ Value emitScalarOpFor<ONNXSignOp>(ConversionPatternRewriter &rewriter,
// ConstantOp 0,
// %Y)
Value plusSelect;
if (create.math.isUnsignedIntegerWithVector(elementType)) {
if (create.math.isScalarOrVectorUnsignedInteger(elementType)) {
// Unsigned integers are by definition positive.
plusSelect = one;
} else {
Expand Down Expand Up @@ -1188,7 +1189,7 @@ Value emitScalarOpFor<ONNXModOp>(ConversionPatternRewriter &rewriter,
MultiDialectBuilder<MathBuilder, KrnlBuilder> create(rewriter, loc);

// TODO: here we assume fmod=1, what should if that is not the case?
if (create.math.isFloatWithVector(elementType)) {
if (create.math.isScalarOrVectorFloat(elementType)) {
// fmod is always 1. Behavior is like numpy.fmod.
// The sign of the remainder is the same as the dividend.
Value rem = create.math.rem(dividend, divisor);
Expand All @@ -1201,7 +1202,7 @@ Value emitScalarOpFor<ONNXModOp>(ConversionPatternRewriter &rewriter,
return create.math.copySign(rem, dividend);
#endif
}
if (create.math.isIntegerWithVector(elementType)) {
if (create.math.isScalarOrVectorInteger(elementType)) {
// "math.rem" returns "minus" for minus dividend and "plus or zero" for plus
// dividend. We call the math.rem's return value "mathRemainder". However
// onnx.ModOp should return "minus" for minus divisor and "plus or zero" for
Expand Down
2 changes: 1 addition & 1 deletion src/Conversion/ONNXToKrnl/ONNXToKrnlCommon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ mlir::Value emitScalarOpFor(mlir::ConversionPatternRewriter &rewriter,
// int. Thus we look at the type the first input argument, and not the output
// elementType.
mlir::Type actualElementType =
MathBuilder::elementTypeWithVector(scalarOperands[0].getType());
MathBuilder::elementTypeOfScalarOrVector(scalarOperands[0]);
// Perform int or float operation depending on the actual elementary type.
if (mlir::isa<mlir::IntegerType>(actualElementType)) {
// Generate the integer code only if the scalar integer op is non-void
Expand Down
Loading
Loading