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

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

上级 158bf13f
......@@ -189,7 +189,7 @@ static PyObject* eager_tensor__clear_gradient(EagerTensorObject* self,
<< " is initialized, will be released.";
auto dense_tensor =
std::dynamic_pointer_cast<pten::DenseTensor>(grad->impl());
dense_tensor->release();
dense_tensor->MoveMemoryHolder();
}
Py_INCREF(Py_None);
return Py_None;
......
......@@ -306,10 +306,8 @@ void MovesStorage(pten::DenseTensor* src, paddle::framework::Tensor* dst) {
"The destination Tensor is nullptr when move storage."));
dst->Resize(src->dims());
dst->set_type(pten::TransToProtoVarType(src->dtype()));
auto storage = src->release();
std::shared_ptr<pten::Allocation> holder(
new TensorStorage(std::move(storage)));
dst->ResetHolderWithType(holder, pten::TransToProtoVarType(src->dtype()));
auto storage = src->MoveMemoryHolder();
dst->ResetHolderWithType(storage, pten::TransToProtoVarType(src->dtype()));
dst->set_offset(src->meta().offset);
}
......
......@@ -172,12 +172,6 @@ class DenseTensor : public TensorBase,
/// \return The actual storage size occupied by tensor.
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.
/// Memory allocation may occur when calling this interface:
/// 1. When the storage size is not enough to meet the current shape of the
......
......@@ -116,9 +116,6 @@ TEST(dense_tensor, resize) {
CHECK_EQ(tensor_0.capacity(), 6u);
tensor_0.mutable_data<int8_t>();
CHECK_EQ(tensor_0.capacity(), 6u);
auto storage = tensor_0.release();
CHECK_EQ(storage->size(), 6u);
}
TEST(dense_tensor, shallow_copy) {
......@@ -133,10 +130,6 @@ TEST(dense_tensor, shallow_copy) {
DenseTensor tensor_1(tensor_0);
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册