Skip to content

Commit

Permalink
[CPU] Remove dnnl desc copy from the memory size routine (openvinotoo…
Browse files Browse the repository at this point in the history
…lkit#26757)

### Details:
To process offset0 for `dnnl::blocked` desc correctly in the memory size
calculation routine we have to make another copy of the memory
descriptor, which triggers additional dynamic memory allocation via
`posix_memalign` that leads to known perf and memory overheads. But the
thing is that offset0 has not been directly used by the plugin for quite
some time, thus we don't even need to process it anymore. Therefore the
copy has been removed and a sanity check added to avoid any related
unexpected behavior.

### Tickets:
 - CVS-148778
  • Loading branch information
maxnick authored Sep 26, 2024
1 parent 0874c1e commit c864266
Showing 1 changed file with 3 additions and 19 deletions.
22 changes: 3 additions & 19 deletions src/plugins/intel_cpu/src/dnnl_extension_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,30 +171,14 @@ DnnlMemoryDescPtr DnnlExtensionUtils::makeDescriptor(const_dnnl_memory_desc_t de
}
}

static size_t sub_byte_data_type_multiplier(dnnl::memory::data_type dataType) {
switch (dataType) {
case dnnl::memory::data_type::nf4:
case dnnl::memory::data_type::s4:
case dnnl::memory::data_type::u4:
case dnnl::memory::data_type::f4_e2m1:
return 2;
default:
return 1;
}
}

size_t DnnlExtensionUtils::getMemSizeForDnnlDesc(const dnnl::memory::desc& desc) {
auto tmpDesc = desc;

const auto offset0 = tmpDesc.get()->offset0;
tmpDesc.get()->offset0 = 0;
OPENVINO_ASSERT(IMPLICATION(desc.get_format_kind() == dnnl::memory::format_kind::blocked, desc.get()->offset0 == 0),
"Unexpected non zero offset for a dnnl blocked memory desc");

size_t size = tmpDesc.get_size();
size_t size = desc.get_size();
if (size == DNNL_RUNTIME_SIZE_VAL)
return MemoryDesc::UNDEFINED_SIZE;

size += div_up(offset0 * sizeOfDataType(tmpDesc.get_data_type()),
sub_byte_data_type_multiplier(tmpDesc.get_data_type()));
return size;
}

Expand Down

0 comments on commit c864266

Please sign in to comment.