未验证 提交 9ff989ae 编写于 作者: 石晓伟 提交者: GitHub

remove interface: DenseTensor::release, test=develop (#38937)

上级 158bf13f
...@@ -189,7 +189,7 @@ static PyObject* eager_tensor__clear_gradient(EagerTensorObject* self, ...@@ -189,7 +189,7 @@ static PyObject* eager_tensor__clear_gradient(EagerTensorObject* self,
<< " is initialized, will be released."; << " is initialized, will be released.";
auto dense_tensor = auto dense_tensor =
std::dynamic_pointer_cast<pten::DenseTensor>(grad->impl()); std::dynamic_pointer_cast<pten::DenseTensor>(grad->impl());
dense_tensor->release(); dense_tensor->MoveMemoryHolder();
} }
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
......
...@@ -306,10 +306,8 @@ void MovesStorage(pten::DenseTensor* src, paddle::framework::Tensor* dst) { ...@@ -306,10 +306,8 @@ void MovesStorage(pten::DenseTensor* src, paddle::framework::Tensor* dst) {
"The destination Tensor is nullptr when move storage.")); "The destination Tensor is nullptr when move storage."));
dst->Resize(src->dims()); dst->Resize(src->dims());
dst->set_type(pten::TransToProtoVarType(src->dtype())); dst->set_type(pten::TransToProtoVarType(src->dtype()));
auto storage = src->release(); auto storage = src->MoveMemoryHolder();
std::shared_ptr<pten::Allocation> holder( dst->ResetHolderWithType(storage, pten::TransToProtoVarType(src->dtype()));
new TensorStorage(std::move(storage)));
dst->ResetHolderWithType(holder, pten::TransToProtoVarType(src->dtype()));
dst->set_offset(src->meta().offset); dst->set_offset(src->meta().offset);
} }
......
...@@ -172,12 +172,6 @@ class DenseTensor : public TensorBase, ...@@ -172,12 +172,6 @@ class DenseTensor : public TensorBase,
/// \return The actual storage size occupied by tensor. /// \return The actual storage size occupied by tensor.
size_t capacity() const { return storage_->size(); } size_t capacity() const { return storage_->size(); }
/// \brief Release the storage area for other purposes. Because of the
/// destruction of encapsulation, we do not support two dense tensors directly
/// sharing the same intrusive pointer.
/// \return The rvalue of instrusize pointer releated to the released storage.
intrusive_ptr<Storage> release() { return std::move(storage_); }
/// \brief Get the mutable data pointer value of type T. /// \brief Get the mutable data pointer value of type T.
/// Memory allocation may occur when calling this interface: /// Memory allocation may occur when calling this interface:
/// 1. When the storage size is not enough to meet the current shape of the /// 1. When the storage size is not enough to meet the current shape of the
......
...@@ -116,9 +116,6 @@ TEST(dense_tensor, resize) { ...@@ -116,9 +116,6 @@ TEST(dense_tensor, resize) {
CHECK_EQ(tensor_0.capacity(), 6u); CHECK_EQ(tensor_0.capacity(), 6u);
tensor_0.mutable_data<int8_t>(); tensor_0.mutable_data<int8_t>();
CHECK_EQ(tensor_0.capacity(), 6u); CHECK_EQ(tensor_0.capacity(), 6u);
auto storage = tensor_0.release();
CHECK_EQ(storage->size(), 6u);
} }
TEST(dense_tensor, shallow_copy) { TEST(dense_tensor, shallow_copy) {
...@@ -133,10 +130,6 @@ TEST(dense_tensor, shallow_copy) { ...@@ -133,10 +130,6 @@ TEST(dense_tensor, shallow_copy) {
DenseTensor tensor_1(tensor_0); DenseTensor tensor_1(tensor_0);
CHECK(tensor_0.meta() == tensor_1.meta()); CHECK(tensor_0.meta() == tensor_1.meta());
// Copy constructor: Now shares the underlying shared_ptr<Allocation> instead
// of Storage
CHECK(tensor_0.release() != tensor_1.release());
} }
} // namespace tests } // namespace tests
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册