fix buffer overuse in addtofeed() (#13733)

### Description
<!-- Describe your changes. -->



### Motivation and Context
<!-- - Why is this change required? What problem does it solve?
- If it fixes an open issue, please link to the issue here. -->
This commit is contained in:
Ye Wang 2022-11-23 10:53:53 -08:00 committed by GitHub
parent e306b44e98
commit c1bda4c1cc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -99,7 +99,7 @@ Status AddToFeeds(const IExecutionProvider* execution_provider,
size_t total_bytes = 0;
for (auto& input : inputs) {
if (input.IsAllocated()) {
total_bytes += input.Get<Tensor>().Shape().Size() * input.Type()->Size();
total_bytes += input.Get<Tensor>().SizeInBytes();
}
}
@ -115,7 +115,7 @@ Status AddToFeeds(const IExecutionProvider* execution_provider,
for (auto& input : inputs) {
if (input.IsAllocated()) {
const Tensor& tensor = input.Get<Tensor>();
const size_t bytes = input.Type()->Size() * tensor.Shape().Size();
const size_t bytes = tensor.SizeInBytes();
MLDataType dataType = tensor.DataType();
if (dataType == DataTypeImpl::GetType<int32_t>()) {
memcpy(destination, input.Get<Tensor>().Data<int32_t>(), bytes);
@ -152,7 +152,7 @@ Status AddToFeeds(const IExecutionProvider* execution_provider,
if (input.IsAllocated()) {
const Tensor& tensor = input.Get<Tensor>();
const TensorShape& shape = tensor.Shape();
const size_t bytes = input.Type()->Size() * shape.Size();
const size_t bytes = tensor.SizeInBytes();
MLDataType dataType = tensor.DataType();
OrtValue device_input;