[GPU] Adding copy functions for image2d memory (#15330)
* implemented copy functions for image2d * updated to dump data using copy_to without lock * calculating _bytes_count for image2d
This commit is contained in:
parent
e88210c95d
commit
3ace063040
@ -68,8 +68,10 @@ void data_inst::save(cldnn::BinaryOutputBuffer& ob) const {
|
||||
if (_allocation_type == allocation_type::usm_host || _allocation_type == allocation_type::usm_shared) {
|
||||
ob << make_data(_outputs[0]->buffer_ptr(), data_size);
|
||||
} else {
|
||||
mem_lock<char, mem_lock_type::read> lock{_outputs[0], get_node().get_program().get_stream()};
|
||||
ob << make_data(lock.data(), data_size);
|
||||
std::vector<uint8_t> _buf;
|
||||
_buf.resize(data_size);
|
||||
_outputs[0]->copy_to(get_network().get_stream(), _buf.data());
|
||||
ob << make_data(_buf.data(), data_size);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -178,6 +178,8 @@ gpu_image2d::gpu_image2d(ocl_engine* engine, const layout& layout)
|
||||
|
||||
cl::ImageFormat imageFormat(order, type);
|
||||
_buffer = cl::Image2D(engine->get_cl_context(), CL_MEM_READ_WRITE, imageFormat, _width, _height, 0);
|
||||
size_t elem_size = _buffer.getImageInfo<CL_IMAGE_ELEMENT_SIZE>();
|
||||
_bytes_count = elem_size * _width * _height;
|
||||
}
|
||||
|
||||
gpu_image2d::gpu_image2d(ocl_engine* engine,
|
||||
@ -248,20 +250,54 @@ shared_mem_params gpu_image2d::get_internal_params() const {
|
||||
0};
|
||||
}
|
||||
|
||||
event::ptr gpu_image2d::copy_from(stream& /* stream */, const memory& /* other */, bool /* blocking */) {
|
||||
throw std::runtime_error("[GPU] copy_from is not implemented for gpu_image2d");
|
||||
event::ptr gpu_image2d::copy_from(stream& stream, const memory& other, bool blocking) {
|
||||
auto& cl_stream = downcast<const ocl_stream>(stream);
|
||||
auto& casted = downcast<const gpu_image2d>(other);
|
||||
auto ev = stream.create_base_event();
|
||||
cl::Event* ev_ocl = &downcast<ocl_event>(ev.get())->get();
|
||||
cl_stream.get_cl_queue().enqueueCopyImage(casted.get_buffer(), get_buffer(),
|
||||
{0, 0, 0}, {0, 0, 0}, {_width, _height, 1},
|
||||
nullptr, ev_ocl);
|
||||
|
||||
if (blocking)
|
||||
ev->wait();
|
||||
|
||||
return ev;
|
||||
}
|
||||
|
||||
event::ptr gpu_image2d::copy_from(stream& /* stream */, const void* /* host_ptr */, bool /* blocking */) {
|
||||
throw std::runtime_error("[GPU] copy_from is not implemented for gpu_image2d");
|
||||
event::ptr gpu_image2d::copy_from(stream& stream, const void* host_ptr, bool blocking) {
|
||||
auto& cl_stream = downcast<ocl_stream>(stream);
|
||||
auto ev = blocking ? stream.create_user_event(true) : stream.create_base_event();
|
||||
cl::Event* ev_ocl = blocking ? nullptr : &downcast<ocl_event>(ev.get())->get();
|
||||
cl_stream.get_cl_queue().enqueueWriteImage(_buffer, blocking, {0, 0, 0}, {_width, _height, 1},
|
||||
_row_pitch, _slice_pitch, host_ptr, nullptr, ev_ocl);
|
||||
|
||||
return ev;
|
||||
}
|
||||
|
||||
event::ptr gpu_image2d::copy_to(stream& /* stream */, memory& /* other */, bool /* blocking */) {
|
||||
throw std::runtime_error("[GPU] copy_to is not implemented for gpu_image2d");
|
||||
event::ptr gpu_image2d::copy_to(stream& stream, memory& other, bool blocking) {
|
||||
auto& cl_stream = downcast<const ocl_stream>(stream);
|
||||
auto& casted = downcast<const gpu_image2d>(other);
|
||||
auto ev = stream.create_base_event();
|
||||
cl::Event* ev_ocl = &downcast<ocl_event>(ev.get())->get();
|
||||
cl_stream.get_cl_queue().enqueueCopyImage(get_buffer(), casted.get_buffer(),
|
||||
{0, 0, 0}, {0, 0, 0}, {_width, _height, 1},
|
||||
nullptr, ev_ocl);
|
||||
|
||||
if (blocking)
|
||||
ev->wait();
|
||||
|
||||
return ev;
|
||||
}
|
||||
|
||||
event::ptr gpu_image2d::copy_to(stream& /* stream */, void* /* host_ptr */, bool /* blocking */) {
|
||||
throw std::runtime_error("[GPU] copy_to is not implemented for gpu_image2d");
|
||||
event::ptr gpu_image2d::copy_to(stream& stream, void* host_ptr, bool blocking) {
|
||||
auto& cl_stream = downcast<ocl_stream>(stream);
|
||||
auto ev = blocking ? stream.create_user_event(true) : stream.create_base_event();
|
||||
cl::Event* ev_ocl = blocking ? nullptr : &downcast<ocl_event>(ev.get())->get();
|
||||
cl_stream.get_cl_queue().enqueueReadImage(_buffer, blocking, {0, 0, 0}, {_width, _height, 1},
|
||||
_row_pitch, _slice_pitch, host_ptr, nullptr, ev_ocl);
|
||||
|
||||
return ev;
|
||||
}
|
||||
|
||||
gpu_media_buffer::gpu_media_buffer(ocl_engine* engine,
|
||||
|
@ -67,11 +67,11 @@ struct gpu_image2d : public lockable_gpu_mem, public memory {
|
||||
return _buffer;
|
||||
}
|
||||
|
||||
event::ptr copy_from(stream& /* stream */, const memory& /* other */, bool /* blocking */) override;
|
||||
event::ptr copy_from(stream& /* stream */, const void* /* other */, bool /* blocking */) override;
|
||||
event::ptr copy_from(stream& stream, const memory& other, bool blocking) override;
|
||||
event::ptr copy_from(stream& stream, const void* other, bool blocking) override;
|
||||
|
||||
event::ptr copy_to(stream& /* stream */, memory& /* other */, bool /* blocking */) override;
|
||||
event::ptr copy_to(stream& /* stream */, void* /* other */, bool /* blocking */) override;
|
||||
event::ptr copy_to(stream& stream, memory& other, bool blocking) override;
|
||||
event::ptr copy_to(stream& stream, void* other, bool blocking) override;
|
||||
|
||||
protected:
|
||||
cl::Image2D _buffer;
|
||||
|
Loading…
Reference in New Issue
Block a user