Skip to content

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

Support 7dim shape of (#29669)

Paul Youngsoo Ahnf53394f1d096
diff --git a/src/plugins/intel_gpu/src/graph/graph_optimizer/add_required_reorders.cpp b/src/plugins/intel_gpu/src/graph/graph_optimizer/add_required_reorders.cpp
index cffb4457000..faa5051476f 100644
--- a/src/plugins/intel_gpu/src/graph/graph_optimizer/add_required_reorders.cpp
+++ b/src/plugins/intel_gpu/src/graph/graph_optimizer/add_required_reorders.cpp
@@ -324,7 +324,11 @@ void add_required_reorders::run(program& p) {
}
// This list of preferred layouts has been selected arbitrary due to developers' experience
preferred_layout_formats = { cldnn::format::get_default_format(max_in_dims) };
- if (max_in_dims == 5) {
+ if (max_in_dims == 7) {
+ preferred_layout_formats.push_back(cldnn::format::bfuwzyx);
+ } else if (max_in_dims == 6) {
+ preferred_layout_formats.push_back(cldnn::format::bfwzyx);
+ } else if (max_in_dims == 5) {
preferred_layout_formats.push_back(cldnn::format::bzyxf);
} else if (max_in_dims == 4) {
preferred_layout_formats.push_back(cldnn::format::yxfb);
diff --git a/src/plugins/intel_gpu/src/graph/impls/cpu/shape_of.cpp b/src/plugins/intel_gpu/src/graph/impls/cpu/shape_of.cpp
index 6baebeafc32..1eb70ddd73e 100644
--- a/src/plugins/intel_gpu/src/graph/impls/cpu/shape_of.cpp
+++ b/src/plugins/intel_gpu/src/graph/impls/cpu/shape_of.cpp
@@ -84,6 +84,7 @@ attach_shape_of_impl::attach_shape_of_impl() {
format::bfyx,
format::bfzyx,
format::bfwzyx,
+ format::bfuwzyx
};
auto types = {
diff --git a/src/plugins/intel_gpu/tests/unit/test_cases/shape_of_gpu_test.cpp b/src/plugins/intel_gpu/tests/unit/test_cases/shape_of_gpu_test.cpp
index ebb62dc769c..ff64c919fd9 100644
--- a/src/plugins/intel_gpu/tests/unit/test_cases/shape_of_gpu_test.cpp
+++ b/src/plugins/intel_gpu/tests/unit/test_cases/shape_of_gpu_test.cpp
@@ -16,6 +16,9 @@
using namespace cldnn;
using namespace ::tests;
+namespace cldnn {
+namespace {
+
TEST(shape_of_gpu, bfyx) {
auto& engine = get_test_engine();
@@ -243,3 +246,83 @@ TEST(shape_of_gpu, shape_infer_optimization_dynamic) {
}
}
}
+
+struct shape_of_test_params {
+ std::vector<std::vector<int64_t>> data;
+
+ shape_of_test_params(std::initializer_list<std::vector<int64_t>> init) : data(init) {}
+};
+
+std::ostream& operator<<(std::ostream& ost, const shape_of_test_params& params) {
+ ost << "[" << params.data.size() << "] {";
+ for (auto& in_vec : params.data) {
+ ost << "{";
+ for (auto& in : in_vec) {
+ ost << std::to_string(in) << ",";
+ }
+ ost << "},";
+ }
+ ost << "}";
+ return ost;
+}
+
+struct smoke_shape_of_test : testing::TestWithParam<shape_of_test_params> {};
+TEST_P(smoke_shape_of_test, basic) {
+ auto params = GetParam();
+ auto& engine = get_test_engine();
+
+ auto inputs = params.data;
+ auto& first_input = inputs.front();
+ auto dims_size = first_input.size();
+ auto test_format = format::bfyx;
+ if (dims_size == 5) {
+ test_format = format::bzyxf;
+ } else if (dims_size == 6) {
+ test_format = format::bfwzyx;
+ } else if (dims_size == 7) {
+ test_format = format::bfuwzyx;
+ }
+
+ layout in_layout = {ov::PartialShape::dynamic(dims_size), data_types::f32, test_format};
+
+ cldnn::topology topology;
+ topology.add(input_layout("input", in_layout));
+ topology.add(shape_of("shape_of", input_info("input"), data_types::i32));
+
+ ExecutionConfig config = get_test_default_config(engine);
+ config.set_property(ov::intel_gpu::allow_new_shape_infer(true));
+ network network(engine, topology, config);
+
+ auto inst = network.get_primitive("shape_of");
+ auto impl = inst->get_impl();
+ ASSERT_TRUE(impl != nullptr);
+ ASSERT_TRUE(impl->is_dynamic());
+
+ for (const auto& input : inputs) {
+ layout in_mem_layout = {input, data_types::f32, test_format};
+ auto input_mem = engine.allocate_memory(in_mem_layout);
+ network.set_input_data("input", input_mem);
+
+ auto outputs = network.execute();
+
+ auto output = outputs.at("shape_of").get_memory();
+ cldnn::mem_lock<int32_t> output_ptr(output, get_test_stream());
+
+ for (size_t i = 0; i < input.size(); ++i) {
+ ASSERT_EQ(input[i], output_ptr[i]);
+ }
+ }
+}
+
+
+INSTANTIATE_TEST_SUITE_P(shape_of_gpu,
+ smoke_shape_of_test,
+ testing::Values(
+ shape_of_test_params({{1,2,3,4}, {3,2,4,1}, {5,8,2,1}, {4,6,2,1}}),
+ shape_of_test_params({{5,4,3,2,1}, {2,3,6,3,1}, {8,2,1,1,3}, {9,4,3,7,8}}),
+ shape_of_test_params({{8,1,3,4,5,2}, {9,2,4,3,6,8}, {2,5,3,7,8,1}, {9,4,7,2,8,1}}),
+ shape_of_test_params({{4,2,5,6,7,3,8}, {1,9,8,2,3,4,6}, {9,2,4,6,8,7,1}, {9,1,8,2,3,6,7}})
+ ));
+
+} // namespace
+} // namespace cldnn