Skip to content

Commit

Permalink
Remove isAllocated check from the memory class
Browse files Browse the repository at this point in the history
  • Loading branch information
maxnick committed Aug 6, 2024
1 parent f211b01 commit f723360
Show file tree
Hide file tree
Showing 39 changed files with 191 additions and 232 deletions.
36 changes: 0 additions & 36 deletions src/plugins/intel_cpu/src/cpu_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,22 +184,6 @@ dnnl::memory Memory::DnnlMemPrimHandle::getPrim() const {
return m_prim;
}

bool Memory::isAllocated() const noexcept {
if (m_blockHandle->getRawPtr()) {
return true;
}
if (!m_pMemDesc) {
return false;
}
if (!(m_pMemDesc->isDefined())) {
return true;
}
if (m_pMemDesc->getCurrentMemSize() == 0) {
return true;
}
return false;
}

void* Memory::getData() const {
void* data = getDataNoThrow();
if (data == nullptr &&
Expand Down Expand Up @@ -306,22 +290,6 @@ void StringMemory::nullify() {
}
}

bool StringMemory::isAllocated() const noexcept {
if (getData()) {
return true;
}
if (!m_mem_desc) {
return false;
}
if (!(m_mem_desc->isDefined())) {
return true;
}
if (m_mem_desc->getCurrentMemSize() == 0) {
return true;
}
return false;
}

size_t StringMemory::getSize() const { // In bytes
auto size = getDesc().getCurrentMemSize();
if (size == MemoryDesc::UNDEFINED_SIZE) {
Expand Down Expand Up @@ -461,10 +429,6 @@ StaticMemory::StaticMemory(const dnnl::engine& eng, MemoryDescPtr desc, const vo
StaticMemory::StaticMemory(const dnnl::engine& eng, const MemoryDesc& desc, const void* data, bool pads_zeroing) :
StaticMemory::StaticMemory(eng, desc.clone(), data, pads_zeroing) {}

bool StaticMemory::isAllocated() const noexcept {
return 0 == m_size || getData() != nullptr;
}

const MemoryDesc& StaticMemory::getDesc() const {
return *m_pMemDesc;
}
Expand Down
19 changes: 9 additions & 10 deletions src/plugins/intel_cpu/src/cpu_memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,6 @@ class IMemory {
public:
virtual ~IMemory() = default;

virtual bool isAllocated() const noexcept = 0;

virtual const MemoryDesc& getDesc() const = 0;
virtual MemoryDescPtr getDescPtr() const = 0;

Expand Down Expand Up @@ -191,6 +189,15 @@ class IMemory {

virtual MemoryBlockPtr getMemoryBlock() const = 0;

virtual void nullify() = 0;

bool isDefined() const noexcept {
if (auto desc = getDescPtr()) {
return desc->isDefined();
}
return false;
}

//oneDNN specifics for backward compatibility
virtual dnnl::memory getPrimitive() const = 0;

Expand All @@ -202,8 +209,6 @@ class IMemory {
return DnnlExtensionUtils::ElementTypeToDataType(getDesc().getPrecision());
}

virtual void nullify() = 0;

template <typename T,
typename std::enable_if<!std::is_pointer<T>::value && !std::is_reference<T>::value, int>::type = 0,
typename std::enable_if<std::is_base_of<MemoryDesc, T>::value, int>::type = 0>
Expand Down Expand Up @@ -240,8 +245,6 @@ class StaticMemory final : public IMemory {
StaticMemory(Memory&&) = delete;
StaticMemory& operator= (StaticMemory&&) = delete;

bool isAllocated() const noexcept override;

const MemoryDesc& getDesc() const override;
MemoryDescPtr getDescPtr() const override;

Expand Down Expand Up @@ -287,8 +290,6 @@ class Memory : public IMemory {

dnnl::memory getPrimitive() const override;

bool isAllocated() const noexcept override;

const MemoryDesc& getDesc() const override {
return *m_pMemDesc;
}
Expand Down Expand Up @@ -393,8 +394,6 @@ class StringMemory : public IMemory {
StringMemory(const dnnl::engine& engine, const MemoryDesc& desc, const StringMemoryBlockPtr& block)
: StringMemory(engine, desc.clone(), block) {}

bool isAllocated() const noexcept override;

const MemoryDesc& getDesc() const override {
return *m_mem_desc;
}
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/intel_cpu/src/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1496,7 +1496,7 @@ bool Node::isInputTensorAtPortEmpty(size_t port) const {
auto edge = getParentEdgeAt(port);
if (one_of(edge->getStatus(), Edge::Status::Allocated, Edge::Status::Validated)) {
auto&& mem = edge->getMemory();
if (mem.isAllocated()) {
if (mem.isDefined()) {
return mem.getShape().hasZeroDims();
}
}
Expand All @@ -1511,7 +1511,7 @@ bool Node::isOutputTensorAtPortEmpty(size_t port) const {
return outputShapes[port].hasZeroDims();
}
auto&& mem = getChildEdgeAt(port)->getMemory();
if (mem.isAllocated()) {
if (mem.isDefined()) {
return mem.getShape().hasZeroDims();
}
return false;
Expand Down
12 changes: 6 additions & 6 deletions src/plugins/intel_cpu/src/nodes/bucketize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,12 @@ void Bucketize::prepareParams() {
auto inputTensorMemPtr = getSrcMemoryAtPort(INPUT_TENSOR_PORT);
auto inputBinsMemPtr = getSrcMemoryAtPort(INPUT_BINS_PORT);
auto dstMemPtr = getDstMemoryAtPort(0);
if (!dstMemPtr || !dstMemPtr->isAllocated())
OPENVINO_THROW("Destination memory didn't allocate.");
if (!inputTensorMemPtr || !inputTensorMemPtr->isAllocated())
OPENVINO_THROW("Input tensor didn't allocate.");
if (!inputBinsMemPtr || !inputBinsMemPtr->isAllocated())
OPENVINO_THROW("Input bins didn't allocate.");
if (!dstMemPtr || !dstMemPtr->isDefined())
OPENVINO_THROW("Destination memory is undefined.");
if (!inputTensorMemPtr || !inputTensorMemPtr->isDefined())
OPENVINO_THROW("Input tensor is undefined.");
if (!inputBinsMemPtr || !inputBinsMemPtr->isDefined())
OPENVINO_THROW("Input bins is undefined.");
if (getSelectedPrimitiveDescriptor() == nullptr)
OPENVINO_THROW("Preferable primitive descriptor is not set.");

Expand Down
8 changes: 4 additions & 4 deletions src/plugins/intel_cpu/src/nodes/concat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,8 @@ void Concat::prepareParams() {
return;

const auto& dstMemPtr = getDstMemoryAtPort(0);
if (!dstMemPtr || !dstMemPtr->isAllocated())
OPENVINO_THROW("Destination memory didn't allocate.");
if (!dstMemPtr || !dstMemPtr->isDefined())
OPENVINO_THROW("Destination memory is undefined.");
auto dstMemDesc = dstMemPtr->getDescWithType<BlockedMemoryDesc>();
if (getSelectedPrimitiveDescriptor() == nullptr)
OPENVINO_THROW("Preferable primitive descriptor is not set.");
Expand Down Expand Up @@ -375,9 +375,9 @@ void Concat::prepareParams() {
nelemTotal = 0;
for (size_t i = 0; i < getParentEdges().size(); i++) {
const auto& srcMemPtr = getSrcMemoryAtPort(i);
if (!srcMemPtr || !srcMemPtr->isAllocated()) {
if (!srcMemPtr || !srcMemPtr->isDefined()) {
auto parent = getParentEdgeAt(i)->getParent();
OPENVINO_THROW("Source memory from ", parent->getName(), " didn't allocate for node ", getName(), ".");
OPENVINO_THROW("Source memory from ", parent->getName(), " is undefined for node ", getName(), ".");
}

if (canExecRef) {
Expand Down
16 changes: 8 additions & 8 deletions src/plugins/intel_cpu/src/nodes/conv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1233,17 +1233,17 @@ void Convolution::prepareParams() {
auto srcMemPtr = getSrcMemoryAtPort(0);
auto wghMemPtr = getSrcMemoryAtPort(1);
auto dstMemPtr = getOutputMemory();
if (!dstMemPtr || !dstMemPtr->isAllocated())
OPENVINO_THROW("Destination memory was not allocated.");
if (!srcMemPtr || !srcMemPtr->isAllocated())
OPENVINO_THROW("Input memory was not allocated.");
if (!wghMemPtr || !wghMemPtr->isAllocated())
OPENVINO_THROW("Weight memory was not allocated.");
if (!dstMemPtr || !dstMemPtr->isDefined())
OPENVINO_THROW("Destination memory was undefined.");
if (!srcMemPtr || !srcMemPtr->isDefined())
OPENVINO_THROW("Input memory was undefined.");
if (!wghMemPtr || !wghMemPtr->isDefined())
OPENVINO_THROW("Weight memory was undefined.");
MemoryPtr biasMemPtr = nullptr;
if (withBiases) {
biasMemPtr = getSrcMemoryAtPort(2);
if (!biasMemPtr || !biasMemPtr->isAllocated())
OPENVINO_THROW("Input memory didn't allocate.");
if (!biasMemPtr || !biasMemPtr->isDefined())
OPENVINO_THROW("Input memory is undefined.");
}

const NodeDesc *selected_pd = getSelectedPrimitiveDescriptor();
Expand Down
20 changes: 10 additions & 10 deletions src/plugins/intel_cpu/src/nodes/deconv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -812,12 +812,12 @@ void Deconvolution::prepareParams() {
auto srcMemPtr = getSrcMemoryAtPort(0);
auto wghMemPtr = getSrcMemoryAtPort(1);
auto dstMemPtr = getDstMemoryAtPort(0);
if (!dstMemPtr || !dstMemPtr->isAllocated())
OPENVINO_THROW("Destination memory has not been allocated.");
if (!srcMemPtr || !srcMemPtr->isAllocated())
OPENVINO_THROW("Input memory has not been allocated.");
if (!wghMemPtr || !wghMemPtr->isAllocated())
OPENVINO_THROW("Weight memory has not been allocated.");
if (!dstMemPtr || !dstMemPtr->isDefined())
OPENVINO_THROW("Destination memory is undefined.");
if (!srcMemPtr || !srcMemPtr->isDefined())
OPENVINO_THROW("Input memory is undefined.");
if (!wghMemPtr || !wghMemPtr->isDefined())
OPENVINO_THROW("Weight memory is undefined.");
auto selected_pd = getSelectedPrimitiveDescriptor();
if (selected_pd == nullptr)
OPENVINO_THROW("Preferable primitive descriptor is not set for node ", getName(), ".");
Expand Down Expand Up @@ -869,8 +869,8 @@ void Deconvolution::prepareParams() {

if (withBiases) {
biasMemPtr = getSrcMemoryAtPort(biasPort);
if (!biasMemPtr || !biasMemPtr->isAllocated())
OPENVINO_THROW("Bias memory memory didn't allocate.");
if (!biasMemPtr || !biasMemPtr->isDefined())
OPENVINO_THROW("Bias memory memory is undefined.");
biasDesc = biasMemPtr->getDescWithType<DnnlMemoryDesc>();
}
bool is1x1PaddingAsymmetric = false;
Expand Down Expand Up @@ -1094,8 +1094,8 @@ std::vector<int32_t> Deconvolution::readOutputSpatialDims() const {
OPENVINO_THROW("Can't get output spatial dims. Inputs number = ", getParentEdges().size());
}
const auto &shapeMemPtr = getSrcMemoryAtPort(2);
if (!shapeMemPtr || !shapeMemPtr->isAllocated()) {
OPENVINO_THROW("'output_shape' input memory is not allocated.");
if (!shapeMemPtr || !shapeMemPtr->isDefined()) {
OPENVINO_THROW("'output_shape' input memory is undefined.");
}
const auto spDimsNum = getInputShapeAtPort(0).getRank() - 2;
if (shapeMemPtr->getStaticDims()[0] != spDimsNum) {
Expand Down
20 changes: 10 additions & 10 deletions src/plugins/intel_cpu/src/nodes/def_conv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1184,19 +1184,19 @@ void DeformableConvolution::prepareParams() {
auto offMemPtr = getSrcMemoryAtPort(OFF_ID);
auto weiMemPtr = getSrcMemoryAtPort(WEI_ID);

if (!dstMemPtr || !dstMemPtr->isAllocated())
OPENVINO_THROW(errorPrefix, " did not allocate destination memory");
if (!srcMemPtr || !srcMemPtr->isAllocated())
OPENVINO_THROW(errorPrefix, " did not allocate input memory");
if (!offMemPtr || !offMemPtr->isAllocated())
OPENVINO_THROW(errorPrefix, " did not allocate offsets shape memory");
if (!weiMemPtr || !weiMemPtr->isAllocated())
OPENVINO_THROW(errorPrefix, " did not allocate weights memory");
if (!dstMemPtr || !dstMemPtr->isDefined())
OPENVINO_THROW(errorPrefix, " has undefined destination memory");
if (!srcMemPtr || !srcMemPtr->isDefined())
OPENVINO_THROW(errorPrefix, " has undefined input memory");
if (!offMemPtr || !offMemPtr->isDefined())
OPENVINO_THROW(errorPrefix, " has undefined offsets shape memory");
if (!weiMemPtr || !weiMemPtr->isDefined())
OPENVINO_THROW(errorPrefix, " has undefined weights memory");

if (getOriginalInputsNumber() > 3) {
auto modMemPtr = getSrcMemoryAtPort(MOD_ID);
if (!modMemPtr || !modMemPtr->isAllocated())
OPENVINO_THROW(errorPrefix, " did not allocate modulations memory");
if (!modMemPtr || !modMemPtr->isDefined())
OPENVINO_THROW(errorPrefix, " has undefined modulations memory");
}

auto selectedPrimitiveDescriptor = getSelectedPrimitiveDescriptor();
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/intel_cpu/src/nodes/depth_to_space.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,10 @@ void DepthToSpace::initSupportedPrimitiveDescriptors() {
void DepthToSpace::createPrimitive() {
auto dstMemPtr = getDstMemoryAtPort(0);
auto srcMemPtr = getSrcMemoryAtPort(0);
if (!dstMemPtr || !dstMemPtr->isAllocated())
THROW_ERROR("has not allocated destination memory");
if (!srcMemPtr || !srcMemPtr->isAllocated())
THROW_ERROR("has not allocated input memory");
if (!dstMemPtr || !dstMemPtr->isDefined())
THROW_ERROR("has undefined destination memory");
if (!srcMemPtr || !srcMemPtr->isDefined())
THROW_ERROR("has undefined input memory");
if (getSelectedPrimitiveDescriptor() == nullptr)
THROW_ERROR("has unidentified preferable primitive descriptor");

Expand Down
8 changes: 4 additions & 4 deletions src/plugins/intel_cpu/src/nodes/extract_image_patches.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,10 @@ ExtractImagePatches::ExtractImagePatches(const std::shared_ptr<ov::Node>& op, co
void ExtractImagePatches::prepareParams() {
const auto& srcMemPtr0 = getSrcMemoryAtPort(0);
const auto& dstMemPtr = getDstMemoryAtPort(0);
if (!srcMemPtr0 || !srcMemPtr0->isAllocated())
OPENVINO_THROW("Input memory has not been allocated.");
if (!dstMemPtr || !dstMemPtr->isAllocated())
OPENVINO_THROW("Destination memory has not been allocated.");
if (!srcMemPtr0 || !srcMemPtr0->isDefined())
OPENVINO_THROW("Input memory is undefined.");
if (!dstMemPtr || !dstMemPtr->isDefined())
OPENVINO_THROW("Destination memory is undefined.");
if (getSelectedPrimitiveDescriptor() == nullptr)
OPENVINO_THROW("Preferable primitive descriptor is not set.");

Expand Down
4 changes: 2 additions & 2 deletions src/plugins/intel_cpu/src/nodes/eye.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ void Eye::executeSpecified() {
const size_t colNum = getColNum();
const int64_t shift = getDiagIndex();
auto outPtr = getDstMemoryAtPort(0);
if (!outPtr || !outPtr ->isAllocated())
THROW_ERROR(errorPrefix, "Destination memory didn't allocate.");
if (!outPtr || !outPtr ->isDefined())
THROW_ERROR(errorPrefix, "Destination memory is undefined.");
T *dst = outPtr->getDataAs<T>();

const size_t batchVolume = getBatchVolume(getBatchShape());
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/intel_cpu/src/nodes/gather.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,11 +338,11 @@ bool Gather::needPrepareParams() const {

void Gather::prepareParams() {
auto dataMemPtr = getSrcMemoryAtPort(GATHER_DATA);
if (!dataMemPtr || !dataMemPtr->isAllocated())
THROW_ERROR(" has not allocated input data memory.");
if (!dataMemPtr || !dataMemPtr->isDefined())
THROW_ERROR(" has undefined input data memory.");
auto idxMemPtr = getSrcMemoryAtPort(GATHER_INDICES);
if (!idxMemPtr || !idxMemPtr->isAllocated())
THROW_ERROR(" has not allocated input indices memory.");
if (!idxMemPtr || !idxMemPtr->isDefined())
THROW_ERROR(" has undefined input indices memory.");
if (getSelectedPrimitiveDescriptor() == nullptr)
THROW_ERROR(" has unidentified preferable primitive descriptor.");

Expand Down
12 changes: 6 additions & 6 deletions src/plugins/intel_cpu/src/nodes/gather_nd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ void GatherND::prepareParams() {
auto srcMemPtr = getSrcMemoryAtPort(GATHERND_DATA);
auto idxMemPtr = getSrcMemoryAtPort(GATHERND_INDEXES);
auto dstMemPtr = getDstMemoryAtPort(0);
if (!srcMemPtr || !srcMemPtr->isAllocated())
THROW_ERROR(" has not allocated input memory of 'data'.");
if (!idxMemPtr || !idxMemPtr->isAllocated())
THROW_ERROR(" has not allocated input memory of 'indices'.");
if (!dstMemPtr || !dstMemPtr->isAllocated())
THROW_ERROR(" has not allocated output memory.");
if (!srcMemPtr || !srcMemPtr->isDefined())
THROW_ERROR(" has undefined input memory of 'data'.");
if (!idxMemPtr || !idxMemPtr->isDefined())
THROW_ERROR(" has undefined input memory of 'indices'.");
if (!dstMemPtr || !dstMemPtr->isDefined())
THROW_ERROR(" has undefined output memory.");
if (getSelectedPrimitiveDescriptor() == nullptr)
THROW_ERROR(" has unidentified preferable primitive descriptor.");

Expand Down
16 changes: 8 additions & 8 deletions src/plugins/intel_cpu/src/nodes/gather_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ void GatherTree::prepareParams() {
const auto& maxSeqLenMemPtr = getSrcMemoryAtPort(GATHER_TREE_MAX_SEQ_LEN);
const auto& dstMemPtr = getDstMemoryAtPort(0);

if (!stepIdxMemPtr || !stepIdxMemPtr->isAllocated())
OPENVINO_THROW(errorPrefix, " has not allocated input memory of 'step_ids'.");
if (!parentIdxMemPtr || !parentIdxMemPtr->isAllocated())
OPENVINO_THROW(errorPrefix, " has not allocated input memory of 'parent_ids'.");
if (!maxSeqLenMemPtr || !maxSeqLenMemPtr->isAllocated())
OPENVINO_THROW(errorPrefix, " has not allocated input memory of 'max_seq_len'.");
if (!dstMemPtr || !dstMemPtr->isAllocated())
OPENVINO_THROW(errorPrefix, " has not allocated output memory.");
if (!stepIdxMemPtr || !stepIdxMemPtr->isDefined())
OPENVINO_THROW(errorPrefix, " has undefined input memory of 'step_ids'.");
if (!parentIdxMemPtr || !parentIdxMemPtr->isDefined())
OPENVINO_THROW(errorPrefix, " has undefined input memory of 'parent_ids'.");
if (!maxSeqLenMemPtr || !maxSeqLenMemPtr->isDefined())
OPENVINO_THROW(errorPrefix, " has undefined input memory of 'max_seq_len'.");
if (!dstMemPtr || !dstMemPtr->isDefined())
OPENVINO_THROW(errorPrefix, " has undefined output memory.");
if (getSelectedPrimitiveDescriptor() == nullptr)
OPENVINO_THROW(errorPrefix, " has unidentified preferable primitive descriptor.");

Expand Down
12 changes: 6 additions & 6 deletions src/plugins/intel_cpu/src/nodes/grid_sample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,14 @@ void GridSample::createPrimitive() {

void GridSample::prepareParams() {
auto dataMemPtr = getSrcMemoryAtPort(IN_DATA);
if (!dataMemPtr || !dataMemPtr->isAllocated())
THROW_CPU_NODE_ERR("has not allocated input data memory.");
if (!dataMemPtr || !dataMemPtr->isDefined())
THROW_CPU_NODE_ERR("has undefined input data memory.");
auto gridMemPtr = getSrcMemoryAtPort(IN_GRID);
if (!gridMemPtr || !gridMemPtr->isAllocated())
THROW_CPU_NODE_ERR("has not allocated input grid memory.");
if (!gridMemPtr || !gridMemPtr->isDefined())
THROW_CPU_NODE_ERR("has undefined input grid memory.");
auto dstMemPtr = getDstMemoryAtPort(0);
if (!dstMemPtr || !dstMemPtr->isAllocated())
THROW_CPU_NODE_ERR("has not allocated output memory.");
if (!dstMemPtr || !dstMemPtr->isDefined())
THROW_CPU_NODE_ERR("has undefined output memory.");
if (getSelectedPrimitiveDescriptor() == nullptr)
THROW_CPU_NODE_ERR("has unidentified preferable primitive descriptor.");

Expand Down
Loading

0 comments on commit f723360

Please sign in to comment.