From 9e75ebf0dc77b65eb7729f14638a5df62d6c2e7d Mon Sep 17 00:00:00 2001 From: cristei <51248378+cristeigabriel@users.noreply.github.com> Date: Mon, 29 Nov 2021 18:32:16 +0200 Subject: [PATCH] Remove redundant inline specifiers, sync server IsLittleEndianOrder with runtime core (#9856) * Remove redundant inline * Make server IsLittleEndianOrder represent runtime core endianness implementation, make the endianness check constexpr --- .../test/fuzzing/include/BetaDistribution.h | 2 +- server/serializing/tensorprotoutils.cc | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/onnxruntime/test/fuzzing/include/BetaDistribution.h b/onnxruntime/test/fuzzing/include/BetaDistribution.h index 221ac3e176..5818d01d45 100644 --- a/onnxruntime/test/fuzzing/include/BetaDistribution.h +++ b/onnxruntime/test/fuzzing/include/BetaDistribution.h @@ -118,7 +118,7 @@ private: // A constant value used for internal computation. // - constexpr inline double sqrtpi() + constexpr double sqrtpi() { return std::sqrt( std::atan(1)*4 ); } diff --git a/server/serializing/tensorprotoutils.cc b/server/serializing/tensorprotoutils.cc index ee6d6abf7f..145e483d2c 100644 --- a/server/serializing/tensorprotoutils.cc +++ b/server/serializing/tensorprotoutils.cc @@ -47,16 +47,16 @@ inline std::string MakeString(const char* p_str) { namespace server { -#ifdef __GNUC__ -constexpr inline bool IsLittleEndianOrder() noexcept { return __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__; } +constexpr bool IsLittleEndianOrder() noexcept { +#if defined(_WIN32) + return true; +#elif defined(__GNUC__) || defined(__clang__) + return __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__; #else -// On Windows and Mac, this function should always return true -GSL_SUPPRESS(type .1) // allow use of reinterpret_cast for this special case -inline bool IsLittleEndianOrder() noexcept { - static int n = 1; - return (*reinterpret_cast(&n) == 1); -} +#error server::IsLittleEndianOrder() is not implemented in this environment. #endif +} + std::vector GetTensorShapeFromTensorProto(const onnx::TensorProto& tensor_proto) { const auto& dims = tensor_proto.dims(); std::vector tensor_shape_vec(static_cast(dims.size())); @@ -107,7 +107,7 @@ static void UnpackTensorWithRawData(const void* raw_data, size_t raw_data_length throw Ort::Exception(MakeString("UnpackTensor: the pre-allocated size does not match the raw data size, expected ", expected_size_in_bytes, ", got ", raw_data_length), OrtErrorCode::ORT_FAIL); - if (IsLittleEndianOrder()) { + if constexpr (IsLittleEndianOrder()) { memcpy(p_data, raw_data, raw_data_length); } else { const size_t type_size = sizeof(T);