Skip to content

Commit b9669d6

Browse files
[GPU] Reinterpret from 1 dim mem to 0 dim mem instead of allocating 0 bytes layout to OpenCL
1 parent 1a26e6f commit b9669d6

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

src/plugins/intel_gpu/src/runtime/ocl/ocl_engine.cpp

+22-4
Original file line numberDiff line numberDiff line change
@@ -174,23 +174,41 @@ memory::ptr ocl_engine::allocate_memory(const layout& layout, allocation_type ty
174174

175175
check_allocatable(layout, type);
176176

177+
auto zero_bytes_layout = false;
178+
auto non_zero_layout = layout;
179+
if (layout.bytes_count() == 0) {
180+
cldnn::layout zero_dim_layout = layout;
181+
auto mem_ps = zero_dim_layout.get_partial_shape();
182+
for (size_t k = 0; k < mem_ps.size(); k++) {
183+
if (mem_ps[k] == 0)
184+
mem_ps[k] = 1;
185+
}
186+
187+
non_zero_layout = cldnn::layout(mem_ps, zero_dim_layout.data_type, zero_dim_layout.format);
188+
zero_bytes_layout = true;
189+
}
190+
177191
try {
178192
memory::ptr res = nullptr;
179193
if (layout.format.is_image_2d()) {
180-
res = std::make_shared<ocl::gpu_image2d>(this, layout);
194+
res = std::make_shared<ocl::gpu_image2d>(this, non_zero_layout);
181195
} else if (type == allocation_type::cl_mem) {
182-
res = std::make_shared<ocl::gpu_buffer>(this, layout);
196+
res = std::make_shared<ocl::gpu_buffer>(this, non_zero_layout);
183197
} else {
184-
res = std::make_shared<ocl::gpu_usm>(this, layout, type);
198+
res = std::make_shared<ocl::gpu_usm>(this, non_zero_layout, type);
185199
}
186200

187-
if (reset || res->is_memory_reset_needed(layout)) {
201+
if (reset || res->is_memory_reset_needed(non_zero_layout)) {
188202
auto ev = res->fill(get_service_stream());
189203
if (ev) {
190204
get_service_stream().wait_for_events({ev});
191205
}
192206
}
193207

208+
if (zero_bytes_layout) {
209+
res = reinterpret_buffer(*res, layout);
210+
}
211+
194212
return res;
195213
} catch (const cl::Error& clErr) {
196214
switch (clErr.err()) {

0 commit comments

Comments
 (0)