diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2020-03-10 20:09:22 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2020-03-10 20:09:22 +0000 |
commit | 8d52222315d29507930750941e268491ade98934 (patch) | |
tree | 5762764d05bd1cd1350a35594b347ef6448b97cc /vespalib | |
parent | 03bd3b755650d828e63458379d5c120da63d7221 (diff) |
Followup from code review.
- Update copyright
- euclidian -> euclidean
- better testdata.
Diffstat (limited to 'vespalib')
11 files changed, 42 insertions, 39 deletions
diff --git a/vespalib/src/tests/hwaccelrated/CMakeLists.txt b/vespalib/src/tests/hwaccelrated/CMakeLists.txt index 9dda949d088..49501341098 100644 --- a/vespalib/src/tests/hwaccelrated/CMakeLists.txt +++ b/vespalib/src/tests/hwaccelrated/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +# Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. vespa_add_executable(vespalib_hwaccelrated_test_app TEST SOURCES hwaccelrated_test.cpp diff --git a/vespalib/src/tests/hwaccelrated/hwaccelrated_test.cpp b/vespalib/src/tests/hwaccelrated/hwaccelrated_test.cpp index 757626ead94..421f3f6f520 100644 --- a/vespalib/src/tests/hwaccelrated/hwaccelrated_test.cpp +++ b/vespalib/src/tests/hwaccelrated/hwaccelrated_test.cpp @@ -1,4 +1,4 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/vespalib/testkit/test_kit.h> #include <vespa/vespalib/hwaccelrated/iaccelrated.h> @@ -10,14 +10,15 @@ template<typename T> std::vector<T> createAndFill(size_t sz) { std::vector<T> v(sz); for (size_t i(0); i < sz; i++) { - v[i] = i; + v[i] = rand()%500; } return v; } template<typename T> -void verifyEuclidianDistance(const hwaccelrated::IAccelrated & accel) { +void verifyEuclideanDistance(const hwaccelrated::IAccelrated & accel) { const size_t testLength(255); + srand(1); std::vector<T> a = createAndFill<T>(testLength); std::vector<T> b = createAndFill<T>(testLength); for (size_t j(0); j < 0x20; j++) { @@ -25,15 +26,15 @@ void verifyEuclidianDistance(const hwaccelrated::IAccelrated & accel) { for (size_t i(j); i < testLength; i++) { sum += (a[i] - b[i]) * (a[i] - b[i]); } - T hwComputedSum(accel.squaredEuclidianDistance(&a[j], &b[j], testLength - j)); - EXPECT_EQUAL (sum, hwComputedSum); + T hwComputedSum(accel.squaredEuclideanDistance(&a[j], &b[j], testLength - j)); + EXPECT_EQUAL(sum, hwComputedSum); } } -TEST("test euclidian distance") { +TEST("test euclidean distance") { hwaccelrated::GenericAccelrator genericAccelrator; - verifyEuclidianDistance<float>(genericAccelrator); - verifyEuclidianDistance<double >(genericAccelrator); + verifyEuclideanDistance<float>(genericAccelrator); + verifyEuclideanDistance<double >(genericAccelrator); } TEST_MAIN() { TEST_RUN_ALL(); } diff --git a/vespalib/src/vespa/vespalib/hwaccelrated/avx2.cpp b/vespalib/src/vespa/vespalib/hwaccelrated/avx2.cpp index 2c784f5dda2..7ff393c87f8 100644 --- a/vespalib/src/vespa/vespalib/hwaccelrated/avx2.cpp +++ b/vespalib/src/vespa/vespalib/hwaccelrated/avx2.cpp @@ -11,13 +11,13 @@ Avx2Accelrator::populationCount(const uint64_t *a, size_t sz) const { } double -Avx2Accelrator::squaredEuclidianDistance(const float * a, const float * b, size_t sz) const { - return avx::euclidianDistanceSelectAlignment<float, 32>(a, b, sz); +Avx2Accelrator::squaredEuclideanDistance(const float * a, const float * b, size_t sz) const { + return avx::euclideanDistanceSelectAlignment<float, 32>(a, b, sz); } double -Avx2Accelrator::squaredEuclidianDistance(const double * a, const double * b, size_t sz) const { - return avx::euclidianDistanceSelectAlignment<double, 32>(a, b, sz); +Avx2Accelrator::squaredEuclideanDistance(const double * a, const double * b, size_t sz) const { + return avx::euclideanDistanceSelectAlignment<double, 32>(a, b, sz); } } diff --git a/vespalib/src/vespa/vespalib/hwaccelrated/avx2.h b/vespalib/src/vespa/vespalib/hwaccelrated/avx2.h index 68c0bb5695c..3e0dbb28110 100644 --- a/vespalib/src/vespa/vespalib/hwaccelrated/avx2.h +++ b/vespalib/src/vespa/vespalib/hwaccelrated/avx2.h @@ -13,8 +13,8 @@ class Avx2Accelrator : public GenericAccelrator { public: size_t populationCount(const uint64_t *a, size_t sz) const override; - double squaredEuclidianDistance(const float * a, const float * b, size_t sz) const override; - double squaredEuclidianDistance(const double * a, const double * b, size_t sz) const override; + double squaredEuclideanDistance(const float * a, const float * b, size_t sz) const override; + double squaredEuclideanDistance(const double * a, const double * b, size_t sz) const override; }; } diff --git a/vespalib/src/vespa/vespalib/hwaccelrated/avx512.cpp b/vespalib/src/vespa/vespalib/hwaccelrated/avx512.cpp index 45126c366ad..0941e6d6ad8 100644 --- a/vespalib/src/vespa/vespalib/hwaccelrated/avx512.cpp +++ b/vespalib/src/vespa/vespalib/hwaccelrated/avx512.cpp @@ -23,13 +23,13 @@ Avx512Accelrator::populationCount(const uint64_t *a, size_t sz) const { } double -Avx512Accelrator::squaredEuclidianDistance(const float * a, const float * b, size_t sz) const { - return avx::euclidianDistanceSelectAlignment<float, 64>(a, b, sz); +Avx512Accelrator::squaredEuclideanDistance(const float * a, const float * b, size_t sz) const { + return avx::euclideanDistanceSelectAlignment<float, 64>(a, b, sz); } double -Avx512Accelrator::squaredEuclidianDistance(const double * a, const double * b, size_t sz) const { - return avx::euclidianDistanceSelectAlignment<double, 64>(a, b, sz); +Avx512Accelrator::squaredEuclideanDistance(const double * a, const double * b, size_t sz) const { + return avx::euclideanDistanceSelectAlignment<double, 64>(a, b, sz); } } diff --git a/vespalib/src/vespa/vespalib/hwaccelrated/avx512.h b/vespalib/src/vespa/vespalib/hwaccelrated/avx512.h index 78712811b8b..209ec06c857 100644 --- a/vespalib/src/vespa/vespalib/hwaccelrated/avx512.h +++ b/vespalib/src/vespa/vespalib/hwaccelrated/avx512.h @@ -15,8 +15,8 @@ public: float dotProduct(const float * a, const float * b, size_t sz) const override; double dotProduct(const double * a, const double * b, size_t sz) const override; size_t populationCount(const uint64_t *a, size_t sz) const override; - double squaredEuclidianDistance(const float * a, const float * b, size_t sz) const override; - double squaredEuclidianDistance(const double * a, const double * b, size_t sz) const override; + double squaredEuclideanDistance(const float * a, const float * b, size_t sz) const override; + double squaredEuclideanDistance(const double * a, const double * b, size_t sz) const override; }; } diff --git a/vespalib/src/vespa/vespalib/hwaccelrated/avxprivate.hpp b/vespalib/src/vespa/vespalib/hwaccelrated/avxprivate.hpp index 406757d239c..087729a23b2 100644 --- a/vespalib/src/vespa/vespalib/hwaccelrated/avxprivate.hpp +++ b/vespalib/src/vespa/vespalib/hwaccelrated/avxprivate.hpp @@ -88,7 +88,7 @@ T dotProductSelectAlignment(const T * af, const T * bf, size_t sz) template <typename T, unsigned VLEN, unsigned AlignA, unsigned AlignB> double -euclidianDistanceT(const T * af, const T * bf, size_t sz) +euclideanDistanceT(const T * af, const T * bf, size_t sz) { constexpr unsigned VectorsPerChunk = 4; constexpr unsigned ChunkSize = VLEN*VectorsPerChunk/sizeof(T); @@ -116,20 +116,20 @@ euclidianDistanceT(const T * af, const T * bf, size_t sz) } template <typename T, unsigned VLEN> -double euclidianDistanceSelectAlignment(const T * af, const T * bf, size_t sz) +double euclideanDistanceSelectAlignment(const T * af, const T * bf, size_t sz) { constexpr unsigned ALIGN = 32; if (validAlignment(af, ALIGN)) { if (validAlignment(bf, ALIGN)) { - return euclidianDistanceT<T, VLEN, ALIGN, ALIGN>(af, bf, sz); + return euclideanDistanceT<T, VLEN, ALIGN, ALIGN>(af, bf, sz); } else { - return euclidianDistanceT<T, ALIGN, ALIGN, 1>(af, bf, sz); + return euclideanDistanceT<T, ALIGN, ALIGN, 1>(af, bf, sz); } } else { if (validAlignment(bf, ALIGN)) { - return euclidianDistanceT<T, VLEN, 1, ALIGN>(af, bf, sz); + return euclideanDistanceT<T, VLEN, 1, ALIGN>(af, bf, sz); } else { - return euclidianDistanceT<T, VLEN, 1, 1>(af, bf, sz); + return euclideanDistanceT<T, VLEN, 1, 1>(af, bf, sz); } } } diff --git a/vespalib/src/vespa/vespalib/hwaccelrated/generic.cpp b/vespalib/src/vespa/vespalib/hwaccelrated/generic.cpp index 13929a288f9..f9684e88c63 100644 --- a/vespalib/src/vespa/vespalib/hwaccelrated/generic.cpp +++ b/vespalib/src/vespa/vespalib/hwaccelrated/generic.cpp @@ -34,7 +34,7 @@ multiplyAdd(const T * a, const T * b, size_t sz) template <typename T, size_t UNROLL> double -euclidianDistanceT(const T * a, const T * b, size_t sz) +euclideanDistanceT(const T * a, const T * b, size_t sz) { T partial[UNROLL]; for (size_t i(0); i < UNROLL; i++) { @@ -156,13 +156,13 @@ GenericAccelrator::populationCount(const uint64_t *a, size_t sz) const { } double -GenericAccelrator::squaredEuclidianDistance(const float * a, const float * b, size_t sz) const { - return euclidianDistanceT<float, 8>(a, b, sz); +GenericAccelrator::squaredEuclideanDistance(const float * a, const float * b, size_t sz) const { + return euclideanDistanceT<float, 8>(a, b, sz); } double -GenericAccelrator::squaredEuclidianDistance(const double * a, const double * b, size_t sz) const { - return euclidianDistanceT<double, 4>(a, b, sz); +GenericAccelrator::squaredEuclideanDistance(const double * a, const double * b, size_t sz) const { + return euclideanDistanceT<double, 4>(a, b, sz); } } diff --git a/vespalib/src/vespa/vespalib/hwaccelrated/generic.h b/vespalib/src/vespa/vespalib/hwaccelrated/generic.h index 224394a9595..50a3d59d49d 100644 --- a/vespalib/src/vespa/vespalib/hwaccelrated/generic.h +++ b/vespalib/src/vespa/vespalib/hwaccelrated/generic.h @@ -23,8 +23,8 @@ public: void andNotBit(void * a, const void * b, size_t bytes) const override; void notBit(void * a, size_t bytes) const override; size_t populationCount(const uint64_t *a, size_t sz) const override; - double squaredEuclidianDistance(const float * a, const float * b, size_t sz) const override; - double squaredEuclidianDistance(const double * a, const double * b, size_t sz) const override; + double squaredEuclideanDistance(const float * a, const float * b, size_t sz) const override; + double squaredEuclideanDistance(const double * a, const double * b, size_t sz) const override; }; } diff --git a/vespalib/src/vespa/vespalib/hwaccelrated/iaccelrated.cpp b/vespalib/src/vespa/vespalib/hwaccelrated/iaccelrated.cpp index b298ffdc4af..86bd4d2c7b2 100644 --- a/vespalib/src/vespa/vespalib/hwaccelrated/iaccelrated.cpp +++ b/vespalib/src/vespa/vespalib/hwaccelrated/iaccelrated.cpp @@ -40,7 +40,7 @@ template<typename T> std::vector<T> createAndFill(size_t sz) { std::vector<T> v(sz); for (size_t i(0); i < sz; i++) { - v[i] = i; + v[i] = rand()%100; } return v; } @@ -49,12 +49,13 @@ template<typename T> void verifyDotproduct(const IAccelrated & accel) { const size_t testLength(255); + srand(1); std::vector<T> a = createAndFill<T>(testLength); std::vector<T> b = createAndFill<T>(testLength); for (size_t j(0); j < 0x20; j++) { T sum(0); for (size_t i(j); i < testLength; i++) { - sum += i*i; + sum += a[i]*b[i]; } T hwComputedSum(accel.dotProduct(&a[j], &b[j], testLength - j)); if (sum != hwComputedSum) { @@ -67,6 +68,7 @@ void verifyDotproduct(const IAccelrated & accel) template<typename T> void verifyEuclidianDistance(const IAccelrated & accel) { const size_t testLength(255); + srand(1); std::vector<T> a = createAndFill<T>(testLength); std::vector<T> b = createAndFill<T>(testLength); for (size_t j(0); j < 0x20; j++) { @@ -74,7 +76,7 @@ void verifyEuclidianDistance(const IAccelrated & accel) { for (size_t i(j); i < testLength; i++) { sum += (a[i] - b[i]) * (a[i] - b[i]); } - T hwComputedSum(accel.squaredEuclidianDistance(&a[j], &b[j], testLength - j)); + T hwComputedSum(accel.squaredEuclideanDistance(&a[j], &b[j], testLength - j)); if (sum != hwComputedSum) { fprintf(stderr, "Accelrator is not computing euclidian distance correctly.\n"); LOG_ABORT("should not be reached"); diff --git a/vespalib/src/vespa/vespalib/hwaccelrated/iaccelrated.h b/vespalib/src/vespa/vespalib/hwaccelrated/iaccelrated.h index 61739e1837a..ea7e268bc6f 100644 --- a/vespalib/src/vespa/vespalib/hwaccelrated/iaccelrated.h +++ b/vespalib/src/vespa/vespalib/hwaccelrated/iaccelrated.h @@ -27,8 +27,8 @@ public: virtual void andNotBit(void * a, const void * b, size_t bytes) const = 0; virtual void notBit(void * a, size_t bytes) const = 0; virtual size_t populationCount(const uint64_t *a, size_t sz) const = 0; - virtual double squaredEuclidianDistance(const float * a, const float * b, size_t sz) const = 0; - virtual double squaredEuclidianDistance(const double * a, const double * b, size_t sz) const = 0; + virtual double squaredEuclideanDistance(const float * a, const float * b, size_t sz) const = 0; + virtual double squaredEuclideanDistance(const double * a, const double * b, size_t sz) const = 0; static IAccelrated::UP getAccelrator() __attribute__((noinline)); }; |