Skip to content

Commit 7512324

Browse files
[GPU] Add condition which empty layout is regareded as 1 dim with value 1 at check memory
1 parent 5a8d75d commit 7512324

File tree

2 files changed

+62
-6
lines changed

2 files changed

+62
-6
lines changed

src/plugins/intel_gpu/src/graph/primitive_inst.cpp

+17-6
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,21 @@ kernel_impl_params primitive_impl::static_canonicalize_shapes(const kernel_impl_
199199

200200
uint32_t primitive_inst::get_network_id() const { return _network.get_id(); }
201201

202-
void primitive_inst::check_memory_to_set(const memory& mem, const layout& layout) const {
203-
OPENVINO_ASSERT((mem.get_layout() == layout) || layout.is_dynamic(), "[GPU] Unexpected layout of input memory for ", id(), " node!\n",
204-
"Node layout: ", layout.to_short_string(), "\n",
205-
"Memory layout: ", mem.get_layout().to_short_string());
202+
void primitive_inst::check_memory_to_set(const memory& mem, const layout& l) const {
203+
// The layout with empty tensor (scalar) is regarded as 1 dimension with value 1
204+
bool single_value_layout = false;
205+
if (!l.is_dynamic()) {
206+
auto layout_ps = l.get_partial_shape();
207+
single_value_layout = (layout_ps.size() == 1 && layout_ps[0] == 1);
208+
}
209+
210+
auto mem_layout = mem.get_layout();
211+
OPENVINO_ASSERT((mem_layout == l)
212+
|| l.is_dynamic()
213+
|| (mem_layout.get_partial_shape().size() == 0 && single_value_layout),
214+
"[GPU] Unexpected layout of input memory for ", id(), " node!\n",
215+
"Node layout: ", l.to_short_string(), "\n",
216+
"Memory layout: ", mem_layout.to_short_string());
206217

207218
// check shared image/buffer compatibility, if applicable
208219
auto params = mem.get_internal_params();
@@ -218,11 +229,11 @@ void primitive_inst::check_memory_to_set(const memory& mem, const layout& layout
218229
switch (params.mem_type) {
219230
case shared_mem_type::shared_mem_vasurface:
220231
case shared_mem_type::shared_mem_image:
221-
OPENVINO_ASSERT(layout.format.is_image_2d(), "Attempt to set user-supplied input or output image instead of a buffer");
232+
OPENVINO_ASSERT(l.format.is_image_2d(), "Attempt to set user-supplied input or output image instead of a buffer");
222233
break;
223234
case shared_mem_type::shared_mem_buffer:
224235
case shared_mem_type::shared_mem_dxbuffer:
225-
OPENVINO_ASSERT(!layout.format.is_image_2d(), "Attempt to set user-supplied input or output buffer instead of an image");
236+
OPENVINO_ASSERT(!l.format.is_image_2d(), "Attempt to set user-supplied input or output buffer instead of an image");
226237
break;
227238
case shared_mem_type::shared_mem_usm:
228239
break;

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

+45
Original file line numberDiff line numberDiff line change
@@ -2373,3 +2373,48 @@ TEST(gather_gpu_fp32, dynamic_support_neg_ind) {
23732373
ASSERT_EQ(expected_results[i], output_ptr[i]) << i;
23742374
}
23752375
}
2376+
2377+
TEST(gather_gpu_fp32, dynamic_support_scalar_indice_empty_memory) {
2378+
auto& engine = get_test_engine();
2379+
2380+
ov::Shape data_shape = { 3, 3 };
2381+
int64_t axis = 1;
2382+
2383+
auto data_layout = layout{ov::PartialShape::dynamic(data_shape.size()), data_types::f32, format::bfyx};
2384+
auto indices_layout = layout{ov::PartialShape({1}), data_types::i32, format::bfyx};
2385+
2386+
auto data_mem = engine.allocate_memory(layout{ov::PartialShape(data_shape), data_types::f32, format::bfyx});
2387+
auto indices_mem = engine.allocate_memory(layout{ov::PartialShape({}), data_types::i32, format::bfyx});
2388+
2389+
set_values(data_mem, { 0.f, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f });
2390+
set_values(indices_mem, { -1 });
2391+
2392+
topology topology;
2393+
topology.add(input_layout("data", data_layout));
2394+
topology.add(input_layout("indices", indices_layout));
2395+
topology.add(gather("gather", input_info("data"), input_info("indices"), axis, data_shape.size(), ov::Shape{}, 0, true));
2396+
2397+
ExecutionConfig config = get_test_default_config(engine);
2398+
config.set_property(ov::intel_gpu::allow_new_shape_infer(true));
2399+
network network(engine, topology, config);
2400+
2401+
network.set_input_data("data", data_mem);
2402+
network.set_input_data("indices", indices_mem);
2403+
2404+
auto inst = network.get_primitive("gather");
2405+
auto impl = inst->get_impl();
2406+
ASSERT_TRUE(impl != nullptr);
2407+
ASSERT_TRUE(impl->is_dynamic());
2408+
2409+
auto outputs = network.execute();
2410+
2411+
auto output = outputs.at("gather").get_memory();
2412+
cldnn::mem_lock<float> output_ptr(output, get_test_stream());
2413+
2414+
std::vector<float> expected_results = { 2.f, 5.f, 8.f };
2415+
2416+
ASSERT_EQ(expected_results.size(), output_ptr.size());
2417+
for (size_t i = 0; i < expected_results.size(); ++i) {
2418+
ASSERT_EQ(expected_results[i], output_ptr[i]) << i;
2419+
}
2420+
}

0 commit comments

Comments
 (0)