From 8a0f5c50abba92175912fcda813512d8d7386499 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xavier=20Dupr=C3=A9?= Date: Mon, 28 Dec 2020 12:52:41 +0100 Subject: [PATCH] Minor change to improve performance for operator Pad. (#5537) * small improvment for pad --- onnxruntime/core/providers/cpu/tensor/pad.cc | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/onnxruntime/core/providers/cpu/tensor/pad.cc b/onnxruntime/core/providers/cpu/tensor/pad.cc index 51e1ebfe27..a5ae7d0632 100644 --- a/onnxruntime/core/providers/cpu/tensor/pad.cc +++ b/onnxruntime/core/providers/cpu/tensor/pad.cc @@ -97,8 +97,18 @@ static void PadInnermostAxis(T* output, T* input, ptrdiff_t input_delta, size_t // For constant padding, there is no input, just a size to write the constant to template static void PadAxisConstant(T* output, T constant, size_t size) { - for (size_t i = 0; i < size; i++) - *output++ = constant; + if (size == 1) { + *output = constant; + } else if (size == 2) { + *output = constant; + *(output + 1) = constant; + } else { + // This would be faster with SSE instructions. + // That would mean to have an implementation for each type (uint8, uint32, uint64). + T* end = output + size; + for (; output != end;) + *output++ = constant; + } } Status PadBase::HandleDimValueZero(const Mode& mode, const TensorShape& input_shape, TensorShape& output_shape) {