diff options
Diffstat (limited to 'runtime/onert/backend/cpu/Tensor.h')
-rw-r--r-- | runtime/onert/backend/cpu/Tensor.h | 87 |
1 files changed, 1 insertions, 86 deletions
diff --git a/runtime/onert/backend/cpu/Tensor.h b/runtime/onert/backend/cpu/Tensor.h index 2ad2ad0fb..d663c3f50 100644 --- a/runtime/onert/backend/cpu/Tensor.h +++ b/runtime/onert/backend/cpu/Tensor.h @@ -28,92 +28,7 @@ namespace cpu { using Tensor = cpu_common::Tensor; - -/** - * @brief Class that uses data from external memory that is not managed by a backend - * instead of allocating and copying the data. ExternalTensor's data pointer points to - * an address of memory such as where memory is already allocated, or mmapped area. - * This is meaning that ExternalTensor can take all of types' ir::Data. - * To support this, assume below things no padding, always NHWC layout, - * constant tensor and not dynamic. - */ -class ExternalTensor : public Tensor -{ -public: - ExternalTensor() = delete; - virtual ~ExternalTensor(); - -public: - ExternalTensor(const ir::OperandInfo &info, const ir::Layout layout) - : Tensor(info, layout, nullptr) - { - assert(_layout == ir::Layout::NHWC); - assert(_info.isConstant()); - assert(_info.isDynamic() == false); - } - -public: - /** - * @brief set Data to be shared from external so that this ExternalTensor will not be - * allocated on CPU backend - * @param[in] data data of Operand to be set - */ - void setData(const std::shared_ptr<ir::Data> data) - { - assert(data != nullptr); - _data = data; - // Note. Some op such as cker::Conv could take buffer as nullptr. - // That's why _buffer also would be used - _buffer = const_cast<uint8_t *>(_data->base()); - } - -public: - uint8_t *buffer() const override { return _buffer; } - - bool is_constant() const override { return true; } - bool is_dynamic() const override { return false; } - void set_dynamic() override - { - throw std::runtime_error("This tensor does not support changing dynamic"); - } - - void setShape(const ir::Shape &) override - { - throw std::runtime_error("This tensor does not support changing shape"); - } - - void increase_ref() override { ++_num_references; } - - void decrease_ref() override - { - assert(_data != nullptr); - assert(_num_references > 0); - --_num_references; - if (_num_references == 0) - { - _data.reset(); - _buffer = nullptr; - } - } - - /** - * @brief Reset reference count to zero and release data - */ - void reset_ref() override - { - assert(_data != nullptr); - assert(_num_references > 0); - _num_references = 0; - - _data.reset(); - _buffer = nullptr; - } - - int32_t num_references() override { return _num_references; } - -private: - std::shared_ptr<const ir::Data> _data; -}; +using ExternalTensor = cpu_common::ExternalTensor; } // namespace cpu } // namespace backend |