diff options
10 files changed, 33 insertions, 40 deletions
diff --git a/eval/src/tests/ann/nns-l2.h b/eval/src/tests/ann/nns-l2.h index 857866ff73b..82a95741200 100644 --- a/eval/src/tests/ann/nns-l2.h +++ b/eval/src/tests/ann/nns-l2.h @@ -1,7 +1,7 @@ // Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once -#include <string.h> +#include <cstring> #include <vespa/vespalib/util/arrayref.h> #include <vespa/vespalib/hwaccelrated/iaccelrated.h> @@ -34,7 +34,7 @@ static double hw_l2_sq_dist(const T * af, const T * bf, size_t sz) template <typename FltType = float> struct L2DistCalc { - vespalib::hwaccelrated::IAccelrated::UP _hw; + const vespalib::hwaccelrated::IAccelrated & _hw; L2DistCalc() : _hw(vespalib::hwaccelrated::IAccelrated::getAccelrator()) {} @@ -42,16 +42,16 @@ struct L2DistCalc { using ConstArr = vespalib::ConstArrayRef<FltType>; double product(const FltType *v1, const FltType *v2, size_t sz) { - return _hw->dotProduct(v1, v2, sz); + return _hw.dotProduct(v1, v2, sz); } double product(ConstArr v1, ConstArr v2) { const FltType *p1 = v1.begin(); const FltType *p2 = v2.begin(); - return _hw->dotProduct(p1, p2, v1.size()); + return _hw.dotProduct(p1, p2, v1.size()); } double l2sq(ConstArr vector) { const FltType *v = vector.begin(); - return _hw->dotProduct(v, v, vector.size()); + return _hw.dotProduct(v, v, vector.size()); } double l2sq_dist(ConstArr v1, ConstArr v2, Arr tmp) { for (size_t i = 0; i < v1.size(); ++i) { diff --git a/eval/src/vespa/eval/tensor/sparse/direct_sparse_tensor_builder.cpp b/eval/src/vespa/eval/tensor/sparse/direct_sparse_tensor_builder.cpp index 4a28b54d201..c47521e702d 100644 --- a/eval/src/vespa/eval/tensor/sparse/direct_sparse_tensor_builder.cpp +++ b/eval/src/vespa/eval/tensor/sparse/direct_sparse_tensor_builder.cpp @@ -43,18 +43,6 @@ DirectSparseTensorBuilder::build() { return std::make_unique<SparseTensor>(std::move(_type), std::move(_cells), std::move(_stash)); } -void -DirectSparseTensorBuilder::insertCell(SparseTensorAddressRef address, double value) { - // This address should not already exist and a new cell should be inserted. - insertCell(address, value, [](double, double) -> double { HDR_ABORT("should not be reached"); }); -} - -void -DirectSparseTensorBuilder::insertCell(SparseTensorAddressBuilder &address, double value) { - // This address should not already exist and a new cell should be inserted. - insertCell(address.getAddressRef(), value, [](double, double) -> double { HDR_ABORT("should not be reached"); }); -} - void DirectSparseTensorBuilder::reserve(uint32_t estimatedCells) { _cells.resize(estimatedCells*2); } diff --git a/eval/src/vespa/eval/tensor/sparse/direct_sparse_tensor_builder.h b/eval/src/vespa/eval/tensor/sparse/direct_sparse_tensor_builder.h index f9182a199be..bcb22c0761d 100644 --- a/eval/src/vespa/eval/tensor/sparse/direct_sparse_tensor_builder.h +++ b/eval/src/vespa/eval/tensor/sparse/direct_sparse_tensor_builder.h @@ -45,15 +45,20 @@ public: } } - void insertCell(SparseTensorAddressRef address, double value); + void insertCell(SparseTensorAddressRef address, double value) { + // This address should not already exist and a new cell should be inserted. + insertCell(address, value, [](double, double) -> double { HDR_ABORT("should not be reached"); }); + } template <class Function> - void insertCell(SparseTensorAddressBuilder &address, double value, Function &&func) - { + void insertCell(SparseTensorAddressBuilder &address, double value, Function &&func) { insertCell(address.getAddressRef(), value, func); } - void insertCell(SparseTensorAddressBuilder &address, double value); + void insertCell(SparseTensorAddressBuilder &address, double value) { + // This address should not already exist and a new cell should be inserted. + insertCell(address.getAddressRef(), value, [](double, double) -> double { HDR_ABORT("should not be reached"); }); + } eval::ValueType &fast_type() { return _type; } Cells &cells() { return _cells; } diff --git a/searchlib/src/vespa/searchlib/common/bitvector.cpp b/searchlib/src/vespa/searchlib/common/bitvector.cpp index e28ebe6682f..2e70e9f2603 100644 --- a/searchlib/src/vespa/searchlib/common/bitvector.cpp +++ b/searchlib/src/vespa/searchlib/common/bitvector.cpp @@ -165,7 +165,7 @@ BitVector::countInterval(Index start, Index end) const ++endw; } if (startw < endw) { - res += IAccelrated::getAccelrator()->populationCount(bitValues + startw, endw - startw); + res += IAccelrated::getAccelrator().populationCount(bitValues + startw, endw - startw); } if (partialEnd) { res += Optimized::popCount(bitValues[endw] & ~endBits(last)); @@ -178,7 +178,7 @@ void BitVector::orWith(const BitVector & right) { verifyContains(*this, right); - IAccelrated::getAccelrator()->orBit(getActiveStart(), right.getWordIndex(getStartIndex()), getActiveBytes()); + IAccelrated::getAccelrator().orBit(getActiveStart(), right.getWordIndex(getStartIndex()), getActiveBytes()); repairEnds(); invalidateCachedCount(); @@ -201,7 +201,7 @@ BitVector::andWith(const BitVector & right) { verifyContains(*this, right); - IAccelrated::getAccelrator()->andBit(getActiveStart(), right.getWordIndex(getStartIndex()), getActiveBytes()); + IAccelrated::getAccelrator().andBit(getActiveStart(), right.getWordIndex(getStartIndex()), getActiveBytes()); setGuardBit(); invalidateCachedCount(); @@ -213,7 +213,7 @@ BitVector::andNotWith(const BitVector& right) { verifyContains(*this, right); - IAccelrated::getAccelrator()->andNotBit(getActiveStart(), right.getWordIndex(getStartIndex()), getActiveBytes()); + IAccelrated::getAccelrator().andNotBit(getActiveStart(), right.getWordIndex(getStartIndex()), getActiveBytes()); setGuardBit(); invalidateCachedCount(); @@ -221,7 +221,7 @@ BitVector::andNotWith(const BitVector& right) void BitVector::notSelf() { - IAccelrated::getAccelrator()->notBit(getActiveStart(), getActiveBytes()); + IAccelrated::getAccelrator().notBit(getActiveStart(), getActiveBytes()); setGuardBit(); invalidateCachedCount(); } diff --git a/searchlib/src/vespa/searchlib/features/dotproductfeature.cpp b/searchlib/src/vespa/searchlib/features/dotproductfeature.cpp index 811a318682b..ec31bcb5117 100644 --- a/searchlib/src/vespa/searchlib/features/dotproductfeature.cpp +++ b/searchlib/src/vespa/searchlib/features/dotproductfeature.cpp @@ -268,7 +268,7 @@ void DotProductExecutorBase<BaseType>::execute(uint32_t docId) { size_t count = getAttributeValues(docId, values); size_t commonRange = std::min(count, _queryVector.size()); static_assert(std::is_same<typename AT::ValueType, BaseType>::value); - outputs().set_number(0, _multiplier->dotProduct( + outputs().set_number(0, _multiplier.dotProduct( &_queryVector[0], reinterpret_cast<const typename AT::ValueType *>(values), commonRange)); } diff --git a/searchlib/src/vespa/searchlib/features/dotproductfeature.h b/searchlib/src/vespa/searchlib/features/dotproductfeature.h index a13fc6794fc..bca6983877c 100644 --- a/searchlib/src/vespa/searchlib/features/dotproductfeature.h +++ b/searchlib/src/vespa/searchlib/features/dotproductfeature.h @@ -181,8 +181,8 @@ public: using AT = multivalue::Value<BaseType>; using V = std::vector<BaseType>; private: - vespalib::hwaccelrated::IAccelrated::UP _multiplier; - V _queryVector; + const vespalib::hwaccelrated::IAccelrated & _multiplier; + V _queryVector; virtual size_t getAttributeValues(uint32_t docid, const AT * & count) = 0; public: DotProductExecutorBase(const V & queryVector); diff --git a/searchlib/src/vespa/searchlib/tensor/distance_functions.h b/searchlib/src/vespa/searchlib/tensor/distance_functions.h index 09f538269d8..d4636b04ef7 100644 --- a/searchlib/src/vespa/searchlib/tensor/distance_functions.h +++ b/searchlib/src/vespa/searchlib/tensor/distance_functions.h @@ -23,9 +23,9 @@ public: auto rhs_vector = rhs.typify<FloatType>(); size_t sz = lhs_vector.size(); assert(sz == rhs_vector.size()); - return _computer->squaredEuclideanDistance(&lhs_vector[0], &rhs_vector[0], sz); + return _computer.squaredEuclideanDistance(&lhs_vector[0], &rhs_vector[0], sz); } - vespalib::hwaccelrated::IAccelrated::UP _computer; + const vespalib::hwaccelrated::IAccelrated & _computer; }; template class SquaredEuclideanDistance<float>; diff --git a/vespalib/src/tests/dotproduct/dotproductbenchmark.cpp b/vespalib/src/tests/dotproduct/dotproductbenchmark.cpp index 3588e0ce239..d6e1aef9394 100644 --- a/vespalib/src/tests/dotproduct/dotproductbenchmark.cpp +++ b/vespalib/src/tests/dotproduct/dotproductbenchmark.cpp @@ -48,12 +48,12 @@ public: FullBenchmark(size_t numDocs, size_t numValue); ~FullBenchmark(); void compute(size_t docId) const override { - _dp->dotProduct(&_query[0], &_values[docId * _query.size()], _query.size()); + _dp.dotProduct(&_query[0], &_values[docId * _query.size()], _query.size()); } private: std::vector<T> _values; std::vector<T> _query; - IAccelrated::UP _dp; + const IAccelrated & _dp; }; template <typename T> diff --git a/vespalib/src/vespa/vespalib/hwaccelrated/iaccelrated.cpp b/vespalib/src/vespa/vespalib/hwaccelrated/iaccelrated.cpp index ffa994641e9..bb132165e53 100644 --- a/vespalib/src/vespa/vespalib/hwaccelrated/iaccelrated.cpp +++ b/vespalib/src/vespa/vespalib/hwaccelrated/iaccelrated.cpp @@ -106,7 +106,7 @@ class RuntimeVerificator public: RuntimeVerificator(); private: - void verify(IAccelrated & accelrated) { + void verify(const IAccelrated & accelrated) { verifyDotproduct<float>(accelrated); verifyDotproduct<double>(accelrated); verifyDotproduct<int32_t>(accelrated); @@ -122,8 +122,8 @@ RuntimeVerificator::RuntimeVerificator() GenericAccelrator generic; verify(generic); - IAccelrated::UP thisCpu(IAccelrated::getAccelrator()); - verify(*thisCpu); + const IAccelrated & thisCpu(IAccelrated::getAccelrator()); + verify(thisCpu); } class Selector @@ -154,11 +154,11 @@ static Selector _G_selector; RuntimeVerificator _G_verifyAccelrator; - -IAccelrated::UP +const IAccelrated & IAccelrated::getAccelrator() { - return _G_selector.create(); + 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 ea7e268bc6f..0292ad14643 100644 --- a/vespalib/src/vespa/vespalib/hwaccelrated/iaccelrated.h +++ b/vespalib/src/vespa/vespalib/hwaccelrated/iaccelrated.h @@ -30,7 +30,7 @@ public: 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)); + static const IAccelrated & getAccelrator() __attribute__((noinline)); }; } |