summaryrefslogtreecommitdiffstats
path: root/eval
diff options
context:
space:
mode:
authorArne Juul <arnej@verizonmedia.com>2020-10-19 07:06:39 +0000
committerArne Juul <arnej@verizonmedia.com>2020-10-19 11:47:46 +0000
commit0391088a6ae0b0d3e11a634088141a4bdd3fe660 (patch)
treef38e48615644d74f6aae301ed42d94933b693c65 /eval
parent926970025dd7c5cd8c2a4cf7ae642653d7bb9440 (diff)
add "immediate" forms for generic operations (temporary fallback)
Diffstat (limited to 'eval')
-rw-r--r--eval/src/vespa/eval/instruction/generic_concat.cpp43
-rw-r--r--eval/src/vespa/eval/instruction/generic_concat.h5
-rw-r--r--eval/src/vespa/eval/instruction/generic_join.cpp39
-rw-r--r--eval/src/vespa/eval/instruction/generic_join.h7
-rw-r--r--eval/src/vespa/eval/instruction/generic_map.cpp38
-rw-r--r--eval/src/vespa/eval/instruction/generic_map.h4
-rw-r--r--eval/src/vespa/eval/instruction/generic_merge.cpp21
-rw-r--r--eval/src/vespa/eval/instruction/generic_merge.h7
-rw-r--r--eval/src/vespa/eval/instruction/generic_reduce.cpp34
-rw-r--r--eval/src/vespa/eval/instruction/generic_reduce.h22
-rw-r--r--eval/src/vespa/eval/instruction/generic_rename.cpp22
-rw-r--r--eval/src/vespa/eval/instruction/generic_rename.h6
12 files changed, 218 insertions, 30 deletions
diff --git a/eval/src/vespa/eval/instruction/generic_concat.cpp b/eval/src/vespa/eval/instruction/generic_concat.cpp
index cb8b5ee3b2f..eaa2dbf95ae 100644
--- a/eval/src/vespa/eval/instruction/generic_concat.cpp
+++ b/eval/src/vespa/eval/instruction/generic_concat.cpp
@@ -121,6 +121,15 @@ struct SelectGenericConcatOp {
}
};
+struct PerformGenericConcat {
+ template <typename LCT, typename RCT, typename OCT>
+ static auto invoke(const Value &a, const Value &b, const ConcatParam &param) {
+ return generic_concat<LCT, RCT, OCT>(a, b,
+ param.sparse_plan, param.dense_plan,
+ param.res_type, param.factory);
+ }
+};
+
enum class Case { NONE, OUT, CONCAT, BOTH };
} // namespace <unnamed>
@@ -183,6 +192,21 @@ DenseConcatPlan::InOutLoop::fill_from(const ValueType &in_type,
return std::make_pair(offset_for_concat, output_size_for_concat);
}
+DenseConcatPlan::DenseConcatPlan(const ValueType &lhs_type,
+ const ValueType &rhs_type,
+ std::string concat_dimension,
+ const ValueType &out_type)
+{
+ std::tie(right_offset, output_size) = left.fill_from(lhs_type, concat_dimension, out_type);
+ auto [ other_offset, other_size ] = right.fill_from(rhs_type, concat_dimension, out_type);
+ assert(other_offset > 0);
+ assert(output_size == other_size);
+}
+
+DenseConcatPlan::~DenseConcatPlan() = default;
+DenseConcatPlan::InOutLoop::~InOutLoop() = default;
+
+
InterpretedFunction::Instruction
GenericConcat::make_instruction(const ValueType &lhs_type, const ValueType &rhs_type,
const vespalib::string &dimension,
@@ -195,18 +219,15 @@ GenericConcat::make_instruction(const ValueType &lhs_type, const ValueType &rhs_
return Instruction(fun, wrap_param<ConcatParam>(param));
}
-DenseConcatPlan::DenseConcatPlan(const ValueType &lhs_type,
- const ValueType &rhs_type,
- std::string concat_dimension,
- const ValueType &out_type)
+Value::UP
+GenericConcat::perform_concat(const Value &a, const Value &b,
+ const vespalib::string &dimension,
+ const ValueBuilderFactory &factory)
{
- std::tie(right_offset, output_size) = left.fill_from(lhs_type, concat_dimension, out_type);
- auto [ other_offset, other_size ] = right.fill_from(rhs_type, concat_dimension, out_type);
- assert(other_offset > 0);
- assert(output_size == other_size);
+ ConcatParam param(a.type(), b.type(), dimension, factory);
+ return typify_invoke<3,TypifyCellType,PerformGenericConcat>(
+ a.type().cell_type(), b.type().cell_type(), param.res_type.cell_type(),
+ a, b, param);
}
-DenseConcatPlan::~DenseConcatPlan() = default;
-DenseConcatPlan::InOutLoop::~InOutLoop() = default;
-
} // namespace
diff --git a/eval/src/vespa/eval/instruction/generic_concat.h b/eval/src/vespa/eval/instruction/generic_concat.h
index 5578c5a0dca..d41d161900a 100644
--- a/eval/src/vespa/eval/instruction/generic_concat.h
+++ b/eval/src/vespa/eval/instruction/generic_concat.h
@@ -17,6 +17,11 @@ struct GenericConcat {
make_instruction(const ValueType &lhs_type, const ValueType &rhs_type,
const vespalib::string &dimension,
const ValueBuilderFactory &factory, Stash &stash);
+
+ static Value::UP
+ perform_concat(const Value &a, const Value &b,
+ const vespalib::string &dimension,
+ const ValueBuilderFactory &factory);
};
struct DenseConcatPlan {
diff --git a/eval/src/vespa/eval/instruction/generic_join.cpp b/eval/src/vespa/eval/instruction/generic_join.cpp
index 83c50fdc0a2..c7bb17a808e 100644
--- a/eval/src/vespa/eval/instruction/generic_join.cpp
+++ b/eval/src/vespa/eval/instruction/generic_join.cpp
@@ -24,8 +24,9 @@ namespace {
//-----------------------------------------------------------------------------
template <typename LCT, typename RCT, typename OCT, typename Fun>
-void my_mixed_join_op(State &state, uint64_t param_in) {
- const auto &param = unwrap_param<JoinParam>(param_in);
+Value::UP
+generic_mixed_join(const Value &lhs, const Value &rhs, const JoinParam &param)
+{
Fun fun(param.function);
auto dense_join = [&](const LCT *my_lhs, const RCT *my_rhs, OCT *my_res)
{
@@ -33,8 +34,6 @@ void my_mixed_join_op(State &state, uint64_t param_in) {
*my_res++ = fun(my_lhs[lhs_idx], my_rhs[rhs_idx]);
});
};
- const Value &lhs = state.peek(1);
- const Value &rhs = state.peek(0);
auto lhs_cells = lhs.cells().typify<LCT>();
auto rhs_cells = rhs.cells().typify<RCT>();
SparseJoinState sparse(param.sparse_plan, lhs.index(), rhs.index());
@@ -50,7 +49,16 @@ void my_mixed_join_op(State &state, uint64_t param_in) {
builder->add_subspace(sparse.full_address).begin());
}
}
- auto &result = state.stash.create<std::unique_ptr<Value>>(builder->build(std::move(builder)));
+ return builder->build(std::move(builder));
+};
+
+template <typename LCT, typename RCT, typename OCT, typename Fun>
+void my_mixed_join_op(State &state, uint64_t param_in) {
+ const auto &param = unwrap_param<JoinParam>(param_in);
+ const Value &lhs = state.peek(1);
+ const Value &rhs = state.peek(0);
+ auto up = generic_mixed_join<LCT, RCT, OCT, Fun>(lhs, rhs, param);
+ auto &result = state.stash.create<std::unique_ptr<Value>>(std::move(up));
const Value &result_ref = *(result.get());
state.pop_pop_push(result_ref);
};
@@ -141,6 +149,16 @@ struct SelectGenericJoinOp {
}
};
+struct PerformGenericJoin {
+ template <typename LCT, typename RCT, typename OCT, typename Fun>
+ static auto invoke(const Value &a, const Value &b, const JoinParam &param)
+ {
+ return generic_mixed_join<LCT, RCT, OCT, Fun>(a, b, param);
+ }
+};
+
+
+
//-----------------------------------------------------------------------------
} // namespace <unnamed>
@@ -263,4 +281,15 @@ GenericJoin::make_instruction(const ValueType &lhs_type, const ValueType &rhs_ty
return Instruction(fun, wrap_param<JoinParam>(param));
}
+
+Value::UP
+GenericJoin::perform_join(const Value &a, const Value &b, join_fun_t function,
+ const ValueBuilderFactory &factory)
+{
+ JoinParam param(a.type(), b.type(), function, factory);
+ return typify_invoke<4,JoinTypify,PerformGenericJoin>(
+ a.type().cell_type(), b.type().cell_type(), param.res_type.cell_type(), function,
+ a, b, param);
+}
+
} // namespace
diff --git a/eval/src/vespa/eval/instruction/generic_join.h b/eval/src/vespa/eval/instruction/generic_join.h
index 3b1b4433032..49cdb3499a9 100644
--- a/eval/src/vespa/eval/instruction/generic_join.h
+++ b/eval/src/vespa/eval/instruction/generic_join.h
@@ -18,8 +18,13 @@ using join_fun_t = vespalib::eval::operation::op2_t;
struct GenericJoin {
static InterpretedFunction::Instruction
- make_instruction(const ValueType &lhs_type, const ValueType &rhs_type, join_fun_t function,
+ make_instruction(const ValueType &lhs_type, const ValueType &rhs_type,
+ join_fun_t function,
const ValueBuilderFactory &factory, Stash &stash);
+
+ static Value::UP
+ perform_join(const Value &a, const Value &b, join_fun_t function,
+ const ValueBuilderFactory &factory);
};
//-----------------------------------------------------------------------------
diff --git a/eval/src/vespa/eval/instruction/generic_map.cpp b/eval/src/vespa/eval/instruction/generic_map.cpp
index 7ead705328a..689339af5b3 100644
--- a/eval/src/vespa/eval/instruction/generic_map.cpp
+++ b/eval/src/vespa/eval/instruction/generic_map.cpp
@@ -38,6 +38,36 @@ struct SelectGenericMapOp {
}
};
+struct PerformGenericMap {
+ template <typename CT, typename Func>
+ static auto invoke(const Value &input, map_fun_t function_in,
+ const ValueBuilderFactory &factory)
+ {
+ Func fun(function_in);
+ const auto &type = input.type();
+ size_t subspace_size = type.dense_subspace_size();
+ size_t num_mapped = type.count_mapped_dimensions();
+ auto builder = factory.create_value_builder<CT>(type, num_mapped, subspace_size, input.index().size());
+ auto input_cells = input.cells().typify<CT>();
+ auto view = input.index().create_view({});
+ std::vector<vespalib::stringref> output_address(num_mapped);
+ std::vector<vespalib::stringref *> input_address;
+ for (auto & label : output_address) {
+ input_address.push_back(&label);
+ }
+ view->lookup({});
+ size_t subspace;
+ while (view->next_result(input_address, subspace)) {
+ auto dst = builder->add_subspace(output_address);
+ size_t input_offset = subspace_size * subspace;
+ for (size_t i = 0; i < subspace_size; ++i) {
+ dst[i] = fun(input_cells[input_offset + i]);
+ }
+ }
+ return builder->build(std::move(builder));
+ }
+};
+
} // namespace <unnamed>
using MapTypify = TypifyValue<TypifyCellType,operation::TypifyOp1>;
@@ -49,4 +79,12 @@ GenericMap::make_instruction(const ValueType &lhs_type, map_fun_t function)
return Instruction(op, to_param(function));
}
+Value::UP
+GenericMap::perform_map(const Value &a, map_fun_t function,
+ const ValueBuilderFactory &factory)
+{
+ return typify_invoke<2,MapTypify,PerformGenericMap>(a.type().cell_type(), function,
+ a, function, factory);
+}
+
} // namespace
diff --git a/eval/src/vespa/eval/instruction/generic_map.h b/eval/src/vespa/eval/instruction/generic_map.h
index ad29d2c1073..9c8fb17c153 100644
--- a/eval/src/vespa/eval/instruction/generic_map.h
+++ b/eval/src/vespa/eval/instruction/generic_map.h
@@ -15,6 +15,10 @@ using map_fun_t = vespalib::eval::operation::op1_t;
struct GenericMap {
static InterpretedFunction::Instruction
make_instruction(const ValueType &input_type, map_fun_t function);
+
+ static Value::UP
+ perform_map(const Value &a, map_fun_t function,
+ const ValueBuilderFactory &factory);
};
} // namespace
diff --git a/eval/src/vespa/eval/instruction/generic_merge.cpp b/eval/src/vespa/eval/instruction/generic_merge.cpp
index f54ae651374..51c9dcdbb15 100644
--- a/eval/src/vespa/eval/instruction/generic_merge.cpp
+++ b/eval/src/vespa/eval/instruction/generic_merge.cpp
@@ -122,6 +122,13 @@ struct SelectGenericMergeOp {
}
};
+struct PerformGenericMerge {
+ template <typename LCT, typename RCT, typename OCT, typename Fun>
+ static auto invoke(const Value &a, const Value &b, const MergeParam &param) {
+ return generic_mixed_merge<LCT,RCT,OCT,Fun>(a, b, param);
+ }
+};
+
//-----------------------------------------------------------------------------
} // namespace <unnamed>
@@ -137,4 +144,18 @@ GenericMerge::make_instruction(const ValueType &lhs_type, const ValueType &rhs_t
return Instruction(fun, wrap_param<MergeParam>(param));
}
+
+Value::UP
+GenericMerge::perform_merge(const Value &a, const Value &b, join_fun_t function,
+ const ValueBuilderFactory &factory)
+{
+ MergeParam param(a.type(), b.type(), function, factory);
+ return typify_invoke<4,MergeTypify,PerformGenericMerge>(
+ a.type().cell_type(),
+ b.type().cell_type(),
+ param.res_type.cell_type(), function,
+ a, b, param);
+}
+
+
} // namespace
diff --git a/eval/src/vespa/eval/instruction/generic_merge.h b/eval/src/vespa/eval/instruction/generic_merge.h
index 02e2d18715a..e9ffcc87997 100644
--- a/eval/src/vespa/eval/instruction/generic_merge.h
+++ b/eval/src/vespa/eval/instruction/generic_merge.h
@@ -8,8 +8,13 @@ namespace vespalib::eval::instruction {
struct GenericMerge {
static InterpretedFunction::Instruction
- make_instruction(const ValueType &lhs_type, const ValueType &rhs_type, join_fun_t function,
+ make_instruction(const ValueType &lhs_type, const ValueType &rhs_type,
+ join_fun_t function,
const ValueBuilderFactory &factory, Stash &stash);
+
+ static Value::UP
+ perform_merge(const Value &a, const Value &b, join_fun_t function,
+ const ValueBuilderFactory &factory);
};
} // namespace
diff --git a/eval/src/vespa/eval/instruction/generic_reduce.cpp b/eval/src/vespa/eval/instruction/generic_reduce.cpp
index a76ee322759..305f51ea445 100644
--- a/eval/src/vespa/eval/instruction/generic_reduce.cpp
+++ b/eval/src/vespa/eval/instruction/generic_reduce.cpp
@@ -94,10 +94,9 @@ struct SparseReduceState {
SparseReduceState::~SparseReduceState() = default;
template <typename ICT, typename OCT, typename AGGR>
-void my_generic_reduce_op(State &state, uint64_t param_in) {
- const auto &param = unwrap_param<ReduceParam>(param_in);
+Value::UP
+generic_reduce(const Value &value, const ReduceParam &param) {
SparseReduceState sparse(param.sparse_plan);
- const Value &value = state.peek(0);
sparse.populate_map(value.index().create_view({}));
auto cells = value.cells().typify<ICT>();
AGGR aggr;
@@ -123,7 +122,15 @@ void my_generic_reduce_op(State &state, uint64_t param_in) {
zero[i] = OCT{};
}
}
- auto &result = state.stash.create<std::unique_ptr<Value>>(builder->build(std::move(builder)));
+ return builder->build(std::move(builder));
+}
+
+template <typename ICT, typename OCT, typename AGGR>
+void my_generic_reduce_op(State &state, uint64_t param_in) {
+ const auto &param = unwrap_param<ReduceParam>(param_in);
+ const Value &value = state.peek(0);
+ auto up = generic_reduce<ICT, OCT, AGGR>(value, param);
+ auto &result = state.stash.create<std::unique_ptr<Value>>(std::move(up));
const Value &result_ref = *(result.get());
state.pop_push(result_ref);
};
@@ -134,6 +141,13 @@ struct SelectGenericReduceOp {
}
};
+struct PerformGenericReduce {
+ template <typename ICT, typename OCT, typename AGGR>
+ static auto invoke(const Value &input, const ReduceParam &param) {
+ return generic_reduce<ICT, OCT, typename AGGR::template templ<ICT>>(input, param);
+ }
+};
+
//-----------------------------------------------------------------------------
} // namespace <unnamed>
@@ -213,4 +227,16 @@ GenericReduce::make_instruction(const ValueType &type, Aggr aggr, const std::vec
return Instruction(fun, wrap_param<ReduceParam>(param));
}
+
+Value::UP
+GenericReduce::perform_reduce(const Value &a, Aggr aggr,
+ const std::vector<vespalib::string> &dimensions,
+ const ValueBuilderFactory &factory)
+{
+ ReduceParam param(a.type(), dimensions, factory);
+ return typify_invoke<3,ReduceTypify,PerformGenericReduce>(
+ a.type().cell_type(), param.res_type.cell_type(), aggr,
+ a, param);
+}
+
} // namespace
diff --git a/eval/src/vespa/eval/instruction/generic_reduce.h b/eval/src/vespa/eval/instruction/generic_reduce.h
index e412f8795ac..856cfe362ae 100644
--- a/eval/src/vespa/eval/instruction/generic_reduce.h
+++ b/eval/src/vespa/eval/instruction/generic_reduce.h
@@ -14,14 +14,6 @@ namespace vespalib::eval::instruction {
//-----------------------------------------------------------------------------
-struct GenericReduce {
- static InterpretedFunction::Instruction
- make_instruction(const ValueType &type, Aggr aggr, const std::vector<vespalib::string> &dimensions,
- const ValueBuilderFactory &factory, Stash &stash);
-};
-
-//-----------------------------------------------------------------------------
-
struct DenseReducePlan {
size_t in_size;
size_t out_size;
@@ -51,4 +43,18 @@ struct SparseReducePlan {
//-----------------------------------------------------------------------------
+struct GenericReduce {
+ static InterpretedFunction::Instruction
+ make_instruction(const ValueType &type, Aggr aggr,
+ const std::vector<vespalib::string> &dimensions,
+ const ValueBuilderFactory &factory, Stash &stash);
+
+ static Value::UP
+ perform_reduce(const Value &a, Aggr aggr,
+ const std::vector<vespalib::string> &dimensions,
+ const ValueBuilderFactory &factory);
+};
+
+//-----------------------------------------------------------------------------
+
} // namespace
diff --git a/eval/src/vespa/eval/instruction/generic_rename.cpp b/eval/src/vespa/eval/instruction/generic_rename.cpp
index 1ce18597ec2..3d8de356001 100644
--- a/eval/src/vespa/eval/instruction/generic_rename.cpp
+++ b/eval/src/vespa/eval/instruction/generic_rename.cpp
@@ -107,6 +107,14 @@ struct SelectGenericRenameOp {
}
};
+struct PerformGenericRename {
+ template <typename CT>
+ static auto invoke(const Value &a, const RenameParam &param) {
+ return generic_rename<CT>(a, param.sparse_plan, param.dense_plan,
+ param.res_type, param.factory);
+ }
+};
+
} // namespace <unnamed>
//-----------------------------------------------------------------------------
@@ -186,5 +194,19 @@ GenericRename::make_instruction(const ValueType &lhs_type,
return Instruction(fun, wrap_param<RenameParam>(param));
}
+
+Value::UP
+GenericRename::perform_rename(const Value &a,
+ const std::vector<vespalib::string> &rename_dimension_from,
+ const std::vector<vespalib::string> &rename_dimension_to,
+ const ValueBuilderFactory &factory)
+{
+ RenameParam param(a.type(),
+ rename_dimension_from, rename_dimension_to,
+ factory);
+ return typify_invoke<1,TypifyCellType,PerformGenericRename>(a.type().cell_type(),
+ a, param);
+}
+
} // namespace
diff --git a/eval/src/vespa/eval/instruction/generic_rename.h b/eval/src/vespa/eval/instruction/generic_rename.h
index 6c94ff02b24..4088e817b90 100644
--- a/eval/src/vespa/eval/instruction/generic_rename.h
+++ b/eval/src/vespa/eval/instruction/generic_rename.h
@@ -44,6 +44,12 @@ struct GenericRename {
const std::vector<vespalib::string> &rename_dimension_from,
const std::vector<vespalib::string> &rename_dimension_to,
const ValueBuilderFactory &factory, Stash &stash);
+
+ static Value::UP
+ perform_rename(const Value &a,
+ const std::vector<vespalib::string> &rename_dimension_from,
+ const std::vector<vespalib::string> &rename_dimension_to,
+ const ValueBuilderFactory &factory);
};
} // namespace