diff --git a/include/aidge/backend/TensorImpl.hpp b/include/aidge/backend/TensorImpl.hpp index 600f0badc849046e69c02a5e4e003788ad0ff473..510e243eba684bda3c43eaf49dbeae639da8f7c9 100644 --- a/include/aidge/backend/TensorImpl.hpp +++ b/include/aidge/backend/TensorImpl.hpp @@ -54,6 +54,17 @@ public: /// @details Copy all characteristics of calling TensorImpl and its data (deep copy). /// @return Pointer to a copy of the TensorImpl object virtual detail::pimpl::ImplPtr_t Clone() const = 0; + /// @brief Creates a new TensorImpl with same properties as self but restricted to a + /// given area + /// @param i_FirstDataCoordinates Logical coordinates of the data at null natural + /// coordinates + /// @param i_Dimensions Tensor dimensions + /// @details Copy all characteristics of calling TensorImpl and its data (deep copy), + /// restricting data to the given area. + /// @return Pointer to an extract of the TensorImpl object + virtual detail::pimpl::ImplPtr_t Extract( + std::vector<Coord_t> const &i_FirstDataCoordinates, + std::vector<DimSize_t> const &i_Dimensions) const = 0; /// @param src pointer to the raw host buffer from which the data will be copied /// @param length Nb of element to copy from the buffer virtual void copyFromHost(Byte_t const *const src, NbElts_t length) = 0; diff --git a/include/aidge/data/Tensor.hpp b/include/aidge/data/Tensor.hpp index 345586b5a72ffbc9e5895d49da5eaa8adca4e4c2..baa33d8e91197894fcbc7081f5acc2f42c5d4a46 100644 --- a/include/aidge/data/Tensor.hpp +++ b/include/aidge/data/Tensor.hpp @@ -38,7 +38,16 @@ namespace detail { namespace pimpl { +/// @brief Pointer type used to reference TensorImpl using ImplPtr_t = std::shared_ptr<TensorImpl>; +/// @brief Mandatory function used to release TensorImpl ressource when a Tensor is +/// destroyed. +/// @param PImpl Referenced TensorImpl to be released +inline void releasePImpl(ImplPtr_t &PImpl) +{ + // for a shared_ptr, merely remove a ref + PImpl = nullptr; +} } // namespace pimpl /// @brief Check if a valid area is included in another one. @@ -123,6 +132,14 @@ private: public: static constexpr const char *Type = "Tensor"; + /// @brief Tensor destructor + /// @details Release any associated TensorImpl (but not necessarily deallocate it as + /// it may be shared) + ~Tensor() + { + detail::pimpl::releasePImpl(mImpl); + } + /** * @brief Construct a new empty Tensor object. * @param dataType Sets the type of inserted data. diff --git a/src/data/Tensor.cpp b/src/data/Tensor.cpp index f2364ce312b74238aa7593697b1b6d4681740a01..b9ec6389b2379f30b9168da12e72e362e0276662 100644 --- a/src/data/Tensor.cpp +++ b/src/data/Tensor.cpp @@ -246,9 +246,8 @@ Tensor::Tensor( } else { - /// @todo WIP - mImpl = Registrar<Tensor>::create({otherTensor.mImpl->backend(), mDataType})( - mDataType, mvActiveAreaOrigin, mDims); + // forming an extract + mImpl = otherTensor.mImpl->Extract(i_FirstDataLogicalCoordinates, i_Dimensions); } }