Skip to content

Commit

Permalink
Change to std::fill (#21759)
Browse files Browse the repository at this point in the history
### Description
Replace `memset(0)` with `std::fill(T{})`. This would ensure that all
the types are initialized in a portable way.

### Motivation and Context
Some platforms exhibit intermittent failures with NaN results.
Follow up to: #21525

Cc: @ranjitshs
  • Loading branch information
yuslepukhin authored Aug 15, 2024
1 parent b9f3a5d commit 754dba2
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion onnxruntime/core/providers/cpu/math/matmul.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ Status MatMul<T>::Compute(OpKernelContext* ctx) const {
if (helper.K() == 0) {
// When we have (M, 0, N) then the inputs are empty, but the output should
// be filled out with zeros.
memset(y->MutableDataRaw(), 0, y->SizeInBytes());
auto output_span = y->MutableDataAsSpan<T>();
std::fill(output_span.begin(), output_span.end(), T{});
return Status::OK();
}

Expand Down

0 comments on commit 754dba2

Please sign in to comment.