Skip to content

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

[GPU] Fix zero-dimension shape inference from f64 constant op with empty tensor (#32567)

Andrew Kwangwoong Park32d594754780
diff --git a/src/plugins/intel_gpu/src/graph/graph_optimizer/prepare_primitive_fusing_through.cpp b/src/plugins/intel_gpu/src/graph/graph_optimizer/prepare_primitive_fusing_through.cpp
index ea4c36aab4d..21801247ebb 100644
--- a/src/plugins/intel_gpu/src/graph/graph_optimizer/prepare_primitive_fusing_through.cpp
+++ b/src/plugins/intel_gpu/src/graph/graph_optimizer/prepare_primitive_fusing_through.cpp
@@ -105,7 +105,8 @@ void prepare_primitive_fusing_through::run(program& p) {
bool has_constant_input = false;
for (size_t i = 0; i < node->get_dependencies().size(); i++) {
auto& dep = node->get_dependency(i);
- if (dep.is_constant() && dep.get_output_layout().get_tensor() == cldnn::tensor(1)) {
+ auto dep_layout = dep.get_output_layout();
+ if (dep.is_constant() && dep_layout.is_static() && dep_layout.get_tensor() == cldnn::tensor(1)) {
second_input_idx = i ^ 1;
has_constant_input = true;
break;
diff --git a/src/plugins/intel_gpu/src/plugin/ops/constant.cpp b/src/plugins/intel_gpu/src/plugin/ops/constant.cpp
index 08308ab8615..662e663d95c 100644
--- a/src/plugins/intel_gpu/src/plugin/ops/constant.cpp
+++ b/src/plugins/intel_gpu/src/plugin/ops/constant.cpp
@@ -116,7 +116,17 @@ static void create_data(ProgramBuilder& p, const ov::Shape& const_shape, const s
auto buf = lock.data();
auto bufSize = constLayout.bytes_count();
- std::memcpy(&buf[0], &data[0], bufSize);
+ // If a constant has element type f64 but contains no elements (empty tensor),
+ // convert it to f32 because the GPU plugin only supports the f32 data type internally.
+ if (ov::shape_size(const_shape) == 1 &&
+ out_dtype == cldnn::data_types::f32 &&
+ op->get_output_element_type(0) == ov::element::f64) {
+ const auto* f64data = op->get_data_ptr<double>();
+ auto f32buf = reinterpret_cast<float*>(buf);
+ f32buf[0] = static_cast<float>(f64data[0]);
+ } else {
+ std::memcpy(&buf[0], &data[0], bufSize);
+ }
p.add_primitive(*op, cldnn::data(initialconstPrimID, mem));
p.blobMemCache[cache_key] = initialconstPrimID;
constPrimID = initialconstPrimID;
diff --git a/src/plugins/intel_gpu/tests/functional/single_layer_tests/dynamic/range.cpp b/src/plugins/intel_gpu/tests/functional/single_layer_tests/dynamic/range.cpp
index 18b2636a205..6b2f5ae5ac3 100644
--- a/src/plugins/intel_gpu/tests/functional/single_layer_tests/dynamic/range.cpp
+++ b/src/plugins/intel_gpu/tests/functional/single_layer_tests/dynamic/range.cpp
@@ -18,7 +18,8 @@ typedef std::tuple<
std::vector<InputShape>, // input shapes
std::vector<float>, // input values
ov::element::Type, // Model type
- std::string // Device name
+ bool, // Use constant for start input
+ std::string // Device name
> RangeDynamicGPUTestParamsSet;
class RangeDynamicGPUTest : public testing::WithParamInterface<RangeDynamicGPUTestParamsSet>,
@@ -28,7 +29,7 @@ public:
RangeDynamicGPUTestParamsSet basicParamsSet = obj.param;
std::ostringstream result;
- const auto& [inputShapes, inputValues, model_type, targetDevice] = basicParamsSet;
+ const auto& [inputShapes, inputValues, model_type, useConstantStart, targetDevice] = basicParamsSet;
result << "IS=";
for (const auto& shape : inputShapes) {
@@ -42,6 +43,7 @@ public:
result << v << "_";
}
result << "model_type=" << model_type << "_";
+ result << "useConstantStart=" << useConstantStart << "_";
result << "targetDevice=" << targetDevice;
return result.str();
}
@@ -125,7 +127,7 @@ protected:
RangeDynamicGPUTestParamsSet basicParamsSet = this->GetParam();
ov::ParameterVector params;
- const auto& [inputShapes, inputValues, _model_type, _targetDevice] = basicParamsSet;
+ const auto& [inputShapes, inputValues, _model_type, useConstantStart, _targetDevice] = basicParamsSet;
auto model_type = _model_type;
targetDevice = _targetDevice;
@@ -134,22 +136,32 @@ protected:
init_input_shapes(inputShapes);
- if (model_type == ov::element::dynamic) {
- std::vector<ov::element::Type> types = { ov::element::f32, ov::element::i32, ov::element::f32 };
- for (size_t i = 0; i < types.size(); i++) {
- auto paramNode = std::make_shared<ov::op::v0::Parameter>(types[i], inputDynamicShapes[i]);
- params.push_back(paramNode);
- }
- model_type = ov::element::f32;
+ if (useConstantStart) {
+ auto start = std::make_shared<ov::op::v0::Constant>(model_type, ov::Shape{}, input_values[0]);
+ auto step = std::make_shared<ov::op::v0::Parameter>(model_type, inputDynamicShapes[1]);
+ auto stop = std::make_shared<ov::op::v0::Parameter>(model_type, inputDynamicShapes[2]);
+
+ params = {step, stop};
+
+ const auto range = std::make_shared<ov::op::v4::Range>(start, step, stop, model_type);
+ ov::ResultVector results = {std::make_shared<ov::op::v0::Result>(range)};
+ function = std::make_shared<ov::Model>(results, ov::ParameterVector{step, stop}, "RangeGPU");
} else {
- for (auto&& shape : inputDynamicShapes) {
- params.push_back(std::make_shared<ov::op::v0::Parameter>(model_type, shape));
+ if (model_type == ov::element::dynamic) {
+ std::vector<ov::element::Type> types = { ov::element::f32, ov::element::i32, ov::element::f32 };
+ for (size_t i = 0; i < types.size(); i++) {
+ params.push_back(std::make_shared<ov::op::v0::Parameter>(types[i], inputDynamicShapes[i]));
+ }
+ model_type = ov::element::f32;
+ } else {
+ for (auto&& shape : inputDynamicShapes) {
+ params.push_back(std::make_shared<ov::op::v0::Parameter>(model_type, shape));
+ }
}
+ const auto range = std::make_shared<ov::op::v4::Range>(params[0], params[1], params[2], model_type);
+ ov::ResultVector results = {std::make_shared<ov::op::v0::Result>(range)};
+ function = std::make_shared<ov::Model>(results, params, "shapeof_out");
}
- const auto range = std::make_shared<ov::op::v4::Range>(params[0], params[1], params[2], model_type);
-
- ov::ResultVector results = {std::make_shared<ov::op::v0::Result>(range)};
- function = std::make_shared<ov::Model>(results, params, "shapeof_out");
}
private:
@@ -190,6 +202,7 @@ const std::vector<ov::element::Type> netPrecisions = {
const auto testParams_smoke = ::testing::Combine(::testing::ValuesIn(dynInputShapes),
::testing::ValuesIn(inputValues),
::testing::ValuesIn(netPrecisions),
+ ::testing::Values(false),
::testing::Values(ov::test::utils::DEVICE_GPU));
INSTANTIATE_TEST_SUITE_P(smoke_dynamic_range_01, RangeDynamicGPUTest,
@@ -207,11 +220,15 @@ const std::vector<std::vector<float>> inputFloatValues = {
const std::vector<ov::element::Type> netFloatPrecisions = {
ov::element::f16,
ov::element::f32,
+ ov::element::f64,
};
+const std::vector<bool> useConstStart = {true, false};
+
const auto testFloatParams_smoke = ::testing::Combine(::testing::ValuesIn(dynInputShapes),
::testing::ValuesIn(inputFloatValues),
::testing::ValuesIn(netFloatPrecisions),
+ ::testing::ValuesIn(useConstStart),
::testing::Values(ov::test::utils::DEVICE_GPU));
INSTANTIATE_TEST_SUITE_P(smoke_dynamic_range_02, RangeDynamicGPUTest,
@@ -232,6 +249,7 @@ const std::vector<ov::element::Type> netMixedPrecisions = {
const auto testMixedParams_smoke = ::testing::Combine(::testing::ValuesIn(dynInputShapes),
::testing::ValuesIn(inputMixedValues),
::testing::ValuesIn(netMixedPrecisions),
+ ::testing::Values(false),
::testing::Values(ov::test::utils::DEVICE_GPU));
INSTANTIATE_TEST_SUITE_P(smoke_dynamic_diff_types, RangeDynamicGPUTest,