提交 669a6634 编写于 作者: H hjchen2

update

上级 d8d866dd
...@@ -67,6 +67,15 @@ class Tensor : public TensorBase { ...@@ -67,6 +67,15 @@ class Tensor : public TensorBase {
/*! 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) { inline Tensor &ShareDataWith(const Tensor &src) {
src.check_memory_size();
if (holder_.get() != src.holder_.get()) {
*this = src;
}
return *this;
}
/*! The internal of two tensors share the same memory block. */
inline Tensor &ShareHolderWith(const Tensor &src) {
src.check_memory_size(); src.check_memory_size();
if (holder_.get() != src.holder_.get()) { if (holder_.get() != src.holder_.get()) {
holder_ = src.holder_; holder_ = src.holder_;
......
...@@ -131,7 +131,7 @@ void MemoryOptPass::operator()(const framework::ProgramDesc *program, ...@@ -131,7 +131,7 @@ void MemoryOptPass::operator()(const framework::ProgramDesc *program,
DLOG << node->name; DLOG << node->name;
auto *var = scope->Var(node->name); auto *var = scope->Var(node->name);
auto *tensor = var->template GetMutable<framework::LoDTensor>(); auto *tensor = var->template GetMutable<framework::LoDTensor>();
tensor->ShareDataWith(*reuse_tensor); tensor->ShareHolderWith(*reuse_tensor);
} }
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册