forked from openvinotoolkit/openvino
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add AlignedBuffer to OpenVINO developer API (openvinotoolkit#20532)
* Add AlignedBuffer to OpenVINO developer API * Fixed build * Fixed code style and remove opset deprecation * Fixed Windows build * Fixed GNA * Fixed comment
- Loading branch information
Showing
30 changed files
with
351 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Copyright (C) 2018-2023 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#pragma once | ||
|
||
#include <memory> | ||
|
||
#include "openvino/core/attribute_adapter.hpp" | ||
#include "openvino/core/core_visibility.hpp" | ||
|
||
namespace ov { | ||
/// \brief Allocates a block of memory on the specified alignment. The actual size of the | ||
/// allocated memory is larger than the requested size by the alignment, so allocating 1 | ||
/// byte | ||
/// on 64 byte alignment will allocate 65 bytes. | ||
class OPENVINO_API AlignedBuffer { | ||
public: | ||
// Allocator objects and the allocation interfaces are owned by the | ||
// creators of AlignedBuffers. They need to ensure that the lifetime of | ||
// allocator exceeds the lifetime of this AlignedBuffer. | ||
AlignedBuffer(size_t byte_size, size_t alignment = 64); | ||
|
||
AlignedBuffer(); | ||
virtual ~AlignedBuffer(); | ||
|
||
AlignedBuffer(AlignedBuffer&& other); | ||
AlignedBuffer& operator=(AlignedBuffer&& other); | ||
|
||
size_t size() const { | ||
return m_byte_size; | ||
} | ||
void* get_ptr(size_t offset) const { | ||
return m_aligned_buffer + offset; | ||
} | ||
void* get_ptr() { | ||
return m_aligned_buffer; | ||
} | ||
const void* get_ptr() const { | ||
return m_aligned_buffer; | ||
} | ||
template <typename T> | ||
T* get_ptr() { | ||
return reinterpret_cast<T*>(m_aligned_buffer); | ||
} | ||
template <typename T> | ||
const T* get_ptr() const { | ||
return reinterpret_cast<const T*>(m_aligned_buffer); | ||
} | ||
|
||
template <typename T> | ||
explicit operator T*() { | ||
return get_ptr<T>(); | ||
} | ||
|
||
private: | ||
AlignedBuffer(const AlignedBuffer&) = delete; | ||
AlignedBuffer& operator=(const AlignedBuffer&) = delete; | ||
|
||
protected: | ||
char* m_allocated_buffer; | ||
char* m_aligned_buffer; | ||
size_t m_byte_size; | ||
}; | ||
|
||
template <> | ||
class OPENVINO_API AttributeAdapter<std::shared_ptr<ov::AlignedBuffer>> | ||
: public DirectValueAccessor<std::shared_ptr<ov::AlignedBuffer>> { | ||
public: | ||
AttributeAdapter(std::shared_ptr<ov::AlignedBuffer>& value); | ||
|
||
OPENVINO_RTTI("AttributeAdapter<std::shared_ptr<ov::AlignedBuffer>"); | ||
}; | ||
|
||
} // namespace ov |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright (C) 2018-2023 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#pragma once | ||
|
||
#include "openvino/runtime/aligned_buffer.hpp" | ||
|
||
namespace ov { | ||
|
||
/// \brief SharedBuffer class to store pointer to pre-acclocated buffer. | ||
template <typename T> | ||
class SharedBuffer : public ov::AlignedBuffer { | ||
public: | ||
SharedBuffer(char* data, size_t size, const T& shared_object) : _shared_object(shared_object) { | ||
m_allocated_buffer = data; | ||
m_aligned_buffer = data; | ||
m_byte_size = size; | ||
} | ||
|
||
virtual ~SharedBuffer() { | ||
m_aligned_buffer = nullptr; | ||
m_allocated_buffer = nullptr; | ||
m_byte_size = 0; | ||
} | ||
|
||
private: | ||
T _shared_object; | ||
}; | ||
|
||
} // namespace ov |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.