Skip to content

Commit 09d1712

Browse files
authored
[NPU] Fix test to not align tensor for import (#32207)
### Details: - *Fix test to not align tensor for import* ### Tickets: - *E#179607* --------- Signed-off-by: Bogdan Pereanu <[email protected]>
1 parent 8ab2bff commit 09d1712

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

src/plugins/intel_npu/tests/functional/common/utils.hpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,23 @@ std::string appendDriverVersionTestName(testing::TestParamInfo<typename T::Param
107107
return ov::test::utils::appendPlatformTypeTestName<T>(obj) + "_driverVersion=" + driverVersion.as<std::string>();
108108
}
109109

110+
class DefaultAllocatorNotAligned final {
111+
public:
112+
void* allocate(const size_t bytes, const size_t alignment = 4096) {
113+
auto handle = (::operator new(bytes + _offset, std::align_val_t(alignment)));
114+
return static_cast<uint8_t*>(handle) + _offset;
115+
}
116+
void deallocate(void* handle, const size_t bytes, size_t alignment = 4096) noexcept {
117+
::operator delete(static_cast<uint8_t*>(handle) - _offset, std::align_val_t(alignment));
118+
}
119+
bool is_equal(const DefaultAllocatorNotAligned& other) const {
120+
return false;
121+
}
122+
123+
private:
124+
size_t _offset = 16;
125+
};
126+
110127
} // namespace utils
111128

112129
} // namespace test

src/plugins/intel_npu/tests/functional/internal/overload/ov_plugin/life_time.hpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include "behavior/ov_plugin/life_time.hpp"
88
#include "common/npu_test_env_cfg.hpp"
9+
#include "common/utils.hpp"
910
#include "common_test_utils/subgraph_builders/conv_pool_relu.hpp"
1011
#include "intel_npu/utils/zero/zero_init.hpp"
1112
#include "openvino/runtime/make_tensor.hpp"
@@ -236,11 +237,13 @@ TEST_P(OVHoldersTestOnImportedNetworkNPU, CanInferAfterTensorIsDestroyed) {
236237
{
237238
std::stringstream sstream;
238239
core.compile_model(function, target_device, configuration).export_model(sstream);
239-
auto strSO = std::make_shared<std::string>(sstream.str());
240-
auto tensor = ov::Tensor(ov::element::u8, ov::Shape{strSO->size()}, strSO->data());
241-
auto impl = ov::get_tensor_impl(tensor);
242-
impl._so = strSO;
243-
tensor = ov::make_tensor(impl);
240+
241+
const std::string& str = sstream.str();
242+
size_t size = str.size();
243+
ov::test::utils::DefaultAllocatorNotAligned default_allocator_not_aligned;
244+
auto tensor = ov::Tensor(ov::element::u8, ov::Shape{size}, default_allocator_not_aligned);
245+
std::memcpy(tensor.data(), str.data(), size);
246+
244247
compiled_model = core.import_model(tensor, target_device, configuration);
245248
}
246249

0 commit comments

Comments
 (0)