From e1a238c6953a70e1c9e698dabc9229b3c892ea4b Mon Sep 17 00:00:00 2001 From: Joseph Schuchart Date: Sun, 25 Jun 2023 22:19:52 -0400 Subject: [PATCH 1/3] SPMM: take input by reference, not by value Use input_refs_tuple_type instead of input_values_tuple_type. Otherwise inputs will be copied into the tuple, needlessly. Signed-off-by: Joseph Schuchart --- examples/spmm/spmm.cc | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/examples/spmm/spmm.cc b/examples/spmm/spmm.cc index 4403c1012..e8220e841 100644 --- a/examples/spmm/spmm.cc +++ b/examples/spmm/spmm.cc @@ -193,7 +193,7 @@ class Write_SpMatrix : public TT, std::tuple<>, Write_SpMatrix, ttg: Write_SpMatrix(SpMatrix &matrix, Edge, Blk> &in, Keymap2 &&ij_keymap) : baseT(edges(in), edges(), "write_spmatrix", {"Cij"}, {}, ij_keymap), matrix_(matrix) {} - void op(const Key<2> &key, typename baseT::input_values_tuple_type &&elem, std::tuple<> &) { + void op(const Key<2> &key, typename baseT::input_refs_tuple_type &&elem, std::tuple<> &) { std::lock_guard lock(mtx_); ttg::trace("rank =", default_execution_context().rank(), "/ thread_id =", reinterpret_cast(pthread_self()), "spmm.cc Write_SpMatrix wrote {", @@ -310,7 +310,7 @@ class SpMM25D { , b_rowidx_to_colidx_(b_rowidx_to_colidx) , ijk_keymap_(ijk_keymap) {} - void op(const Key<3> &ikp, typename baseT::input_values_tuple_type &&a_ik, std::tuple, Blk>> &a_ijk) { + void op(const Key<3> &ikp, typename baseT::input_refs_tuple_type &&a_ik, std::tuple, Blk>> &a_ijk) { const auto i = ikp[0]; const auto k = ikp[1]; const auto p = ikp[2]; @@ -346,7 +346,7 @@ class SpMM25D { , b_rowidx_to_colidx_(b_rowidx_to_colidx) , ijk_keymap_(ijk_keymap) {} - void op(const Key<2> &ik, typename baseT::input_values_tuple_type &&a_ik, std::tuple, Blk>> &a_ikp) { + void op(const Key<2> &ik, typename baseT::input_refs_tuple_type &&a_ik, std::tuple, Blk>> &a_ikp) { const auto i = ik[0]; const auto k = ik[1]; ttg::trace("BcastA(", i, ", ", k, ")"); @@ -385,7 +385,7 @@ class SpMM25D { , a_colidx_to_rowidx_(a_colidx_to_rowidx) , ijk_keymap_(ijk_keymap) {} - void op(const Key<3> &kjp, typename baseT::input_values_tuple_type &&b_kj, std::tuple, Blk>> &b_ijk) { + void op(const Key<3> &kjp, typename baseT::input_refs_tuple_type &&b_kj, std::tuple, Blk>> &b_ijk) { const auto k = kjp[0]; const auto j = kjp[1]; const auto p = kjp[2]; @@ -420,7 +420,7 @@ class SpMM25D { , a_colidx_to_rowidx_(a_colidx_to_rowidx) , ijk_keymap_(ijk_keymap) {} - void op(const Key<2> &kj, typename baseT::input_values_tuple_type &&b_kj, std::tuple, Blk>> &b_kjp) { + void op(const Key<2> &kj, typename baseT::input_refs_tuple_type &&b_kj, std::tuple, Blk>> &b_kjp) { const auto k = kj[0]; const auto j = kj[1]; // broadcast b_kj to all processors which will contain at least one c_ij such that a_ik exists @@ -489,7 +489,7 @@ class SpMM25D { } } - void op(const Key<3> &ijk, typename baseT::input_values_tuple_type &&_ijk, + void op(const Key<3> &ijk, typename baseT::input_refs_tuple_type &&_ijk, std::tuple, Blk>, Out, Blk>> &result) { const auto i = ijk[0]; const auto j = ijk[1]; @@ -643,7 +643,7 @@ class SpMM25D { ReduceC(Edge, Blk> &c_ij_p, Edge, Blk> &c_ij, const Keymap2 &ij_keymap) : baseT(edges(c_ij_p), edges(c_ij), "SpMM25D::reduce_c", {"c_ij(p)"}, {"c_ij"}, ij_keymap) {} - void op(const Key<2> &ij, typename baseT::input_values_tuple_type &&c_ij_p, std::tuple, Blk>> &c_ij) { + void op(const Key<2> &ij, typename baseT::input_refs_tuple_type &&c_ij_p, std::tuple, Blk>> &c_ij) { ttg::trace("ReduceC(", ij[0], ", ", ij[1], ")"); ::send<0>(ij, baseT::template get<0>(c_ij_p), c_ij); } From 987fc9f850af4e1a37f9396da40aedfcd41aa050 Mon Sep 17 00:00:00 2001 From: Joseph Schuchart Date: Mon, 26 Jun 2023 20:57:54 -0400 Subject: [PATCH 2/3] SPMM: move tiles into send/broadcast Signed-off-by: Joseph Schuchart --- examples/spmm/spmm.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/spmm/spmm.cc b/examples/spmm/spmm.cc index e8220e841..3136fcf92 100644 --- a/examples/spmm/spmm.cc +++ b/examples/spmm/spmm.cc @@ -327,7 +327,7 @@ class SpMM25D { ijk_keys.emplace_back(Key<3>({i, j, k})); } } - ::broadcast<0>(ijk_keys, baseT::template get<0>(a_ik), a_ijk); + ::broadcast<0>(ijk_keys, std::move(baseT::template get<0>(a_ik)), a_ijk); } private: @@ -364,7 +364,7 @@ class SpMM25D { procmap[p] = true; } } - ::broadcast<0>(ikp_keys, baseT::template get<0>(a_ik), a_ikp); + ::broadcast<0>(ikp_keys, std::move(baseT::template get<0>(a_ik)), a_ikp); } private: @@ -401,7 +401,7 @@ class SpMM25D { ijk_keys.emplace_back(Key<3>({i, j, k})); } } - ::broadcast<0>(ijk_keys, baseT::template get<0>(b_kj), b_ijk); + ::broadcast<0>(ijk_keys, std::move(baseT::template get<0>(b_kj)), b_ijk); } private: @@ -437,7 +437,7 @@ class SpMM25D { procmap[p] = true; } } - ::broadcast<0>(kjp_keys, baseT::template get<0>(b_kj), b_kjp); + ::broadcast<0>(kjp_keys, std::move(baseT::template get<0>(b_kj)), b_kjp); } private: @@ -645,7 +645,7 @@ class SpMM25D { void op(const Key<2> &ij, typename baseT::input_refs_tuple_type &&c_ij_p, std::tuple, Blk>> &c_ij) { ttg::trace("ReduceC(", ij[0], ", ", ij[1], ")"); - ::send<0>(ij, baseT::template get<0>(c_ij_p), c_ij); + ::send<0>(ij, std::move(baseT::template get<0>(c_ij_p)), c_ij); } }; // class ReduceC From 27af10bca78788380ca56e6de29f46398487fdc3 Mon Sep 17 00:00:00 2001 From: Eduard Valeyev Date: Thu, 6 Jul 2023 14:53:52 -0400 Subject: [PATCH 3/3] fixup In::broadcast(keylist) --- ttg/ttg/terminal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ttg/ttg/terminal.h b/ttg/ttg/terminal.h index 09ae64cad..f4ed76087 100644 --- a/ttg/ttg/terminal.h +++ b/ttg/ttg/terminal.h @@ -239,7 +239,7 @@ namespace ttg { std::enable_if_t, void> broadcast(const rangeT &keylist, const Value &value) { if (broadcast_callback) { if constexpr (ttg::meta::is_iterable_v) { - broadcast_callback(ttg::span(&(*std::begin(keylist)), std::distance(std::begin(keylist), std::end(keylist))), + broadcast_callback(ttg::span(&(*std::begin(keylist)), std::distance(std::begin(keylist), std::end(keylist))), value); } else { /* got something we cannot iterate over (single element?) so put one element in the span */