Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ set(src-util-h-sources src/util/SSE-Double.h src/util/SSE-Float.h
src/util/treeStrategy_nodeAware_minBytes.h
src/util/treeStrategy_nodeAware_minGens.h src/util/treeStrategy_topoUnaware.h
src/util/uFcontext.h src/util/uJcontext.h src/util/valgrind.h
src/util/vector2d.h)
src/util/vector2d.h src/util/fastforest.h)

foreach(filename ${src-util-h-sources})
configure_file(${filename} include/ COPYONLY)
Expand Down
1 change: 1 addition & 0 deletions cmake/converse.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ set(conv-util-cxx-sources
src/util/pup_util.C
src/util/pup_xlater.C
src/util/spanningTree.C
src/util/fastforest.C
)

if(CMK_CAN_LINK_FORTRAN)
Expand Down
2 changes: 2 additions & 0 deletions src/ck-ldb/LBManager.C
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ void _loadbalancerInit()
CmiGetArgStringDesc(argv, "+MetaLBModelDir", &_lb_args.metaLbModelDir(),
"Use this directory to read model for MetaLB");

_lb_args.treeMetaLbOn() = CmiGetArgFlagDesc(argv, "+TreeMetaLB", "use MetaLB within TreeLB");

if (_lb_args.metaLbOn() && _lb_args.metaLbModelDir() != nullptr)
{
#if CMK_USE_ZLIB
Expand Down
3 changes: 3 additions & 0 deletions src/ck-ldb/LBManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class CkLBArgs
double _lb_targetRatio; // Specifies the target load ratio for LBs that aim for a
// particular load ratio
bool _lb_metaLbOn;
bool _lb_treeMetaLbOn;
char* _lb_metaLbModelDir;
char* _lb_treeLBFile = (char*)"treelb.json";

Expand All @@ -56,6 +57,7 @@ class CkLBArgs
_lb_maxDistPhases = 10;
_lb_targetRatio = 1.05;
_lb_metaLbOn = false;
_lb_treeMetaLbOn = false;
_lb_metaLbModelDir = nullptr;
}
inline char*& treeLBFile() { return _lb_treeLBFile; }
Expand All @@ -78,6 +80,7 @@ class CkLBArgs
inline int& maxDistPhases() { return _lb_maxDistPhases; }
inline double& targetRatio() { return _lb_targetRatio; }
inline bool& metaLbOn() { return _lb_metaLbOn; }
inline bool& treeMetaLbOn() {return _lb_treeMetaLbOn; }
inline char*& metaLbModelDir() { return _lb_metaLbModelDir; }
};

Expand Down
29 changes: 26 additions & 3 deletions src/ck-ldb/MetaBalancer.C
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#define NEGLECT_IDLE 2 // Should never be == 1
#define MIN_STATS 6
#define STATS_COUNT 29 // The number of stats collected during reduction
#define CLASSES 6

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

Expand All @@ -36,6 +37,7 @@ using std::max;
CkReductionMsg* lbDataCollection(int nMsg, CkReductionMsg** msgs) {
double *lb_data;
lb_data = (double*)msgs[0]->getData();
lb_data = (double*)msgs[0]->getData();
for (int i = 1; i < nMsg; i++) {
CkAssert(msgs[i]->getSize() == STATS_COUNT*sizeof(double));
if (msgs[i]->getSize() != STATS_COUNT*sizeof(double)) {
Expand Down Expand Up @@ -178,6 +180,12 @@ void MetaBalancer::init(void) {
srand(time(NULL));
rFmodel = new ForestModel;
rFmodel->readModel(_lb_args.metaLbModelDir());

std::vector <std::string> features{"f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10", "f11",
"f12", "f13", "f14", "f15", "f16", "f17", "f18", "f19", "f20", "f21", "f22",
"f23", "f24"};
xgboost = fastforest::load_txt("model/model.txt", features, CLASSES);

}
}
}
Expand Down Expand Up @@ -295,9 +303,9 @@ bool MetaBalancer::AddLoad(int it_n, double load) {
int index = it_n % VEC_SIZE;
total_count_vec[index]++;
adaptive_struct.total_syncs_called++;
CkPrintf("At PE %d Total contribution for iteration %d is %d \
DEBAD(("At PE %d Total contribution for iteration %d is %d \
total objs %d\n", CkMyPe(), it_n, total_count_vec[index],
lbmanager->GetObjDataSz());
lbmanager->GetObjDataSz()));

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

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

