|
|
@ -54,26 +54,24 @@ class Tensor {
|
|
|
|
|
|
|
|
|
|
|
|
/*! Return a pointer to mutable memory block. */
|
|
|
|
/*! Return a pointer to mutable memory block. */
|
|
|
|
template <typename T>
|
|
|
|
template <typename T>
|
|
|
|
inline T* data();
|
|
|
|
T* data();
|
|
|
|
|
|
|
|
|
|
|
|
/*! Return a pointer to constant memory block. */
|
|
|
|
/*! Return a pointer to constant memory block. */
|
|
|
|
template <typename T>
|
|
|
|
template <typename T>
|
|
|
|
inline const T* data() const;
|
|
|
|
const T* data() const;
|
|
|
|
|
|
|
|
|
|
|
|
inline bool IsInitialized() const;
|
|
|
|
bool IsInitialized() const;
|
|
|
|
|
|
|
|
|
|
|
|
inline void switch_place(platform::Place new_place);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @brief Return a pointer to mutable memory block.
|
|
|
|
* @brief Return a pointer to mutable memory block.
|
|
|
|
* @note If not exist, then allocation.
|
|
|
|
* @note If not exist, then allocation.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
template <typename T>
|
|
|
|
template <typename T>
|
|
|
|
inline T* mutable_data(platform::Place place);
|
|
|
|
T* mutable_data(platform::Place place);
|
|
|
|
|
|
|
|
|
|
|
|
inline void* mutable_data(platform::Place place, std::type_index type);
|
|
|
|
void* mutable_data(platform::Place place, std::type_index type);
|
|
|
|
|
|
|
|
|
|
|
|
inline void* mutable_data(platform::Place place);
|
|
|
|
void* mutable_data(platform::Place place);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @brief Return a pointer to mutable memory block.
|
|
|
|
* @brief Return a pointer to mutable memory block.
|
|
|
@ -84,19 +82,19 @@ class Tensor {
|
|
|
|
* @note If not exist, then allocation.
|
|
|
|
* @note If not exist, then allocation.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
template <typename T>
|
|
|
|
template <typename T>
|
|
|
|
inline T* mutable_data(DDim dims, platform::Place place);
|
|
|
|
T* mutable_data(DDim dims, platform::Place place);
|
|
|
|
|
|
|
|
|
|
|
|
/*! Return the dimensions of the memory block. */
|
|
|
|
/*! Return the dimensions of the memory block. */
|
|
|
|
inline const DDim& dims() const;
|
|
|
|
const DDim& dims() const;
|
|
|
|
|
|
|
|
|
|
|
|
/*! Return the numel of the memory block. */
|
|
|
|
/*! Return the numel of the memory block. */
|
|
|
|
inline int64_t numel() const;
|
|
|
|
int64_t numel() const;
|
|
|
|
|
|
|
|
|
|
|
|
/*! Resize the dimensions of the memory block. */
|
|
|
|
/*! Resize the dimensions of the memory block. */
|
|
|
|
inline Tensor& Resize(const DDim& dims);
|
|
|
|
Tensor& Resize(const DDim& dims);
|
|
|
|
|
|
|
|
|
|
|
|
/*! The internal of two tensors share the same memory block. */
|
|
|
|
/*! The internal of two tensors share the same memory block. */
|
|
|
|
inline Tensor& ShareDataWith(const Tensor& src);
|
|
|
|
Tensor& ShareDataWith(const Tensor& src);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @brief Return a sub-tensor of the given tensor.
|
|
|
|
* @brief Return a sub-tensor of the given tensor.
|
|
|
@ -106,7 +104,7 @@ class Tensor {
|
|
|
|
* @param[in] end_idx The index of the end row(exclusive) to slice.
|
|
|
|
* @param[in] end_idx The index of the end row(exclusive) to slice.
|
|
|
|
* The index number begins from 0.
|
|
|
|
* The index number begins from 0.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
inline Tensor Slice(int begin_idx, int end_idx) const;
|
|
|
|
Tensor Slice(int begin_idx, int end_idx) const;
|
|
|
|
|
|
|
|
|
|
|
|
platform::Place place() const {
|
|
|
|
platform::Place place() const {
|
|
|
|
PADDLE_ENFORCE_NOT_NULL(
|
|
|
|
PADDLE_ENFORCE_NOT_NULL(
|
|
|
@ -123,11 +121,11 @@ class Tensor {
|
|
|
|
// memory size returns the holding memory size in byte.
|
|
|
|
// memory size returns the holding memory size in byte.
|
|
|
|
size_t memory_size() const;
|
|
|
|
size_t memory_size() const;
|
|
|
|
|
|
|
|
|
|
|
|
inline void check_memory_size() const;
|
|
|
|
void check_memory_size() const;
|
|
|
|
|
|
|
|
|
|
|
|
inline DataLayout layout() const { return layout_; }
|
|
|
|
DataLayout layout() const { return layout_; }
|
|
|
|
|
|
|
|
|
|
|
|
inline void set_layout(const DataLayout layout) { layout_ = layout; }
|
|
|
|
void set_layout(const DataLayout layout) { layout_ = layout; }
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
private:
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -210,15 +208,6 @@ class Tensor {
|
|
|
|
size_t offset_;
|
|
|
|
size_t offset_;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
inline void Tensor::switch_place(platform::Place new_place) {
|
|
|
|
|
|
|
|
if (holder_->place() == new_place) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO(tonyyang-svail): do memcpy here.
|
|
|
|
|
|
|
|
PADDLE_THROW("Not Implemented");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace framework
|
|
|
|
} // namespace framework
|
|
|
|
} // namespace paddle
|
|
|
|
} // namespace paddle
|
|
|
|
|
|
|
|
|
|
|
|