From cbe5992506fad7f37d71f2518223247d422d17db Mon Sep 17 00:00:00 2001 From: Nikolay Bogoychev Date: Mon, 20 Apr 2020 15:48:24 +0100 Subject: Rename and fix interface --- avx2_gemm.h | 2 +- avx512_gemm.h | 2 +- intgemm.cc | 2 +- intgemm.h | 10 +++--- multiply.h | 6 ++-- sse2_gemm.h | 2 +- test/quantize_test.cc | 84 +++++++++++++++++++++++++-------------------------- 7 files changed, 55 insertions(+), 53 deletions(-) diff --git a/avx2_gemm.h b/avx2_gemm.h index 41f705b..68eb37e 100644 --- a/avx2_gemm.h +++ b/avx2_gemm.h @@ -192,7 +192,7 @@ class QuantizeTile8 { // Technically only requires AVX INTGEMM_MAXABSOLUTE(__m256, INTGEMM_AVX2) -INTGEMM_EUCLIDEANNORM(__m256, INTGEMM_AVX2) +INTGEMM_VECTORMEANSTD(__m256, INTGEMM_AVX2) } // namespace diff --git a/avx512_gemm.h b/avx512_gemm.h index 7488ff2..a0087b3 100644 --- a/avx512_gemm.h +++ b/avx512_gemm.h @@ -159,7 +159,7 @@ class QuantizeTile8 { /* Only INTGEMM_AVX512F is necessary but due to GCC 5.4 bug we have to set INTGEMM_AVX512BW */ INTGEMM_MAXABSOLUTE(__m512, INTGEMM_AVX512BW) -INTGEMM_EUCLIDEANNORM(__m512, INTGEMM_AVX512BW) +INTGEMM_VECTORMEANSTD(__m512, INTGEMM_AVX512BW) } // namespace diff --git a/intgemm.cc b/intgemm.cc index c959105..05337c8 100644 --- a/intgemm.cc +++ b/intgemm.cc @@ -40,7 +40,7 @@ const CPUType kCPU = ChooseCPU(CPUType::AVX512VNNI, CPUType::AVX512BW, CPUType:: float (*MaxAbsolute)(const float *begin, const float *end) = ChooseCPU(avx512f::MaxAbsolute, avx512f::MaxAbsolute, avx2::MaxAbsolute, sse2::MaxAbsolute, sse2::MaxAbsolute, Unsupported_MaxAbsolute); -MeanStd (*EuclideanNorm)(const float *begin, const float *end, bool absolute) = ChooseCPU(avx512f::EuclideanNorm, avx512f::EuclideanNorm, avx2::EuclideanNorm, sse2::EuclideanNorm, sse2::EuclideanNorm, sse2::EuclideanNorm); +MeanStd (*VectorMeanStd)(const float *begin, const float *end, bool absolute) = ChooseCPU(avx512f::VectorMeanStd, avx512f::VectorMeanStd, avx2::VectorMeanStd, sse2::VectorMeanStd, sse2::VectorMeanStd, sse2::VectorMeanStd); constexpr const char *const Unsupported_16bit::kName; constexpr const char *const Unsupported_8bit::kName; diff --git a/intgemm.h b/intgemm.h index daf94dd..3bd6af8 100644 --- a/intgemm.h +++ b/intgemm.h @@ -128,7 +128,7 @@ namespace avx512f { static inline float MaxAbsolute(const float * /*begin*/, const float * /*end*/) { throw UnsupportedCPU(); } -static inline MeanStd QuantizerStd(const float * /*begin*/, const float * /*end*/, bool) { +static inline MeanStd EuclideanNorm(const float * /*begin*/, const float * /*end*/, bool) { throw UnsupportedCPU(); } } //namespace @@ -420,10 +420,12 @@ extern const CPUType kCPU; extern float (*MaxAbsolute)(const float *begin, const float *end); // Get a Quantization value that is equant to the mean of the data +N standard deviations. Use 2 by default -extern MeanStd (*EuclideanNorm)(const float *begin, const float *end, bool); +extern MeanStd (*VectorMeanStd)(const float *begin, const float *end, bool); -static inline MeanStd GetQuantizerStd(const float * begin, const float * end, bool absolute=false) { - return EuclideanNorm(begin, end, absolute); +/* Returns the Mean and the Standard deviation of a vector. + * If "absolute" is set to true, it computes the mean and the standard deviation of the absolute values of the vector */ +static inline MeanStd GetVectorMeanStd(const float * begin, const float * end, bool absolute=false) { + return VectorMeanStd(begin, end, absolute); } diff --git a/multiply.h b/multiply.h index 0514bca..9047697 100644 --- a/multiply.h +++ b/multiply.h @@ -665,8 +665,8 @@ target static inline float MaxAbsolute(const float *begin_float, const float *en return ret; \ } \ -#define INTGEMM_EUCLIDEANNORM(Register, target) \ -target static inline MeanStd EuclideanNorm(const float *begin_float, const float *end_float, bool absolute) { \ +#define INTGEMM_VECTORMEANSTD(Register, target) \ +target static inline MeanStd VectorMeanStd(const float *begin_float, const float *end_float, bool absolute) { \ /* Computes the euclidean norm and returns the mean and the standard deviation. Optionally it can be the mean and standard deviation in absolute terms. */ \ assert(end_float > begin_float); \ assert((end_float - begin_float) % (sizeof(Register) / sizeof(float)) == 0); \ @@ -679,7 +679,7 @@ target static inline MeanStd EuclideanNorm(const float *begin_float, const float const Register mask = set1_ps(-0.f); \ for (; begin != end; begin++) { \ Register vec = *begin; \ - vec = andnot_ps(mask, vec); \ + vec = andnot_ps(mask, vec); \ squares = add_ps(squares, mul_ps(vec, vec)); \ sums = add_ps(sums, vec); \ } \ diff --git a/sse2_gemm.h b/sse2_gemm.h index 84b2f27..8b8f1c2 100644 --- a/sse2_gemm.h +++ b/sse2_gemm.h @@ -53,7 +53,7 @@ class QuantizeTile16 { INTGEMM_MAXABSOLUTE(__m128, INTGEMM_SSE2) -INTGEMM_EUCLIDEANNORM(__m128, INTGEMM_SSE2) +INTGEMM_VECTORMEANSTD(__m128, INTGEMM_SSE2) } //namespace // This should be pure INTGEMM_SSE2 (and below). diff --git a/test/quantize_test.cc b/test/quantize_test.cc index 9e99274..d2046f6 100644 --- a/test/quantize_test.cc +++ b/test/quantize_test.cc @@ -30,7 +30,7 @@ void QuantizeRef(const float *input, int8_t *output, float quant_mult, std::size } } -MeanStd EuclideanNorm(AlignedVector& vals, int num_items, bool absolute) { +MeanStd VectorMeanStd(AlignedVector& vals, int num_items, bool absolute) { float normal_sums = 0; float squares_sum = 0; if (absolute) { @@ -47,7 +47,7 @@ MeanStd EuclideanNorm(AlignedVector& vals, int num_items, bool absolute) } template -void testEuclideanNorm(int num_items, bool absolute=false) { +void testVectorMeanStd(int num_items, bool absolute=false) { std::mt19937 gen; std::uniform_real_distribution dist(-1.0f, 1.0f); AlignedVector inputVec(num_items); @@ -56,7 +56,7 @@ void testEuclideanNorm(int num_items, bool absolute=false) { it = dist(gen); } - MeanStd reference = EuclideanNorm(inputVec, num_items, absolute); + MeanStd reference = VectorMeanStd(inputVec, num_items, absolute); MeanStd fast = Backend(inputVec.begin(), inputVec.end(), absolute); float meanDifference = fabs(reference.mean - fast.mean); @@ -132,53 +132,53 @@ TEST_CASE ("Quantize AVX2", "[quantize]") { } #endif -TEST_CASE("QuantizeStd SSSE3", "[EuclideanNorm]") { +TEST_CASE("QuantizeStd SSSE3", "[VectorMeanStd]") { if (kCPU < CPUType::SSSE3) return; - testEuclideanNorm(64); - testEuclideanNorm(64, true); - testEuclideanNorm(256); - testEuclideanNorm(256, true); - testEuclideanNorm(2048); - testEuclideanNorm(2048, true); - testEuclideanNorm(65536); - testEuclideanNorm(65536, true); - testEuclideanNorm(81920); - testEuclideanNorm(81920, true); - testEuclideanNorm(120832); - testEuclideanNorm(120832, true); + testVectorMeanStd(64); + testVectorMeanStd(64, true); + testVectorMeanStd(256); + testVectorMeanStd(256, true); + testVectorMeanStd(2048); + testVectorMeanStd(2048, true); + testVectorMeanStd(65536); + testVectorMeanStd(65536, true); + testVectorMeanStd(81920); + testVectorMeanStd(81920, true); + testVectorMeanStd(120832); + testVectorMeanStd(120832, true); } -TEST_CASE("QuantizeStd AVX2", "[EuclideanNorm]") { +TEST_CASE("QuantizeStd AVX2", "[VectorMeanStd]") { if (kCPU < CPUType::AVX2) return; - testEuclideanNorm(64); - testEuclideanNorm(64, true); - testEuclideanNorm(256); - testEuclideanNorm(256, true); - testEuclideanNorm(2048); - testEuclideanNorm(2048, true); - testEuclideanNorm(65536); - testEuclideanNorm(65536, true); - testEuclideanNorm(81920); - testEuclideanNorm(81920, true); - testEuclideanNorm(120832); - testEuclideanNorm(120832, true); + testVectorMeanStd(64); + testVectorMeanStd(64, true); + testVectorMeanStd(256); + testVectorMeanStd(256, true); + testVectorMeanStd(2048); + testVectorMeanStd(2048, true); + testVectorMeanStd(65536); + testVectorMeanStd(65536, true); + testVectorMeanStd(81920); + testVectorMeanStd(81920, true); + testVectorMeanStd(120832); + testVectorMeanStd(120832, true); } #ifdef INTGEMM_COMPILER_SUPPORTS_AVX512BW -TEST_CASE("QuantizeStd AVX512", "[EuclideanNorm]") { +TEST_CASE("QuantizeStd AVX512", "[VectorMeanStd]") { if (kCPU < CPUType::AVX512BW) return; - testEuclideanNorm(64); - testEuclideanNorm(64, true); - testEuclideanNorm(256); - testEuclideanNorm(256, true); - testEuclideanNorm(2048); - testEuclideanNorm(2048, true); - testEuclideanNorm(65536); - testEuclideanNorm(65536, true); - testEuclideanNorm(81920); - testEuclideanNorm(81920, true); - testEuclideanNorm(120832); - testEuclideanNorm(120832, true); + testVectorMeanStd(64); + testVectorMeanStd(64, true); + testVectorMeanStd(256); + testVectorMeanStd(256, true); + testVectorMeanStd(2048); + testVectorMeanStd(2048, true); + testVectorMeanStd(65536); + testVectorMeanStd(65536, true); + testVectorMeanStd(81920); + testVectorMeanStd(81920, true); + testVectorMeanStd(120832); + testVectorMeanStd(120832, true); } #endif -- cgit v1.2.3