18 #include <flecsi-config.h> 20 #if !defined(__FLECSI_PRIVATE__) 21 #error Do not include this file directly! 31 #include "flecsi/util/serialize.hh" 35 #if !defined(FLECSI_ENABLE_LEGION) 36 #error FLECSI_ENABLE_LEGION not defined! This file depends on Legion! 46 inline log::devel_tag task_wrapper_tag(
"task_wrapper");
49 template<
class T, std::
size_t Priv>
52 using Rep = std::size_t;
53 static Rep put(
const type & r) {
54 return r.identifier();
56 static type
get(
const Rep & r) {
60 template<
class T, std::
size_t Priv>
63 using Base =
typename type::base_type;
64 static const Base & put(
const type & a) {
67 static type
get(Base b) {
77 static Rep put(
const type &) {
80 static type
get(
const Rep &) {
89 inline task_id_t last_task;
100 template<
typename RETURN, task<RETURN> * TASK, std::
size_t A>
105 template<
class... TT>
107 using type = std::tuple<std::decay_t<TT>...>;
112 tuple_get(
const Legion::Task & t) {
114 const std::byte *b, *e;
115 Check(
const Legion::Task & t)
116 : b(static_cast<const std::byte *>(t.args)), e(b + t.arglen) {}
133 template<auto & F,
size_t A = loc | leaf>
135 extern const task_id_t
140 ++detail::last_task);
142 template<
typename RETURN, task<RETURN> * TASK, std::
size_t A>
145 constexpr
auto processor_type = mask_to_processor_type(A);
146 static_assert(processor_type != task_processor_type_t::mpi,
147 "Legion tasks cannot use MPI");
149 const std::string name = util::symbol<*TASK>();
152 flog_devel(info) <<
"registering pure Legion task " << name << std::endl;
155 Legion::TaskVariantRegistrar registrar(task_id<*TASK, A>, name.c_str());
156 Legion::Processor::Kind kind = processor_type == task_processor_type_t::toc
157 ? Legion::Processor::TOC_PROC
158 : Legion::Processor::LOC_PROC;
159 registrar.add_constraint(Legion::ProcessorConstraint(kind));
160 registrar.set_leaf(leaf_task(A));
161 registrar.set_inner(inner_task(A));
162 registrar.set_idempotent(idempotent_task(A));
170 if constexpr(std::is_same_v<RETURN, void>) {
171 Legion::Runtime::preregister_task_variant<TASK>(registrar, name.c_str());
174 Legion::Runtime::preregister_task_variant<RETURN, TASK>(
175 registrar, name.c_str());
182 verb(
const Legion::Task *,
183 const std::vector<Legion::PhysicalRegion> &,
199 template<auto & F, task_processor_type_t P>
203 using RETURN =
typename Traits::return_type;
204 using param_tuple =
typename Traits::arguments_type;
212 static RETURN
execute(
const Legion::Task * task,
213 const std::vector<Legion::PhysicalRegion> & regions,
214 Legion::Context context,
215 Legion::Runtime * runtime) {
218 flog_devel(info) <<
"In execute_user_task" << std::endl;
224 auto task_args = detail::tuple_get<param_tuple>(*task);
227 bind_accessors.
walk(task_args);
229 if constexpr(std::is_same_v<RETURN, void>) {
230 apply(F, std::forward<param_tuple>(task_args));
237 RETURN result = apply(F, std::forward<param_tuple>(task_args));
252 using RETURN =
typename Traits::return_type;
253 using param_tuple =
typename Traits::arguments_type;
255 static constexpr
auto LegionProcessor = task_processor_type_t::loc;
257 static void execute(
const Legion::Task * task,
258 const std::vector<Legion::PhysicalRegion> &,
269 flog_assert(task->arglen ==
sizeof p,
"Bad Task::arglen");
270 std::memcpy(&p, task->args,
sizeof p);
271 auto & mpi_task_args = *p;
278 auto & c = run::context::instance();
279 c.set_mpi_task([&] { apply(F, std::move(mpi_task_args)); });
Definition: task_wrapper.hh:104
task_processor_type_t
Definition: task_attributes.hh:60
Definition: task_wrapper.hh:200
void register_task()
Definition: task_wrapper.hh:144
static RETURN execute(const Legion::Task *task, const std::vector< Legion::PhysicalRegion > ®ions, Legion::Context context, Legion::Runtime *runtime)
Definition: task_wrapper.hh:212
Definition: serialize.hh:206
decltype(auto) execute(ARGS &&... args)
Definition: execution.hh:382
#define flog_assert(test, message)
Definition: flog.hh:411
std::string type()
Definition: demangle.hh:44
void walk(TUPLE_TYPE &t)
Definition: tuple_walker.hh:75
Definition: function_traits.hh:29
Definition: bind_accessors.hh:51
Definition: control.hh:31