Skip to content

Commit

Permalink
preventing copies from happening
Browse files Browse the repository at this point in the history
  • Loading branch information
mdorier committed Jun 24, 2021
1 parent 5ce29fb commit e0e9354
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 13 deletions.
8 changes: 4 additions & 4 deletions include/thallium/callable_remote_procedure.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class callable_remote_procedure_with_context {
double timeout_ms = -1.0) {
hg_return_t ret;
meta_proc_fn mproc = [this, &args](hg_proc_t proc) {
return proc_object(proc, const_cast<std::tuple<T...>&>(args),
return proc_object_encode(proc, const_cast<std::tuple<T...>&>(args),
m_engine_impl, m_context);
};
if(timeout_ms > 0.0) {
Expand Down Expand Up @@ -160,8 +160,8 @@ class callable_remote_procedure_with_context {
hg_return_t ret;
margo_request req;
meta_proc_fn mproc = [this, &args](hg_proc_t proc) {
return proc_object(proc, const_cast<std::tuple<T...>&>(args),
m_engine_impl, m_context);
return proc_object_encode(proc, const_cast<std::tuple<T...>&>(args),
m_engine_impl, m_context);
};
if(timeout_ms > 0.0) {
ret = margo_provider_iforward_timed(
Expand Down Expand Up @@ -311,7 +311,7 @@ class callable_remote_procedure_with_context {
* @return a packed_data object containing the returned value.
*/
template <typename... T> packed_data<> operator()(const T&... args) {
return forward(std::make_tuple<const T&...>(args...));
return forward(std::make_tuple(std::cref(args)...));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion include/thallium/engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ engine::define(const std::string& name,
typename std::decay<Tn>::type...> iargs;
meta_proc_fn mproc = [w_impl, &iargs](hg_proc_t proc) {
auto ctx = std::tuple<>(); // TODO make this context available as argument
return proc_object(proc, iargs, w_impl, ctx);
return proc_object_decode(proc, iargs, w_impl, ctx);
};
hg_return_t ret = margo_get_input(r.m_handle, &mproc);
if(ret != HG_SUCCESS)
Expand Down
6 changes: 3 additions & 3 deletions include/thallium/packed_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ class packed_data {
}
std::tuple<T> t;
meta_proc_fn mproc = [this, &t](hg_proc_t proc) {
return proc_object(proc, t, m_engine_impl, m_context);
return proc_object_decode(proc, t, m_engine_impl, m_context);
};
hg_return_t ret = m_unpack_fn(m_handle, &mproc);
MARGO_ASSERT(ret, m_unpack_fn);
ret = margo_free_output(m_handle, &mproc);
MARGO_ASSERT(ret, m_free_fn);
return std::get<0>(t);
return std::get<0>(std::move(t));
}

/**
Expand Down Expand Up @@ -134,7 +134,7 @@ class packed_data {
typename std::decay<Tn>::type...>
t;
meta_proc_fn mproc = [this, &t](hg_proc_t proc) {
return proc_object(proc, t, m_engine_impl, m_context);
return proc_object_decode(proc, t, m_engine_impl, m_context);
};
hg_return_t ret = m_unpack_fn(m_handle, &mproc);
MARGO_ASSERT(ret, m_unpack_fn);
Expand Down
22 changes: 19 additions & 3 deletions include/thallium/proc_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ inline hg_return_t hg_proc_meta_serialization(hg_proc_t proc, void* data) {
}

template <typename T, typename ... CtxArg>
hg_return_t proc_object(hg_proc_t proc, T& data,
const std::weak_ptr<detail::engine_impl>& e,
std::tuple<CtxArg...>& ctx) {
hg_return_t proc_object_encode(hg_proc_t proc, T& data,
const std::weak_ptr<detail::engine_impl>& e,
std::tuple<CtxArg...>& ctx) {
switch(hg_proc_get_op(proc)) {
case HG_ENCODE: {
proc_output_archive<CtxArg...> ar(proc, ctx, e);
Expand All @@ -69,6 +69,22 @@ hg_return_t proc_object(hg_proc_t proc, T& data,
#endif
ar << data;
} break;
case HG_DECODE:
return HG_INVALID_ARG; // not supposed to happen
case HG_FREE:
default:
break;
}
return HG_SUCCESS;
}

template <typename T, typename ... CtxArg>
hg_return_t proc_object_decode(hg_proc_t proc, T& data,
const std::weak_ptr<detail::engine_impl>& e,
std::tuple<CtxArg...>& ctx) {
switch(hg_proc_get_op(proc)) {
case HG_ENCODE:
return HG_INVALID_ARG; // not supposed to happen
case HG_DECODE: {
proc_input_archive<CtxArg...> ar(proc, ctx, e);
#ifdef THALLIUM_DEBUG_RPC_TYPES
Expand Down
4 changes: 2 additions & 2 deletions include/thallium/request.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ class request_with_context {
"Calling respond from an RPC that has disabled responses");
}
if(m_handle != HG_HANDLE_NULL) {
auto args = std::make_tuple<const T1&, const T&...>(t1, t...);
auto args = std::make_tuple(std::cref(t1), std::cref(t)...);
meta_proc_fn mproc = [this, &args](hg_proc_t proc) {
return proc_object(proc, args, m_engine_impl, m_context);
return proc_object_encode(proc, args, m_engine_impl, m_context);
};
hg_return_t ret = margo_respond(m_handle, &mproc);
MARGO_ASSERT(ret, margo_respond);
Expand Down

0 comments on commit e0e9354

Please sign in to comment.