Cortenn
eval.hpp
Go to the documentation of this file.
1 
9 #include "ade/traveler.hpp"
10 
11 #include "llo/generated/opmap.hpp"
12 
13 #include "llo/operator.hpp"
14 
15 #ifndef LLO_EVAL_HPP
16 #define LLO_EVAL_HPP
17 
18 namespace llo
19 {
20 
26 struct Evaluator final : public ade::iTraveler
27 {
28  Evaluator (age::_GENERATED_DTYPE dtype) : dtype_(dtype) {}
29 
31  void visit (ade::iLeaf* leaf) override
32  {
33  const char* data = (const char*) leaf->data();
34  age::_GENERATED_DTYPE dtype = (age::_GENERATED_DTYPE) leaf->type_code();
35  const ade::Shape& shape = leaf->shape();
36  out_ = GenericData(shape, dtype_);
37  out_.copyover(data, dtype);
38  }
39 
41  void visit (ade::iFunctor* func) override
42  {
43  age::_GENERATED_OPCODE opcode = (age::_GENERATED_OPCODE)
44  func->get_opcode().code_;
45  out_ = GenericData(func->shape(), dtype_);
46 
47  ade::ArgsT children = func->get_children();
48  uint8_t nargs = children.size();
49  DataArgsT argdata = DataArgsT(nargs);
50  if (func->get_opcode().code_ == age::RAND_BINO)
51  {
52  if (nargs != 2)
53  {
54  logs::fatalf("cannot RAND_BINO without exactly 2 arguments: "
55  "using %d arguments", nargs);
56  }
57  Evaluator left_eval(dtype_);
58  children[0].get_tensor()->accept(left_eval);
59  argdata[0] = {
60  left_eval.out_.data_,
61  left_eval.out_.shape_,
62  children[0].get_coorder(),
63  children[0].map_io(),
64  };
65 
66  Evaluator right_eval(age::DOUBLE);
67  children[1].get_tensor()->accept(right_eval);
68  argdata[1] = DataArg{
69  right_eval.out_.data_,
70  right_eval.out_.shape_,
71  children[1].get_coorder(),
72  children[1].map_io(),
73  };
74  }
75  else
76  {
77  for (uint8_t i = 0; i < nargs; ++i)
78  {
79  Evaluator evaler(dtype_);
80  children[i].get_tensor()->accept(evaler);
81  argdata[i] = DataArg{
82  evaler.out_.data_,
83  evaler.out_.shape_,
84  children[i].get_coorder(),
85  children[i].map_io(),
86  };
87  }
88  }
89 
90  op_exec(opcode, out_.dtype_, out_.data_.get(), out_.shape_, argdata);
91  }
92 
95 
96 private:
98  age::_GENERATED_DTYPE dtype_;
99 };
100 
102 GenericData eval (ade::TensptrT tens, age::_GENERATED_DTYPE dtype);
103 
104 }
105 
106 #endif // LLO_EVAL_HPP
std::vector< DataArg > DataArgsT
Vector of DataArgs to hold arguments.
Definition: data.hpp:241
void copyover(const char *indata, age::_GENERATED_DTYPE intype)
Data to pass around when evaluating.
Definition: data.hpp:224
ade::Shape shape_
Shape of data_.
Definition: data.hpp:38
GenericData out_
Output data evaluated upon visiting node.
Definition: eval.hpp:94
void visit(ade::iLeaf *leaf) override
Implementation of iTraveler.
Definition: eval.hpp:31
Evaluator(age::_GENERATED_DTYPE dtype)
Definition: eval.hpp:28
GenericData eval(ade::TensptrT tens, age::_GENERATED_DTYPE dtype)
Evaluate generic data of tens converted to specified dtype.
GenericData for holding data when passing up the tensor graph.
Definition: data.hpp:24
age::_GENERATED_DTYPE dtype_
Type encoding of data_.
Definition: data.hpp:41
age::_GENERATED_DTYPE dtype_
Output type when evaluating data.
Definition: eval.hpp:98
std::shared_ptr< char > data_
Smartpointer to a block of untyped data.
Definition: data.hpp:35
void visit(ade::iFunctor *func) override
Implementation of iTraveler.
Definition: eval.hpp:41
Definition: data.hpp:20
Definition: eval.hpp:26