Cyclops Tensor Framework
parallel arithmetic on multidimensional arrays
schedule.h
Go to the documentation of this file.
1 #ifndef __SCHEDULE_H__
2 #define __SCHEDULE_H__
3 #include "common.h"
4 #include <queue>
5 #include "idx_tensor.h"
6 
7 namespace CTF {
8 
19 
24  public:
25  virtual ~TensorOperationBase() {}
26  };
27 
35  public:
40  Idx_Tensor* lhs,
41  const CTF_int::Term* rhs) :
42  dependency_count(0),
43  op(op),
44  lhs(lhs),
45  rhs(rhs),
46  cached_estimated_cost(0) {}
47 
51  void get_outputs(std::set<Idx_Tensor*, CTF_int::tensor_name_less >* outputs_set) const;
52 
57  void get_inputs(std::set<Idx_Tensor*, CTF_int::tensor_name_less >* inputs_set) const;
58 
63  void execute(std::map<CTF_int::tensor*, CTF_int::tensor*>* remap = NULL);
64 
68  double estimate_time();
69 
70  bool is_dummy() {
71  return op == TENSOR_OP_NONE;
72  }
73 
77  // Number of dependencies I have
79  // List of all successors - operations that depend on me
80  std::vector<TensorOperation* > successors;
81  std::vector<TensorOperation* > reads;
82 
87 
91  const char* name() {
92  return lhs->parent->name;
93  }
94 
95  protected:
99 
101  };
102 
103  // untemplatized scheduler abstract base class to assist in global operations
104  class ScheduleBase {
105  public:
106  virtual void add_operation(TensorOperationBase* op) = 0;
107  };
108 
110 
111  struct ScheduleTimer {
113  double exec_time;
116  double comm_up_time;
117  double total_time;
118 
120  comm_down_time(0),
121  exec_time(0),
122  imbalance_wall_time(0),
123  imbalance_acuum_time(0),
124  comm_up_time(0),
125  total_time(0) {}
126 
127  void operator+=(ScheduleTimer const & B) {
128  comm_down_time += B.comm_down_time;
129  exec_time += B.exec_time;
130  imbalance_wall_time += B.imbalance_wall_time;
131  imbalance_acuum_time += B.imbalance_acuum_time;
132  comm_up_time += B.comm_up_time;
133  total_time += B.total_time;
134  }
135  };
136 
137 
138  class Schedule : public ScheduleBase {
139  public:
144  Schedule(World* world = NULL) :
145  world(world),
146  partitions(0) {}
147 
152  void record();
153 
157  ScheduleTimer execute();
158 
163  inline ScheduleTimer partition_and_execute();
164 
168  inline void schedule_op_successors(TensorOperation* op);
169 
175  void add_operation_typed(TensorOperation* op);
176  void add_operation(TensorOperationBase* op);
177 
181  void set_max_partitions(int in_partitions) {
182  partitions = in_partitions;
183  }
184 
185  protected:
187 
216  // Tasks with no dependencies, which can be executed at the start
217  std::deque<TensorOperation*> root_tasks;
218 
219  // For debugging purposes - the steps in the original input order
220  std::deque<TensorOperation*> steps_original;
221 
222  // Last operation writing to the key tensor
223  std::map<CTF_int::tensor*, TensorOperation*> latest_write;
224 
228  // Ready queue of tasks with all dependencies satisfied
229  std::deque<TensorOperation*> ready_tasks;
230 
235 
236  };
237 
238 }
244 #endif
a term is an abstract object representing some expression of tensors
Definition: term.h:33
World * world
Definition: schedule.h:186
virtual ~TensorOperationBase()
Definition: schedule.h:25
void operator+=(ScheduleTimer const &B)
Definition: schedule.h:127
const char * name()
Definition: schedule.h:91
double comm_down_time
Definition: schedule.h:112
A tensor operation, containing all the data (op, lhs, rhs) required to run it. Also provides methods ...
Definition: schedule.h:34
an instance of the CTF library (world) on a MPI communicator
Definition: world.h:19
std::deque< TensorOperation * > root_tasks
Definition: schedule.h:217
const CTF_int::Term * rhs
Definition: schedule.h:98
std::deque< TensorOperation * > steps_original
Definition: schedule.h:220
TensorOperation(TensorOperationTypes op, Idx_Tensor *lhs, const CTF_int::Term *rhs)
Constructor, create the tensor operation lhs op= rhs.
Definition: schedule.h:39
std::vector< TensorOperation * > successors
Definition: schedule.h:80
std::map< CTF_int::tensor *, TensorOperation * > latest_write
Definition: schedule.h:223
Schedule(World *world=NULL)
Constructor, optionally specifying a world to restrict processor allocations to.
Definition: schedule.h:144
Provides a untemplated base class for tensor operations.
Definition: schedule.h:23
TensorOperationTypes op
Definition: schedule.h:96
double imbalance_acuum_time
Definition: schedule.h:115
Idx_Tensor * lhs
Definition: schedule.h:97
std::vector< TensorOperation * > reads
Definition: schedule.h:81
Definition: apsp.cxx:17
double cached_estimated_cost
Definition: schedule.h:100
double comm_up_time
Definition: schedule.h:116
double imbalance_wall_time
Definition: schedule.h:114
ScheduleBase * global_schedule
Definition: schedule.cxx:8
int partitions
Definition: schedule.h:234
void set_max_partitions(int in_partitions)
Definition: schedule.h:181
std::deque< TensorOperation * > ready_tasks
Definition: schedule.h:229
a tensor with an index map associated with it (necessary for overloaded operators) ...
Definition: idx_tensor.h:15
TensorOperationTypes
Definition: schedule.h:13