From f4b47ad9f693ea86909dd820bed8ba68aeabaafa Mon Sep 17 00:00:00 2001 From: Scott McKay Date: Mon, 1 Apr 2019 15:19:21 +1000 Subject: [PATCH] Move call to log and fmaxf outside of inner loop. (#745) --- onnxruntime/core/providers/cpu/math/softmax_shared.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/onnxruntime/core/providers/cpu/math/softmax_shared.cc b/onnxruntime/core/providers/cpu/math/softmax_shared.cc index 32df249f36..8ee6ec79c2 100644 --- a/onnxruntime/core/providers/cpu/math/softmax_shared.cc +++ b/onnxruntime/core/providers/cpu/math/softmax_shared.cc @@ -79,8 +79,9 @@ common::Status SoftmaxCPU(const int64_t N, } } else { for (int i = 0; i < N; ++i) { + auto log_fmaxf_scale_i = log(fmaxf(scale[i], 1e-20f)); for (int j = 0; j < D; ++j) { - Ydata[i * D + j] = Xdata[i * D + j] - rowmax[i] - log(fmaxf(scale[i], 1e-20f)); + Ydata[i * D + j] = Xdata[i * D + j] - rowmax[i] - log_fmaxf_scale_i; } } }