DEBAD(
DEBAD(
("Features:%lf %lf %lf %lf %lf %lf %lf %lf \
%lf %lf %lf %lf %lf %lf %lf %lf %lf \
%lf %lf %lf %lf %lf %lf %lf %d %lf\n",
Expand Down Expand Up @@ -532,10 +541,24 @@ void MetaBalancer::ReceiveMinStats(double *load, int n) {
avg_hops,
avg_hop_Kbytes,
comm_comp_ratio};

//Note:Predict LB
// Model returns value [1,num_lbs]
int predicted_lb = rFmodel->forestTest(test_data, 1, 26);
DEBAD(("***********Final classification = %d *****************\n", predicted_lb));

std::vector<double> prob = xgboost.softmax(test_data.data());
int cur_pred = 1;
double cur_prob = 0.0;
for(int i = 0; i < prob.size(); ++i) {
if(prob[i] > cur_prob) {
cur_prob = prob[i];
cur_pred = i+1;
}
}

predicted_lb = cur_pred;

// predicted_lb-1 since predicted_lb class count in the model starts at 1
thisProxy.MetaLBSetLBOnChares(current_balancer, predicted_lb - 1);
current_balancer = predicted_lb - 1;
Expand Down
6 changes: 5 additions & 1 deletion src/ck-ldb/MetaBalancer.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include "LBManager.h"
#include "RandomForestModel.h"
#include "fastforest.h"
#include <vector>

#include "MetaBalancer.decl.h"
Expand Down Expand Up @@ -89,7 +90,9 @@ class MetaBalancer : public CBase_MetaBalancer {
MetaBalancer(void) : rFmodel(NULL) { init(); }
MetaBalancer(CkMigrateMessage* m) : CBase_MetaBalancer(m) { init(); }
~MetaBalancer() {
if (CkMyPe() == 0) delete rFmodel;
if (CkMyPe() == 0) {
delete rFmodel;
}
}

private:
Expand Down Expand Up @@ -176,6 +179,7 @@ class MetaBalancer : public CBase_MetaBalancer {
int total_ovld_pes;
int current_balancer;
ForestModel* rFmodel;
fastforest::FastForest xgboost;

struct AdaptiveData {
double iteration;
Expand Down
1 change: 1 addition & 0 deletions src/ck-ldb/TreeLB.C
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ TreeLB::~TreeLB()
#endif
}

//Note: Each level configured with choice of load balancer
void TreeLB::configure(LBTreeBuilder& builder, json& config)
{
#if CMK_LBDB_ON
Expand Down
26 changes: 26 additions & 0 deletions src/ck-ldb/TreeLB.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@
#include "BaseLB.h"
#include "TreeLB.decl.h"
#include "json.hpp"
#include "fastforest.h"
#include <vector>
using json = nlohmann::json;
//using namespace rfmodel;

#define DEBUG__TREE_LB_L1 0
#define DEBUG__TREE_LB_L2 0
#define DEBUG__TREE_LB_L3 0
#define STATS_COUNT 29
#define CLASSES 3

extern CkLBArgs _lb_args;

void CreateTreeLB();

Expand All @@ -24,12 +30,28 @@ class TreeLBMessage
{
public:
uint8_t level;
//TODO Metabalancer stats
double lb_data[STATS_COUNT];
// WARNING: don't add any virtual methods here
};

class LevelLogic
{
public:

//TODO: Initialize if only Metabalancer called
LevelLogic() {
//rfModel = new ForestModel;
//rfmodel->readModel(_lb_args.metaLbModelDir());
if(_lb_args.treeMetaLbOn()) {
std::vector <std::string> features{"f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10", "f11",
"f12", "f13", "f14", "f15", "f16", "f17", "f18", "f19", "f20", "f21", "f22",
"f23", "f24"};
xgboost = fastforest::load_txt("model_tree/model.txt", features, CLASSES);
}
}


virtual ~LevelLogic() {}

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

protected:
std::vector<TreeLBMessage*> stats_msgs;
//TODO Meta model
//ForestModel* rfmodel;
fastforest::FastForest xgboost;
};

class LBTreeBuilder;
Expand All @@ -140,6 +165,7 @@ class TreeLB : public CBase_TreeLB
loadConfigFile(opts);
init(opts);
}

TreeLB(CkMigrateMessage* m) : CBase_TreeLB(m) {}
virtual ~TreeLB();

Expand Down
Loading