From e0a0f385bb10b5a0c98a8dfe52921de64f0bee51 Mon Sep 17 00:00:00 2001 From: Changming Sun Date: Tue, 14 Dec 2021 14:41:11 -0800 Subject: [PATCH] Fix some warnings in mlas (#10034) --- onnxruntime/core/mlas/lib/convolve.cpp | 8 +++++- onnxruntime/core/mlas/lib/dgemm.cpp | 9 +++++-- .../mlas/lib/intrinsics/avx2/qladd_avx2.cpp | 2 +- onnxruntime/core/mlas/lib/mlasi.h | 9 ++++++- onnxruntime/core/mlas/lib/pooling.cpp | 10 +++---- onnxruntime/core/mlas/lib/qgemm.cpp | 10 +++++-- onnxruntime/core/mlas/lib/qgemm.h | 4 +-- .../core/mlas/lib/qgemm_kernel_avx2.cpp | 2 +- .../core/mlas/lib/qgemm_kernel_default.cpp | 2 +- .../core/mlas/lib/qgemm_kernel_sse.cpp | 2 +- onnxruntime/core/mlas/lib/qlgavgpool.cpp | 27 ++++++++++++------- onnxruntime/core/mlas/lib/sgemm.cpp | 8 +++++- 12 files changed, 66 insertions(+), 27 deletions(-) diff --git a/onnxruntime/core/mlas/lib/convolve.cpp b/onnxruntime/core/mlas/lib/convolve.cpp index bc4f05dda4..78eceda4fc 100644 --- a/onnxruntime/core/mlas/lib/convolve.cpp +++ b/onnxruntime/core/mlas/lib/convolve.cpp @@ -1016,7 +1016,10 @@ Return Value: } } } - +#if defined(_MSC_VER) && !defined(__clang__) +#pragma warning(push) +#pragma warning(disable : 26451) +#endif void MLASCALL MlasConvPrepare( @@ -1289,3 +1292,6 @@ Return Value: *WorkingBufferSize = TargetThreadCount * MLAS_CONV_WORKING_BUFFER_SIZE_PER_THREAD; } } +#if defined(_MSC_VER) && !defined(__clang__) +#pragma warning(pop) +#endif \ No newline at end of file diff --git a/onnxruntime/core/mlas/lib/dgemm.cpp b/onnxruntime/core/mlas/lib/dgemm.cpp index c1d20dfba4..3688699843 100644 --- a/onnxruntime/core/mlas/lib/dgemm.cpp +++ b/onnxruntime/core/mlas/lib/dgemm.cpp @@ -803,7 +803,10 @@ Return Value: Data->alpha, A, lda, B, ldb, Data->beta, C, ldc); } - +#if defined(_MSC_VER) && !defined(__clang__) +#pragma warning(push) +#pragma warning(disable : 26451) +#endif void MLASCALL MlasGemmBatch( @@ -880,5 +883,7 @@ MlasGemmBatch( }); } - +#if defined(_MSC_VER) && !defined(__clang__) +#pragma warning(pop) +#endif #endif diff --git a/onnxruntime/core/mlas/lib/intrinsics/avx2/qladd_avx2.cpp b/onnxruntime/core/mlas/lib/intrinsics/avx2/qladd_avx2.cpp index 30e09e7a4a..8fbee04659 100644 --- a/onnxruntime/core/mlas/lib/intrinsics/avx2/qladd_avx2.cpp +++ b/onnxruntime/core/mlas/lib/intrinsics/avx2/qladd_avx2.cpp @@ -185,7 +185,7 @@ MlasQLinearAddKernelAvx2Helper( if (k > 0) { const __m256i mask = _mm256_cmpgt_epi32(_mm256_set1_epi32(k), _mm256_set_epi32(7, 6, 5, 4, 3, 2, 1, 0)); _mm256_maskstore_epi32((int*)OutputC, mask, vc); - OutputC += k * 4; + OutputC += static_cast(k) * 4; } int r = static_cast(n % 4); diff --git a/onnxruntime/core/mlas/lib/mlasi.h b/onnxruntime/core/mlas/lib/mlasi.h index 6e0bd775c9..e3f224503c 100644 --- a/onnxruntime/core/mlas/lib/mlasi.h +++ b/onnxruntime/core/mlas/lib/mlasi.h @@ -933,6 +933,11 @@ MlasPartitionWork( // // Helpers to cast a floating point type to and from an integer bit format. // +#if defined(_MSC_VER) && !defined(__clang__) + #pragma warning(push) + // VC++ suggests we can attempt to make 'MlasBitsOfFp32' constexpr, but it is not valid. + #pragma warning(disable:26497) +#endif MLAS_FORCEINLINE uint32_t @@ -961,7 +966,9 @@ MlasFp32FromBits( u.IntegerValue = IntegerValue; return u.FloatValue; } - +#if defined(_MSC_VER) && !defined(__clang__) +#pragma warning(pop) +#endif #if defined(MLAS_TARGET_WASM_SCALAR) diff --git a/onnxruntime/core/mlas/lib/pooling.cpp b/onnxruntime/core/mlas/lib/pooling.cpp index de56a3a42e..5abe594685 100644 --- a/onnxruntime/core/mlas/lib/pooling.cpp +++ b/onnxruntime/core/mlas/lib/pooling.cpp @@ -66,7 +66,7 @@ void struct MLAS_MAXIMUM_POOLING { - static float InitialValue() + static constexpr float InitialValue() { return std::numeric_limits::lowest(); } @@ -76,7 +76,7 @@ struct MLAS_MAXIMUM_POOLING return MlasBroadcastFloat32x4(InitialValue()); } - static float Reduce(float Reduction, float Value) + static constexpr float Reduce(float Reduction, float Value) { return std::max(Reduction, Value); } @@ -91,7 +91,7 @@ struct MLAS_MAXIMUM_POOLING return MlasReduceMaximumFloat32x4(Reduction); } - static float AveragePool(float Reduction, float Size) + static constexpr float AveragePool(float Reduction, float Size) { MLAS_UNREFERENCED_PARAMETER(Size); @@ -147,7 +147,7 @@ struct MLAS_AVERAGE_POOLING return MlasZeroFloat32x4(); } - static float Reduce(float Reduction, float Value) + static constexpr float Reduce(float Reduction, float Value) { return Reduction + Value; } @@ -162,7 +162,7 @@ struct MLAS_AVERAGE_POOLING return MlasReduceAddFloat32x4(Reduction); } - static float AveragePool(float Reduction, float Size) + static constexpr float AveragePool(float Reduction, float Size) { return Reduction / Size; } diff --git a/onnxruntime/core/mlas/lib/qgemm.cpp b/onnxruntime/core/mlas/lib/qgemm.cpp index c53a468ce0..1a4c1c3f62 100644 --- a/onnxruntime/core/mlas/lib/qgemm.cpp +++ b/onnxruntime/core/mlas/lib/qgemm.cpp @@ -139,7 +139,11 @@ Return Value: { MlasGemmBatch(Shape, &DataParams, 1, ThreadPool); } - +#if defined(_MSC_VER) && !defined(__clang__) +#pragma warning(push) +// VC++ suggests we can attempt to make 'MlasBitsOfFp32' constexpr, but it is not valid. +#pragma warning(disable : 26451) +#endif void MLASCALL MlasGemmBatch( @@ -216,7 +220,9 @@ MlasGemmBatch( MlasGemmQuantThreaded(&WorkBlock, &Shape, &DataParams[gemm_i], blk_i); }); } - +#if defined(_MSC_VER) && !defined(__clang__) +#pragma warning(pop) +#endif size_t MLASCALL diff --git a/onnxruntime/core/mlas/lib/qgemm.h b/onnxruntime/core/mlas/lib/qgemm.h index 13781bcff7..c4d3532d2a 100644 --- a/onnxruntime/core/mlas/lib/qgemm.h +++ b/onnxruntime/core/mlas/lib/qgemm.h @@ -73,7 +73,7 @@ MlasGemmQuantTryGemvKernel( } template -MLAS_FORCEINLINE +MLAS_FORCEINLINE constexpr int32_t MlasGemmQuantFixupZeroPointA( int32_t ZeroPointA, @@ -84,7 +84,7 @@ MlasGemmQuantFixupZeroPointA( } template -int32_t +int32_t constexpr MlasGemmQuantFixupZeroPointB( int32_t ZeroPointB, bool BIsSigned diff --git a/onnxruntime/core/mlas/lib/qgemm_kernel_avx2.cpp b/onnxruntime/core/mlas/lib/qgemm_kernel_avx2.cpp index bbb64a683b..d9451b878d 100644 --- a/onnxruntime/core/mlas/lib/qgemm_kernel_avx2.cpp +++ b/onnxruntime/core/mlas/lib/qgemm_kernel_avx2.cpp @@ -115,7 +115,7 @@ MlasGemmQuantTryGemvKernel( } template<> -MLAS_FORCEINLINE +MLAS_FORCEINLINE constexpr int32_t MlasGemmQuantFixupZeroPointB( int32_t ZeroPointB, diff --git a/onnxruntime/core/mlas/lib/qgemm_kernel_default.cpp b/onnxruntime/core/mlas/lib/qgemm_kernel_default.cpp index c394ac8661..c968c2aae5 100644 --- a/onnxruntime/core/mlas/lib/qgemm_kernel_default.cpp +++ b/onnxruntime/core/mlas/lib/qgemm_kernel_default.cpp @@ -34,7 +34,7 @@ constexpr MLAS_GEMM_QUANT_STRIDES MLAS_GEMM_QUANT_KERNEL_DEFAULT::Strides; constexpr MLAS_GEMM_QUANT_STRIDES MLAS_GEMM_QUANT_KERNEL_DEFAULT::PackedStrides; template<> -MLAS_FORCEINLINE +MLAS_FORCEINLINE constexpr int32_t MlasGemmQuantFixupZeroPointA( int32_t ZeroPointA, diff --git a/onnxruntime/core/mlas/lib/qgemm_kernel_sse.cpp b/onnxruntime/core/mlas/lib/qgemm_kernel_sse.cpp index b074a4afcc..a2abb4aa7e 100644 --- a/onnxruntime/core/mlas/lib/qgemm_kernel_sse.cpp +++ b/onnxruntime/core/mlas/lib/qgemm_kernel_sse.cpp @@ -32,7 +32,7 @@ constexpr size_t MLAS_GEMM_U8X8_KERNEL_SSE::PackedK; constexpr MLAS_GEMM_QUANT_STRIDES MLAS_GEMM_U8X8_KERNEL_SSE::Strides; template<> -MLAS_FORCEINLINE +MLAS_FORCEINLINE constexpr int32_t MlasGemmQuantFixupZeroPointB( int32_t ZeroPointB, diff --git a/onnxruntime/core/mlas/lib/qlgavgpool.cpp b/onnxruntime/core/mlas/lib/qlgavgpool.cpp index 860f4e1692..d1c15d315a 100644 --- a/onnxruntime/core/mlas/lib/qlgavgpool.cpp +++ b/onnxruntime/core/mlas/lib/qlgavgpool.cpp @@ -624,28 +624,37 @@ MlasQLinearGlobalAveragePoolNhwcSingleBatch( #if defined(MLAS_TARGET_IX86) switch (ImageSize) { case 1: - i1 = ZeroBuffer; /* fall through */ + i1 = ZeroBuffer; + [[fallthrough]]; case 2: - i2 = ZeroBuffer; /* fall through */ + i2 = ZeroBuffer; + [[fallthrough]]; case 3: - i3 = ZeroBuffer; /* fall through */ + i3 = ZeroBuffer; + [[fallthrough]]; default: break; } #else switch (ImageSize) { case 1: - i1 = ZeroBuffer; /* fall through */ + i1 = ZeroBuffer; + [[fallthrough]]; case 2: - i2 = ZeroBuffer; /* fall through */ + i2 = ZeroBuffer; + [[fallthrough]]; case 3: - i3 = ZeroBuffer; /* fall through */ + i3 = ZeroBuffer; + [[fallthrough]]; case 4: - i4 = ZeroBuffer; /* fall through */ + i4 = ZeroBuffer; + [[fallthrough]]; case 5: - i5 = ZeroBuffer; /* fall through */ + i5 = ZeroBuffer; + [[fallthrough]]; case 6: - i6 = ZeroBuffer; /* fall through */ + i6 = ZeroBuffer; + [[fallthrough]]; default: break; } diff --git a/onnxruntime/core/mlas/lib/sgemm.cpp b/onnxruntime/core/mlas/lib/sgemm.cpp index c3bbc9e48d..0360127ca0 100644 --- a/onnxruntime/core/mlas/lib/sgemm.cpp +++ b/onnxruntime/core/mlas/lib/sgemm.cpp @@ -1552,7 +1552,10 @@ Return Value: DataParams->alpha, A, lda, B, ldb, DataParams->beta, C, ldc); } } - +#if defined(_MSC_VER) && !defined(__clang__) +#pragma warning(push) +#pragma warning(disable : 26451) +#endif void MLASCALL MlasGemmBatch( @@ -1631,6 +1634,9 @@ MlasGemmBatch( TransA, TransB, M, N, K, &(Data[GemmIdx]), ThreadIdx); }); } +#if defined(_MSC_VER) && !defined(__clang__) +#pragma warning(pop) +#endif size_t MLASCALL