Skip to content

Commit 2733608

Browse files
TreeLB changes
1 parent 2d58c2f commit 2733608

File tree

18 files changed

+4168
-11
lines changed

18 files changed

+4168
-11
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ set(src-util-h-sources src/util/SSE-Double.h src/util/SSE-Float.h
779779
src/util/treeStrategy_nodeAware_minBytes.h
780780
src/util/treeStrategy_nodeAware_minGens.h src/util/treeStrategy_topoUnaware.h
781781
src/util/uFcontext.h src/util/uJcontext.h src/util/valgrind.h
782-
src/util/vector2d.h)
782+
src/util/vector2d.h src/util/fastforest.h)
783783

784784
foreach(filename ${src-util-h-sources})
785785
configure_file(${filename} include/ COPYONLY)

cmake/converse.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ set(conv-util-cxx-sources
155155
src/util/pup_util.C
156156
src/util/pup_xlater.C
157157
src/util/spanningTree.C
158+
src/util/fastforest.C
158159
)
159160

160161
if(CMK_CAN_LINK_FORTRAN)

src/ck-ldb/LBManager.C

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ void _loadbalancerInit()
198198
CmiGetArgStringDesc(argv, "+MetaLBModelDir", &_lb_args.metaLbModelDir(),
199199
"Use this directory to read model for MetaLB");
200200

201+
_lb_args.treeMetaLbOn() = CmiGetArgFlagDesc(argv, "+TreeMetaLB", "use MetaLB within TreeLB");
202+
201203
if (_lb_args.metaLbOn() && _lb_args.metaLbModelDir() != nullptr)
202204
{
203205
#if CMK_USE_ZLIB

src/ck-ldb/LBManager.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class CkLBArgs
4040
double _lb_targetRatio; // Specifies the target load ratio for LBs that aim for a
4141
// particular load ratio
4242
bool _lb_metaLbOn;
43+
bool _lb_treeMetaLbOn;
4344
char* _lb_metaLbModelDir;
4445
char* _lb_treeLBFile = (char*)"treelb.json";
4546

@@ -56,6 +57,7 @@ class CkLBArgs
5657
_lb_maxDistPhases = 10;
5758
_lb_targetRatio = 1.05;
5859
_lb_metaLbOn = false;
60+
_lb_treeMetaLbOn = false;
5961
_lb_metaLbModelDir = nullptr;
6062
}
6163
inline char*& treeLBFile() { return _lb_treeLBFile; }
@@ -78,6 +80,7 @@ class CkLBArgs
7880
inline int& maxDistPhases() { return _lb_maxDistPhases; }
7981
inline double& targetRatio() { return _lb_targetRatio; }
8082
inline bool& metaLbOn() { return _lb_metaLbOn; }
83+
inline bool& treeMetaLbOn() {return _lb_treeMetaLbOn; }
8184
inline char*& metaLbModelDir() { return _lb_metaLbModelDir; }
8285
};
8386

src/ck-ldb/MetaBalancer.C

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#define NEGLECT_IDLE 2 // Should never be == 1
2424
#define MIN_STATS 6
2525
#define STATS_COUNT 29 // The number of stats collected during reduction
26+
#define CLASSES 6
2627

2728
#define MAXDOUBLE std::numeric_limits<double>::max()
2829

