Skip to content
This repository was archived by the owner on Jun 20, 2025. It is now read-only.

Commit cfd622c

Browse files
slaxman1978facebook-github-bot
authored andcommitted
T138861426: [Bootcamp][PCF][BE][1/2] Migrate the DotproductGame to use the new API that accepts metric collector. (#1967)
Summary: Pull Request resolved: #1967 X-link: facebookresearch/fbpcf#453 As titled. Reviewed By: xyguo Differential Revision: D41640581 fbshipit-source-id: d55b320cea233003d36fe52171d2c4a6cab58014
1 parent d57d61e commit cfd622c

File tree

5 files changed

+26
-9
lines changed

5 files changed

+26
-9
lines changed

fbpcs/emp_games/dotproduct/DotproductApp.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ class DotproductApp {
5151
->create();
5252

5353
DotproductGame<schedulerId> game(
54-
std::move(scheduler), std::move(communicationAgentFactory_));
54+
std::move(scheduler),
55+
std::move(communicationAgentFactory_),
56+
metricCollector_);
5557

5658
XLOG(INFO) << "Start Reading input file ";
5759
auto inputTuple = readCSVInput(inputFilePath_, labelWidth_, numFeatures_);

fbpcs/emp_games/dotproduct/DotproductGame.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include "folly/logging/xlog.h"
1111

12+
#include <fbpcf/util/MetricCollector.h>
1213
#include "fbpcf/frontend/mpcGame.h"
1314
#include "fbpcs/emp_games/common/Debug.h"
1415
#include "fbpcs/emp_games/common/Util.h"
@@ -23,9 +24,11 @@ class DotproductGame : public fbpcf::frontend::MpcGame<schedulerId> {
2324
std::unique_ptr<fbpcf::scheduler::IScheduler> scheduler,
2425
std::shared_ptr<
2526
fbpcf::engine::communication::IPartyCommunicationAgentFactory>
26-
communicationAgentFactory)
27+
communicationAgentFactory,
28+
std::shared_ptr<fbpcf::util::MetricCollector> metricCollector)
2729
: fbpcf::frontend::MpcGame<schedulerId>(std::move(scheduler)),
28-
communicationAgentFactory_(communicationAgentFactory) {}
30+
communicationAgentFactory_(communicationAgentFactory),
31+
metricCollector_{metricCollector} {}
2932

3033
std::vector<double> computeDotProduct(
3134
const int myRole,
@@ -44,6 +47,8 @@ class DotproductGame : public fbpcf::frontend::MpcGame<schedulerId> {
4447
std::shared_ptr<fbpcf::engine::communication::IPartyCommunicationAgentFactory>
4548
communicationAgentFactory_;
4649

50+
std::shared_ptr<fbpcf::util::MetricCollector> metricCollector_;
51+
4752
std::vector<fbpcf::frontend::Bit<true, schedulerId, true>>
4853
createSecretLabelShare(const std::vector<std::vector<bool>>& labelValues);
4954

fbpcs/emp_games/dotproduct/DotproductGame_impl.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ std::vector<double> DotproductGame<schedulerId>::computeDotProduct(
9595
divisor,
9696
*communicationAgentFactory_,
9797
std::move(prgFactory),
98-
std::move(cotWRMFactory));
98+
std::move(cotWRMFactory),
99+
metricCollector_);
99100

100101
XLOG(INFO, "Created Matrix Multiplication Factory");
101102

@@ -117,7 +118,8 @@ std::vector<double> DotproductGame<schedulerId>::computeDotProduct(
117118
divisor,
118119
*communicationAgentFactory_,
119120
std::move(prgFactory),
120-
std::move(cotWRMFactory));
121+
std::move(cotWRMFactory),
122+
metricCollector_);
121123
XLOG(INFO, "Created Matrix Multiplication Factory");
122124

123125
matMulFactoryPartner->create()->matrixVectorMultiplication(

fbpcs/emp_games/dotproduct/test/DotproductGameTest.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ class MockDotProductGame : public DotproductGame<schedulerId> {
3636
std::unique_ptr<fbpcf::scheduler::IScheduler> scheduler,
3737
std::shared_ptr<
3838
fbpcf::engine::communication::IPartyCommunicationAgentFactory>
39-
communicationAgentFactory)
39+
communicationAgentFactory,
40+
std::shared_ptr<fbpcf::util::MetricCollector> metricCollector)
4041
: DotproductGame<schedulerId>(
4142
std::move(scheduler),
42-
std::move(communicationAgentFactory)) {}
43+
std::move(communicationAgentFactory),
44+
metricCollector) {}
4345

4446
MOCK_METHOD(
4547
std::vector<double>,
@@ -55,8 +57,11 @@ std::vector<bool> runORLabelsGame(
5557
fbpcf::SchedulerCreator schedulerCreator,
5658
std::vector<std::vector<bool>> labels) {
5759
auto scheduler = schedulerCreator(PARTY, *factory);
60+
auto metricCollector =
61+
std::make_shared<fbpcf::util::MetricCollector>("dotproduct_test");
5862

59-
DotproductGame<schedulerId> game(std::move(scheduler), std::move(factory));
63+
DotproductGame<schedulerId> game(
64+
std::move(scheduler), std::move(factory), metricCollector);
6065

6166
// Create label secret shares
6267
auto labelShare = game.createSecretLabelShare(labels);
@@ -84,9 +89,11 @@ std::vector<double> runGame(
8489
std::vector<double> dpNoise) {
8590
auto scheduler = schedulerCreator(PARTY, *factory);
8691

92+
auto metricCollector =
93+
std::make_shared<fbpcf::util::MetricCollector>("dotproduct_test");
8794
// create a mock Dotproduct Game
8895
MockDotProductGame<schedulerId> mockGame(
89-
std::move(scheduler), std::move(factory));
96+
std::move(scheduler), std::move(factory), metricCollector);
9097

9198
// mock the dpNoise generation in DotproductGame
9299
ON_CALL(mockGame, generateDpNoise(numFeatures, delta, eps, addDpNoise))
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[0,0,0,0,0,0,0,0.001448442,0,0,0.06863192,0.14435472,0.033341374,0,0.12865546,0.020235294,0.14462507,0,0.17825273,0,0,0,0.46016255,0,0,0.128087239,0.4376182,0.000390805,0.033707865,0.13740458,0,0.000504521,0.07516815,0.03580519,1,0,0.46016255,0.050997782,0.46016258,0,0.002447232,0,0.8,0,0,0.042172838,0.505038259,0,1,0.1516517]

0 commit comments

Comments
 (0)