@@ -174,23 +174,41 @@ memory::ptr ocl_engine::allocate_memory(const layout& layout, allocation_type ty
174
174
175
175
check_allocatable (layout, type);
176
176
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
+
177
191
try {
178
192
memory::ptr res = nullptr ;
179
193
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 );
181
195
} 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 );
183
197
} 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);
185
199
}
186
200
187
- if (reset || res->is_memory_reset_needed (layout )) {
201
+ if (reset || res->is_memory_reset_needed (non_zero_layout )) {
188
202
auto ev = res->fill (get_service_stream ());
189
203
if (ev) {
190
204
get_service_stream ().wait_for_events ({ev});
191
205
}
192
206
}
193
207
208
+ if (zero_bytes_layout) {
209
+ res = reinterpret_buffer (*res, layout);
210
+ }
211
+
194
212
return res;
195
213
} catch (const cl::Error& clErr) {
196
214
switch (clErr.err ()) {
0 commit comments