Skip to content

Commit

Permalink
Delete ngraph AlignedBuffer/SharedBuffer (openvinotoolkit#22182)
Browse files Browse the repository at this point in the history
* Delete ngraph `SharedBuffer`

* Delete ngraph `AlignedBuffer`

* Fix `DenormalNullifyCheck`

* Fix comments
  • Loading branch information
vurusovs authored Jan 19, 2024
1 parent 8e7b1a4 commit 635665a
Show file tree
Hide file tree
Showing 9 changed files with 9 additions and 260 deletions.
11 changes: 0 additions & 11 deletions src/common/snippets/src/pass/hash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,17 +170,6 @@ class SnippetsHasher : public ov::AttributeVisitor {
void on_adapter(const std::string& name, ov::ValueAccessor<void>& adapter) override {
if (const auto& a = ov::as_type<ov::AttributeAdapter<std::shared_ptr<ov::op::util::Variable>>>(&adapter)) {
m_hash = hash_combine(hash_combine(m_hash, name), a->get()->get_info().variable_id);
} else if (const auto& a =
ov::as_type<ov::AttributeAdapter<std::shared_ptr<ngraph::runtime::AlignedBuffer>>>(&adapter)) {
if (name == "value" && m_node_type_name == "Constant") {
m_hash = hash_combine(m_hash, AttrType::constant);
const int64_t size = a->get()->size();
m_hash = hash_combine(hash_combine(m_hash, AttrType::size), size);
auto data = static_cast<const char*>(a->get()->get_ptr());
for (int64_t i = 0; i < size; i++) {
m_hash = hash_combine(m_hash, data[i]);
}
}
} else if (const auto& a =
ov::as_type<ov::AttributeAdapter<std::shared_ptr<ov::AlignedBuffer>>>(&adapter)) {
if (name == "value" && m_node_type_name == "Constant") {
Expand Down
93 changes: 0 additions & 93 deletions src/core/include/ngraph/runtime/aligned_buffer.hpp

This file was deleted.

45 changes: 0 additions & 45 deletions src/core/include/ngraph/runtime/shared_buffer.hpp

This file was deleted.

8 changes: 2 additions & 6 deletions src/core/include/openvino/op/constant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
# define WAS_OV_LIBRARY_DEFINED_CONSTANT
#endif

#include "ngraph/runtime/shared_buffer.hpp"
#include "ngraph/util.hpp"
#include "openvino/core/rtti.hpp"

#ifdef WAS_OV_LIBRARY_DEFINED_CONSTANT
# undef IN_OV_COMPONENT
Expand Down Expand Up @@ -400,11 +401,6 @@ class OPENVINO_API Constant : public Op {
private:
Constant(bool memset_allocation, const element::Type& type, const Shape& shape);

OPENVINO_SUPPRESS_DEPRECATED_START
std::shared_ptr<ov::AlignedBuffer> legacy_to_ov_aligned_buffer(
const std::shared_ptr<ngraph::runtime::AlignedBuffer>& buffer);
OPENVINO_SUPPRESS_DEPRECATED_END

template <element::Type_t Type,
typename StorageDataType = fundamental_type_for<Type>,
typename std::enable_if<Type != element::Type_t::u1 && Type != element::Type_t::u4 &&
Expand Down
1 change: 0 additions & 1 deletion src/core/src/op/constant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "compare.hpp"
#include "element_visitor.hpp"
#include "itt.hpp"
#include "ngraph/runtime/aligned_buffer.hpp"
#include "ngraph/runtime/tensor.hpp"
#include "openvino/core/type/float16.hpp"
#include "openvino/core/type/nf4.hpp"
Expand Down
14 changes: 0 additions & 14 deletions src/core/src/pass/serialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,20 +516,6 @@ class XmlSerializer : public ov::AttributeVisitor {
} else if (const auto& a =
ov::as_type<ov::AttributeAdapter<std::shared_ptr<ov::op::util::Variable>>>(&adapter)) {
m_xml_node.append_attribute(name.c_str()).set_value(a->get()->get_info().variable_id.c_str());
} else if (const auto& a =
ov::as_type<ov::AttributeAdapter<std::shared_ptr<ngraph::runtime::AlignedBuffer>>>(&adapter)) {
if (name == "value" && translate_type_name(m_node_type_name) == "Const") {
const int64_t size = a->get()->size();
size_t new_size;
int64_t offset = m_constant_write_handler.write(static_cast<const char*>(a->get()->get_ptr()),
size,
&new_size,
m_compress_to_fp16,
m_output_element_type);

m_xml_node.append_attribute("offset").set_value(static_cast<unsigned long long>(offset));
m_xml_node.append_attribute("size").set_value(static_cast<unsigned long long>(new_size));
}
} else if (const auto& a = ov::as_type<ov::AttributeAdapter<std::shared_ptr<ov::AlignedBuffer>>>(&adapter)) {
if (name == "value" && translate_type_name(m_node_type_name) == "Const") {
const int64_t size = a->get()->size();
Expand Down
62 changes: 1 addition & 61 deletions src/core/src/runtime/aligned_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,71 +2,11 @@
// SPDX-License-Identifier: Apache-2.0
//

#include "ngraph/runtime/aligned_buffer.hpp"
#include "openvino/runtime/aligned_buffer.hpp"

#include <algorithm>
#include <memory>

#include "ngraph/util.hpp"
#include "openvino/runtime/aligned_buffer.hpp"
#include "openvino/util/log.hpp"

NGRAPH_SUPPRESS_DEPRECATED_START

namespace ngraph {

runtime::AlignedBuffer::AlignedBuffer() : m_allocated_buffer(nullptr), m_aligned_buffer(nullptr), m_byte_size(0) {}

runtime::AlignedBuffer::AlignedBuffer(size_t byte_size, size_t alignment) : m_byte_size(byte_size) {
m_byte_size = std::max<size_t>(1, byte_size);
size_t allocation_size = m_byte_size + alignment;
m_allocated_buffer = new char[allocation_size];
m_aligned_buffer = m_allocated_buffer;
size_t mod = (alignment != 0) ? size_t(m_aligned_buffer) % alignment : 0;

if (mod != 0) {
m_aligned_buffer += (alignment - mod);
}
}

runtime::AlignedBuffer::AlignedBuffer(AlignedBuffer&& other)
: m_allocated_buffer(other.m_allocated_buffer),
m_aligned_buffer(other.m_aligned_buffer),
m_byte_size(other.m_byte_size) {
other.m_allocated_buffer = nullptr;
other.m_aligned_buffer = nullptr;
other.m_byte_size = 0;
}

runtime::AlignedBuffer::~AlignedBuffer() {
if (m_allocated_buffer != nullptr) {
delete[] m_allocated_buffer;
}
}

runtime::AlignedBuffer& runtime::AlignedBuffer::operator=(AlignedBuffer&& other) {
if (this != &other) {
if (m_allocated_buffer != nullptr) {
delete[] m_allocated_buffer;
}
m_allocated_buffer = other.m_allocated_buffer;
m_aligned_buffer = other.m_aligned_buffer;
m_byte_size = other.m_byte_size;
other.m_allocated_buffer = nullptr;
other.m_aligned_buffer = nullptr;
other.m_byte_size = 0;
}
return *this;
}
} // namespace ngraph

namespace ov {
AttributeAdapter<std::shared_ptr<ngraph::runtime::AlignedBuffer>>::AttributeAdapter(
std::shared_ptr<ngraph::runtime::AlignedBuffer>& value)
: DirectValueAccessor<std::shared_ptr<ngraph::runtime::AlignedBuffer>>(value) {}
} // namespace ov
NGRAPH_SUPPRESS_DEPRECATED_END

namespace ov {
AlignedBuffer::AlignedBuffer() : m_allocated_buffer(nullptr), m_aligned_buffer(nullptr), m_byte_size(0) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,14 @@
#include "shared_test_classes/base/ov_subgraph.hpp"
#include "ov_models/utils/ov_helpers.hpp"
#include "ov_models/builders.hpp"
#include "ngraph/runtime/aligned_buffer.hpp"
#include "openvino/runtime/aligned_buffer.hpp"

namespace ov {
namespace test {

template<typename T>
class AlignedBufferWrapper {
public:
AlignedBufferWrapper(size_t size, size_t alignment) {
_buffer.reset(new ngraph::runtime::AlignedBuffer(size * sizeof(T), alignment));
}
AlignedBufferWrapper(const AlignedBufferWrapper&) = delete;
AlignedBufferWrapper& operator=(const AlignedBufferWrapper&) = delete;
AlignedBufferWrapper(AlignedBufferWrapper&&) = default;
AlignedBufferWrapper& operator=(AlignedBufferWrapper&&) = default;

T* get_ptr() {
return _buffer->get_ptr<T>();
}

size_t size() const {
return _buffer->size() / sizeof(T);
}
private:
std::unique_ptr<ngraph::runtime::AlignedBuffer> _buffer = nullptr;
};

class DenormalNullifyCheck : public SubgraphBaseTest {
protected:
std::unique_ptr<AlignedBufferWrapper<float>> pConstStorage;
std::unique_ptr<ov::AlignedBuffer> pConstStorage;

void validate() override {
const auto& actualOutputs = get_plugin_outputs();
Expand Down Expand Up @@ -63,7 +41,7 @@ void SetUp() override {
const auto elemsCount = shape_size(inpShape);
const auto rtPrc = ov::element::f32;
ov::ParameterVector params {std::make_shared<ov::op::v0::Parameter>(rtPrc, ov::Shape(inpShape))};
pConstStorage.reset(new AlignedBufferWrapper<float>(elemsCount, alignment));
pConstStorage.reset(new ov::AlignedBuffer(elemsCount, alignment));

auto constTensor = ov::Tensor(rtPrc, inpShape, pConstStorage->get_ptr());
auto constNode = std::make_shared<ov::op::v0::Constant>(constTensor);
Expand All @@ -78,7 +56,7 @@ void SetUp() override {

TEST_F(DenormalNullifyCheck, smoke_CPU_Denormal_Check) {
using indexInterval = std::pair<size_t, size_t>;
size_t elemsCount = pConstStorage->size();
size_t elemsCount = pConstStorage->size() / sizeof(float);
const indexInterval intervals[] = {
{0, elemsCount/2},
{elemsCount/2, elemsCount},
Expand All @@ -99,9 +77,9 @@ TEST_F(DenormalNullifyCheck, smoke_CPU_Denormal_Check) {
auto denormal = random.Generate(denormalsRange) + 1;
float tmp;
memcpy(&tmp, &denormal, sizeof(float));
pConstStorage->get_ptr()[i] = tmp;
pConstStorage->get_ptr<float>()[i] = tmp;
} else {
pConstStorage->get_ptr()[i] = randomRange[i];
pConstStorage->get_ptr<float>()[i] = randomRange[i];
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include "common_test_utils/ov_tensor_utils.hpp"

#include "ngraph/runtime/aligned_buffer.hpp"
#include "ov_models/builders.hpp"
#include "ov_models/utils/ov_helpers.hpp"
#include "shared_test_classes/base/ov_subgraph.hpp"
Expand Down

0 comments on commit 635665a

Please sign in to comment.