@@ -207,7 +207,36 @@ memory::ptr ocl_engine::allocate_memory(const layout& layout, allocation_type ty
207
207
}
208
208
}
209
209
}
210
+ memory::ptr ocl_engine::create_subbuffer (const memory& memory, const layout& new_layout, size_t byte_offset) {
211
+ OPENVINO_ASSERT (memory.get_engine () == this , " [GPU] trying to create a subbuffer from a buffer allocated by a different engine" );
212
+ try {
213
+ if (new_layout.format .is_image_2d ()) {
214
+ OPENVINO_NOT_IMPLEMENTED;
215
+ } else if (memory_capabilities::is_usm_type (memory.get_allocation_type ())) {
216
+ auto & new_buf = reinterpret_cast <const ocl::gpu_usm&>(memory);
217
+ auto ptr = new_buf.get_buffer ().get ();
218
+ auto sub_buffer = cl::UsmMemory (get_usm_helper (), ptr, byte_offset);
219
+
220
+ return std::make_shared<ocl::gpu_usm>(this ,
221
+ new_layout,
222
+ sub_buffer,
223
+ memory.get_allocation_type (),
224
+ memory.get_mem_tracker ());
225
+ } else {
226
+ auto buffer = reinterpret_cast <const ocl::gpu_buffer&>(memory).get_buffer ();
227
+ cl_buffer_region sub_buffer_region = { byte_offset, new_layout.get_linear_size () };
228
+ auto sub_buffer = buffer.createSubBuffer (CL_MEM_READ_WRITE| CL_MEM_USE_HOST_PTR,
229
+ CL_BUFFER_CREATE_TYPE_REGION, &sub_buffer_region);
210
230
231
+ return std::make_shared<ocl::gpu_buffer>(this ,
232
+ new_layout,
233
+ sub_buffer,
234
+ memory.get_mem_tracker ());
235
+ }
236
+ } catch (cl::Error const & err) {
237
+ OPENVINO_THROW (OCL_ERR_MSG_FMT (err));
238
+ }
239
+ }
211
240
memory::ptr ocl_engine::reinterpret_buffer (const memory& memory, const layout& new_layout) {
212
241
OPENVINO_ASSERT (memory.get_engine () == this , " [GPU] trying to reinterpret buffer allocated by a different engine" );
213
242
OPENVINO_ASSERT (new_layout.format .is_image () == memory.get_layout ().format .is_image (),
@@ -221,7 +250,7 @@ memory::ptr ocl_engine::reinterpret_buffer(const memory& memory, const layout& n
221
250
reinterpret_cast <const ocl::gpu_image2d&>(memory).get_buffer (),
222
251
memory.get_mem_tracker ());
223
252
} else if (memory_capabilities::is_usm_type (memory.get_allocation_type ())) {
224
- return std::make_shared<ocl::gpu_usm>(this ,
253
+ return std::make_shared<ocl::gpu_usm>(this ,
225
254
new_layout,
226
255
reinterpret_cast <const ocl::gpu_usm&>(memory).get_buffer (),
227
256
memory.get_allocation_type (),
0 commit comments