6
6
7
7
#include < cstring>
8
8
#include < optional>
9
- #include < sstream>
10
9
11
- #include " intel_npu/config/config.hpp"
12
10
#include " intel_npu/utils/logger/logger.hpp"
13
- #include " openvino/core/version.hpp"
14
11
#include " openvino/runtime/shared_buffer.hpp"
15
12
16
13
namespace intel_npu {
17
14
18
- OpenvinoVersion::OpenvinoVersion (std::string_view version)
19
- : _version(version),
20
- _size (static_cast <uint32_t >(version.size())) {}
15
+ uint16_t OpenvinoVersion::get_major () const {
16
+ return _major;
17
+ }
18
+
19
+ uint16_t OpenvinoVersion::get_minor () const {
20
+ return _minor;
21
+ }
22
+
23
+ uint16_t OpenvinoVersion::get_patch () const {
24
+ return _patch;
25
+ }
26
+
27
+ bool OpenvinoVersion::operator !=(const OpenvinoVersion& version) {
28
+ return this ->_major != version._major || this ->_minor != version._minor || this ->_patch != version._patch ;
29
+ }
30
+
31
+ OpenvinoVersion::OpenvinoVersion (const OpenvinoVersion& version)
32
+ : _major(version.get_major()),
33
+ _minor (version.get_minor()),
34
+ _patch(version.get_patch()) {}
21
35
22
36
void OpenvinoVersion::read (std::istream& stream) {
23
- stream.read (reinterpret_cast <char *>(&_size ), sizeof (_size ));
24
- _version. resize (_size );
25
- stream.read (_version. data ( ), _size );
37
+ stream.read (reinterpret_cast <char *>(&_major ), sizeof (_major ));
38
+ stream. read ( reinterpret_cast < char *>(&_minor), sizeof (_minor) );
39
+ stream.read (reinterpret_cast < char *>(&_patch ), sizeof (_patch) );
26
40
}
27
41
28
42
void OpenvinoVersion::write (std::ostream& stream) {
29
- stream.write (reinterpret_cast <const char *>(&_size), sizeof (_size));
30
- stream.write (_version.data (), _size);
43
+ stream.write (reinterpret_cast <const char *>(&_major), sizeof (_major));
44
+ stream.write (reinterpret_cast <const char *>(&_minor), sizeof (_minor));
45
+ stream.write (reinterpret_cast <const char *>(&_patch), sizeof (_patch));
31
46
}
32
47
33
- Metadata<METADATA_VERSION_1_0 >::Metadata(uint64_t blobSize, std::optional<std::string_view > ovVersion)
34
- : MetadataBase{METADATA_VERSION_1_0 },
35
- _ovVersion{ovVersion.value_or (ov::get_openvino_version (). buildNumber )},
48
+ Metadata<METADATA_VERSION_2_0 >::Metadata(uint64_t blobSize, std::optional<OpenvinoVersion > ovVersion)
49
+ : MetadataBase{METADATA_VERSION_2_0 },
50
+ _ovVersion{ovVersion.value_or (CURRENT_OPENVINO_VERSION )},
36
51
_blobDataSize{blobSize} {}
37
52
38
- void Metadata<METADATA_VERSION_1_0 >::read(std::istream& stream) {
53
+ void Metadata<METADATA_VERSION_2_0 >::read(std::istream& stream) {
39
54
_ovVersion.read (stream);
40
55
}
41
56
42
- void Metadata<METADATA_VERSION_1_0 >::write(std::ostream& stream) {
57
+ void Metadata<METADATA_VERSION_2_0 >::write(std::ostream& stream) {
43
58
stream.write (reinterpret_cast <const char *>(&_version), sizeof (_version));
44
59
_ovVersion.write (stream);
45
60
stream.write (reinterpret_cast <const char *>(&_blobDataSize), sizeof (_blobDataSize));
@@ -53,25 +68,25 @@ std::unique_ptr<MetadataBase> create_metadata(uint32_t version, uint64_t blobSiz
53
68
}
54
69
55
70
switch (version) {
56
- case METADATA_VERSION_1_0 :
57
- return std::make_unique<Metadata<METADATA_VERSION_1_0 >>(blobSize, std::nullopt);
71
+ case METADATA_VERSION_2_0 :
72
+ return std::make_unique<Metadata<METADATA_VERSION_2_0 >>(blobSize, std::nullopt);
58
73
59
74
default :
60
- OPENVINO_THROW (" Invalid metadata version!" );
75
+ OPENVINO_THROW (" Metadata version is not supported !" );
61
76
}
62
77
}
63
78
64
- std::string OpenvinoVersion::get_version () const {
65
- return _version;
66
- }
67
-
68
- bool Metadata<METADATA_VERSION_1_0>::is_compatible() {
79
+ bool Metadata<METADATA_VERSION_2_0>::is_compatible() {
69
80
auto logger = Logger::global ().clone (" NPUBlobMetadata" );
70
81
// checking if we can import the blob
71
- if (_ovVersion.get_version () != ov::get_openvino_version ().buildNumber ) {
72
- logger.error (" Imported blob OpenVINO version: %s, but the current OpenVINO version is: %s" ,
73
- _ovVersion.get_version ().c_str (),
74
- ov::get_openvino_version ().buildNumber );
82
+ if (_ovVersion != CURRENT_OPENVINO_VERSION) {
83
+ logger.error (" Imported blob OpenVINO version: %d.%d.%d, but the current OpenVINO version is: %d.%d.%d" ,
84
+ _ovVersion.get_major (),
85
+ _ovVersion.get_minor (),
86
+ _ovVersion.get_patch (),
87
+ OPENVINO_VERSION_MAJOR,
88
+ OPENVINO_VERSION_MINOR,
89
+ OPENVINO_VERSION_PATCH);
75
90
return false ;
76
91
}
77
92
return true ;
@@ -146,7 +161,7 @@ std::unique_ptr<MetadataBase> read_metadata_from(std::istream& stream) {
146
161
return storedMeta;
147
162
}
148
163
149
- uint64_t Metadata<METADATA_VERSION_1_0 >::get_blob_size() const {
164
+ uint64_t Metadata<METADATA_VERSION_2_0 >::get_blob_size() const {
150
165
return _blobDataSize;
151
166
}
152
167
0 commit comments