[IE CLDNN] Change memory reset rules (#2909)

This commit is contained in:
Sergey Shlyapnikov 2021-01-19 15:15:24 +03:00 committed by GitHub
parent e9775c1023
commit 559b509b15
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 18 additions and 7 deletions

View File

@ -390,6 +390,12 @@ struct format {
} }
return false; return false;
} }
/// @brief Checks if @p format is simple data format
static bool is_simple_data_format(type fmt) {
return (fmt == yxfb || fmt == byxf ||
fmt == bfyx || fmt == fyxb ||
fmt == bfzyx || fmt == bfwzyx);
}
/// @brief Checks if @p format is of grouped type /// @brief Checks if @p format is of grouped type
static bool is_grouped(type fmt) { return group_num(fmt) != 0; } static bool is_grouped(type fmt) { return group_num(fmt) != 0; }
/// @brief Checks if @p format is of image type /// @brief Checks if @p format is of image type

View File

@ -31,7 +31,7 @@ gpu_buffer::gpu_buffer(const refcounted_obj_ptr<engine_impl>& engine,
bool reset) bool reset)
: lockable_gpu_mem(engine), memory_impl(engine, layout, net_id, allocation_type::cl_mem, false), : lockable_gpu_mem(engine), memory_impl(engine, layout, net_id, allocation_type::cl_mem, false),
_buffer(_context->context(), CL_MEM_READ_WRITE, size()) { _buffer(_context->context(), CL_MEM_READ_WRITE, size()) {
if (reset && is_memory_reset_needed(_layout)) zero_buffer(); if (reset || is_memory_reset_needed(_layout)) zero_buffer();
} }
gpu_buffer::gpu_buffer(const refcounted_obj_ptr<engine_impl>& engine, gpu_buffer::gpu_buffer(const refcounted_obj_ptr<engine_impl>& engine,
@ -256,7 +256,7 @@ gpu_usm::gpu_usm(const refcounted_obj_ptr<engine_impl>& engine, const layout& la
"Unknown unified shared memory type!"); "Unknown unified shared memory type!");
} }
if (reset && is_memory_reset_needed(_layout)) zero_buffer(); if (reset || is_memory_reset_needed(_layout)) zero_buffer();
} }
void* gpu_usm::lock() { void* gpu_usm::lock() {

View File

@ -48,7 +48,7 @@ struct memory_impl : refcounted_obj<memory_impl> {
// - To be Weights format (Data memory can be reused by memory_pool, which can lead to errors) // - To be Weights format (Data memory can be reused by memory_pool, which can lead to errors)
// - To have zero paddings // - To have zero paddings
// - To be completely filled with data // - To be completely filled with data
if (!format::is_weights_format(l.format) || format::is_winograd(l.format) || format::is_image_2d(l.format)) { if ((!format::is_weights_format(l.format) && !format::is_simple_data_format(l.format)) || format::is_winograd(l.format) || format::is_image_2d(l.format)) {
return true; return true;
} }

View File

@ -188,7 +188,11 @@ memory_impl::ptr primitive_inst::allocate_output() {
false); false);
} else if (_network.is_internal() && _node.is_output() && _node.is_type<generic_layer>() && } else if (_network.is_internal() && _node.is_output() && _node.is_type<generic_layer>() &&
engine.supports_allocation(allocation_type::usm_device)) { engine.supports_allocation(allocation_type::usm_device)) {
return engine.allocate_memory(layout, allocation_type::usm_device, net_id); return engine.allocate_memory(layout, allocation_type::usm_device, net_id, false);
} else if (_network.is_internal() && !_node.is_output() && _node.is_type<input_layout>()) {
// Skip memory reset for input_layout primitives, since data will be copied from cldnn::data primitive
// or just reuse primitive's memory
return engine.allocate_memory(layout, alloc_type, net_id, false);
} else if (_network.is_internal() || (!_node.can_share_buffer()) || _node.can_be_optimized() || _node.is_output()) { } else if (_network.is_internal() || (!_node.can_share_buffer()) || _node.can_be_optimized() || _node.is_output()) {
return engine.allocate_memory(layout, alloc_type, net_id); return engine.allocate_memory(layout, alloc_type, net_id);
} }

View File

@ -532,7 +532,8 @@ void program_impl::transfer_memory_to_device() {
// Allocate and transfer memory // Allocate and transfer memory
auto device_mem = mem.get_engine()->allocate_memory(mem.get_layout(), auto device_mem = mem.get_engine()->allocate_memory(mem.get_layout(),
allocation_type::usm_device, allocation_type::usm_device,
mem.get_net_id()); mem.get_net_id(),
false);
dynamic_cast<gpu::gpu_usm&>(*device_mem).copy_from_other(dynamic_cast<gpu::gpu_usm&>(mem)); dynamic_cast<gpu::gpu_usm&>(*device_mem).copy_from_other(dynamic_cast<gpu::gpu_usm&>(mem));
data_node.attach_memory(*device_mem); data_node.attach_memory(*device_mem);
const_cast<memory&>(data_node.get_primitive()->mem).reset(); const_cast<memory&>(data_node.get_primitive()->mem).reset();