Skip to content

Commit a2a392e

Browse files
committed
Added a prototype 'simulator' for Chimbuko, providing an interface whereby users can manually provide data to the Chimbuko stack
and produce appropriately processed output
1 parent 2c61fd6 commit a2a392e

21 files changed

Lines changed: 737 additions & 2 deletions

Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
SUBDIRS = include src app test sphinx 3rdparty scripts
1+
SUBDIRS = include src app test sphinx 3rdparty scripts sim
22
nobase_include_HEADERS = chimbuko_config.h
33

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ AC_CONFIG_HEADERS([chimbuko_config.h])
156156
AC_SUBST([PS_FLAGS])
157157

158158
AC_CONFIG_SRCDIR([src/chimbuko.cpp])
159-
AC_CONFIG_FILES([Makefile src/Makefile app/Makefile sphinx/Makefile include/Makefile 3rdparty/Makefile test/Makefile test/unit_tests/Makefile test/unit_tests/ad/Makefile test/unit_tests/util/Makefile test/unit_tests/pserver/Makefile test/unit_tests/net/Makefile test/unit_tests/param/Makefile scripts/Makefile scripts/launch/Makefile])
159+
AC_CONFIG_FILES([Makefile src/Makefile app/Makefile sphinx/Makefile include/Makefile 3rdparty/Makefile test/Makefile test/unit_tests/Makefile test/unit_tests/ad/Makefile test/unit_tests/util/Makefile test/unit_tests/pserver/Makefile test/unit_tests/net/Makefile test/unit_tests/param/Makefile scripts/Makefile scripts/launch/Makefile sim/Makefile sim/src/Makefile sim/main/Makefile])
160160