@@ -36,6 +37,7 @@ using std::max;
3637
CkReductionMsg* lbDataCollection(int nMsg, CkReductionMsg** msgs) {
3738
double *lb_data;
3839
lb_data = (double*)msgs[0]->getData();
40+
lb_data = (double*)msgs[0]->getData();
3941
for (int i = 1; i < nMsg; i++) {
4042
CkAssert(msgs[i]->getSize() == STATS_COUNT*sizeof(double));
4143
if (msgs[i]->getSize() != STATS_COUNT*sizeof(double)) {
@@ -178,6 +180,12 @@ void MetaBalancer::init(void) {
178180
srand(time(NULL));
179181
rFmodel = new ForestModel;
180182
rFmodel->readModel(_lb_args.metaLbModelDir());
183+
184+
std::vector <std::string> features{"f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10", "f11",
185+
"f12", "f13", "f14", "f15", "f16", "f17", "f18", "f19", "f20", "f21", "f22",
186+
"f23", "f24"};
187+
xgboost = fastforest::load_txt("model/model.txt", features, CLASSES);
188+
181189
}
182190
}
183191
}
@@ -295,9 +303,9 @@ bool MetaBalancer::AddLoad(int it_n, double load) {
295303
int index = it_n % VEC_SIZE;
296304
total_count_vec[index]++;
297305
adaptive_struct.total_syncs_called++;
298-
CkPrintf("At PE %d Total contribution for iteration %d is %d \
306+
DEBAD(("At PE %d Total contribution for iteration %d is %d \
299307
total objs %d\n", CkMyPe(), it_n, total_count_vec[index],
300-
lbmanager->GetObjDataSz());
308+
lbmanager->GetObjDataSz()));
301309

302310
if (it_n <= adaptive_struct.finished_iteration_no) {
303311
CkAbort("Error!! Received load for iteration that has contributed\n");
@@ -324,6 +332,7 @@ bool MetaBalancer::AddLoad(int it_n, double load) {
324332
return true;
325333
}
326334

335+
//NOTE: Data Collection
327336
void MetaBalancer::ContributeStats(int it_n) {
328337
#if CMK_LBDB_ON
329338
int index = it_n % VEC_SIZE;
@@ -493,7 +502,7 @@ void MetaBalancer::ReceiveMinStats(double *load, int n) {
493502
// avg_hops, avg_hop_bytes, _lb_args.alpha(), _lb_args.beta(),
494503
// app_iteration_time);
495504

496-
DEBAD(
505+
DEBAD(
497506
("Features:%lf %lf %lf %lf %lf %lf %lf %lf \
498507
%lf %lf %lf %lf %lf %lf %lf %lf %lf \
499508
%lf %lf %lf %lf %lf %lf %lf %d %lf\n",
@@ -532,10 +541,24 @@ void MetaBalancer::ReceiveMinStats(double *load, int n) {
532541
avg_hops,
533542
avg_hop_Kbytes,
534543
comm_comp_ratio};
544+
545+
//Note:Predict LB
535546
// Model returns value [1,num_lbs]
536547
int predicted_lb = rFmodel->forestTest(test_data, 1, 26);
537548
DEBAD(("***********Final classification = %d *****************\n", predicted_lb));
538549

550+
std::vector<double> prob = xgboost.softmax(test_data.data());
551+
int cur_pred = 1;
552+
double cur_prob = 0.0;
553+
for(int i = 0; i < prob.size(); ++i) {
554+
if(prob[i] > cur_prob) {
555+
cur_prob = prob[i];
556+
cur_pred = i+1;
557+
}
558+
}
559+
560+
predicted_lb = cur_pred;
561+
539562
// predicted_lb-1 since predicted_lb class count in the model starts at 1
540563
thisProxy.MetaLBSetLBOnChares(current_balancer, predicted_lb - 1);
541564
current_balancer = predicted_lb - 1;

src/ck-ldb/MetaBalancer.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
#include "LBManager.h"
3434
#include "RandomForestModel.h"
35+
#include "fastforest.h"
3536
#include <vector>
3637

3738
#include "MetaBalancer.decl.h"
@@ -89,7 +90,9 @@ class MetaBalancer : public CBase_MetaBalancer {
8990
MetaBalancer(void) : rFmodel(NULL) { init(); }
9091
MetaBalancer(CkMigrateMessage* m) : CBase_MetaBalancer(m) { init(); }
9192
~MetaBalancer() {
92-
if (CkMyPe() == 0) delete rFmodel;
93+
if (CkMyPe() == 0) {
94+
delete rFmodel;
95+
}
9396
}
9497

9598
private:
@@ -176,6 +179,7 @@ class MetaBalancer : public CBase_MetaBalancer {
176179
int total_ovld_pes;
177180
int current_balancer;
178181
ForestModel* rFmodel;
182+
fastforest::FastForest xgboost;
179183

180184
struct AdaptiveData {
181185
double iteration;

src/ck-ldb/TreeLB.C

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ TreeLB::~TreeLB()
136136
#endif
137137
}
138138

139+
//Note: Each level configured with choice of load balancer
139140
void TreeLB::configure(LBTreeBuilder& builder, json& config)
140141
{
141142
#if CMK_LBDB_ON

src/ck-ldb/TreeLB.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,18 @@
66
#include "BaseLB.h"
77
#include "TreeLB.decl.h"
88
#include "json.hpp"
9+
#include "fastforest.h"
910
#include <vector>
1011
using json = nlohmann::json;
12+
//using namespace rfmodel;
1113

1214
#define DEBUG__TREE_LB_L1 0
1315
#define DEBUG__TREE_LB_L2 0
1416
#define DEBUG__TREE_LB_L3 0
17+
#define STATS_COUNT 29
18+
#define CLASSES 3
19+
20+
extern CkLBArgs _lb_args;
1521

1622
void CreateTreeLB();
1723

@@ -24,12 +30,28 @@ class TreeLBMessage
2430
{
2531
public:
2632
uint8_t level;
33+
//TODO Metabalancer stats
34+
double lb_data[STATS_COUNT];
2735
// WARNING: don't add any virtual methods here
2836
};
2937

3038
class LevelLogic
3139
{
3240
public:
41+
42+
//TODO: Initialize if only Metabalancer called
43+
LevelLogic() {
44+
//rfModel = new ForestModel;
45+
//rfmodel->readModel(_lb_args.metaLbModelDir());
46+
if(_lb_args.treeMetaLbOn()) {
47+
std::vector <std::string> features{"f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10", "f11",
48+
"f12", "f13", "f14", "f15", "f16", "f17", "f18", "f19", "f20", "f21", "f22",
49+
"f23", "f24"};
50+
xgboost = fastforest::load_txt("model_tree/model.txt", features, CLASSES);
51+
}
52+
}
53+
54+
3355
virtual ~LevelLogic() {}
3456

3557
/// return msg with lb stats for this PE. only needed at leaves
@@ -125,6 +147,9 @@ class LevelLogic
125147

126148
protected:
127149
std::vector<TreeLBMessage*> stats_msgs;
150+
//TODO Meta model
151+
//ForestModel* rfmodel;
152+
fastforest::FastForest xgboost;
128153
};
129154

130155
class LBTreeBuilder;
@@ -140,6 +165,7 @@ class TreeLB : public CBase_TreeLB
140165
loadConfigFile(opts);
141166
init(opts);
142167
}
168+
143169
TreeLB(CkMigrateMessage* m) : CBase_TreeLB(m) {}
144170
virtual ~TreeLB();
145171

0 commit comments

Comments
 (0)