Skip to content

Commit

Permalink
Fix offsets mismatch for HETERO plugin blob headers
Browse files Browse the repository at this point in the history
  • Loading branch information
MirceaDan99 committed Jan 15, 2025
1 parent 2d290ef commit 49e880b
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 94 deletions.
52 changes: 0 additions & 52 deletions src/plugins/intel_npu/src/plugin/include/metadata.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,58 +64,6 @@ struct MetadataBase {
}
};

struct MetadataBase {
protected:
uint32_t _version;

public:
MetadataBase(uint32_t version) : _version(version) {}

/**
* @brief Reads metadata from a stream.
*/
virtual void read(std::istream& stream) = 0;

/**
* @brief Writes metadata to a stream.
*/
virtual void write(std::ostream& stream) = 0;

virtual bool is_compatible() = 0;

virtual uint64_t get_blob_size() const = 0;

virtual ~MetadataBase() = default;

/**
* @brief Returns a uint32_t value which represents two uint16_t values concatenated.
* @details Convention for bumping the metadata version:
* - Increment Major in case of: removing a current field OR adding a new field in between fields.
* - Increment Minor in case of: adding a new field at the end.
*
* @return Major and minor versions concatenated into a single uint32_t value.
*/
static constexpr uint32_t make_version(uint16_t major, uint16_t minor) {
return major << 16 | (minor & 0x0000ffff);
}

/**
* @brief Gets the major version.
* @return Major version.
*/
static constexpr uint16_t get_major(uint32_t version) {
return static_cast<uint16_t>(version >> 16);
}

/**
* @brief Gets the minor version.
* @return Minor version.
*/
static constexpr uint16_t get_minor(uint32_t version) {
return static_cast<uint16_t>(version);
}
};

/**
* @brief Magic bytes used for identifying NPU blobs.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/intel_npu/src/plugin/src/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ std::shared_ptr<ov::ICompiledModel> Plugin::import_model(std::istream& stream, c
npu_plugin_properties.erase(ov::internal::cached_model_buffer.name());
}

const std::map<std::string, std::string> propertiesMap = any_copy(npu_plugin_properties);
const auto propertiesMap = any_copy(npu_plugin_properties);

auto localConfig = merge_configs(_globalConfig, propertiesMap, OptionMode::RunTime);
_logger.setLevel(localConfig.get<LOG_LEVEL>());
Expand Down
41 changes: 0 additions & 41 deletions src/plugins/intel_npu/tests/unit/npu/metadata_version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,44 +199,3 @@ TEST_F(MetadataUnitTests, writeAndReadMetadataWithRemovedField) {
std::unique_ptr<MetadataBase> storedMeta;
EXPECT_ANY_THROW(storedMeta = read_metadata_from(stream));
}

struct MetadataVersionTestFixture : Metadata<CURRENT_METADATA_VERSION>, ::testing::TestWithParam<uint32_t> {
public:
std::stringstream blob;

void set_version(uint32_t newVersion) {
_version = newVersion;
}

MetadataVersionTestFixture() : Metadata<CURRENT_METADATA_VERSION>(0, std::nullopt) {}

MetadataVersionTestFixture(uint64_t blobSize, std::optional<std::string_view> ovVersion)
: Metadata<CURRENT_METADATA_VERSION>(blobSize, ovVersion) {}

void TestBody() override {}
};

TEST_P(MetadataVersionTestFixture, readInvalidMetadataVersion) {
auto dummyMeta = MetadataVersionTestFixture(0, ov::get_openvino_version().buildNumber);
auto metaVersion = GetParam();

dummyMeta.set_version(metaVersion);

OV_ASSERT_NO_THROW(dummyMeta.write(blob));

ASSERT_ANY_THROW(read_metadata_from(blob));
}

constexpr uint16_t currentMajor = get_major(CURRENT_METADATA_VERSION),
currentMinor = get_minor(CURRENT_METADATA_VERSION);

INSTANTIATE_TEST_CASE_P(MetadataUnitTests,
MetadataVersionTestFixture,
::testing::Values(make_version(currentMajor, currentMinor + 1),
make_version(currentMajor, currentMinor - 1),
make_version(currentMajor + 1, currentMinor),
make_version(currentMajor + 1, currentMinor + 1),
make_version(currentMajor + 1, currentMinor - 1),
make_version(currentMajor - 1, currentMinor),
make_version(currentMajor - 1, currentMinor + 1),
make_version(currentMajor - 1, currentMinor - 1)));

0 comments on commit 49e880b

Please sign in to comment.