summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArne H Juul <arnej27959@users.noreply.github.com>2020-12-08 13:14:57 +0100
committerGitHub <noreply@github.com>2020-12-08 13:14:57 +0100
commitb7133833ca2ab63ebe388b65d645f463e228a461 (patch)
tree34762b0e374985ceafd6326b8d51a7804ad30deb
parent2fe8b70c43865afd9c5c6970ecd53905e08c36b3 (diff)
parenta27cdab6ab2c946e2ad61a429f96ebf23e0167ca (diff)
Merge pull request #15687 from vespa-engine/arnej/untangle-onnx-from-dense-tensor
Arnej/untangle onnx from dense tensor
-rw-r--r--eval/src/tests/tensor/onnx_wrapper/onnx_wrapper_test.cpp15
-rw-r--r--eval/src/vespa/eval/eval/CMakeLists.txt1
-rw-r--r--eval/src/vespa/eval/eval/dense_cells_value.cpp19
-rw-r--r--eval/src/vespa/eval/eval/dense_cells_value.h30
-rw-r--r--eval/src/vespa/eval/tensor/dense/onnx_wrapper.cpp5
-rw-r--r--eval/src/vespa/eval/tensor/dense/onnx_wrapper.h2
-rw-r--r--searchlib/src/vespa/searchlib/queryeval/nearest_neighbor_blueprint.cpp12
7 files changed, 67 insertions, 17 deletions
diff --git a/eval/src/tests/tensor/onnx_wrapper/onnx_wrapper_test.cpp b/eval/src/tests/tensor/onnx_wrapper/onnx_wrapper_test.cpp
index 3cd7f697067..0f125717d47 100644
--- a/eval/src/tests/tensor/onnx_wrapper/onnx_wrapper_test.cpp
+++ b/eval/src/tests/tensor/onnx_wrapper/onnx_wrapper_test.cpp
@@ -1,8 +1,7 @@
// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+#include <vespa/eval/eval/tensor_spec.h>
#include <vespa/eval/tensor/dense/onnx_wrapper.h>
-#include <vespa/eval/tensor/dense/dense_tensor_view.h>
-#include <vespa/eval/tensor/dense/mutable_dense_tensor_view.h>
#include <vespa/vespalib/util/stringfmt.h>
#include <vespa/vespalib/gtest/gtest.h>
@@ -165,13 +164,13 @@ TEST(OnnxTest, simple_onnx_model_can_be_evaluated)
auto cells = output.cells();
EXPECT_EQ(cells.type, CellType::FLOAT);
EXPECT_EQ(cells.size, 1);
- EXPECT_EQ(GetCell::from(cells, 0), 79.0);
+ EXPECT_EQ(cells.typify<float>()[0], 79.0);
//-------------------------------------------------------------------------
std::vector<float> new_bias_values({10.0});
DenseValueView new_bias(bias_type, TypedCells(new_bias_values));
ctx.bind_param(2, new_bias);
ctx.eval();
- EXPECT_EQ(GetCell::from(output.cells(), 0), 80.0);
+ EXPECT_EQ(output.cells().typify<float>()[0], 80.0);
//-------------------------------------------------------------------------
}
@@ -211,13 +210,13 @@ TEST(OnnxTest, dynamic_onnx_model_can_be_evaluated)
auto cells = output.cells();
EXPECT_EQ(cells.type, CellType::FLOAT);
EXPECT_EQ(cells.size, 1);
- EXPECT_EQ(GetCell::from(cells, 0), 79.0);
+ EXPECT_EQ(cells.typify<float>()[0], 79.0);
//-------------------------------------------------------------------------
std::vector<float> new_bias_values({5.0,6.0});
DenseValueView new_bias(bias_type, TypedCells(new_bias_values));
ctx.bind_param(2, new_bias);
ctx.eval();
- EXPECT_EQ(GetCell::from(output.cells(), 0), 81.0);
+ EXPECT_EQ(output.cells().typify<float>()[0], 81.0);
//-------------------------------------------------------------------------
}
@@ -257,13 +256,13 @@ TEST(OnnxTest, int_types_onnx_model_can_be_evaluated)
auto cells = output.cells();
EXPECT_EQ(cells.type, CellType::DOUBLE);
EXPECT_EQ(cells.size, 1);
- EXPECT_EQ(GetCell::from(cells, 0), 79.0);
+ EXPECT_EQ(cells.typify<double>()[0], 79.0);
//-------------------------------------------------------------------------
std::vector<double> new_bias_values({10.0});
DenseValueView new_bias(bias_type, TypedCells(new_bias_values));
ctx.bind_param(2, new_bias);
ctx.eval();
- EXPECT_EQ(GetCell::from(output.cells(), 0), 80.0);
+ EXPECT_EQ(output.cells().typify<double>()[0], 80.0);
//-------------------------------------------------------------------------
}
diff --git a/eval/src/vespa/eval/eval/CMakeLists.txt b/eval/src/vespa/eval/eval/CMakeLists.txt
index d32841520a6..57c0db1719b 100644
--- a/eval/src/vespa/eval/eval/CMakeLists.txt
+++ b/eval/src/vespa/eval/eval/CMakeLists.txt
@@ -8,6 +8,7 @@ vespa_add_library(eval_eval OBJECT
cell_type.cpp
compile_tensor_function.cpp
delete_node.cpp
+ dense_cells_value.cpp
double_value_builder.cpp
fast_forest.cpp
fast_sparse_map.cpp
diff --git a/eval/src/vespa/eval/eval/dense_cells_value.cpp b/eval/src/vespa/eval/eval/dense_cells_value.cpp
new file mode 100644
index 00000000000..126ef806668
--- /dev/null
+++ b/eval/src/vespa/eval/eval/dense_cells_value.cpp
@@ -0,0 +1,19 @@
+// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#include "dense_cells_value.h"
+
+namespace vespalib::eval {
+
+template<typename T> DenseCellsValue<T>::~DenseCellsValue() = default;
+
+template<typename T> MemoryUsage
+DenseCellsValue<T>::get_memory_usage() const {
+ auto usage = self_memory_usage<DenseCellsValue<T>>();
+ usage.merge(vector_extra_memory_usage(_cells));
+ return usage;
+}
+
+template class DenseCellsValue<double>;
+template class DenseCellsValue<float>;
+
+}
diff --git a/eval/src/vespa/eval/eval/dense_cells_value.h b/eval/src/vespa/eval/eval/dense_cells_value.h
new file mode 100644
index 00000000000..ccf6c1388aa
--- /dev/null
+++ b/eval/src/vespa/eval/eval/dense_cells_value.h
@@ -0,0 +1,30 @@
+// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#include <vespa/eval/eval/value.h>
+#include <cassert>
+
+namespace vespalib::eval {
+
+/**
+ * A dense-only value that just owns a vector of cells.
+ **/
+template<typename T>
+class DenseCellsValue : public Value {
+private:
+ ValueType _type;
+ std::vector<T> _cells;
+public:
+ DenseCellsValue(const ValueType &type_ref, std::vector<T> cells)
+ : _type(type_ref), _cells(std::move(cells))
+ {
+ assert(check_cell_type<T>(_type.cell_type()));
+ assert(_cells.size() == _type.dense_subspace_size());
+ }
+ const ValueType &type() const override { return _type; }
+ TypedCells cells() const override { return TypedCells(_cells); }
+ const Index &index() const override { return TrivialIndex::get(); }
+ MemoryUsage get_memory_usage() const override;
+ ~DenseCellsValue();
+};
+
+}
diff --git a/eval/src/vespa/eval/tensor/dense/onnx_wrapper.cpp b/eval/src/vespa/eval/tensor/dense/onnx_wrapper.cpp
index 0dc8b343627..521d2382666 100644
--- a/eval/src/vespa/eval/tensor/dense/onnx_wrapper.cpp
+++ b/eval/src/vespa/eval/tensor/dense/onnx_wrapper.cpp
@@ -1,8 +1,8 @@
// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "onnx_wrapper.h"
+#include <vespa/eval/eval/dense_cells_value.h>
#include <vespa/eval/eval/value_type.h>
-#include "dense_tensor.h"
#include <vespa/vespalib/util/arrayref.h>
#include <vespa/vespalib/util/stringfmt.h>
#include <vespa/vespalib/util/typify.h>
@@ -20,6 +20,7 @@ using vespalib::ArrayRef;
using vespalib::ConstArrayRef;
using vespalib::eval::CellType;
using vespalib::eval::DenseValueView;
+using vespalib::eval::DenseCellsValue;
using vespalib::eval::TypedCells;
using vespalib::eval::TypifyCellType;
using vespalib::eval::ValueType;
@@ -85,7 +86,7 @@ struct CreateVespaTensor {
template <typename T> static eval::Value::UP invoke(const eval::ValueType &type) {
size_t num_cells = type.dense_subspace_size();
std::vector<T> cells(num_cells, T{});
- return std::make_unique<DenseTensor<T>>(type, std::move(cells));
+ return std::make_unique<DenseCellsValue<T>>(type, std::move(cells));
}
eval::Value::UP operator()(const eval::ValueType &type) {
return typify_invoke<1,MyTypify,CreateVespaTensor>(type.cell_type(), type);
diff --git a/eval/src/vespa/eval/tensor/dense/onnx_wrapper.h b/eval/src/vespa/eval/tensor/dense/onnx_wrapper.h
index 1f043a7de5e..f42b926d17e 100644
--- a/eval/src/vespa/eval/tensor/dense/onnx_wrapper.h
+++ b/eval/src/vespa/eval/tensor/dense/onnx_wrapper.h
@@ -2,7 +2,6 @@
#pragma once
-#include "dense_tensor_view.h"
#ifdef __APPLE__
#include <onnxruntime/core/session/onnxruntime_cxx_api.h>
#else
@@ -10,6 +9,7 @@
#endif
#include <vespa/vespalib/stllike/string.h>
#include <vespa/eval/eval/value_type.h>
+#include <vespa/eval/eval/value.h>
#include <vector>
#include <map>
#include <set>
diff --git a/searchlib/src/vespa/searchlib/queryeval/nearest_neighbor_blueprint.cpp b/searchlib/src/vespa/searchlib/queryeval/nearest_neighbor_blueprint.cpp
index d75cda2e513..d3ecffd1605 100644
--- a/searchlib/src/vespa/searchlib/queryeval/nearest_neighbor_blueprint.cpp
+++ b/searchlib/src/vespa/searchlib/queryeval/nearest_neighbor_blueprint.cpp
@@ -4,16 +4,16 @@
#include "nearest_neighbor_blueprint.h"
#include "nearest_neighbor_iterator.h"
#include "nns_index_iterator.h"
+#include <vespa/eval/eval/dense_cells_value.h>
#include <vespa/searchlib/fef/termfieldmatchdataarray.h>
-#include <vespa/eval/tensor/dense/dense_tensor.h>
#include <vespa/searchlib/tensor/dense_tensor_attribute.h>
#include <vespa/searchlib/tensor/distance_function_factory.h>
#include <vespa/log/log.h>
LOG_SETUP(".searchlib.queryeval.nearest_neighbor_blueprint");
+using vespalib::eval::DenseCellsValue;
using vespalib::eval::Value;
-using vespalib::tensor::DenseTensor;
namespace search::queryeval {
@@ -21,7 +21,7 @@ namespace {
template<typename LCT, typename RCT>
void
-convert_cells(std::unique_ptr<Value> &original, vespalib::eval::ValueType want_type)
+convert_cells(std::unique_ptr<Value> &original, const vespalib::eval::ValueType &want_type)
{
auto old_cells = original->cells().typify<LCT>();
std::vector<RCT> new_cells;
@@ -30,16 +30,16 @@ convert_cells(std::unique_ptr<Value> &original, vespalib::eval::ValueType want_t
RCT conv = value;
new_cells.push_back(conv);
}
- original = std::make_unique<DenseTensor<RCT>>(want_type, std::move(new_cells));
+ original = std::make_unique<DenseCellsValue<RCT>>(want_type, std::move(new_cells));
}
template<>
void
-convert_cells<float,float>(std::unique_ptr<Value> &, vespalib::eval::ValueType) {}
+convert_cells<float,float>(std::unique_ptr<Value> &, const vespalib::eval::ValueType &) {}
template<>
void
-convert_cells<double,double>(std::unique_ptr<Value> &, vespalib::eval::ValueType) {}
+convert_cells<double,double>(std::unique_ptr<Value> &, const vespalib::eval::ValueType &) {}
struct ConvertCellsSelector
{