@@ -128,6 +128,10 @@ allocation_type ocl_engine::detect_usm_allocation_type(const void* memory) const
128
128
bool ocl_engine::check_allocatable (const layout& layout, allocation_type type) {
129
129
OPENVINO_ASSERT (supports_allocation (type) || type == allocation_type::cl_mem, " [GPU] Unsupported allocation type: " , type);
130
130
131
+ // if (layout.bytes_count() == 0) {
132
+ // return false;
133
+ // }
134
+
131
135
bool exceed_allocatable_mem_size = (layout.bytes_count () > get_device_info ().max_alloc_mem_size );
132
136
133
137
// When dynamic shape upper bound makes bigger buffer, then return false.
@@ -172,25 +176,46 @@ bool ocl_engine::check_allocatable(const layout& layout, allocation_type type) {
172
176
memory::ptr ocl_engine::allocate_memory (const layout& layout, allocation_type type, bool reset) {
173
177
OPENVINO_ASSERT (!layout.is_dynamic () || layout.has_upper_bound (), " [GPU] Can't allocate memory for dynamic layout" );
174
178
175
- check_allocatable (layout, type);
179
+ if (!check_allocatable (layout, type))
180
+ return nullptr ;
181
+
182
+ auto zero_bytes_layout = false ;
183
+ auto non_zero_layout = layout;
184
+ if (layout.bytes_count () == 0 ) {
185
+ cldnn::layout zero_dim_layout = layout;
186
+ auto mem_ps = zero_dim_layout.get_partial_shape ();
187
+ for (size_t k = 0 ; k < mem_ps.size (); k++) {
188
+ if (mem_ps[k] == 0 )
189
+ mem_ps[k] = 1 ;
190
+ }
191
+
192
+ non_zero_layout = cldnn::layout (mem_ps, zero_dim_layout.data_type , zero_dim_layout.format );
193
+ zero_bytes_layout = true ;
194
+ }
195
+
196
+
176
197
177
198
try {
178
199
memory::ptr res = nullptr ;
179
200
if (layout.format .is_image_2d ()) {
180
- res = std::make_shared<ocl::gpu_image2d>(this , layout );
201
+ res = std::make_shared<ocl::gpu_image2d>(this , non_zero_layout );
181
202
} else if (type == allocation_type::cl_mem) {
182
- res = std::make_shared<ocl::gpu_buffer>(this , layout );
203
+ res = std::make_shared<ocl::gpu_buffer>(this , non_zero_layout );
183
204
} else {
184
- res = std::make_shared<ocl::gpu_usm>(this , layout , type);
205
+ res = std::make_shared<ocl::gpu_usm>(this , non_zero_layout , type);
185
206
}
186
207
187
- if (reset || res->is_memory_reset_needed (layout )) {
208
+ if (reset || res->is_memory_reset_needed (non_zero_layout )) {
188
209
auto ev = res->fill (get_service_stream ());
189
210
if (ev) {
190
211
get_service_stream ().wait_for_events ({ev});
191
212
}
192
213
}
193
214
215
+ if (zero_bytes_layout) {
216
+ res = reinterpret_buffer (*res, layout);
217
+ }
218
+
194
219
return res;
195
220
} catch (const cl::Error& clErr) {
196
221
switch (clErr.err ()) {
0 commit comments