From 754dba26747fdd0f29830d041e7c29ffa9dd3e86 Mon Sep 17 00:00:00 2001 From: Dmitri Smirnov Date: Thu, 15 Aug 2024 16:16:54 -0700 Subject: [PATCH] Change to std::fill (#21759) ### 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: https://github.com/microsoft/onnxruntime/pull/21525 Cc: @ranjitshs --- onnxruntime/core/providers/cpu/math/matmul.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/onnxruntime/core/providers/cpu/math/matmul.cc b/onnxruntime/core/providers/cpu/math/matmul.cc index 16bb1ddfce407..e95ac44af158b 100644 --- a/onnxruntime/core/providers/cpu/math/matmul.cc +++ b/onnxruntime/core/providers/cpu/math/matmul.cc @@ -106,7 +106,8 @@ Status MatMul::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(); + std::fill(output_span.begin(), output_span.end(), T{}); return Status::OK(); }