|
| 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 | +}; |
0 commit comments