From 80905bba37ce55e8db293b1405a78b63dc1855cb Mon Sep 17 00:00:00 2001 From: James Ward Date: Wed, 25 Jan 2023 15:51:27 +0000 Subject: Remove zero pad from float attrribute serialization * For Clamp/Pad float attributes * Necessary for the outputs from Python and C++ code to be consistent Signed-off-by: James Ward Change-Id: I41530aa1805968becd861e4dee190a88d1973cec --- src/tosa_serialization_handler.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/tosa_serialization_handler.cpp b/src/tosa_serialization_handler.cpp index 2062522..d84e0ab 100644 --- a/src/tosa_serialization_handler.cpp +++ b/src/tosa_serialization_handler.cpp @@ -619,11 +619,16 @@ tosa_err_t TosaSerializationHandler::Deserialize(const uint8_t* buf) return TOSA_OK; } -std::vector float_to_u8_wrapper(float f_in) +std::vector float_to_u8_helper(float f_in) { - const std::vector f_vec{ f_in }; + // Push back a single float value to the buffer with *NO PADDING* + // Therefore ConvertF32toU8 function not used std::vector u8_out; - TosaSerializationHandler::ConvertF32toU8(f_vec, u8_out); + uint32_t* val_u32 = reinterpret_cast(&f_in); + u8_out.push_back(*val_u32 & 0xFF); + u8_out.push_back((*val_u32 >> 8) & 0xFF); + u8_out.push_back((*val_u32 >> 16) & 0xFF); + u8_out.push_back((*val_u32 >> 24) & 0xFF); return u8_out; } @@ -691,7 +696,7 @@ tosa_err_t TosaSerializationHandler::Serialize() break; #define DEF_ARGS_S_STR(NAME, V) , _builder.CreateString(reinterpret_cast(op->GetAttribute())->V().c_str()) #define DEF_ARGS_S_FP_as_U8(NAME, V) \ - , _builder.CreateVector(float_to_u8_wrapper(reinterpret_cast(op->GetAttribute())->V())) + , _builder.CreateVector(float_to_u8_helper(reinterpret_cast(op->GetAttribute())->V())) #define DEF_ARGS_S_DEFAULT(NAME, V) , reinterpret_cast(op->GetAttribute())->V() #define DEF_ARGS_S_int32_t(NAME, V) DEF_ARGS_S_DEFAULT(NAME, V) #define DEF_ARGS_S_float(NAME, V) DEF_ARGS_S_FP_as_U8(NAME, V) -- cgit v1.2.1