Skip to content

Commit

Permalink
Enable the use of connect<i, j> for dynamic producer/consumer
Browse files Browse the repository at this point in the history
Signed-off-by: Joseph Schuchart <[email protected]>
  • Loading branch information
devreal committed Nov 27, 2023
1 parent 1146810 commit c2f8836
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cmake/modules/ExternalDependenciesVersions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ set(TTG_TRACKED_BOOST_VERSION 1.66)
set(TTG_TRACKED_CATCH2_VERSION 2.13.1)
set(TTG_TRACKED_CEREAL_VERSION 1.3.0)
set(TTG_TRACKED_MADNESS_TAG 31b2470ca722a6a2d84d4de08d32fb72ae8fdeda)
set(TTG_TRACKED_PARSEC_TAG 6a5a986d6ec1f9cace09f3ad475c553632077a24)
set(TTG_TRACKED_PARSEC_TAG 8690b1eb6080500af1ad32ffcd4b95aa38f65c22)
set(TTG_TRACKED_BTAS_TAG d73153ad9bc41a177e441ef04eceff7fab0c766d)
2 changes: 1 addition & 1 deletion cmake/modules/FindOrFetchPARSEC.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ if (NOT TARGET PaRSEC::parsec)

FetchContent_Declare(
PARSEC
GIT_REPOSITORY https://github.com/ICLDisco/parsec.git
GIT_REPOSITORY https://github.com/devreal/parsec-1.git
GIT_TAG ${TTG_TRACKED_PARSEC_TAG}
)
FetchContent_MakeAvailable(PARSEC)
Expand Down
16 changes: 14 additions & 2 deletions tests/unit/tt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ TEST_CASE("TemplateTask", "[core]") {
}
}

//#if 0
#if 0
SECTION("split_construction") {
ttg::Edge<int, float> a2b, b2a;
/* construct without edges */
Expand All @@ -455,5 +455,17 @@ TEST_CASE("TemplateTask", "[core]") {
bool is_executable = ttg::make_graph_executable(tta);
CHECK(is_executable);
}
//#endif // 0
#endif // 0


SECTION("make_connect") {
ttg::Edge<int, float> a2b, b2a;
/* construct without edges */
auto tta = ttg::make_tt([](int key, float value){});
auto ttb = ttg::make_tt([](int key, float value){});
ttg::connect<0, 0>(ttb, tta); // B -> A
ttg::connect<0, 0>(tta, ttb); // A -> B
bool is_executable = ttg::make_graph_executable(tta);
CHECK(is_executable);
}
}
20 changes: 17 additions & 3 deletions ttg/ttg/func.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,25 @@ namespace ttg {
inline void connect(ttg::TerminalBase *out, ttg::TerminalBase *in) { out->connect(in); }

/// \brief Connect producer output terminal outindex to consumer input terminal inindex (via unique or otherwise
/// wrapped pointers to TTs) \tparam outindex The index of the output terminal on the producer. \tparam inindex The
/// index of the input terminal on the consumer. \param p The producer TT \param c The consumer TT
/// wrapped pointers to TTs)
/// \tparam outindex The index of the output terminal on the producer.
/// \tparam inindex The index of the input terminal on the consumer.
/// \param p The producer TT
/// \param c The consumer TT
template <std::size_t outindex, std::size_t inindex, typename producer_tt_ptr, typename successor_tt_ptr>
inline void connect(producer_tt_ptr &p, successor_tt_ptr &s) {
connect(p->template out<outindex>(), s->template in<inindex>());
// check whether the output terminal is available at compile time
using producer_type = typename std::pointer_traits<producer_tt_ptr>::element_type;
if constexpr (std::tuple_size_v<typename producer_type::output_terminals_type> == 0) {
// need to make sure the output terminal is available
using successor_type = typename std::pointer_traits<successor_tt_ptr>::element_type;
using input_terminal_type = std::tuple_element_t<inindex, typename successor_type::input_terminals_type>;
using key_type = typename input_terminal_type::key_type;
using value_type = typename input_terminal_type::value_type;
connect(p->template out<outindex, key_type, value_type>(), s->template in<inindex>());
} else {
connect(p->template out<outindex>(), s->template in<inindex>());
}
}

/// \brief Connect producer output terminal outindex to consumer input terminal inindex (via bare pointers to TTs)
Expand Down
42 changes: 40 additions & 2 deletions ttg/ttg/parsec/ttg.h
Original file line number Diff line number Diff line change
Expand Up @@ -2791,7 +2791,7 @@ namespace ttg_parsec {
, priomap(decltype(keymap)(std::forward<priomapT>(priomap_)))
, static_stream_goal() {
// Cannot call these in base constructor since terminals not yet constructed
if (innames.size() != numinedges) throw std::logic_error("ttg_parsec::TT: #input names != #input terminals");
//if (innames.size() != numinedges) throw std::logic_error("ttg_parsec::TT: #input names != #input terminals");
if (outnames.size() != numouts) throw std::logic_error("ttg_parsec::TT: #output names != #output terminals");

auto &world_impl = world.impl();
Expand Down Expand Up @@ -3021,10 +3021,48 @@ namespace ttg_parsec {
// cannot be copied, moved or assigned.
// Only valid if terminals are provided during construction.
template <std::size_t i>
std::tuple_element_t<i, output_terminalsT> *out() {
auto *out() {
static_assert(std::tuple_size_v<output_terminalsT> > 0,
"TT::out<i>() only available for statically known output terminals. "
"Use TT::out<i, K, V>() instead!");
return &std::get<i>(output_terminals);
}

template <std::size_t i, typename KeyT, typename ValueT>
auto *out(const std::string name = {}) {
using terminal_type = typename ttg::Out<KeyT, ValueT>;
if constexpr (std::tuple_size_v<output_terminalsT> == 0) {
auto& outputs = this->get_outputs();
terminal_type *terminal;
if (outputs.size() <= i || nullptr == outputs[i]) {
// create a new terminal
std::string auto_name;
if (name.empty()) {
auto_name = "DynamicOut" + std::to_string(i);
}
terminal = new terminal_type();
dynamic_outterms.push_back(std::unique_ptr<ttg::TerminalBase>(terminal));
register_terminal<true, terminal_type, i>(*terminal, name.empty() ? auto_name : name, &ttT::set_output_dynamic);
} else {
#ifndef NDEBUG
// use dyanmic cast in debug builds
terminal = dynamic_cast<terminal_type*>(outputs[i]);
if (nullptr == terminal) {
throw std::runtime_error(std::string("TT::out<i, K, V>(): failed to cast existing output terminal ") + std::to_string(i));
}
#else
terminal = static_cast<terminal_type*>(outputs[i]);
#endif // NDEBUG
}
return terminal;
} else {
static_assert(std::is_same_v<terminal_type, std::tuple_element_t<i, output_terminalsT>>,
"TT::out<i, K, V>() key/value types do not match compile-time output terminals.");
return &std::get<i>(output_terminals);
}
}


// Manual injection of a task with all input arguments specified as a tuple
template <typename Key = keyT>
std::enable_if_t<!ttg::meta::is_void_v<Key> && !ttg::meta::is_empty_tuple_v<input_values_tuple_type>, void> invoke(
Expand Down

0 comments on commit c2f8836

Please sign in to comment.