未验证 提交 708c4f88 编写于 作者: W Weilong Wu 提交者: GitHub

[Eager, Performance Optimization] modify AllocateFrom to reduce deconstruction...

[Eager, Performance Optimization] modify AllocateFrom to reduce deconstruction of shared_ptr (#48548)
上级 d1e93be1
......@@ -128,7 +128,16 @@ void* DenseTensor::AllocateFrom(Allocator* allocator,
if (!holder_ || holder_->size() < bytes + meta_.offset) {
meta_.offset = 0;
VLOG(10) << "Allocate data with bytes: " << bytes;
ResetHolder(allocator->Allocate(bytes));
auto holder = allocator->Allocate(bytes);
if (holder_) {
PADDLE_ENFORCE_LE(
numel() * static_cast<int64_t>(SizeOf(dtype)) +
static_cast<int64_t>(meta_.offset),
static_cast<int64_t>(holder->size()),
phi::errors::InvalidArgument(
"The size of Holder is not enough to store the Tensor."));
}
holder_ = std::move(holder);
}
return reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(holder_->ptr()) +
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册