diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2020-06-07 13:50:17 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2020-06-07 13:50:17 +0000 |
commit | 633d97a8c892bbff4cb1c8bb58c5797435dd2ee0 (patch) | |
tree | 35a06e428904cbfbe2c69b32150cb0d757816932 /vespalib | |
parent | 8c2c60de38041e579cfaae4a8987248fbfc3d16c (diff) |
- Stick to void * and byte offsets.
- Correct spelling error.
Diffstat (limited to 'vespalib')
10 files changed, 37 insertions, 31 deletions
diff --git a/vespalib/src/tests/dotproduct/dotproductbenchmark.cpp b/vespalib/src/tests/dotproduct/dotproductbenchmark.cpp index d6e1aef9394..e95e8a5c58b 100644 --- a/vespalib/src/tests/dotproduct/dotproductbenchmark.cpp +++ b/vespalib/src/tests/dotproduct/dotproductbenchmark.cpp @@ -60,7 +60,7 @@ template <typename T> FullBenchmark<T>::FullBenchmark(size_t numDocs, size_t numValues) : _values(numDocs*numValues), _query(numValues), - _dp(IAccelrated::getAccelrator()) + _dp(IAccelrated::getAccelerator()) { for (size_t i(0); i < numDocs; i++) { for (size_t j(0); j < numValues; j++) { diff --git a/vespalib/src/vespa/vespalib/hwaccelrated/avx2.cpp b/vespalib/src/vespa/vespalib/hwaccelrated/avx2.cpp index 233609d505b..8588a5510f7 100644 --- a/vespalib/src/vespa/vespalib/hwaccelrated/avx2.cpp +++ b/vespalib/src/vespa/vespalib/hwaccelrated/avx2.cpp @@ -21,12 +21,12 @@ Avx2Accelrator::squaredEuclideanDistance(const double * a, const double * b, siz } void -Avx2Accelrator::and64(size_t offset, const std::vector<std::pair<const uint64_t *, bool>> &src, uint64_t *dest) const { +Avx2Accelrator::and64(size_t offset, const std::vector<std::pair<const void *, bool>> &src, void *dest) const { helper::andChunks<32u, 2u>(offset, src, dest); } void -Avx2Accelrator::or64(size_t offset, const std::vector<std::pair<const uint64_t *, bool>> &src, uint64_t *dest) const { +Avx2Accelrator::or64(size_t offset, const std::vector<std::pair<const void *, bool>> &src, void *dest) const { helper::orChunks<32u, 2u>(offset, src, dest); } diff --git a/vespalib/src/vespa/vespalib/hwaccelrated/avx2.h b/vespalib/src/vespa/vespalib/hwaccelrated/avx2.h index 292961a6f4d..b6f3d299748 100644 --- a/vespalib/src/vespa/vespalib/hwaccelrated/avx2.h +++ b/vespalib/src/vespa/vespalib/hwaccelrated/avx2.h @@ -15,8 +15,8 @@ public: size_t populationCount(const uint64_t *a, 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; - void and64(size_t offset, const std::vector<std::pair<const uint64_t *, bool>> &src, uint64_t *dest) const override; - void or64(size_t offset, const std::vector<std::pair<const uint64_t *, bool>> &src, uint64_t *dest) const override; + void and64(size_t offset, const std::vector<std::pair<const void *, bool>> &src, void *dest) const override; + void or64(size_t offset, const std::vector<std::pair<const void *, bool>> &src, void *dest) const override; }; } diff --git a/vespalib/src/vespa/vespalib/hwaccelrated/avx512.cpp b/vespalib/src/vespa/vespalib/hwaccelrated/avx512.cpp index 9cfae4757b9..4dade08e77a 100644 --- a/vespalib/src/vespa/vespalib/hwaccelrated/avx512.cpp +++ b/vespalib/src/vespa/vespalib/hwaccelrated/avx512.cpp @@ -33,12 +33,12 @@ Avx512Accelrator::squaredEuclideanDistance(const double * a, const double * b, s } void -Avx512Accelrator::and64(size_t offset, const std::vector<std::pair<const uint64_t *, bool>> &src, uint64_t *dest) const { +Avx512Accelrator::and64(size_t offset, const std::vector<std::pair<const void *, bool>> &src, void *dest) const { helper::andChunks<64, 1>(offset, src, dest); } void -Avx512Accelrator::or64(size_t offset, const std::vector<std::pair<const uint64_t *, bool>> &src, uint64_t *dest) const { +Avx512Accelrator::or64(size_t offset, const std::vector<std::pair<const void *, bool>> &src, void *dest) const { helper::orChunks<64, 1>(offset, src, dest); } diff --git a/vespalib/src/vespa/vespalib/hwaccelrated/avx512.h b/vespalib/src/vespa/vespalib/hwaccelrated/avx512.h index ee422b57171..a54d57407b2 100644 --- a/vespalib/src/vespa/vespalib/hwaccelrated/avx512.h +++ b/vespalib/src/vespa/vespalib/hwaccelrated/avx512.h @@ -17,8 +17,8 @@ public: size_t populationCount(const uint64_t *a, 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; - void and64(size_t offset, const std::vector<std::pair<const uint64_t *, bool>> &src, uint64_t *dest) const override; - void or64(size_t offset, const std::vector<std::pair<const uint64_t *, bool>> &src, uint64_t *dest) const override; + void and64(size_t offset, const std::vector<std::pair<const void *, bool>> &src, void *dest) const override; + void or64(size_t offset, const std::vector<std::pair<const void *, bool>> &src, void *dest) const override; }; } diff --git a/vespalib/src/vespa/vespalib/hwaccelrated/generic.cpp b/vespalib/src/vespa/vespalib/hwaccelrated/generic.cpp index 460ae7e7388..f9dfaacf626 100644 --- a/vespalib/src/vespa/vespalib/hwaccelrated/generic.cpp +++ b/vespalib/src/vespa/vespalib/hwaccelrated/generic.cpp @@ -166,12 +166,12 @@ GenericAccelrator::squaredEuclideanDistance(const double * a, const double * b, } void -GenericAccelrator::and64(size_t offset, const std::vector<std::pair<const uint64_t *, bool>> &src, uint64_t *dest) const { +GenericAccelrator::and64(size_t offset, const std::vector<std::pair<const void *, bool>> &src, void *dest) const { helper::andChunks<16, 4>(offset, src, dest); } void -GenericAccelrator::or64(size_t offset, const std::vector<std::pair<const uint64_t *, bool>> &src, uint64_t *dest) const { +GenericAccelrator::or64(size_t offset, const std::vector<std::pair<const void *, bool>> &src, void *dest) const { helper::orChunks<16,4>(offset, src, dest); } diff --git a/vespalib/src/vespa/vespalib/hwaccelrated/generic.h b/vespalib/src/vespa/vespalib/hwaccelrated/generic.h index 8ce320cd4c4..2335b40fe85 100644 --- a/vespalib/src/vespa/vespalib/hwaccelrated/generic.h +++ b/vespalib/src/vespa/vespalib/hwaccelrated/generic.h @@ -25,8 +25,8 @@ public: size_t populationCount(const uint64_t *a, 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; - void and64(size_t offset, const std::vector<std::pair<const uint64_t *, bool>> &src, uint64_t *dest) const override; - void or64(size_t offset, const std::vector<std::pair<const uint64_t *, bool>> &src, uint64_t *dest) const override; + void and64(size_t offset, const std::vector<std::pair<const void *, bool>> &src, void *dest) const override; + void or64(size_t offset, const std::vector<std::pair<const void *, bool>> &src, void *dest) const override; }; } diff --git a/vespalib/src/vespa/vespalib/hwaccelrated/iaccelrated.cpp b/vespalib/src/vespa/vespalib/hwaccelrated/iaccelrated.cpp index 068833357c3..de917c5f065 100644 --- a/vespalib/src/vespa/vespalib/hwaccelrated/iaccelrated.cpp +++ b/vespalib/src/vespa/vespalib/hwaccelrated/iaccelrated.cpp @@ -149,7 +149,7 @@ void verifyOr64(const IAccelrated & accel, const std::vector<std::vector<uint64_t>> & vectors, size_t offset, size_t num_vectors, bool invertSome) { - std::vector<std::pair<const uint64_t *, bool>> vRefs; + std::vector<std::pair<const void *, bool>> vRefs; for (size_t j(0); j < num_vectors; j++) { vRefs.emplace_back(&vectors[j][0], shouldInvert(invertSome)); } @@ -160,7 +160,7 @@ verifyOr64(const IAccelrated & accel, const std::vector<std::vector<uint64_t>> & } uint64_t dest[8] __attribute((aligned(64))); - accel.or64(offset, vRefs, dest); + accel.or64(offset*sizeof(uint64_t), vRefs, dest); int diff = memcmp(&expected[offset], dest, sizeof(dest)); if (diff != 0) { LOG_ABORT("Accelerator fails to compute correct 64 bytes OR"); @@ -171,7 +171,7 @@ void verifyAnd64(const IAccelrated & accel, const std::vector<std::vector<uint64_t>> & vectors, size_t offset, size_t num_vectors, bool invertSome) { - std::vector<std::pair<const uint64_t *, bool>> vRefs; + std::vector<std::pair<const void *, bool>> vRefs; for (size_t j(0); j < num_vectors; j++) { vRefs.emplace_back(&vectors[j][0], shouldInvert(invertSome)); } @@ -181,7 +181,7 @@ verifyAnd64(const IAccelrated & accel, const std::vector<std::vector<uint64_t>> } uint64_t dest[8] __attribute((aligned(64))); - accel.and64(offset, vRefs, dest); + accel.and64(offset*sizeof(uint64_t), vRefs, dest); int diff = memcmp(&expected[offset], dest, sizeof(dest)); if (diff != 0) { LOG_ABORT("Accelerator fails to compute correct 64 bytes AND"); @@ -239,7 +239,7 @@ RuntimeVerificator::RuntimeVerificator() GenericAccelrator generic; verify(generic); - const IAccelrated & thisCpu(IAccelrated::getAccelrator()); + const IAccelrated & thisCpu(IAccelrated::getAccelerator()); verify(thisCpu); } @@ -272,7 +272,7 @@ static Selector _G_selector; RuntimeVerificator _G_verifyAccelrator; const IAccelrated & -IAccelrated::getAccelrator() +IAccelrated::getAccelerator() { static IAccelrated::UP accelrator = _G_selector.create(); return *accelrator; diff --git a/vespalib/src/vespa/vespalib/hwaccelrated/iaccelrated.h b/vespalib/src/vespa/vespalib/hwaccelrated/iaccelrated.h index f352fb292ce..2594a48dd33 100644 --- a/vespalib/src/vespa/vespalib/hwaccelrated/iaccelrated.h +++ b/vespalib/src/vespa/vespalib/hwaccelrated/iaccelrated.h @@ -30,11 +30,12 @@ public: virtual size_t populationCount(const uint64_t *a, 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; - // And 64 bytes from multiple sources - virtual void and64(size_t offset, const std::vector<std::pair<const uint64_t *, bool>> &src, uint64_t *dest) const = 0; - virtual void or64(size_t offset, const std::vector<std::pair<const uint64_t *, bool>> &src, uint64_t *dest) const = 0; + // AND 64 bytes from multiple, optionally inverted sources + virtual void and64(size_t offset, const std::vector<std::pair<const void *, bool>> &src, void *dest) const = 0; + // OR 64 bytes from multiple, optionally inverted sources + virtual void or64(size_t offset, const std::vector<std::pair<const void *, bool>> &src, void *dest) const = 0; - static const IAccelrated & getAccelrator() __attribute__((noinline)); + static const IAccelrated & getAccelerator() __attribute__((noinline)); }; } diff --git a/vespalib/src/vespa/vespalib/hwaccelrated/private_helpers.hpp b/vespalib/src/vespa/vespalib/hwaccelrated/private_helpers.hpp index 2759cc35ba9..6fc49f969f2 100644 --- a/vespalib/src/vespa/vespalib/hwaccelrated/private_helpers.hpp +++ b/vespalib/src/vespa/vespalib/hwaccelrated/private_helpers.hpp @@ -31,17 +31,22 @@ T get(const void * base, bool invert) { return __builtin_expect(invert, false) ? ~v : v; } +template <typename T> +const T * cast(const void * ptr, size_t offsetBytes) { + return static_cast<const T *>(static_cast<const void *>(static_cast<const char *>(ptr) + offsetBytes)); +} + template<unsigned ChunkSize, unsigned Chunks> void -andChunks(size_t offset, const std::vector<std::pair<const uint64_t *, bool>> & src, uint64_t * dest) { +andChunks(size_t offset, const std::vector<std::pair<const void *, bool>> & src, void * dest) { typedef uint64_t Chunk __attribute__ ((vector_size (ChunkSize))); - Chunk * chunk = reinterpret_cast<Chunk *>(dest); - const Chunk * tmp = reinterpret_cast<const Chunk *>(src[0].first+offset); + Chunk * chunk = static_cast<Chunk *>(dest); + const Chunk * tmp = cast<Chunk>(src[0].first, offset); for (size_t n=0; n < Chunks; n++) { chunk[n] = get<Chunk>(tmp+n, src[0].second); } for (size_t i(1); i < src.size(); i++) { - tmp = reinterpret_cast<const Chunk *>(src[i].first+offset); + tmp = cast<Chunk>(src[i].first, offset); for (size_t n=0; n < Chunks; n++) { chunk[n] &= get<Chunk>(tmp+n, src[i].second); } @@ -50,15 +55,15 @@ andChunks(size_t offset, const std::vector<std::pair<const uint64_t *, bool>> & template<unsigned ChunkSize, unsigned Chunks> void -orChunks(size_t offset, const std::vector<std::pair<const uint64_t *, bool>> & src, uint64_t * dest) { +orChunks(size_t offset, const std::vector<std::pair<const void *, bool>> & src, void * dest) { typedef uint64_t Chunk __attribute__ ((vector_size (ChunkSize))); - Chunk * chunk = reinterpret_cast<Chunk *>(dest); - const Chunk * tmp = reinterpret_cast<const Chunk *>(src[0].first+offset); + Chunk * chunk = static_cast<Chunk *>(dest); + const Chunk * tmp = cast<Chunk>(src[0].first, offset); for (size_t n=0; n < Chunks; n++) { chunk[n] = get<Chunk>(tmp+n, src[0].second); } for (size_t i(1); i < src.size(); i++) { - tmp = reinterpret_cast<const Chunk *>(src[i].first+offset); + tmp = cast<Chunk>(src[i].first, offset); for (size_t n=0; n < Chunks; n++) { chunk[n] |= get<Chunk>(tmp+n, src[i].second); } |