Browse Source

docs(lite): initial part of lite::Tensor comments as template

GitOrigin-RevId: d89636f1f6
release-1.10
Megvii Engine Team 3 years ago
parent
commit
5821c0b679
1 changed files with 41 additions and 17 deletions
  1. +41
    -17
      lite/include/lite/tensor.h

+ 41
- 17
lite/include/lite/tensor.h View File

@@ -28,19 +28,27 @@ struct LITE_API Layout {
/*! /*!
* \brief warpper of the MegEngine Tensor * \brief warpper of the MegEngine Tensor
* *
* The memory is not alloc directly, when call get_memory_ptr() the memory
* will be allocated in tensor implement, which will be deleted automatically
* \verbatim embed:rst:leading-asterisk
* *
* Note: if the tensor memory is set through reset() interface, the memory is
* managed by the user, it will not be freed by the tensor
* Some more things here.
* *
* If the device or layout is not set, when copy form other source tensor, its
* device and layout will be copy form the source tensor
* .. note::
* *
* if is_pinned_host is set, the storage memory of the tensor is pinned memory,
* this is used to Optimize the H2D or D2H memory copy, if the device or layout
* is not set, when copy form other device(CUDA) tensor, this tensor
* will be automatically set to pinned tensor
* * If the tensor memory is set through :cpp:func:`~reset()` interface, the memory
* is managed by the user, it will not be freed by the tensor;
* * If the ``device_type`` or ``layout`` is not set, when copy form other source
* tensor, its device and layout will be copy form the source tensor;
* * If ``is_pinned_host`` is set, the storage memory of the tensor is pinned memory,
* this is used to Optimize the H2D or D2H memory copy, if the device or layout
* is not set, when copy form other device(CUDA) tensor, this tensor
* will be automatically set to pinned tensor.
*
* .. warning::
*
* The memory is not alloc directly, when call :cpp:func:`get_memory_ptr()` the
* memory will be allocated in tensor implement, which will be deleted automatically.
*
* \endverbatim
*/ */
class LITE_API Tensor { class LITE_API Tensor {
class TensorImpl; class TensorImpl;
@@ -48,6 +56,16 @@ class LITE_API Tensor {
public: public:
class TensorImplBase; class TensorImplBase;


/*!
* @name Constructor
*
* @param device_type The desired device type of created Tensor.
* @param device_id The desired device id of created Tensor.
* @param is_pinned_host Whether to use pinned memory.
* @param layout The desired layout of created Tensor.
*
*/
//@{
Tensor(); Tensor();
Tensor(LiteDeviceType device_type, bool is_pinned_host = false); Tensor(LiteDeviceType device_type, bool is_pinned_host = false);
Tensor(LiteDeviceType device_type, const Layout& layout, Tensor(LiteDeviceType device_type, const Layout& layout,
@@ -58,8 +76,13 @@ public:
bool is_pinned_host = false); bool is_pinned_host = false);
Tensor(LiteBackend backend, LiteDeviceType device_type = LiteDeviceType::LITE_CPU, Tensor(LiteBackend backend, LiteDeviceType device_type = LiteDeviceType::LITE_CPU,
int device_id = 0, const Layout& layout = {}, bool is_pinned_host = false); int device_id = 0, const Layout& layout = {}, bool is_pinned_host = false);
//@}
~Tensor(); ~Tensor();


/*!
* @name Getter
*/
//@{
LiteDeviceType get_device_type() const { return m_device_type; }; LiteDeviceType get_device_type() const { return m_device_type; };


int get_device_id() const { return m_device_id; }; int get_device_id() const { return m_device_id; };
@@ -68,9 +91,6 @@ public:


bool is_pinned_host() const { return m_is_pinned_host; }; bool is_pinned_host() const { return m_is_pinned_host; };


//! set layout will change the layout and reallocate memory of the tensor
void set_layout(const Layout& layout);

//! which will trigger memory alloc in tensor implement //! which will trigger memory alloc in tensor implement
void* get_memory_ptr() const; void* get_memory_ptr() const;


@@ -80,6 +100,13 @@ public:
//! get the tensor capacity in byte //! get the tensor capacity in byte
size_t get_tensor_total_size_in_byte() const; size_t get_tensor_total_size_in_byte() const;


//! whether the memory of tensor is continue
bool is_continue_memory() const;
//@}

//! set layout will change the layout and reallocate memory of the tensor
void set_layout(const Layout& layout);

//! use the user allocated data to reset the memory of the tensor, the //! use the user allocated data to reset the memory of the tensor, the
//! memory will not be managed by the lite, later, the user should delete //! memory will not be managed by the lite, later, the user should delete
//! it. //! it.
@@ -102,7 +129,7 @@ public:
void fill_zero(); void fill_zero();


//! copy tensor form other tensor //! copy tensor form other tensor
//! Note: the best way for tensor copy is just set the dst device, left
//! @note the best way for tensor copy is just set the dst device, left
//! layout empty, when copying the dst layout will be set the same with //! layout empty, when copying the dst layout will be set the same with
//! src //! src
void copy_from(const Tensor& src); void copy_from(const Tensor& src);
@@ -110,9 +137,6 @@ public:
//! share memory with other tensor //! share memory with other tensor
void share_memory_with(const Tensor& src_tensor); void share_memory_with(const Tensor& src_tensor);


//! whether the memory of tensor is continue
bool is_continue_memory() const;

//! update the menbers from the implement //! update the menbers from the implement
void update_from_implement(); void update_from_implement();




Loading…
Cancel
Save