diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2020-03-19 15:17:43 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-19 15:17:43 +0100 |
commit | b54b22e44a661f84882f581c5f82d248c4d54104 (patch) | |
tree | 14dd5bc24bf6178d6450327e18ae455515df57ca /eval | |
parent | 13eb0fce976e4206ad9bfda75249ca309cc36e60 (diff) | |
parent | 0c3d8f089e46df6b6da9477991c79e4f4cc3502a (diff) |
Merge pull request #12619 from vespa-engine/balder/optimize-value-excutors
Balder/optimize value excutors.
Diffstat (limited to 'eval')
5 files changed, 74 insertions, 48 deletions
diff --git a/eval/src/vespa/eval/tensor/sparse/CMakeLists.txt b/eval/src/vespa/eval/tensor/sparse/CMakeLists.txt index 8e1d18a87b7..a25d2abb477 100644 --- a/eval/src/vespa/eval/tensor/sparse/CMakeLists.txt +++ b/eval/src/vespa/eval/tensor/sparse/CMakeLists.txt @@ -1,6 +1,7 @@ # Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. vespa_add_library(eval_tensor_sparse OBJECT SOURCES + direct_sparse_tensor_builder.cpp sparse_tensor.cpp sparse_tensor_add.cpp sparse_tensor_address_builder.cpp 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 new file mode 100644 index 00000000000..4a28b54d201 --- /dev/null +++ b/eval/src/vespa/eval/tensor/sparse/direct_sparse_tensor_builder.cpp @@ -0,0 +1,62 @@ +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include "direct_sparse_tensor_builder.h" + +namespace vespalib::tensor { + +void +DirectSparseTensorBuilder::copyCells(const Cells &cells_in) +{ + for (const auto &cell : cells_in) { + SparseTensorAddressRef oldRef = cell.first; + SparseTensorAddressRef newRef(oldRef, _stash); + _cells[newRef] = cell.second; + } +} + +DirectSparseTensorBuilder::DirectSparseTensorBuilder() + : _stash(SparseTensor::STASH_CHUNK_SIZE), + _type(eval::ValueType::double_type()), + _cells() +{ +} + +DirectSparseTensorBuilder::DirectSparseTensorBuilder(const eval::ValueType &type_in) + : _stash(SparseTensor::STASH_CHUNK_SIZE), + _type(type_in), + _cells() +{ +} + +DirectSparseTensorBuilder::DirectSparseTensorBuilder(const eval::ValueType &type_in, const Cells &cells_in) + : _stash(SparseTensor::STASH_CHUNK_SIZE), + _type(type_in), + _cells() +{ + copyCells(cells_in); +} + +DirectSparseTensorBuilder::~DirectSparseTensorBuilder() = default; + +Tensor::UP +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); +} + +}
\ No newline at end of file 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 d54c8810a81..f9182a199be 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 @@ -25,43 +25,13 @@ private: Cells _cells; public: - void - copyCells(const Cells &cells_in) - { - for (const auto &cell : cells_in) { - SparseTensorAddressRef oldRef = cell.first; - SparseTensorAddressRef newRef(oldRef, _stash); - _cells[newRef] = cell.second; - } - } - - DirectSparseTensorBuilder() - : _stash(SparseTensor::STASH_CHUNK_SIZE), - _type(eval::ValueType::double_type()), - _cells() - { - } - - DirectSparseTensorBuilder(const eval::ValueType &type_in) - : _stash(SparseTensor::STASH_CHUNK_SIZE), - _type(type_in), - _cells() - { - } - - DirectSparseTensorBuilder(const eval::ValueType &type_in, const Cells &cells_in) - : _stash(SparseTensor::STASH_CHUNK_SIZE), - _type(type_in), - _cells() - { - copyCells(cells_in); - } + void copyCells(const Cells &cells_in); + DirectSparseTensorBuilder(); + DirectSparseTensorBuilder(const eval::ValueType &type_in); + DirectSparseTensorBuilder(const eval::ValueType &type_in, const Cells &cells_in); + ~DirectSparseTensorBuilder(); - ~DirectSparseTensorBuilder() {}; - - Tensor::UP build() { - return std::make_unique<SparseTensor>(std::move(_type), std::move(_cells), std::move(_stash)); - } + Tensor::UP build(); template <class Function> void insertCell(SparseTensorAddressRef address, double value, Function &&func) @@ -75,10 +45,7 @@ public: } } - 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"); }); - } + void insertCell(SparseTensorAddressRef address, double value); template <class Function> void insertCell(SparseTensorAddressBuilder &address, double value, Function &&func) @@ -86,14 +53,11 @@ public: insertCell(address.getAddressRef(), value, func); } - 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"); }); - } + void insertCell(SparseTensorAddressBuilder &address, double value); eval::ValueType &fast_type() { return _type; } Cells &cells() { return _cells; } - void reserve(uint32_t estimatedCells) { _cells.resize(estimatedCells*2); } + void reserve(uint32_t estimatedCells); }; } diff --git a/eval/src/vespa/eval/tensor/sparse/sparse_tensor.cpp b/eval/src/vespa/eval/tensor/sparse/sparse_tensor.cpp index 1fc93e8234f..d183c33f5cd 100644 --- a/eval/src/vespa/eval/tensor/sparse/sparse_tensor.cpp +++ b/eval/src/vespa/eval/tensor/sparse/sparse_tensor.cpp @@ -245,5 +245,4 @@ SparseTensor::remove(const CellValues &cellAddresses) const } -VESPALIB_HASH_MAP_INSTANTIATE_H_E_M(vespalib::tensor::SparseTensorAddressRef, double, vespalib::hash<vespalib::tensor::SparseTensorAddressRef>, - std::equal_to<vespalib::tensor::SparseTensorAddressRef>, vespalib::hashtable_base::and_modulator); +VESPALIB_HASH_MAP_INSTANTIATE(vespalib::tensor::SparseTensorAddressRef, double); diff --git a/eval/src/vespa/eval/tensor/sparse/sparse_tensor.h b/eval/src/vespa/eval/tensor/sparse/sparse_tensor.h index 880cd32c605..e5ea639b460 100644 --- a/eval/src/vespa/eval/tensor/sparse/sparse_tensor.h +++ b/eval/src/vespa/eval/tensor/sparse/sparse_tensor.h @@ -22,7 +22,7 @@ class SparseTensor : public Tensor { public: using Cells = hash_map<SparseTensorAddressRef, double, hash<SparseTensorAddressRef>, - std::equal_to<SparseTensorAddressRef>, hashtable_base::and_modulator>; + std::equal_to<>, hashtable_base::and_modulator>; static constexpr size_t STASH_CHUNK_SIZE = 16384u; |