Skip to content
Snippets Groups Projects
Commit 9af2a358 authored by laurent soulier's avatar laurent soulier
Browse files

[WIP][IMPR] working on extraction

Expliciting resource management in Tensor (a bit overkill so far as we're using standard smart-pointers but it paves the way for other possible implementation)
parent 9c1aa27c
No related branches found
No related tags found
2 merge requests!41Support for any backend storage,!13Refactoring Tensor
......@@ -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;
......
......@@ -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.
......
......@@ -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);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment