diff --git a/paddle/fluid/framework/lod_tensor_array.h b/paddle/fluid/framework/lod_tensor_array.h index 0ad6a709008406257d6c0a220bce38bb24e188cd..36a5c3c5d601390beedaf37ceb98ee2c63ecf5a6 100644 --- a/paddle/fluid/framework/lod_tensor_array.h +++ b/paddle/fluid/framework/lod_tensor_array.h @@ -19,81 +19,7 @@ limitations under the License. */ namespace paddle { namespace framework { -// NOTE The vector can't be replaced with the class LoDTensorArray -// directly, because there are many vector used accross the project, -// and some of them are treated as LoDTensorArray. -#if !defined(PADDLE_ON_INFERENCE) - using LoDTensorArray = std::vector; -#else // !PADDLE_ON_INFERENCE - -#pragma message "LoDTensorArray is replaced with the inference one." -/* - * A LoDTensorArray which will not deallocate buffer when resized, fix the data - * diff in inference, and more performance friendly in the concurrency - * scenerios. - */ -class LoDTensorArray { - public: - LoDTensorArray() = default; - - using iterator = std::vector::iterator; - using const_iterator = std::vector::const_iterator; - - const_iterator begin() const { return array_.begin(); } - const_iterator end() const { return array_.begin() + size_; } - iterator begin() { return array_.begin(); } - iterator end() { return array_.begin() + size_; } - - void push_back(const LoDTensor& x) { - if (size_ < array_.size()) { - array_[size_++] = x; - } else { - array_.push_back(x); - ++size_; - } - } - void resize(size_t size) { - if (array_.size() < size) { - array_.resize(size); - } - size_ = size; - } - - void emplace_back() { array_.emplace_back(); } - - void emplace_back(LoDTensor&& x) { array_.emplace_back(std::move(x)); } - - LoDTensor& back() { return array_.back(); } - - size_t space() const { return array_.size(); } - - void reserve(size_t size) { - // Naive warning to tell user this array might be to large. The memory and - // buffer used by this TensorArray will not be deleted during the training - // and inference phase, so attention not to make it expand too long. - if (size > 800UL) { - LOG(WARNING) << "TensorArray has more than 800 items"; - } - array_.reserve(size); - } - - bool empty() const { return size_ == 0UL; } - void clear() { size_ = 0UL; } - - LoDTensor& operator[](size_t id) { return array_[id]; } - const LoDTensor& operator[](size_t id) const { return array_[id]; } - LoDTensor& at(size_t id) { return array_.at(id); } - const LoDTensor& at(size_t id) const { return array_.at(id); } - - size_t size() const { return size_; } - - private: - size_t size_{0}; - std::vector array_; -}; -#endif // !PADDLE_ON_INFERENCE - } // namespace framework } // namespace paddle