OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[NPU] Fix test to not align tensor for import (#32207)
Bogdan Pereanu09d17127f23f
diff --git a/src/plugins/intel_npu/tests/functional/common/utils.hpp b/src/plugins/intel_npu/tests/functional/common/utils.hppindex 245f50b974a..3b9aac5c1c3 100644--- a/src/plugins/intel_npu/tests/functional/common/utils.hpp+++ b/src/plugins/intel_npu/tests/functional/common/utils.hpp@@ -107,6 +107,23 @@ std::string appendDriverVersionTestName(testing::TestParamInfo<typename T::Paramreturn ov::test::utils::appendPlatformTypeTestName<T>(obj) + "_driverVersion=" + driverVersion.as<std::string>();}+class DefaultAllocatorNotAligned final {+public:+ void* allocate(const size_t bytes, const size_t alignment = 4096) {+ auto handle = (::operator new(bytes + _offset, std::align_val_t(alignment)));+ return static_cast<uint8_t*>(handle) + _offset;+ }+ void deallocate(void* handle, const size_t bytes, size_t alignment = 4096) noexcept {+ ::operator delete(static_cast<uint8_t*>(handle) - _offset, std::align_val_t(alignment));+ }+ bool is_equal(const DefaultAllocatorNotAligned& other) const {+ return false;+ }++private:+ size_t _offset = 16;+};+} // namespace utils} // namespace testdiff --git a/src/plugins/intel_npu/tests/functional/internal/overload/ov_plugin/life_time.hpp b/src/plugins/intel_npu/tests/functional/internal/overload/ov_plugin/life_time.hppindex 8ef55c8f7aa..c03ead8ba77 100644--- a/src/plugins/intel_npu/tests/functional/internal/overload/ov_plugin/life_time.hpp+++ b/src/plugins/intel_npu/tests/functional/internal/overload/ov_plugin/life_time.hpp@@ -6,6 +6,7 @@#include "behavior/ov_plugin/life_time.hpp"#include "common/npu_test_env_cfg.hpp"+#include "common/utils.hpp"#include "common_test_utils/subgraph_builders/conv_pool_relu.hpp"#include "intel_npu/utils/zero/zero_init.hpp"#include "openvino/runtime/make_tensor.hpp"@@ -236,11 +237,13 @@ TEST_P(OVHoldersTestOnImportedNetworkNPU, CanInferAfterTensorIsDestroyed) {{std::stringstream sstream;core.compile_model(function, target_device, configuration).export_model(sstream);- auto strSO = std::make_shared<std::string>(sstream.str());- auto tensor = ov::Tensor(ov::element::u8, ov::Shape{strSO->size()}, strSO->data());- auto impl = ov::get_tensor_impl(tensor);- impl._so = strSO;- tensor = ov::make_tensor(impl);++ const std::string& str = sstream.str();+ size_t size = str.size();+ ov::test::utils::DefaultAllocatorNotAligned default_allocator_not_aligned;+ auto tensor = ov::Tensor(ov::element::u8, ov::Shape{size}, default_allocator_not_aligned);+ std::memcpy(tensor.data(), str.data(), size);+compiled_model = core.import_model(tensor, target_device, configuration);}