From e6563f52231c603b409638b22530d016757542c8 Mon Sep 17 00:00:00 2001 From: Kevin Cheng Date: Wed, 20 Oct 2021 12:12:02 -0700 Subject: Bring back TosaVersion struct - check fails only when major/minor mismatches - dump warning if major/minor matches but patch/draft mismatches Signed-off-by: Kevin Cheng Change-Id: I0464f1018faa69b81fa93d42e51e1afd7412977a --- include/tosa_serialization_handler.h | 62 ++++++++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/tosa_serialization_handler.h b/include/tosa_serialization_handler.h index 7fd8282..61c02db 100644 --- a/include/tosa_serialization_handler.h +++ b/include/tosa_serialization_handler.h @@ -26,6 +26,7 @@ #include #include +// Keep version number in sync with the version default value with schema/tosa.fbs #define TOSA_VERSION_MAJOR 0 #define TOSA_VERSION_MINOR 23 #define TOSA_VERSION_PATCH 0 @@ -47,6 +48,62 @@ enum tosa_err_t NUM_TOSA_ERROR }; +struct TosaVersion +{ + int32_t _major; + int32_t _minor; + int32_t _patch; + bool _draft; + + enum class compat_t + { + COMPLETELY_COMPATIBLE, + PARTIALLY_COMPATIBLE, + NOT_COMPATIBLE + }; + + TosaVersion() = default; + TosaVersion(int32_t major, int32_t minor, int32_t patch, bool draft) + { + set_version(major, minor, patch, draft); + } + + void set_version(int32_t major, int32_t minor, int32_t patch, bool draft) + { + _major = major; + _minor = minor; + _patch = patch; + _draft = draft; + } + + std::string to_string() const + { + std::string str; + str += std::to_string(_major) + "."; + str += std::to_string(_minor) + "."; + str += std::to_string(_patch); + if (_draft) + str += "d"; + return str; + } + + compat_t is_compatible(const TosaVersion& rhs) const + { + if (rhs._major == _major && rhs._minor == _minor) + { + if (rhs._patch == _patch && rhs._draft == _draft) + { + return TosaVersion::compat_t::COMPLETELY_COMPATIBLE; + } + else + { + return TosaVersion::compat_t::PARTIALLY_COMPATIBLE; + } + } + return TosaVersion::compat_t::NOT_COMPATIBLE; + } +}; + class TosaSerializationHandler; class TosaSerializationTensor @@ -247,7 +304,7 @@ public: static tosa_err_t ConvertU8toBool(const std::vector& in, uint32_t out_size, std::vector& out); // version - const std::string& GetVersionStr() + const TosaVersion& GetVersion() { return _version; } @@ -296,10 +353,9 @@ protected: tosa_err_t Clear(); tosa_err_t Deserialize(const uint8_t* buf); tosa_err_t Serialize(); - std::string VersionToStr(int32_t major, int32_t minor, int32_t patch, bool draft); private: - std::string _version; /* version string */ + TosaVersion _version; /* version struct */ flatbuffers::FlatBufferBuilder _builder; /* flatbuffer builder */ flatbuffers::Parser _parser; /* flatbuffer parser, used for json parsing */ std::vector _blocks; /* array structure to store all TosaSerializationBasicBlock */ -- cgit v1.2.1