161161
AC_CONFIG_FILES([app/ws_flask_stat.py:app/ws_flask_stat.py app/sst_view_parse.pl:app/sst_view_parse.pl])
162162
AC_CONFIG_FILES([run_test.sh:run_test.sh test/run_all.sh:test/run_all.sh test/run_ad.sh:test/run_ad.sh test/run_net.sh:test/run_net.sh test/run_provdb_client_test.sh:test/run_provdb_client_test.sh test/run_provdb_autoshutdown_test.sh:test/run_provdb_autoshutdown_test.sh test/unit_tests/run_all.sh:test/unit_tests/run_all.sh test/run_ad_with_provdb.sh:test/run_ad_with_provdb.sh test/run_stat_sender.sh:test/run_stat_sender.sh scripts/launch/run_services.sh:scripts/launch/run_services.sh], [chmod u+x $(echo $ac_tag | sed s/.*\://)])

sim/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SUBDIRS = src main

sim/include/sim.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#pragma once
2+
3+
#include "sim/provdb.hpp"
4+
#include "sim/id_map.hpp"
5+
#include "sim/ad_params.hpp"
6+
#include "sim/pserver.hpp"
7+
#include "sim/event_id_map.hpp"
8+
#include "sim/ad.hpp"
9+
#include "sim/thread_execution_api.hpp"

sim/include/sim/ad.hpp

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#pragma once
2+
3+
#include<chimbuko/ad/ADProvenanceDBclient.hpp>
4+
#include<chimbuko/ad/ADMetadataParser.hpp>
5+
#include<chimbuko/ad/ADNormalEventProvenance.hpp>
6+
#include<chimbuko/ad/ADEvent.hpp>
7+
#include<chimbuko/ad/ADCounter.hpp>
8+
9+
namespace chimbuko_sim{
10+
using namespace chimbuko;
11+
12+
enum class CommType { Send, Recv };
13+
14+
//An object that represents a rank of the AD
15+
class ADsim{
16+
std::unordered_map<unsigned long, std::list<ExecData_t> > m_all_execs; //map of thread to execs, never flushed
17+
std::unordered_map<eventID, CallListIterator_t> m_eventid_map; //map from event index to iterator ; never flushed
18+
std::list<CallListIterator_t> m_step_exec_its; //iterators to events on this io step; flushed at end of step
19+
std::unordered_map<unsigned long, std::vector<CallListIterator_t>> m_step_func_exec_its; //map of function id to iterators on this io step; flushed at end of step
20+
21+
int m_step;
22+
int m_window_size;
23+
int m_pid;
24+
int m_rid;
25+
unsigned long m_step_start_time;
26+
ADNormalEventProvenance m_normal_events;
27+
ADCounter m_counters;
28+
ADMetadataParser m_metadata;
29+
std::unique_ptr<ADProvenanceDBclient> m_pdb_client;
30+
public:
31+
void init(int window_size, int pid, int rid);
32+
33+
ADsim(int window_size, int pid, int rid): ADsim(){
34+
init(window_size, pid, rid);
35+
}
36+
ADsim(){}
37+
38+
ADProvenanceDBclient &getProvDBclient(){ return *m_pdb_client; }
39+
40+
//Add a function execution on a specific thread
41+
CallListIterator_t addExec(const int thread,
42+
const std::string &func_name,
43+
unsigned long start,
44+
unsigned long runtime,
45+
bool is_anomaly,
46+
double outlier_score = 0.);
47+
48+
//Attach a counter to an execution t_delta us after the start of the execution
49+
void attachCounter(const std::string &counter_name,
50+
unsigned long value,
51+
long t_delta,
52+
CallListIterator_t to);
53+
54+
//Attach a communication event to an execution t_delta us after the start of the execution
55+
//partner_rank is the origin rank of a receive or the destination rank of a send
56+
void attachComm(CommType type,
57+
unsigned long partner_rank,
58+
unsigned long bytes,
59+
long t_delta,
60+
CallListIterator_t to);
61+
62+
//Register a thread index as corresponding to a GPU thread, allowing population of GPU information in provenance data
63+
void registerGPUthread(const int tid);
64+
65+
//Register a GPU kernel event as originating from a cpu event
66+
void bindCPUparentGPUkernel(CallListIterator_t cpu_parent, CallListIterator_t gpu_kern);
67+
68+
void beginStep(const unsigned long step_start_time);
69+
70+
void endStep(const unsigned long step_end_time);
71+
};
72+
73+
inline std::ostream & operator<<(std::ostream &os, const CallListIterator_t it){
74+
os << it->get_json(true, true).dump(4);
75+
return os;
76+
}
77+
78+
};

sim/include/sim/ad_params.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include<chimbuko/param/sstd_param.hpp>
2+
#include "id_map.hpp"
3+
4+
namespace chimbuko_sim{
5+
using namespace chimbuko;
6+
7+
inline SstdParam & globalParams(){ static SstdParam p; return p; }
8+
9+
//"register" a function, generating fake statistics given a provided mean and standard deviation
10+
void registerFunc(const std::string &func_name, unsigned long mean_runtime, unsigned long std_dev_runtime, int seen_count);
11+
};

sim/include/sim/event_id_map.hpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include<chimbuko/ad/ADEvent.hpp>
2+
3+
namespace chimbuko_sim{
4+
using namespace chimbuko;
5+
6+
/**
7+
* @brief An implementation of ADEventIDmap interface for the simulator using external maps
8+
*/
9+
class eventIDmap: public ADEventIDmap{
10+
const std::unordered_map<unsigned long, std::list<ExecData_t> > &m_thread_exec_map;
11+
const std::unordered_map<eventID, CallListIterator_t> &m_eventid_map;
12+
13+
public:
14+
eventIDmap(const std::unordered_map<unsigned long, std::list<ExecData_t> > &thread_exec_map,
15+
const std::unordered_map<eventID, CallListIterator_t> &eventid_map): m_thread_exec_map(thread_exec_map), m_eventid_map(eventid_map){}
16+
17+
CallListIterator_t getCallData(const eventID &event_id) const override;
18+
19+
std::pair<CallListIterator_t, CallListIterator_t> getCallWindowStartEnd(const eventID &event_id, const int win_size) const override;
20+
};
21+
22+
};

sim/include/sim/id_map.hpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#pragma once
2+
3+
#include<string>
4+
#include<unordered_map>
5+
6+
namespace chimbuko_sim{
7+
//All functions must be registered
8+
std::unordered_map<std::string, unsigned long> & funcIdxMap();
9+
10+
//Automatically register counter names with indices
11+
class CounterIdxManager{
12+
std::unordered_map<std::string, unsigned long> cid_map;
13+
std::unordered_map<int, std::string> cname_map;
14+
15+
public:
16+
/**
17+
* @brief Get an index for the counter 'cname'. A new index will be generated the first time a counter is seen
18+
*/
19+
long getIndex(const std::string &cname);
20+
21+
const std::unordered_map<int, std::string>* getCounterMap(){ return &cname_map; }
22+
};
23+
24+
inline CounterIdxManager & getCidxManager(){ static CounterIdxManager cman; return cman; }
25+
};

sim/include/sim/provdb.hpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include <sonata/Admin.hpp>
2+
#include <sonata/Provider.hpp>
3+
#include<chimbuko/ad/ADProvenanceDBclient.hpp>
4+
5+
namespace chimbuko_sim{
6+
using namespace chimbuko;
7+
8+
//A class the acts as the provenance database admin
9+
class provDBsim{
10+
private:
11+
sonata::Provider *provider;
12+
sonata::Admin *admin;
13+
sonata::Client *client;
14+
std::string addr;
15+
std::vector<std::string> db_shard_names;
16+
std::vector<sonata::Database> db;
17+
sonata::Database glob_db;
18+
public:
19+
provDBsim(int nshards);
20+
21+
const std::string &getAddr() const{ return addr; }
22+
23+
int getNshards() const{ return db.size(); }
24+
25+
~provDBsim();
26+
};
27+
28+
//Set before first ADsim is created
29+
inline int & nshards(){ static int n=1; return n; }
30+
31+
inline provDBsim & getProvDB(){ static provDBsim pdb(nshards()); return pdb; }
32+
33+
};

sim/include/sim/pserver.hpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#pragma once
2+
3+
#include<chimbuko/pserver/global_anomaly_stats.hpp>
4+
#include<chimbuko/pserver/global_counter_stats.hpp>
5+
6+
namespace chimbuko_sim{
7+
using namespace chimbuko;
8+
9+
//An object that represents the pserver for the purposes of aggregating data over AD instances and writing streaming output to disk
10+
class pserverSim{
11+
GlobalAnomalyStats global_func_stats; //global anomaly statistics
12+
GlobalCounterStats global_counter_stats; //global counter statistics
13+
PSstatSenderGlobalAnomalyStatsPayload anomaly_stats_payload;
14+
PSstatSenderGlobalCounterStatsPayload counter_stats_payload;
15+
public:
16+
17+
pserverSim(): anomaly_stats_payload(&global_func_stats), counter_stats_payload(&global_counter_stats){}
18+
19+
//Stand-in for the func statistics comms from AD -> pserver
20+
void addAnomalyData(const ADLocalFuncStatistics &loc){
21+
global_func_stats.add_anomaly_data(loc);
22+
}
23+
void addCounterData(const ADLocalCounterStatistics &loc){
24+
global_counter_stats.add_counter_data(loc);
25+
}
26+
27+
//Mirror write functionality of PSstatSender
28+
void writeStreamingOutput() const;
29+
};
30+
31+
32+
inline pserverSim & getPserver(){ static pserverSim ps; return ps; }
33+
34+
};

0 commit comments

Comments
 (0)