未验证 提交 c719add7 编写于 作者: L Leo Chen 提交者: GitHub

reduce calls to SizeOfType (#36110)

上级 eef0a943
...@@ -29,14 +29,16 @@ void Tensor::check_memory_size() const { ...@@ -29,14 +29,16 @@ void Tensor::check_memory_size() const {
PADDLE_ENFORCE_NOT_NULL(holder_, platform::errors::PreconditionNotMet( PADDLE_ENFORCE_NOT_NULL(holder_, platform::errors::PreconditionNotMet(
"Tensor holds no memory. " "Tensor holds no memory. "
"Call Tensor::mutable_data firstly.")); "Call Tensor::mutable_data firstly."));
size_t size = numel() * SizeOfType(type());
PADDLE_ENFORCE_LE( PADDLE_ENFORCE_LE(
numel() * SizeOfType(type()), memory_size(), size, memory_size(),
platform::errors::PreconditionNotMet( platform::errors::PreconditionNotMet(
"Tensor's dimension is out of bound." "Tensor's dimension is out of bound."
"Tensor's dimension must be equal or less than the size of its " "Tensor's dimension must be equal or less than the size of its "
"memory." "memory."
"But received Tensor's dimension is d%, memory's size is %d.", "But received Tensor's dimension is d%, memory's size is %d.",
numel() * SizeOfType(type()), memory_size())); size, memory_size()));
} }
Tensor::Tensor(const proto::VarType::Type& dtype) Tensor::Tensor(const proto::VarType::Type& dtype)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册