From 40e5279f8faf18be0281a66709f328b93054669e Mon Sep 17 00:00:00 2001 From: Nick Kreeger Date: Tue, 6 Jul 2021 19:18:18 -0500 Subject: [PATCH] Drop unused functions from math.h (#8304) * Drop unused functions from math.h * fix dnnl_conv.h --- .../core/providers/dnnl/subgraph/dnnl_conv.h | 6 ++-- onnxruntime/core/util/math.h | 36 ++----------------- 2 files changed, 7 insertions(+), 35 deletions(-) diff --git a/onnxruntime/core/providers/dnnl/subgraph/dnnl_conv.h b/onnxruntime/core/providers/dnnl/subgraph/dnnl_conv.h index bae1251020..e53d7dde4a 100644 --- a/onnxruntime/core/providers/dnnl/subgraph/dnnl_conv.h +++ b/onnxruntime/core/providers/dnnl/subgraph/dnnl_conv.h @@ -40,8 +40,10 @@ Status ComputePadAndOutputShape( *out_dim = (in_dim + pad_needed - dkernel) / stride + 1; // make sure padding is symmetric - if (ForceSymmetricAutoPadding) - pad_needed = math::roundUpPow2(pad_needed); + if (ForceSymmetricAutoPadding) { + // Round up to the next highest multiple of b, which is power-of-2. + pad_needed = (pad_needed + (2 - 1)) & (~(2 - 1)); + } if (pad_type == AutoPadType::SAME_LOWER) { *pad_head = (pad_needed + 1) / 2; diff --git a/onnxruntime/core/util/math.h b/onnxruntime/core/util/math.h index 16e7c477da..9b5543a667 100644 --- a/onnxruntime/core/util/math.h +++ b/onnxruntime/core/util/math.h @@ -349,43 +349,13 @@ constexpr T roundUp(T a, T b) { return divUp(a, b) * b; } -// Returns true if the given integer type is a power-of-2 (positive only) -// Note(jiayq): windows reported an error per -// https://github.com/caffe2/caffe2/issues/997 -// and as a result will make it a macro. -#ifdef _MSC_VER -#define integerIsPowerOf2(v) ((v) && !((v) & ((v)-1))) -#else // _MSC_VER -template -constexpr bool integerIsPowerOf2(T v) { - return (v && !(v & (v - 1))); -} -#endif // _MSC_VER - -// Returns log2(n) for a positive integer type -template -constexpr int integerLog2(T n, int p = 0) { - return (n <= 1) ? p : integerLog2(n / 2, p + 1); -} - -// Returns the next highest power-of-2 for an integer type -template -constexpr T integerNextHighestPowerOf2(T v) { - return (integerIsPowerOf2(v) ? (T)2 * v : ((T)1 << (integerLog2(v) + 1))); -} - -// Rounds a up to the next highest multiple of b, which is power-of-2. User must be careful -// to ensure that there is no overflow or underflow in the calculation -// of divUp. -template -constexpr T roundUpPow2(T a) { - return (a + (b - 1)) & (~(b - 1)); -} - +// Converts a float32 to a float16 value. uint16_t floatToHalf(float f); +// Converts a double (float64) to a float16 value. uint16_t doubleToHalf(double f); +// Converts a float16 to a float32 value. float halfToFloat(uint16_t h); } // namespace math