diff options
Diffstat (limited to 'src/TosaSerialize.cpp')
-rw-r--r-- | src/TosaSerialize.cpp | 47 |
1 files changed, 29 insertions, 18 deletions
diff --git a/src/TosaSerialize.cpp b/src/TosaSerialize.cpp index 54a1d28..55a11fd 100644 --- a/src/TosaSerialize.cpp +++ b/src/TosaSerialize.cpp @@ -954,10 +954,6 @@ TosaSerializationOperatorBuilder::build<mlir::tosa::ClampOp>( mlir::Operation &op) const { auto min_val_attr = op.getAttr("min_val"); auto max_val_attr = op.getAttr("max_val"); - float min_fp = 0; - float max_fp = 0; - int32_t min_int = 0; - int32_t max_int = 0; mlir::Type input_element_type = llvm::cast<mlir::ShapedType>(op.getOperand(0).getType()).getElementType(); @@ -966,24 +962,33 @@ TosaSerializationOperatorBuilder::build<mlir::tosa::ClampOp>( input_element_type = quantType.getStorageType(); } + std::vector<uint8_t> min_val, max_val; if (input_element_type.isa<mlir::FloatType>()) { - min_fp = + auto min_fp = mlir::cast<mlir::FloatAttr>(min_val_attr).getValue().convertToFloat(); - max_fp = + auto max_fp = mlir::cast<mlir::FloatAttr>(max_val_attr).getValue().convertToFloat(); - } else if (input_element_type.isUnsignedInteger()) { - min_int = mlir::cast<mlir::IntegerAttr>(min_val_attr).getUInt(); - max_int = mlir::cast<mlir::IntegerAttr>(max_val_attr).getUInt(); + TosaSerializationHandler::ConvertF32toU8({min_fp}, min_val); + TosaSerializationHandler::ConvertF32toU8({max_fp}, max_val); } else { - assert(input_element_type.isa<mlir::IntegerType>()); - min_int = mlir::cast<mlir::IntegerAttr>(min_val_attr).getInt(); - max_int = mlir::cast<mlir::IntegerAttr>(max_val_attr).getInt(); + int32_t min_int = 0; + int32_t max_int = 0; + if (input_element_type.isUnsignedInteger()) { + min_int = mlir::cast<mlir::IntegerAttr>(min_val_attr).getUInt(); + max_int = mlir::cast<mlir::IntegerAttr>(max_val_attr).getUInt(); + } else { + assert(input_element_type.isa<mlir::IntegerType>()); + min_int = mlir::cast<mlir::IntegerAttr>(min_val_attr).getInt(); + max_int = mlir::cast<mlir::IntegerAttr>(max_val_attr).getInt(); + } + TosaSerializationHandler::ConvertI32toU8({min_int}, min_val); + TosaSerializationHandler::ConvertI32toU8({max_int}, max_val); } std::string input_name = GetTensorName(op.getOperand(0)); std::string output_name = GetTensorName(op.getResult(0)); - TosaClampAttribute attribute(min_int, max_int, min_fp, max_fp); + TosaClampAttribute attribute(min_val, max_val); TosaSerializationOperator *tyop = new TosaSerializationOperator( Op_CLAMP, Attribute_ClampAttribute, &attribute, @@ -1128,7 +1133,15 @@ TosaSerializationOperatorBuilder::build<mlir::tosa::PadOp>( } } - TosaPadAttribute attribute({}, pad_const_int, pad_const_fp); + std::vector<uint8_t> pad_const; + mlir::Type input_element_type = + llvm::cast<mlir::ShapedType>(op.getOperand(0).getType()).getElementType(); + if (input_element_type.isa<mlir::FloatType>()) { + TosaSerializationHandler::ConvertF32toU8({pad_const_fp}, pad_const); + } else { + TosaSerializationHandler::ConvertI32toU8({pad_const_int}, pad_const); + } + TosaPadAttribute attribute(pad_const); TosaSerializationOperator *tyop = new TosaSerializationOperator( Op_PAD, Attribute_PadAttribute, &attribute, @@ -1386,10 +1399,8 @@ TosaSerializationOperatorBuilder::build<mlir::tosa::RescaleOp>( std::string shift_name = GetTensorName(op.getOperand(2)); std::string output_name = GetTensorName(output); - TosaRescaleAttribute attribute(input_zp, output_zp, - /* multiplier = */ {}, /* shift = */ {}, - scale32, double_round, per_channel, - input_unsigned, output_unsigned); + TosaRescaleAttribute attribute(input_zp, output_zp, scale32, double_round, + per_channel, input_unsigned, output_unsigned); TosaSerializationOperator *tyop = new TosaSerializationOperator( Op_RESCALE, Attribute_RescaleAttribute, &attribute, |