Skip to content

Commit 0882ff6

Browse files
Use get_partial_shape to get dynamic shape (#26907)
### Details: - In the case of dynamic shapes, we need to call get_partial_shape, because `get_shape` will throw if called on dynamic shape ### Tickets: - E88902
1 parent 737caf5 commit 0882ff6

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/plugins/intel_npu/src/compiler/src/zero_compiler_in_driver.cpp

+10-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
#include "zero_compiler_in_driver.hpp"
66

7-
#include <fstream>
87
#include <regex>
98
#include <string_view>
109

@@ -272,13 +271,19 @@ std::string LevelZeroCompilerInDriver<TableExtension>::serializeIOInfo(const std
272271

273272
inputsPrecisionSS << INPUTS_PRECISIONS_KEY << KEY_VALUE_SEPARATOR << VALUE_DELIMITER;
274273
inputsLayoutSS << INPUTS_LAYOUTS_KEY << KEY_VALUE_SEPARATOR << VALUE_DELIMITER;
274+
const auto getRankOrThrow = [](const ov::PartialShape& shape) -> size_t {
275+
if (shape.rank().is_dynamic()) {
276+
OPENVINO_THROW("Dynamic rank is not supported for NPU plugin");
277+
}
278+
return shape.rank().get_length();
279+
};
275280

276281
if (!parameters.empty()) {
277282
size_t parameterIndex = 0;
278283

279284
for (const std::shared_ptr<ov::op::v0::Parameter>& parameter : parameters) {
280-
const ov::element::Type& precision = parameter->get_element_type();
281-
const size_t rank = parameter->get_shape().size();
285+
const auto precision = parameter->get_element_type();
286+
const auto rank = getRankOrThrow(parameter->get_partial_shape());
282287

283288
if (parameterIndex != 0) {
284289
inputsPrecisionSS << VALUES_SEPARATOR;
@@ -310,10 +315,9 @@ std::string LevelZeroCompilerInDriver<TableExtension>::serializeIOInfo(const std
310315
outputsLayoutSS << OUTPUTS_LAYOUTS_KEY << KEY_VALUE_SEPARATOR << VALUE_DELIMITER;
311316

312317
size_t resultIndex = 0;
313-
314318
for (const std::shared_ptr<ov::op::v0::Result>& result : results) {
315-
const ov::element::Type_t precision = result->get_element_type();
316-
const size_t rank = result->get_shape().size();
319+
const auto precision = result->get_element_type();
320+
const auto rank = getRankOrThrow(result->get_output_partial_shape(0));
317321

318322
if (resultIndex != 0) {
319323
outputsPrecisionSS << VALUES_SEPARATOR;

0 commit comments

Comments
 (0)