Skip to content

Commit 337cf18

Browse files
authored
Merge pull request #36593 from vespa-engine/johsol/wire-first-phase-max
Wire firstPhaseMax into mingle
2 parents 5e86cfa + 403e6b0 commit 337cf18

5 files changed

Lines changed: 31 additions & 6 deletions

File tree

searchcore/src/tests/proton/matching/match_loop_communicator/match_loop_communicator_test.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
22
#include <vespa/searchcore/proton/matching/match_loop_communicator.h>
3+
#include <vespa/searchlib/features/first_phase_max_feature.h>
34
#include <vespa/searchlib/features/first_phase_rank_lookup.h>
45
#include <vespa/searchlib/fef/objectstore.h>
56
#include <vespa/vespalib/gtest/gtest.h>
@@ -17,6 +18,7 @@ using Hits = MatchLoopCommunicator::Hits;
1718
using TaggedHit = MatchLoopCommunicator::TaggedHit;
1819
using TaggedHits = MatchLoopCommunicator::TaggedHits;
1920
using ObjectStore = search::fef::ObjectStore;
21+
using search::features::FirstPhaseMaxBlueprint;
2022
using search::features::FirstPhaseRankLookup;
2123
using search::queryeval::SortedHitSequence;
2224
using vespalib::test::Nexus;
@@ -321,6 +323,19 @@ TEST(MatchLoopCommunicatorTest, require_that_first_phase_rank_lookup_is_populate
321323
EXPECT_EQ(FeatureVec({1, unranked, 3, unranked, 5}), extract_ranks(l2));
322324
}
323325

326+
TEST(MatchLoopCommunicatorTest, require_that_first_phase_max_is_populated)
327+
{
328+
constexpr size_t num_threads = 1;
329+
constexpr size_t thread_id = 0;
330+
ObjectStore store;
331+
FirstPhaseMaxBlueprint::make_shared_state(store);
332+
MatchLoopCommunicator f1(num_threads, 3, {}, &store, do_nothing);
333+
const auto& first_phase_max = *FirstPhaseMaxBlueprint::get_shared_state(store);
334+
auto hits_in = hit_vec({{21, 5}, {22, 4}, {23, 3}, {24, 2}, {25, 1}});
335+
auto result = second_phase(f1, hits_in, thread_id, 10);
336+
EXPECT_EQ(5, first_phase_max);
337+
}
338+
324339
TEST(MatchLoopCommunicatorTest, require_that_before_second_phase_is_called_once)
325340
{
326341
constexpr size_t num_threads = 5;

searchcore/src/vespa/searchcore/proton/matching/match_loop_communicator.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
22

33
#include "match_loop_communicator.h"
4+
#include <vespa/searchlib/features/first_phase_max_feature.h>
45
#include <vespa/searchlib/features/first_phase_rank_lookup.h>
56
#include <vespa/vespalib/util/priority_queue.h>
67
#include <vespa/vespalib/util/rendezvous.hpp>
78

9+
using search::features::FirstPhaseMaxBlueprint;
810
using search::features::FirstPhaseRankLookup;
911

1012
namespace proton:: matching {
@@ -89,9 +91,11 @@ MatchLoopCommunicator::GetSecondPhaseWork::GetSecondPhaseWork(size_t n, size_t t
8991
_diversifier(std::move(diversifier)),
9092
_object_store(object_store),
9193
_first_phase_rank_lookup(nullptr),
94+
_first_phase_max(nullptr),
9295
_before_second_phase(std::move(before_second_phase)) {
9396
if (_object_store) {
9497
_first_phase_rank_lookup = FirstPhaseRankLookup::get_mutable_shared_state(*_object_store);
98+
_first_phase_max = FirstPhaseMaxBlueprint::get_mutable_shared_state(*_object_store);
9599
}
96100
}
97101

@@ -163,6 +167,10 @@ MatchLoopCommunicator::GetSecondPhaseWork::mingle()
163167
} else {
164168
mingle(queue, NoRegisterFirstPhaseRank());
165169
}
170+
171+
if (_first_phase_max != nullptr) {
172+
*_first_phase_max = best_scores.high;
173+
}
166174
}
167175

168176
void

searchcore/src/vespa/searchcore/proton/matching/match_loop_communicator.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class MatchLoopCommunicator final : public IMatchLoopCommunicator
3333
std::unique_ptr<IDiversifier> _diversifier;
3434
IObjectStore* _object_store;
3535
FirstPhaseRankLookup* _first_phase_rank_lookup;
36+
double* _first_phase_max;
3637
std::function<void()> _before_second_phase;
3738
GetSecondPhaseWork(size_t n, size_t topN_in, Range &best_scores_in, BestDropped &best_dropped_in, std::unique_ptr<IDiversifier> diversifier, IObjectStore* object_store, std::function<void()> before_second_phase);
3839
~GetSecondPhaseWork() override;

searchlib/src/vespa/searchlib/features/first_phase_max_feature.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,6 @@ namespace {
4242

4343
const std::string key = "firstPhaseMax";
4444

45-
static void make_shared_state(IObjectStore& store) {
46-
if (store.get(key) == nullptr) {
47-
store.add(key, std::make_unique<AnyWrapper<feature_t>>(-std::numeric_limits<feature_t>::infinity()));
48-
}
49-
}
50-
5145
}
5246

5347
FirstPhaseMaxBlueprint::FirstPhaseMaxBlueprint()
@@ -61,6 +55,12 @@ bool FirstPhaseMaxBlueprint::setup(const IIndexEnvironment&, const ParameterList
6155
return true;
6256
}
6357

58+
void FirstPhaseMaxBlueprint::make_shared_state(IObjectStore& store) {
59+
if (store.get(key) == nullptr) {
60+
store.add(key, std::make_unique<AnyWrapper<feature_t>>(-std::numeric_limits<feature_t>::infinity()));
61+
}
62+
}
63+
6464
const feature_t* FirstPhaseMaxBlueprint::get_shared_state(const IObjectStore& store) {
6565
auto* wrapper = dynamic_cast<const AnyWrapper<feature_t>*>(store.get(key));
6666
if (wrapper != nullptr) {

searchlib/src/vespa/searchlib/features/first_phase_max_feature.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class FirstPhaseMaxBlueprint : public fef::Blueprint {
3030
~FirstPhaseMaxBlueprint() override;
3131

3232
// for tests
33+
static void make_shared_state(fef::IObjectStore& store);
3334
static const feature_t* get_shared_state(const fef::IObjectStore& store);
3435
static feature_t* get_mutable_shared_state(fef::IObjectStore& store);
3536

0 commit comments

Comments
 (0)