21 static bool trace =
false;
26 static bool lazy_pull =
false;
37 std::vector<TerminalBase *> inputs;
38 std::vector<TerminalBase *> outputs;
39 bool trace_instance =
false;
40 const TTBase *owning_ttg =
nullptr;
41 template <
typename input_terminalsT,
typename output_terminalsT>
44 bool executable =
false;
46 bool lazy_pull_instance =
false;
49 static uint64_t next_instance_id() {
50 static uint64_t
id = 0;
56 if (i >= inputs.size())
throw(name +
":TTBase: out of range i setting input");
61 if (i >= outputs.size())
throw(name +
":TTBase: out of range i setting output");
65 template <
bool out,
typename terminalT, std::
size_t i,
typename setfuncT>
67 term.set(
this, i, name, detail::demangled_type_name<typename terminalT::key_type>(),
68 detail::demangled_type_name<typename terminalT::value_type>(),
72 (this->*setfunc)(i, &term);
75 template <
bool out, std::size_t... IS,
typename terminalsT,
typename namesT,
typename setfuncT>
77 const setfuncT setfunc) {
79 0, (register_terminal<out, std::tuple_element_t<IS, terminalsT>, IS>(std::get<IS>(terms), names[IS], setfunc),
85 template <
typename terminalsT,
typename namesT>
87 register_terminals<false>(std::make_index_sequence<std::tuple_size_v<terminalsT>>{}, terms, names,
92 template <
typename terminalsT,
typename namesT>
94 register_terminals<true>(std::make_index_sequence<std::tuple_size_v<terminalsT>>{}, terms, names,
99 template <std::size_t... IS,
typename terminalsT,
typename setfuncT>
100 void set_terminals(std::index_sequence<IS...>, terminalsT &terms,
const setfuncT setfunc) {
101 int junk[] = {0, ((this->*setfunc)(IS, std::get<IS>(terms)), 0)...};
106 template <
typename terminalsT,
typename setfuncT>
108 set_terminals(std::make_index_sequence<std::tuple_size_v<terminalsT>>{}, terms, setfunc);
118 : instance_id(other.instance_id)
119 , is_ttg_(
std::move(other.is_ttg_))
120 , name(
std::move(other.name))
121 , inputs(
std::move(other.inputs))
122 , outputs(
std::move(other.outputs)) {
123 other.instance_id = -1;
126 instance_id = other.instance_id;
127 is_ttg_ = std::move(other.is_ttg_);
128 name = std::move(other.name);
129 inputs = std::move(other.inputs);
130 outputs = std::move(other.outputs);
131 other.instance_id = -1;
135 TTBase(
const std::string &name,
size_t numins,
size_t numouts)
136 : instance_id(next_instance_id()), is_ttg_(false), name(name), inputs(numins), outputs(numouts) {}
139 static thread_local const std::vector<TerminalBase *> *outputs_tls_ptr =
nullptr;
140 return outputs_tls_ptr;
152 std::cerr <<
"TTBase::invoke() invoked on a TT that did not override it" << std::endl;
174 if constexpr (
trace_enabled()) std::swap(trace_instance, value);
187 template <
typename T,
typename... Ts>
188 inline void trace(
const T &t,
const Ts &...ts) {
197 std::swap(lazy_pull_instance, value);
203 std::optional<std::reference_wrapper<const TTBase>>
ttg()
const {
204 return owning_ttg ? std::cref(*owning_ttg) : std::optional<std::reference_wrapper<const TTBase>>{};
216 void set_name(
const std::string &name) { this->name = name; }
219 const std::string &
get_name()
const {
return name; }
222 std::string
get_class_name()
const {
return ttg::detail::demangled_type_name(
this); }
225 const std::vector<TerminalBase *> &
get_inputs()
const {
return inputs; }
228 const std::vector<TerminalBase *> &
get_outputs()
const {
return outputs; }
238 if (i >= inputs.size())
throw name +
":TTBase: you are requesting an input terminal that does not exist";
244 if (i >= outputs.size())
throw name +
"TTBase: you are requesting an output terminal that does not exist";
249 template <std::
size_t i>
255 template <std::
size_t i>
278#define TTG_OP_ASSERT_EXECUTABLE() \
280 if (!this->is_executable()) { \
281 std::ostringstream oss; \
282 oss << "TT is not executable at " << __FILE__ << ":" << __LINE__; \
283 throw std::logic_error(oss.str().c_str()); \
A base class for all template tasks.
void set_terminals(const terminalsT &terms, const setfuncT setfunc)
void set_outputs_tls_ptr(const std::vector< TerminalBase * > *ptr)
virtual ~TTBase()=default
void trace(const T &t, const Ts &...ts)
Like ttg::trace(), but only produces tracing output if this->tracing()==true
TTBase(const std::string &name, size_t numins, size_t numouts)
auto get_instance_id() const
void register_terminal(terminalT &term, const std::string &name, const setfuncT setfunc)
const std::vector< TerminalBase * > & get_outputs() const
Returns the vector of output terminals.
void set_terminals(std::index_sequence< IS... >, terminalsT &terms, const setfuncT setfunc)
bool set_trace_instance(bool value)
virtual void make_executable()=0
Marks this executable.
std::optional< std::reference_wrapper< const TTBase > > ttg() const
ttg::TerminalBase * in(size_t i)
Returns a pointer to the i'th input terminal.
ttg::TerminalBase * out(size_t i)
Returns a pointer to the i'th output terminal.
virtual ttg::World get_world() const =0
TTBase & operator=(TTBase &&other)
ttg::TerminalBase * out()
Returns a pointer to the i'th output terminal ... to make API consistent with TT.
std::string get_class_name() const
Gets the demangled class name (uses RTTI)
bool set_lazy_pull_instance(bool value)
bool is_executable() const
void set_output(size_t i, TerminalBase *t)
void set_name(const std::string &name)
Sets the name of this operation.
ttg::TerminalBase * in()
Returns a pointer to the i'th input terminal ... to make API consistent with TT.
static bool set_lazy_pull(bool value)
static const std::vector< TerminalBase * > *& outputs_tls_ptr_accessor()
static const std::vector< TerminalBase * > * get_outputs_tls_ptr()
Returns this thread's pointer to the vector of output terminals.
const std::vector< TerminalBase * > & get_inputs() const
Returns the vector of input terminals.
static bool set_trace_all(bool value)
void register_input_terminals(terminalsT &terms, const namesT &names)
void register_terminals(std::index_sequence< IS... >, terminalsT &terms, const namesT &names, const setfuncT setfunc)
const TTBase * ttg_ptr() const
const std::string & get_name() const
Gets the name of this operation.
void set_input(size_t i, TerminalBase *t)
void register_output_terminals(terminalsT &terms, const namesT &names)
void set_outputs_tls_ptr()
a template task graph implementation
@ Write
can only be written to
@ Read
can only be used to read immutable data
@ Consume
can only be used to read consumable data
bool & tt_base_trace_accessor(void)
bool & op_base_lazy_pull_accessor(void)
top-level TTG namespace contains runtime-neutral functionality
void abort()
Aborts the TTG program using the default backend's ttg_abort method.
void log(const T &t, const Ts &... ts)
atomically prints to std::clog a sequence of items (separated by ttg::print_separator) followed by st...
bool tracing()
returns whether tracing is enabled
void trace(const T &t, const Ts &... ts)
constexpr bool trace_enabled()
returns whether tracing was enabled at configure time