Skip to content

Commit a634b38

Browse files
Support 7dim shape of (#29669) (#29770)
### Details: - *Support 7 dimension case for shape of input* ### Tickets: - *164660*
1 parent 7dc944d commit a634b38

File tree

3 files changed

+89
-1
lines changed

3 files changed

+89
-1
lines changed

src/plugins/intel_gpu/src/graph/graph_optimizer/add_required_reorders.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,11 @@ void add_required_reorders::run(program& p) {
324324
}
325325
// This list of preferred layouts has been selected arbitrary due to developers' experience
326326
preferred_layout_formats = { cldnn::format::get_default_format(max_in_dims) };
327-
if (max_in_dims == 5) {
327+
if (max_in_dims == 7) {
328+
preferred_layout_formats.push_back(cldnn::format::bfuwzyx);
329+
} else if (max_in_dims == 6) {
330+
preferred_layout_formats.push_back(cldnn::format::bfwzyx);
331+
} else if (max_in_dims == 5) {
328332
preferred_layout_formats.push_back(cldnn::format::bzyxf);
329333
} else if (max_in_dims == 4) {
330334
preferred_layout_formats.push_back(cldnn::format::yxfb);

src/plugins/intel_gpu/src/graph/impls/cpu/shape_of.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ attach_shape_of_impl::attach_shape_of_impl() {
8484
format::bfyx,
8585
format::bfzyx,
8686
format::bfwzyx,
87+
format::bfuwzyx
8788
};
8889

8990
auto types = {

src/plugins/intel_gpu/tests/unit/test_cases/shape_of_gpu_test.cpp

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
using namespace cldnn;
1717
using namespace ::tests;
1818

19+
namespace cldnn {
20+
namespace {
21+
1922
TEST(shape_of_gpu, bfyx) {
2023
auto& engine = get_test_engine();
2124

@@ -243,3 +246,83 @@ TEST(shape_of_gpu, shape_infer_optimization_dynamic) {
243246
}
244247
}
245248
}
249+
250+
struct shape_of_test_params {
251+
std::vector<std::vector<int64_t>> data;
252+
253+
shape_of_test_params(std::initializer_list<std::vector<int64_t>> init) : data(init) {}
254+
};
255+
256+
std::ostream& operator<<(std::ostream& ost, const shape_of_test_params& params) {
257+
ost << "[" << params.data.size() << "] {";
258+
for (auto& in_vec : params.data) {
259+
ost << "{";
260+
for (auto& in : in_vec) {
261+
ost << std::to_string(in) << ",";
262+
}
263+
ost << "},";
264+
}
265+
ost << "}";
266+
return ost;
267+
}
268+
269+
struct smoke_shape_of_test : testing::TestWithParam<shape_of_test_params> {};
270+
TEST_P(smoke_shape_of_test, basic) {
271+
auto params = GetParam();
272+
auto& engine = get_test_engine();
273+
274+
auto inputs = params.data;
275+
auto& first_input = inputs.front();
276+
auto dims_size = first_input.size();
277+
auto test_format = format::bfyx;
278+
if (dims_size == 5) {
279+
test_format = format::bzyxf;
280+
} else if (dims_size == 6) {
281+
test_format = format::bfwzyx;
282+
} else if (dims_size == 7) {
283+
test_format = format::bfuwzyx;
284+
}
285+
286+
layout in_layout = {ov::PartialShape::dynamic(dims_size), data_types::f32, test_format};
287+
288+
cldnn::topology topology;
289+
topology.add(input_layout("input", in_layout));
290+
topology.add(shape_of("shape_of", input_info("input"), data_types::i32));
291+
292+
ExecutionConfig config = get_test_default_config(engine);
293+
config.set_property(ov::intel_gpu::allow_new_shape_infer(true));
294+
network network(engine, topology, config);
295+
296+
auto inst = network.get_primitive("shape_of");
297+
auto impl = inst->get_impl();
298+
ASSERT_TRUE(impl != nullptr);
299+
ASSERT_TRUE(impl->is_dynamic());
300+
301+
for (const auto& input : inputs) {
302+
layout in_mem_layout = {input, data_types::f32, test_format};
303+
auto input_mem = engine.allocate_memory(in_mem_layout);
304+
network.set_input_data("input", input_mem);
305+
306+
auto outputs = network.execute();
307+
308+
auto output = outputs.at("shape_of").get_memory();
309+
cldnn::mem_lock<int32_t> output_ptr(output, get_test_stream());
310+
311+
for (size_t i = 0; i < input.size(); ++i) {
312+
ASSERT_EQ(input[i], output_ptr[i]);
313+
}
314+
}
315+
}
316+
317+
318+
INSTANTIATE_TEST_SUITE_P(shape_of_gpu,
319+
smoke_shape_of_test,
320+
testing::Values(
321+
shape_of_test_params({{1,2,3,4}, {3,2,4,1}, {5,8,2,1}, {4,6,2,1}}),
322+
shape_of_test_params({{5,4,3,2,1}, {2,3,6,3,1}, {8,2,1,1,3}, {9,4,3,7,8}}),
323+
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}}),
324+
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}})
325+
));
326+
327+
} // namespace
328+
} // namespace cldnn

0 commit comments

Comments
 (0)