Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[NPU] Port dynamic tests (#37225)

Alexandru Enachefcf6f3d63b41
diff --git a/src/plugins/intel_npu/tests/functional/behavior/ov_infer_request/compile_and_infer_different_element_type.cpp b/src/plugins/intel_npu/tests/functional/behavior/ov_infer_request/compile_and_infer_different_element_type.cpp
index 96b5b9ef1cf..f30fc73236f 100644
--- a/src/plugins/intel_npu/tests/functional/behavior/ov_infer_request/compile_and_infer_different_element_type.cpp
+++ b/src/plugins/intel_npu/tests/functional/behavior/ov_infer_request/compile_and_infer_different_element_type.cpp
@@ -4,11 +4,16 @@
#include "compile_and_infer_different_element_type.hpp"
+#include <vector>
+
#include "common/utils.hpp"
+#include "intel_npu/npu_private_properties.hpp"
namespace {
-const std::vector<ov::AnyMap> configs = {};
+const std::vector<ov::AnyMap> configs = {
+ {ov::intel_npu::compiler_type(ov::intel_npu::CompilerType::PLUGIN), {"NPU_COMPILATION_MODE", "DefaultHW"}},
+ {ov::intel_npu::compiler_type(ov::intel_npu::CompilerType::DRIVER), {"NPU_COMPILATION_MODE", "DefaultHW"}}};
INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests,
InferRequestElementTypeTests,
diff --git a/src/plugins/intel_npu/tests/functional/behavior/ov_infer_request/infer_request_dynamic.cpp b/src/plugins/intel_npu/tests/functional/behavior/ov_infer_request/infer_request_dynamic.cpp
index 5bd973de18d..bd801e9a865 100644
--- a/src/plugins/intel_npu/tests/functional/behavior/ov_infer_request/infer_request_dynamic.cpp
+++ b/src/plugins/intel_npu/tests/functional/behavior/ov_infer_request/infer_request_dynamic.cpp
@@ -2,18 +2,154 @@
// SPDX-License-Identifier: Apache-2.0
//
-#include "infer_request_dynamic.hpp"
+#include "infer_request_dynamic_utils.hpp"
+#include <map>
+#include <sstream>
+#include <string>
+#include <utility>
#include <vector>
#include "common/utils.hpp"
+#include "common_test_utils/ov_tensor_utils.hpp"
+#include "openvino/core/partial_shape.hpp"
+#include "openvino/runtime/compiled_model.hpp"
using namespace ov::test::behavior;
namespace {
+const std::string inputName = "Parameter_1";
+const std::string outputName = "Relu_2";
+
const std::vector<ov::AnyMap> config = {{{"NPU_COMPILATION_MODE", "ReferenceSW"}}};
+} // namespace
+
+TEST_P(InferRequestDynamicTests, InferDynamicNetwork) {
+ std::vector<ov::Shape> vectorShapes{inOutShapes[0].first, inOutShapes[0].second};
+ std::map<std::string, ov::PartialShape> shapes;
+ shapes[inputName] = {ov::Dimension(inOutShapes[1].first[0], inOutShapes[1].second[0]),
+ ov::Dimension(inOutShapes[1].first[1], inOutShapes[1].second[1]),
+ ov::Dimension(inOutShapes[1].first[2], inOutShapes[1].second[2])};
+ OV_ASSERT_NO_THROW(function->reshape(shapes));
+
+ auto model = ie->compile_model(function, target_device, configuration);
+
+ ov::InferRequest req;
+ for (auto& shape : vectorShapes) {
+ ov::Tensor inTensor = ov::test::utils::create_and_fill_tensor(ov::element::f32, shape, 100, 0);
+ OV_ASSERT_NO_THROW(req = model.create_infer_request());
+
+ if (exceedsUpperBounds(shape, shapes[inputName])) {
+ EXPECT_THROW(req.set_tensor(inputName, inTensor), ov::Exception);
+ continue;
+ }
+
+ OV_ASSERT_NO_THROW(req.infer());
+ OV_ASSERT_NO_THROW(checkOutputFP16(req.get_tensor(inputName), req.get_tensor(outputName)));
+ }
+}
+
+TEST_P(InferRequestDynamicTests, InferDynamicNetworkSetShape) {
+ std::vector<ov::Shape> vectorShapes{inOutShapes[0].first, inOutShapes[0].second};
+ std::map<std::string, ov::PartialShape> shapes;
+ shapes[inputName] = {ov::Dimension(inOutShapes[1].first[0], inOutShapes[1].second[0]),
+ ov::Dimension(inOutShapes[1].first[1], inOutShapes[1].second[1]),
+ ov::Dimension(inOutShapes[1].first[2], inOutShapes[1].second[2])};
+ OV_ASSERT_NO_THROW(function->reshape(shapes));
+
+ auto model = ie->compile_model(function, target_device, configuration);
+
+ ov::InferRequest req;
+ OV_ASSERT_NO_THROW(req = model.create_infer_request());
+ auto inputTensor = req.get_tensor(inputName);
+ OV_ASSERT_NO_THROW(req.infer());
+ OV_ASSERT_NO_THROW(checkOutputFP16(inputTensor, req.get_tensor(outputName)));
+
+ for (auto& shape : vectorShapes) {
+ OV_ASSERT_NO_THROW(inputTensor.set_shape(shape));
+
+ if (exceedsUpperBounds(shape, shapes[inputName])) {
+ EXPECT_THROW(req.infer(), ov::Exception);
+ continue;
+ }
+
+ OV_ASSERT_NO_THROW(req.infer());
+ OV_ASSERT_NO_THROW(checkOutputFP16(inputTensor, req.get_tensor(outputName)));
+ }
+}
+
+TEST_P(InferRequestDynamicTests, InferDynamicNetworkSetShapeCPUTensor) {
+ std::vector<ov::Shape> vectorShapes{inOutShapes[0].first, inOutShapes[0].second};
+ std::map<std::string, ov::PartialShape> shapes;
+ shapes[inputName] = {ov::Dimension(inOutShapes[1].first[0], inOutShapes[1].second[0]),
+ ov::Dimension(inOutShapes[1].first[1], inOutShapes[1].second[1]),
+ ov::Dimension(inOutShapes[1].first[2], inOutShapes[1].second[2])};
+ OV_ASSERT_NO_THROW(function->reshape(shapes));
+
+ auto model = ie->compile_model(function, target_device, configuration);
+
+ const ov::Shape originalShape = {1, 1, 5};
+ auto inputTensor = ov::test::utils::create_and_fill_tensor(ov::element::f32, originalShape, 100, 0);
+
+ ov::InferRequest req;
+ OV_ASSERT_NO_THROW(req = model.create_infer_request());
+ OV_ASSERT_NO_THROW(req.set_tensor(inputName, inputTensor));
+ OV_ASSERT_NO_THROW(req.infer());
+ OV_ASSERT_NO_THROW(checkOutputFP16(inputTensor, req.get_tensor(outputName)));
+
+ for (auto& shape : vectorShapes) {
+ OV_ASSERT_NO_THROW(inputTensor.set_shape(shape));
+
+ if (exceedsUpperBounds(shape, shapes[inputName])) {
+ EXPECT_THROW(req.infer(), ov::Exception);
+ continue;
+ }
+
+ OV_ASSERT_NO_THROW(req.infer());
+ OV_ASSERT_NO_THROW(checkOutputFP16(inputTensor, req.get_tensor(outputName)));
+ }
+}
+
+TEST_P(InferRequestDynamicTests, InferDynamicNetworkImportSetShapeCPUTensor) {
+ std::vector<ov::Shape> vectorShapes{inOutShapes[0].first, inOutShapes[0].second};
+ std::map<std::string, ov::PartialShape> shapes;
+ shapes[inputName] = {ov::Dimension(inOutShapes[1].first[0], inOutShapes[1].second[0]),
+ ov::Dimension(inOutShapes[1].first[1], inOutShapes[1].second[1]),
+ ov::Dimension(inOutShapes[1].first[2], inOutShapes[1].second[2])};
+ OV_ASSERT_NO_THROW(function->reshape(shapes));
+
+ auto compiled_model = ie->compile_model(function, target_device, configuration);
+
+ std::stringstream stream;
+ compiled_model.export_model(stream);
+ auto imported_model = ie->import_model(stream, target_device, configuration);
+
+ const ov::Shape originalShape = {1, 1, 5};
+ auto inputTensor = ov::test::utils::create_and_fill_tensor(ov::element::f32, originalShape, 100, 0);
+
+ ov::InferRequest req;
+ OV_ASSERT_NO_THROW(req = imported_model.create_infer_request());
+ OV_ASSERT_NO_THROW(req.set_tensor(inputName, inputTensor));
+ OV_ASSERT_NO_THROW(req.infer());
+ OV_ASSERT_NO_THROW(checkOutputFP16(inputTensor, req.get_tensor(outputName)));
+
+ for (auto& shape : vectorShapes) {
+ OV_ASSERT_NO_THROW(inputTensor.set_shape(shape));
+
+ if (exceedsUpperBounds(shape, shapes[inputName])) {
+ EXPECT_THROW(req.infer(), ov::Exception);
+ continue;
+ }
+
+ OV_ASSERT_NO_THROW(req.infer());
+ OV_ASSERT_NO_THROW(checkOutputFP16(inputTensor, req.get_tensor(outputName)));
+ }
+}
+
+GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(OVInferRequestDynamicTests);
+
INSTANTIATE_TEST_SUITE_P(
smoke_BehaviorTests,
InferRequestDynamicTests,
@@ -25,5 +161,3 @@ INSTANTIATE_TEST_SUITE_P(
::testing::ValuesIn(ov::test::utils::mergeConfigs(config,
ov::test::utils::quietCompilerLogsConfig))),
ov::test::utils::appendPlatformTypeTestName<OVInferRequestDynamicTests>);
-
-} // namespace
diff --git a/src/plugins/intel_npu/tests/functional/behavior/ov_infer_request/infer_request_dynamic.hpp b/src/plugins/intel_npu/tests/functional/behavior/ov_infer_request/infer_request_dynamic.hpp
deleted file mode 100644
index d36598efd47..00000000000
--- a/src/plugins/intel_npu/tests/functional/behavior/ov_infer_request/infer_request_dynamic.hpp
+++ /dev/null
@@ -1,239 +0,0 @@
-// Copyright (C) 2018-2026 Intel Corporation
-// SPDX-License-Identifier: Apache-2.0
-//
-
-#pragma once
-
-#include <gtest/gtest.h>
-
-#include <memory>
-#include <string>
-#include <tuple>
-#include <vector>
-
-#include "common_test_utils/ov_plugin_cache.hpp"
-#include "common_test_utils/ov_tensor_utils.hpp"
-#include "openvino/core/shape.hpp"
-#include "openvino/core/type/element_type.hpp"
-#include "openvino/core/type/element_type_traits.hpp"
-#include "openvino/op/relu.hpp"
-#include "shared_test_classes/base/ov_behavior_test_utils.hpp"
-
-namespace ov {
-namespace test {
-namespace behavior {
-
-using OVInferRequestDynamicParams =
- std::tuple<std::shared_ptr<Model>, // ov Model
- std::vector<std::pair<std::vector<size_t>, std::vector<size_t>>>, // input/expected output shapes per
- // inference
- std::string, // Device name
- ov::AnyMap // Config
- >;
-
-class OVInferRequestDynamicTests : public testing::WithParamInterface<OVInferRequestDynamicParams>,
- public OVInferRequestTestBase {
-public:
- static std::string getTestCaseName(testing::TestParamInfo<OVInferRequestDynamicParams> obj);
-
-protected:
- void SetUp() override;
- bool checkOutput(const ov::Tensor& in, const ov::Tensor& actual);
-
- std::shared_ptr<ov::Core> core = utils::PluginCache::get().core();
- std::shared_ptr<Model> function;
- ov::AnyMap configuration;
- std::vector<std::pair<std::vector<size_t>, std::vector<size_t>>> inOutShapes;
-};
-
-class InferRequestDynamicTests : public OVInferRequestDynamicTests {
-public:
- static std::shared_ptr<ov::Model> getFunction() {
- const std::vector<size_t> inputShape = {1, 10, 12};
- const ov::element::Type_t ngPrc = ov::element::Type_t::f32;
-
- ov::ParameterVector params{std::make_shared<ov::op::v0::Parameter>(ngPrc, ov::Shape({inputShape}))};
- params.front()->get_output_tensor(0).set_names({"Parameter_1"});
-
- auto relu = std::make_shared<ov::op::v0::Relu>(params[0]);
- relu->get_output_tensor(0).set_names({"Relu_2"});
-
- return std::make_shared<ov::Model>(relu, params, "SimpleActivation");
- }
-
-protected:
- void checkOutputFP16(const ov::Tensor& in, const ov::Tensor& actual) {
- auto net = core->compile_model(function, ov::test::utils::DEVICE_TEMPLATE);
- ov::InferRequest req;
- req = net.create_infer_request();
- auto tensor = req.get_tensor(function->inputs().back().get_any_name());
- tensor.set_shape(in.get_shape());
- for (size_t i = 0; i < in.get_size(); i++) {
- tensor.data<ov::element_type_traits<ov::element::f32>::value_type>()[i] =
- in.data<ov::element_type_traits<ov::element::f32>::value_type>()[i];
- }
- req.infer();
- OVInferRequestDynamicTests::checkOutput(actual, req.get_output_tensor(0));
- }
-};
-
-TEST_P(InferRequestDynamicTests, InferDynamicNetwork) {
- std::vector<ov::Shape> vectorShapes{inOutShapes[0].first, inOutShapes[0].second};
- const std::string inputName = "Parameter_1";
- std::map<std::string, ov::PartialShape> shapes;
- shapes[inputName] = {ov::Dimension(inOutShapes[1].first[0], inOutShapes[1].second[0]),
- ov::Dimension(inOutShapes[1].first[1], inOutShapes[1].second[1]),
- ov::Dimension(inOutShapes[1].first[2], inOutShapes[1].second[2])};
- OV_ASSERT_NO_THROW(function->reshape(shapes));
-
- auto model = core->compile_model(function, target_device, configuration);
-
- ov::InferRequest req;
- const std::string outputName = "Relu_2";
- for (auto& shape : vectorShapes) {
- ov::Tensor inTensor = ov::test::utils::create_and_fill_tensor(ov::element::f32, shape, 100, 0);
- OV_ASSERT_NO_THROW(req = model.create_infer_request());
-
- bool inferShallFail = false;
- for (auto i = 0; i < shapes[inputName].rank().get_length(); ++i) {
- if (shape[i] > shapes[inputName].get_max_shape()[i]) {
- inferShallFail = true;
- }
- }
-
- if (!inferShallFail) {
- OV_ASSERT_NO_THROW(req.infer());
- OV_ASSERT_NO_THROW(checkOutputFP16(req.get_tensor(inputName), req.get_tensor(outputName)));
- } else {
- EXPECT_THROW(req.set_tensor(inputName, inTensor), ov::Exception);
- }
- }
-}
-
-TEST_P(InferRequestDynamicTests, InferDynamicNetworkSetShape) {
- std::vector<ov::Shape> vectorShapes{inOutShapes[0].first, inOutShapes[0].second};
- const std::string inputName = "Parameter_1";
- std::map<std::string, ov::PartialShape> shapes;
- shapes[inputName] = {ov::Dimension(inOutShapes[1].first[0], inOutShapes[1].second[0]),
- ov::Dimension(inOutShapes[1].first[1], inOutShapes[1].second[1]),
- ov::Dimension(inOutShapes[1].first[2], inOutShapes[1].second[2])};
- OV_ASSERT_NO_THROW(function->reshape(shapes));
-
- auto model = core->compile_model(function, target_device, configuration);
-
- ov::InferRequest req;
- const std::string outputName = "Relu_2";
-
- OV_ASSERT_NO_THROW(req = model.create_infer_request());
- auto inputTensor = req.get_tensor(inputName);
- OV_ASSERT_NO_THROW(req.infer());
- OV_ASSERT_NO_THROW(checkOutputFP16(inputTensor, req.get_tensor(outputName)));
-
- for (auto& shape : vectorShapes) {
- OV_ASSERT_NO_THROW(inputTensor.set_shape(shape));
-
- bool inferShallFail = false;
- for (auto i = 0; i < shapes[inputName].rank().get_length(); ++i) {
- if (shape[i] > shapes[inputName].get_max_shape()[i]) {
- inferShallFail = true;
- }
- }
-
- if (!inferShallFail) {
- OV_ASSERT_NO_THROW(req.infer());
- OV_ASSERT_NO_THROW(checkOutputFP16(inputTensor, req.get_tensor(outputName)));
- } else {
- EXPECT_THROW(req.infer(), ov::Exception);
- }
- }
-}
-
-TEST_P(InferRequestDynamicTests, InferDynamicNetworkSetShapeCPUTensor) {
- std::vector<ov::Shape> vectorShapes{inOutShapes[0].first, inOutShapes[0].second};
- const std::string inputName = "Parameter_1";
- std::map<std::string, ov::PartialShape> shapes;
- shapes[inputName] = {ov::Dimension(inOutShapes[1].first[0], inOutShapes[1].second[0]),
- ov::Dimension(inOutShapes[1].first[1], inOutShapes[1].second[1]),
- ov::Dimension(inOutShapes[1].first[2], inOutShapes[1].second[2])};
- OV_ASSERT_NO_THROW(function->reshape(shapes));
-
- auto model = core->compile_model(function, target_device, configuration);
-
- ov::InferRequest req;
- const std::string outputName = "Relu_2";
-
- ov::Shape originalShape = {1, 1, 5};
-
- auto inputTensor = ov::test::utils::create_and_fill_tensor(ov::element::f32, originalShape, 100, 0);
- OV_ASSERT_NO_THROW(req = model.create_infer_request());
- OV_ASSERT_NO_THROW(req.set_tensor(inputName, inputTensor));
- OV_ASSERT_NO_THROW(req.infer());
- OV_ASSERT_NO_THROW(checkOutputFP16(inputTensor, req.get_tensor(outputName)));
-
- for (auto& shape : vectorShapes) {
- OV_ASSERT_NO_THROW(inputTensor.set_shape(shape));
-
- bool inferShallFail = false;
- for (auto i = 0; i < shapes[inputName].rank().get_length(); ++i) {
- if (shape[i] > shapes[inputName].get_max_shape()[i]) {
- inferShallFail = true;
- }
- }
-
- if (!inferShallFail) {
- OV_ASSERT_NO_THROW(req.infer());
- OV_ASSERT_NO_THROW(checkOutputFP16(inputTensor, req.get_tensor(outputName)));
- } else {
- EXPECT_THROW(req.infer(), ov::Exception);
- }
- }
-}
-
-TEST_P(InferRequestDynamicTests, InferDynamicNetworkImportSetShapeCPUTensor) {
- std::vector<ov::Shape> vectorShapes{inOutShapes[0].first, inOutShapes[0].second};
- const std::string inputName = "Parameter_1";
- std::map<std::string, ov::PartialShape> shapes;
- shapes[inputName] = {ov::Dimension(inOutShapes[1].first[0], inOutShapes[1].second[0]),
- ov::Dimension(inOutShapes[1].first[1], inOutShapes[1].second[1]),
- ov::Dimension(inOutShapes[1].first[2], inOutShapes[1].second[2])};
- OV_ASSERT_NO_THROW(function->reshape(shapes));
-
- auto compiled_model = core->compile_model(function, target_device, configuration);
-
- std::stringstream stream;
- compiled_model.export_model(stream);
- auto imported_model = core->import_model(stream, target_device, configuration);
-
- ov::InferRequest req;
- const std::string outputName = "Relu_2";
-
- ov::Shape originalShape = {1, 1, 5};
-
- auto inputTensor = ov::test::utils::create_and_fill_tensor(ov::element::f32, originalShape, 100, 0);
- OV_ASSERT_NO_THROW(req = imported_model.create_infer_request());
- OV_ASSERT_NO_THROW(req.set_tensor(inputName, inputTensor));
- OV_ASSERT_NO_THROW(req.infer());
- OV_ASSERT_NO_THROW(checkOutputFP16(inputTensor, req.get_tensor(outputName)));
-
- for (auto& shape : vectorShapes) {
- OV_ASSERT_NO_THROW(inputTensor.set_shape(shape));
-
- bool inferShallFail = false;
- for (auto i = 0; i < shapes[inputName].rank().get_length(); ++i) {
- if (shape[i] > shapes[inputName].get_max_shape()[i]) {
- inferShallFail = true;
- }
- }
-
- if (!inferShallFail) {
- OV_ASSERT_NO_THROW(req.infer());
- OV_ASSERT_NO_THROW(checkOutputFP16(inputTensor, req.get_tensor(outputName)));
- } else {
- EXPECT_THROW(req.infer(), ov::Exception);
- }
- }
-}
-
-} // namespace behavior
-} // namespace test
-} // namespace ov
diff --git a/src/plugins/intel_npu/tests/functional/behavior/ov_infer_request/infer_request_dynamic_utils.hpp b/src/plugins/intel_npu/tests/functional/behavior/ov_infer_request/infer_request_dynamic_utils.hpp
new file mode 100644
index 00000000000..6c3b1bdc054
--- /dev/null
+++ b/src/plugins/intel_npu/tests/functional/behavior/ov_infer_request/infer_request_dynamic_utils.hpp
@@ -0,0 +1,68 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include <memory>
+#include <vector>
+
+#include "behavior/ov_infer_request/infer_request_dynamic.hpp"
+#include "common_test_utils/test_constants.hpp"
+#include "openvino/core/model.hpp"
+#include "openvino/core/partial_shape.hpp"
+#include "openvino/core/shape.hpp"
+#include "openvino/core/type/element_type.hpp"
+#include "openvino/core/type/element_type_traits.hpp"
+#include "openvino/op/parameter.hpp"
+#include "openvino/op/relu.hpp"
+#include "openvino/runtime/infer_request.hpp"
+#include "openvino/runtime/tensor.hpp"
+
+namespace ov {
+namespace test {
+namespace behavior {
+
+class InferRequestDynamicTests : public OVInferRequestDynamicTests {
+public:
+ static std::shared_ptr<ov::Model> getFunction() {
+ const ov::Shape inputShape = {1, 10, 12};
+
+ ov::ParameterVector params{std::make_shared<ov::op::v0::Parameter>(ov::element::f32, inputShape)};
+ params.front()->get_output_tensor(0).set_names({"Parameter_1"});
+
+ auto relu = std::make_shared<ov::op::v0::Relu>(params[0]);
+ relu->get_output_tensor(0).set_names({"Relu_2"});
+
+ return std::make_shared<ov::Model>(relu, params, "SimpleActivation");
+ }
+
+protected:
+ static bool exceedsUpperBounds(const ov::Shape& shape, const ov::PartialShape& bounds) {
+ const auto maxShape = bounds.get_max_shape();
+ for (size_t i = 0; i < maxShape.size(); i++) {
+ if (shape[i] > maxShape[i]) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ void checkOutputFP16(const ov::Tensor& in, const ov::Tensor& actual) {
+ auto net = ie->compile_model(function, ov::test::utils::DEVICE_TEMPLATE);
+ ov::InferRequest req;
+ req = net.create_infer_request();
+ auto tensor = req.get_tensor(function->inputs().back().get_any_name());
+ tensor.set_shape(in.get_shape());
+ for (size_t i = 0; i < in.get_size(); i++) {
+ tensor.data<ov::element_type_traits<ov::element::f32>::value_type>()[i] =
+ in.data<ov::element_type_traits<ov::element::f32>::value_type>()[i];
+ }
+ req.infer();
+ OVInferRequestDynamicTests::checkOutput(actual, req.get_output_tensor(0));
+ }
+};
+
+} // namespace behavior
+} // namespace test
+} // namespace ov
diff --git a/src/plugins/intel_npu/tests/functional/behavior/remote_tensor_tests/dma_buf_remote_run.cpp b/src/plugins/intel_npu/tests/functional/behavior/remote_tensor_tests/dma_buf_remote_run.cpp
index c37d7282ff9..e8456902957 100644
--- a/src/plugins/intel_npu/tests/functional/behavior/remote_tensor_tests/dma_buf_remote_run.cpp
+++ b/src/plugins/intel_npu/tests/functional/behavior/remote_tensor_tests/dma_buf_remote_run.cpp
@@ -12,15 +12,37 @@
# include <linux/version.h>
# if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 10, 0)
+# include <utility>
+# include <vector>
+
using namespace ov::test::behavior;
+namespace {
+
const std::vector<ov::AnyMap> remoteConfigs = {{ov::log::level(ov::log::Level::WARNING)}};
+// C-190157
+const std::vector<ov::AnyMap> dynamicRemoteConfigs = {
+ {{"NPU_COMPILER_TYPE", "PLUGIN"}, {"NPU_COMPILATION_MODE", "DefaultHW"}}};
+
+} // namespace
+
INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTest,
DmaBufRemoteRunTests,
::testing::Combine(::testing::Values(ov::test::utils::DEVICE_NPU),
::testing::ValuesIn(remoteConfigs)),
DmaBufRemoteRunTests::getTestCaseName);
+INSTANTIATE_TEST_SUITE_P(
+ smoke_BehaviorTests,
+ DmaBufRemoteRunDynamicTests,
+ ::testing::Combine(::testing::Values(DmaBufRemoteRunDynamicTests::getFunction()),
+ ::testing::Values(std::vector<std::pair<std::vector<size_t>, std::vector<size_t>>>{
+ {{1, 10, 12}, {1, 10, 12}},
+ {{1, 18, 15}, {1, 18, 15}}}),
+ ::testing::Values(ov::test::utils::DEVICE_NPU),
+ ::testing::ValuesIn(dynamicRemoteConfigs)),
+ ov::test::utils::appendPlatformTypeTestName<OVInferRequestDynamicTests>);
+
# endif
#endif
diff --git a/src/plugins/intel_npu/tests/functional/behavior/remote_tensor_tests/dma_buf_remote_run.hpp b/src/plugins/intel_npu/tests/functional/behavior/remote_tensor_tests/dma_buf_remote_run.hpp
index 99474ba53f3..72c80931a5b 100644
--- a/src/plugins/intel_npu/tests/functional/behavior/remote_tensor_tests/dma_buf_remote_run.hpp
+++ b/src/plugins/intel_npu/tests/functional/behavior/remote_tensor_tests/dma_buf_remote_run.hpp
@@ -10,11 +10,13 @@
#include "common/npu_test_env_cfg.hpp"
#include "common/utils.hpp"
+#include "common_test_utils/ov_tensor_utils.hpp"
#include "openvino/core/any.hpp"
#include "openvino/core/memory_util.hpp"
#include "openvino/runtime/compiled_model.hpp"
#include "openvino/runtime/core.hpp"
#include "openvino/runtime/intel_npu/level_zero/level_zero.hpp"
+#include "ov_infer_request/infer_request_dynamic_utils.hpp"
#include "shared_test_classes/base/ov_behavior_test_utils.hpp"
#ifdef __linux__
@@ -24,8 +26,14 @@
# include <linux/dma-heap.h>
# include <sys/ioctl.h>
# include <sys/mman.h>
+# include <unistd.h>
+# include <cstdint>
+# include <cstring>
# include <filesystem>
+# include <map>
+# include <string>
+# include <vector>
using CompilationParams = std::tuple<std::string, // Device name
ov::AnyMap // Config
@@ -34,13 +42,79 @@ using CompilationParams = std::tuple<std::string, // Device name
namespace ov {
namespace test {
namespace behavior {
+
+// RAII owner of a DMA-BUF system-heap allocation: the heap device fd, the exported buffer fd and the
+// mmap-ed CPU view of it. Construction either yields a fully mapped buffer or throws, so the object is
+// never observable half-initialized.
+class DmaHeapBuffer {
+public:
+ explicit DmaHeapBuffer(const size_t byte_size) : _byte_size(roundUpToPageSize(byte_size)) {
+ if (!std::filesystem::exists(DEVICE_PATH)) {
+ OPENVINO_THROW("Cannot open ", DEVICE_PATH, " file.");
+ }
+
+ _fd_dma_heap = open(DEVICE_PATH, O_RDWR);
+ if (_fd_dma_heap == -1) {
+ OPENVINO_THROW("Cannot open ", DEVICE_PATH, ".");
+ }
+
+ dma_heap_allocation_data heap_alloc = {
+ .len = _byte_size, // the DMA heap only accepts page-aligned allocations
+ .fd = 0,
+ .fd_flags = O_RDWR | O_CLOEXEC,
+ .heap_flags = 0,
+ };
+ if (ioctl(_fd_dma_heap, DMA_HEAP_IOCTL_ALLOC, &heap_alloc) != 0) {
+ close(_fd_dma_heap);
+ OPENVINO_THROW("Cannot initialize DMA heap.");
+ }
+ _fd = static_cast<int32_t>(heap_alloc.fd);
+
+ _data = mmap(nullptr, _byte_size, PROT_WRITE | PROT_READ, MAP_SHARED, _fd, 0);
+ if (_data == MAP_FAILED) {
+ close(_fd);
+ close(_fd_dma_heap);
+ OPENVINO_THROW("mmap failed.");
+ }
+ }
+
+ DmaHeapBuffer(const DmaHeapBuffer&) = delete;
+ DmaHeapBuffer& operator=(const DmaHeapBuffer&) = delete;
+
+ ~DmaHeapBuffer() {
+ munmap(_data, _byte_size);
+ close(_fd);
+ close(_fd_dma_heap);
+ }
+
+ int32_t fd() const {
+ return _fd;
+ }
+
+ void* data() const {
+ return _data;
+ }
+
+private:
+ static constexpr const char* DEVICE_PATH = "/dev/dma_heap/system";
+ static constexpr size_t PAGE_ALIGNMENT = 4096;
+
+ static size_t roundUpToPageSize(const size_t byte_size) {
+ return (byte_size + PAGE_ALIGNMENT - 1) & ~(PAGE_ALIGNMENT - 1);
+ }
+
+ size_t _byte_size;
+ int _fd_dma_heap = -1;
+ int32_t _fd = -1;
+ void* _data = nullptr;
+};
+
class DmaBufRemoteRunTests : public ov::test::behavior::OVPluginTestBase,
public testing::WithParamInterface<CompilationParams> {
protected:
std::shared_ptr<ov::Core> core = utils::PluginCache::get().core();
ov::AnyMap configuration;
std::shared_ptr<ov::Model> ov_model;
- int _fd_dma_heap = -1;
public:
static std::string getTestCaseName(const testing::TestParamInfo<CompilationParams>& obj) {
@@ -76,39 +150,8 @@ public:
utils::PluginCache::get().reset();
}
- if (_fd_dma_heap != -1) {
- close(_fd_dma_heap);
- }
-
APIBaseTest::TearDown();
}
-
- int32_t getFdDmaHeap(const size_t byte_size) {
- if (!std::filesystem::exists("/dev/dma_heap/system")) {
- OPENVINO_THROW("Cannot open /dev/dma_heap/system file.");
- }
-
- _fd_dma_heap = open("/dev/dma_heap/system", O_RDWR);
- if (_fd_dma_heap == -1) {
- OPENVINO_THROW("Cannot open /dev/dma_heap/system.");
- }
-
- static const std::size_t alignment = 4096;
- size_t size = byte_size + alignment - (byte_size % alignment);
- struct dma_heap_allocation_data heapAlloc = {
- .len = size, // this length should be alligned to the page size
- .fd = 0,
- .fd_flags = O_RDWR | O_CLOEXEC,
- .heap_flags = 0,
- };
-
- auto ret = ioctl(_fd_dma_heap, DMA_HEAP_IOCTL_ALLOC, &heapAlloc);
- if (ret != 0) {
- OPENVINO_THROW("Cannot initialize DMA heap");
- }
-
- return static_cast<int32_t>(heapAlloc.fd);
- }
};
TEST_P(DmaBufRemoteRunTests, CheckRemoteTensorSharedBuf) {
@@ -125,14 +168,9 @@ TEST_P(DmaBufRemoteRunTests, CheckRemoteTensorSharedBuf) {
auto context = core->get_default_context(target_device).as<ov::intel_npu::level_zero::ZeroContext>();
- auto fd_heap = getFdDmaHeap(byte_size);
+ DmaHeapBuffer buffer(byte_size);
- auto mmap_ret = mmap(NULL, byte_size, PROT_WRITE | PROT_READ, MAP_SHARED, fd_heap, 0);
- if (mmap_ret == MAP_FAILED) {
- ASSERT_FALSE(true) << "mmap failed.";
- }
-
- auto remote_tensor = context.create_tensor(ov::element::f32, tensor.get_shape(), fd_heap);
+ auto remote_tensor = context.create_tensor(ov::element::f32, tensor.get_shape(), buffer.fd());
ov::Tensor check_remote_tensor;
ASSERT_NO_THROW(check_remote_tensor = remote_tensor);
@@ -140,11 +178,9 @@ TEST_P(DmaBufRemoteRunTests, CheckRemoteTensorSharedBuf) {
OV_ASSERT_NO_THROW(inference_request.set_input_tensor(check_remote_tensor));
OV_ASSERT_NO_THROW(inference_request.infer());
-
- close(fd_heap);
}
-TEST_P(DmaBufRemoteRunTests, CheckRemoteTensorSharedBuChangingTensors) {
+TEST_P(DmaBufRemoteRunTests, CheckRemoteTensorSharedBufChangingTensors) {
// Skip test according to plugin specific disabled_test_patterns() (if any)
SKIP_IF_CURRENT_TEST_IS_DISABLED()
ov::CompiledModel compiled_model;
@@ -158,14 +194,9 @@ TEST_P(DmaBufRemoteRunTests, CheckRemoteTensorSharedBuChangingTensors) {
auto context = core->get_default_context(target_device).as<ov::intel_npu::level_zero::ZeroContext>();
- auto fd_heap = getFdDmaHeap(byte_size);
+ DmaHeapBuffer buffer(byte_size);
- auto mmap_ret = mmap(NULL, byte_size, PROT_WRITE | PROT_READ, MAP_SHARED, fd_heap, 0);
- if (mmap_ret == MAP_FAILED) {
- ASSERT_FALSE(true) << "mmap failed.";
- }
-
- auto remote_tensor = context.create_tensor(ov::element::f32, tensor.get_shape(), fd_heap);
+ auto remote_tensor = context.create_tensor(ov::element::f32, tensor.get_shape(), buffer.fd());
ov::Tensor check_remote_tensor;
ASSERT_NO_THROW(check_remote_tensor = remote_tensor);
@@ -175,9 +206,9 @@ TEST_P(DmaBufRemoteRunTests, CheckRemoteTensorSharedBuChangingTensors) {
OV_ASSERT_NO_THROW(inference_request.infer());
// set random input tensor
- float* random_buffer_tensor = new float[byte_size / sizeof(float)];
- memset(random_buffer_tensor, 1, byte_size);
- ov::Tensor random_tensor_input{ov::element::f32, tensor.get_shape(), random_buffer_tensor};
+ std::vector<float> random_buffer_tensor(byte_size / sizeof(float));
+ memset(random_buffer_tensor.data(), 1, byte_size);
+ ov::Tensor random_tensor_input{ov::element::f32, tensor.get_shape(), random_buffer_tensor.data()};
OV_ASSERT_NO_THROW(inference_request.set_input_tensor(random_tensor_input));
OV_ASSERT_NO_THROW(inference_request.infer());
@@ -186,16 +217,14 @@ TEST_P(DmaBufRemoteRunTests, CheckRemoteTensorSharedBuChangingTensors) {
auto output_tensor = inference_request.get_output_tensor();
const auto output_byte_size = ov::util::get_memory_size(ov::element::f32, shape_size(output_tensor.get_shape()));
- float* output_random_buffer_tensor = new float[output_byte_size / sizeof(float)];
- memset(output_random_buffer_tensor, 1, output_byte_size);
- ov::Tensor outputrandom_tensor_input{ov::element::f32, output_tensor.get_shape(), output_random_buffer_tensor};
+ std::vector<float> output_random_buffer_tensor(output_byte_size / sizeof(float));
+ memset(output_random_buffer_tensor.data(), 1, output_byte_size);
+ ov::Tensor output_random_tensor_input{ov::element::f32,
+ output_tensor.get_shape(),
+ output_random_buffer_tensor.data()};
- OV_ASSERT_NO_THROW(inference_request.set_output_tensor(outputrandom_tensor_input));
+ OV_ASSERT_NO_THROW(inference_request.set_output_tensor(output_random_tensor_input));
OV_ASSERT_NO_THROW(inference_request.infer());
-
- delete[] random_buffer_tensor;
- delete[] output_random_buffer_tensor;
- close(fd_heap);
}
TEST_P(DmaBufRemoteRunTests, CheckOutputDataFromMultipleRuns) {
@@ -204,55 +233,83 @@ TEST_P(DmaBufRemoteRunTests, CheckOutputDataFromMultipleRuns) {
ov::CompiledModel compiled_model;
ov::InferRequest inference_request;
- float* data;
OV_ASSERT_NO_THROW(compiled_model = core->compile_model(ov_model, target_device, configuration));
OV_ASSERT_NO_THROW(inference_request = compiled_model.create_infer_request());
auto tensor = inference_request.get_input_tensor();
- auto shape = tensor.get_shape();
+ const auto shape = tensor.get_shape();
const auto byte_size = ov::util::get_memory_size(ov::element::f32, shape_size(shape));
tensor = {};
- auto fd_heap = getFdDmaHeap(byte_size);
-
- auto mmap_ret = mmap(NULL, byte_size, PROT_WRITE | PROT_READ, MAP_SHARED, fd_heap, 0);
- if (mmap_ret == MAP_FAILED) {
- ASSERT_FALSE(true) << "mmap failed.";
- }
-
- memset(mmap_ret, 99, byte_size);
+ DmaHeapBuffer buffer(byte_size);
+ memset(buffer.data(), 99, byte_size);
auto context = core->get_default_context(target_device).as<ov::intel_npu::level_zero::ZeroContext>();
auto output_tensor = inference_request.get_output_tensor();
const auto output_byte_size = output_tensor.get_byte_size();
- float* output_data_one = new float[output_byte_size / sizeof(float)];
- ov::Tensor output_data_tensor_one{ov::element::f32, output_tensor.get_shape(), output_data_one};
+ std::vector<float> output_data_one(output_byte_size / sizeof(float));
+ ov::Tensor output_data_tensor_one{ov::element::f32, output_tensor.get_shape(), output_data_one.data()};
- auto remote_tensor = context.create_tensor(ov::element::f32, shape, fd_heap);
+ auto remote_tensor = context.create_tensor(ov::element::f32, shape, buffer.fd());
OV_ASSERT_NO_THROW(inference_request.set_input_tensor(remote_tensor));
OV_ASSERT_NO_THROW(inference_request.set_output_tensor(output_data_tensor_one));
OV_ASSERT_NO_THROW(inference_request.infer());
- float* output_data_two = new float[output_byte_size / sizeof(float)];
- ov::Tensor output_data_tensor_two{ov::element::f32, output_tensor.get_shape(), output_data_two};
+ // the same input data, this time passed through a host tensor, must yield the same output
+ std::vector<float> output_data_two(output_byte_size / sizeof(float));
+ ov::Tensor output_data_tensor_two{ov::element::f32, output_tensor.get_shape(), output_data_two.data()};
- data = new float[byte_size / sizeof(float)];
- memset(data, 99, byte_size);
- ov::Tensor input_data_tensor{ov::element::f32, shape, data};
+ std::vector<float> data(byte_size / sizeof(float));
+ memset(data.data(), 99, byte_size);
+ ov::Tensor input_data_tensor{ov::element::f32, shape, data.data()};
OV_ASSERT_NO_THROW(inference_request.set_input_tensor(input_data_tensor));
OV_ASSERT_NO_THROW(inference_request.set_output_tensor(output_data_tensor_two));
OV_ASSERT_NO_THROW(inference_request.infer());
- EXPECT_NE(output_data_one, output_data_two);
- EXPECT_EQ(memcmp(output_data_one, output_data_two, output_byte_size), 0);
+ EXPECT_NE(output_data_one.data(), output_data_two.data());
+ EXPECT_EQ(memcmp(output_data_one.data(), output_data_two.data(), output_byte_size), 0);
+}
+
+// Runs a dynamically-shaped model with a DMA-BUF backed remote tensor as input. A distinct type -- not an
+// alias -- so that gtest registers it as its own suite and it can be instantiated independently.
+class DmaBufRemoteRunDynamicTests : public InferRequestDynamicTests {};
- delete[] data;
- delete[] output_data_one;
- delete[] output_data_two;
+TEST_P(DmaBufRemoteRunDynamicTests, InferDynamicNetworkRemoteTensor) {
+ // Skip test according to plugin specific disabled_test_patterns() (if any)
+ SKIP_IF_CURRENT_TEST_IS_DISABLED()
- close(fd_heap);
+ const std::string inputName = "Parameter_1";
+ const std::string outputName = "Relu_2";
+
+ std::map<std::string, ov::PartialShape> shapes;
+ shapes[inputName] = {ov::Dimension(1, inOutShapes[1].first[0]),
+ ov::Dimension(1, inOutShapes[1].first[1]),
+ ov::Dimension(1, inOutShapes[1].first[2])};
+ OV_ASSERT_NO_THROW(function->reshape(shapes));
+
+ auto context = ie->get_default_context(target_device).as<ov::intel_npu::level_zero::ZeroContext>();
+ auto compiled_model = ie->compile_model(function, target_device, configuration);
+
+ // infer the same shape twice to exercise reuse of the compiled model across remote tensors
+ const std::vector<ov::Shape> vectorShapes{inOutShapes[0].first, inOutShapes[0].first};
+ for (auto& shape : vectorShapes) {
+ ov::Tensor in_tensor = ov::test::utils::create_and_fill_tensor(ov::element::f32, shape, 100, 0);
+
+ const auto byte_size = ov::util::get_memory_size(ov::element::f32, shape_size(shape));
+
+ DmaHeapBuffer buffer(byte_size);
+ memcpy(buffer.data(), in_tensor.data(), byte_size);
+
+ auto remote_tensor = context.create_tensor(ov::element::f32, shape, buffer.fd());
+
+ ov::InferRequest req;
+ OV_ASSERT_NO_THROW(req = compiled_model.create_infer_request());
+ OV_ASSERT_NO_THROW(req.set_tensor(inputName, remote_tensor));
+ OV_ASSERT_NO_THROW(req.infer());
+ OV_ASSERT_NO_THROW(checkOutputFP16(in_tensor, req.get_tensor(outputName)));
+ }
}
} // namespace behavior
diff --git a/src/plugins/intel_npu/tests/functional/behavior/remote_tensor_tests/dx12_remote_run.cpp b/src/plugins/intel_npu/tests/functional/behavior/remote_tensor_tests/dx12_remote_run.cpp
index 3d033234721..64d129440d8 100644
--- a/src/plugins/intel_npu/tests/functional/behavior/remote_tensor_tests/dx12_remote_run.cpp
+++ b/src/plugins/intel_npu/tests/functional/behavior/remote_tensor_tests/dx12_remote_run.cpp
@@ -10,14 +10,36 @@
#ifdef _WIN32
+# include <utility>
+# include <vector>
+
using namespace ov::test::behavior;
+namespace {
+
const std::vector<ov::AnyMap> remoteConfigs = {{ov::log::level(ov::log::Level::WARNING)}};
+// C-190157
+const std::vector<ov::AnyMap> dynamicRemoteConfigs = {
+ {{"NPU_COMPILER_TYPE", "PLUGIN"}, {"NPU_COMPILATION_MODE", "DefaultHW"}}};
+
+} // namespace
+
INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTest,
DX12RemoteRunTests,
::testing::Combine(::testing::Values(ov::test::utils::DEVICE_NPU),
::testing::ValuesIn(remoteConfigs)),
DX12RemoteRunTests::getTestCaseName);
+INSTANTIATE_TEST_SUITE_P(
+ smoke_BehaviorTests,
+ DX12RemoteRunDynamicTests,
+ ::testing::Combine(::testing::Values(DX12RemoteRunDynamicTests::getFunction()),
+ ::testing::Values(std::vector<std::pair<std::vector<size_t>, std::vector<size_t>>>{
+ {{1, 10, 12}, {1, 10, 12}},
+ {{1, 18, 15}, {1, 18, 15}}}),
+ ::testing::Values(ov::test::utils::DEVICE_NPU),
+ ::testing::ValuesIn(dynamicRemoteConfigs)),
+ ov::test::utils::appendPlatformTypeTestName<OVInferRequestDynamicTests>);
+
#endif
diff --git a/src/plugins/intel_npu/tests/functional/behavior/remote_tensor_tests/dx12_remote_run.hpp b/src/plugins/intel_npu/tests/functional/behavior/remote_tensor_tests/dx12_remote_run.hpp
index 9fb206d022a..3df8f6daf1e 100644
--- a/src/plugins/intel_npu/tests/functional/behavior/remote_tensor_tests/dx12_remote_run.hpp
+++ b/src/plugins/intel_npu/tests/functional/behavior/remote_tensor_tests/dx12_remote_run.hpp
@@ -10,11 +10,13 @@
#include "common/npu_test_env_cfg.hpp"
#include "common/utils.hpp"
+#include "common_test_utils/ov_tensor_utils.hpp"
#include "openvino/core/any.hpp"
#include "openvino/core/memory_util.hpp"
#include "openvino/runtime/compiled_model.hpp"
#include "openvino/runtime/core.hpp"
#include "openvino/runtime/intel_npu/level_zero/level_zero.hpp"
+#include "ov_infer_request/infer_request_dynamic_utils.hpp"
#include "shared_test_classes/base/ov_behavior_test_utils.hpp"
#ifdef _WIN32
@@ -29,13 +31,8 @@ using CompilationParams = std::tuple<std::string, // Device name
namespace ov {
namespace test {
namespace behavior {
-class DX12RemoteRunTests : public ov::test::behavior::OVPluginTestBase,
- public testing::WithParamInterface<CompilationParams> {
+class DX12SharedHeapHelper {
protected:
- std::shared_ptr<ov::Core> core = utils::PluginCache::get().core();
- ov::AnyMap configuration;
- std::shared_ptr<ov::Model> ov_model;
-
Microsoft::WRL::ComPtr<ID3D12Device> device;
Microsoft::WRL::ComPtr<ID3D12Heap> heap = nullptr;
Microsoft::WRL::ComPtr<ID3D12Resource> placed_resources = nullptr;
@@ -43,45 +40,6 @@ protected:
HANDLE shared_mem = nullptr;
-public:
- static std::string getTestCaseName(const testing::TestParamInfo<CompilationParams>& obj) {
- std::string targetDevice;
- ov::AnyMap configuration;
- std::tie(targetDevice, configuration) = obj.param;
- std::replace(targetDevice.begin(), targetDevice.end(), ':', '_');
- targetDevice = ov::test::utils::getTestsPlatformFromEnvironmentOr(ov::test::utils::DEVICE_NPU);
-
- std::ostringstream result;
- result << "targetDevice=" << targetDevice << "_";
- result << "targetPlatform=" << ov::test::utils::getTestsPlatformFromEnvironmentOr(targetDevice) << "_";
- if (!configuration.empty()) {
- for (auto& configItem : configuration) {
- result << "configItem=" << configItem.first << "_";
- configItem.second.print(result);
- }
- }
-
- return result.str();
- }
-
- void SetUp() override {
- std::tie(target_device, configuration) = this->GetParam();
-
- SKIP_IF_CURRENT_TEST_IS_DISABLED()
- OVPluginTestBase::SetUp();
- ov_model = getDefaultNGraphFunctionForTheDeviceNPU();
-
- createDevice();
- }
-
- void TearDown() override {
- if (!configuration.empty()) {
- utils::PluginCache::get().reset();
- }
-
- APIBaseTest::TearDown();
- }
-
void createDevice() {
auto res = D3D12CreateDevice(nullptr, D3D_FEATURE_LEVEL_12_0, IID_PPV_ARGS(device.ReleaseAndGetAddressOf()));
ASSERT_FALSE(FAILED(res)) << "D3D12CreateDevice failed.";
@@ -203,9 +161,55 @@ public:
}
};
+class DX12RemoteRunTests : public ov::test::behavior::OVPluginTestBase,
+ public testing::WithParamInterface<CompilationParams>,
+ protected DX12SharedHeapHelper {
+protected:
+ std::shared_ptr<ov::Core> core = utils::PluginCache::get().core();
+ ov::AnyMap configuration;
+ std::shared_ptr<ov::Model> ov_model;
+
+public:
+ static std::string getTestCaseName(const testing::TestParamInfo<CompilationParams>& obj) {
+ std::string targetDevice;
+ ov::AnyMap configuration;
+ std::tie(targetDevice, configuration) = obj.param;
+ std::replace(targetDevice.begin(), targetDevice.end(), ':', '_');
+ targetDevice = ov::test::utils::getTestsPlatformFromEnvironmentOr(ov::test::utils::DEVICE_NPU);
+
+ std::ostringstream result;
+ result << "targetDevice=" << targetDevice << "_";
+ result << "targetPlatform=" << ov::test::utils::getTestsPlatformFromEnvironmentOr(targetDevice) << "_";
+ if (!configuration.empty()) {
+ for (auto& configItem : configuration) {
+ result << "configItem=" << configItem.first << "_";
+ configItem.second.print(result);
+ }
+ }
+
+ return result.str();
+ }
+
+ void SetUp() override {
+ SKIP_IF_CURRENT_TEST_IS_DISABLED();
+ std::tie(target_device, configuration) = this->GetParam();
+
+ OVPluginTestBase::SetUp();
+ ov_model = getDefaultNGraphFunctionForTheDeviceNPU();
+
+ createDevice();
+ }
+
+ void TearDown() override {
+ if (!configuration.empty()) {
+ utils::PluginCache::get().reset();
+ }
+
+ APIBaseTest::TearDown();
+ }
+};
+
TEST_P(DX12RemoteRunTests, CheckRemoteTensorSharedBuf) {
- // Skip test according to plugin specific disabled_test_patterns() (if any)
- SKIP_IF_CURRENT_TEST_IS_DISABLED()
ov::CompiledModel compiled_model;
ov::InferRequest inference_request;
@@ -229,9 +233,7 @@ TEST_P(DX12RemoteRunTests, CheckRemoteTensorSharedBuf) {
OV_ASSERT_NO_THROW(inference_request.infer());
}
-TEST_P(DX12RemoteRunTests, CheckRemoteTensorSharedBuChangingTensors) {
- // Skip test according to plugin specific disabled_test_patterns() (if any)
- SKIP_IF_CURRENT_TEST_IS_DISABLED()
+TEST_P(DX12RemoteRunTests, CheckRemoteTensorSharedBufChangingTensors) {
ov::CompiledModel compiled_model;
ov::InferRequest inference_request;
@@ -274,6 +276,7 @@ TEST_P(DX12RemoteRunTests, CheckRemoteTensorSharedBuChangingTensors) {
OV_ASSERT_NO_THROW(inference_request.infer());
delete[] random_buffer_tensor;
+ delete[] output_random_buffer_tensor;
}
TEST_P(DX12RemoteRunTests, CheckOutputDataFromMultipleRuns) {
@@ -330,6 +333,54 @@ TEST_P(DX12RemoteRunTests, CheckOutputDataFromMultipleRuns) {
delete[] output_data_two;
}
+// Runs a dynamically-shaped model with a DX12-shared-heap backed remote tensor as input.
+class DX12RemoteRunDynamicTests : public InferRequestDynamicTests, protected DX12SharedHeapHelper {
+protected:
+ void SetUp() override {
+ SKIP_IF_CURRENT_TEST_IS_DISABLED();
+ InferRequestDynamicTests::SetUp();
+ createDevice();
+ }
+};
+
+TEST_P(DX12RemoteRunDynamicTests, InferDynamicNetworkRemoteTensor) {
+ const std::string inputName = "Parameter_1";
+ const std::string outputName = "Relu_2";
+
+ std::map<std::string, ov::PartialShape> shapes;
+ shapes[inputName] = {ov::Dimension(1, inOutShapes[1].first[0]),
+ ov::Dimension(1, inOutShapes[1].first[1]),
+ ov::Dimension(1, inOutShapes[1].first[2])};
+ OV_ASSERT_NO_THROW(function->reshape(shapes));
+
+ auto context = ie->get_default_context(target_device).as<ov::intel_npu::level_zero::ZeroContext>();
+ auto compiled_model = ie->compile_model(function, target_device, configuration);
+
+ // infer the same shape twice to exercise reuse of the compiled model across remote tensors
+ const std::vector<ov::Shape> vectorShapes{inOutShapes[0].first, inOutShapes[0].first};
+ for (auto& shape : vectorShapes) {
+ ov::Tensor in_tensor = ov::test::utils::create_and_fill_tensor(ov::element::f32, shape, 100, 0);
+
+ const auto byte_size = ov::util::get_memory_size(ov::element::f32, shape_size(shape));
+
+ createResources(byte_size);
+ void* mem = nullptr;
+ auto res = comitted_resource->Map(0, nullptr, &mem);
+ ASSERT_FALSE(FAILED(res)) << "Map failed.";
+ memcpy(mem, in_tensor.data(), byte_size);
+ comitted_resource->Unmap(0, nullptr);
+ copyResources(byte_size);
+
+ auto remote_tensor = context.create_tensor(ov::element::f32, shape, shared_mem);
+
+ ov::InferRequest req;
+ OV_ASSERT_NO_THROW(req = compiled_model.create_infer_request());
+ OV_ASSERT_NO_THROW(req.set_tensor(inputName, remote_tensor));
+ OV_ASSERT_NO_THROW(req.infer());
+ OV_ASSERT_NO_THROW(checkOutputFP16(in_tensor, req.get_tensor(outputName)));
+ }
+}
+
} // namespace behavior
} // namespace test
} // namespace ov