From 0c3657adab1114a742fd0e3d87dfb15f1efc53c3 Mon Sep 17 00:00:00 2001 From: zyfncg Date: Tue, 25 Jan 2022 10:23:47 +0800 Subject: [PATCH] fix the bug of SetAllocationForOutputTenosr (#39174) --- paddle/pten/core/dense_tensor.cc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/paddle/pten/core/dense_tensor.cc b/paddle/pten/core/dense_tensor.cc index b1a5015f01..7fb532e00f 100644 --- a/paddle/pten/core/dense_tensor.cc +++ b/paddle/pten/core/dense_tensor.cc @@ -231,9 +231,14 @@ void DenseTensor::ResetHolder(const std::shared_ptr& holder) { "Only the offset is supported to zero when the holder is reset.")); if (holder_) { + // TODO(zyfncg): The change of static_cast<> in check will recover back + // when SetAllocationForOutputTenosr is deleted. + // Now the numel() may return -1, and will cast to a very large number when + // compare with a data with unsigned long type, this will make checking + // failed, so it's a temporary solution to deal with this problem. PADDLE_ENFORCE_LE( - numel() * SizeOf(dtype()) + meta_.offset, - holder->size(), + numel() * static_cast(SizeOf(dtype())), + static_cast(holder->size()), paddle::platform::errors::InvalidArgument( "The size of Holder is not enough to store the Tensor.")); } -- GitLab