Minor change to improve performance for operator Pad. (#5537)

* small improvment for pad
This commit is contained in:
Xavier Dupré 2020-12-28 12:52:41 +01:00 committed by GitHub
parent 7ccdfed1a6
commit 8a0f5c50ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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 <typename T>
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) {