2#ifndef TTG_PARSEC_PTR_H
3#define TTG_PARSEC_PTR_H
5#include <unordered_map>
20 template <
typename Value>
27 static inline std::unordered_map<ptr_impl*, bool> m_ptr_map;
28 static inline std::mutex m_ptr_map_mtx;
33 std::cout <<
"ptr drop_copy " << m_copy <<
" ref " << m_copy->
num_ref() << std::endl;
34 if (
nullptr != m_copy && 1 == m_copy->
drop_ref()) {
40 void register_self() {
42 std::lock_guard _{m_ptr_map_mtx};
43 m_ptr_map.insert(std::pair{
this,
true});
46 void deregister_self() {
48 std::lock_guard _{m_ptr_map_mtx};
49 if (m_ptr_map.contains(
this)) {
50 m_ptr_map.erase(
this);
60 std::cout <<
"ptr copy_obj ref " << m_copy->
num_ref() << std::endl;
72 std::cout <<
"ptr cpy " << m_copy <<
" ref " << m_copy->
num_ref() << std::endl;
80 std::cout <<
"ptr mov " << m_copy <<
" ref " << m_copy->
num_ref() << std::endl;
93 std::cout <<
"ptr cpy " << m_copy <<
" ref " << m_copy->
num_ref() << std::endl;
101 std::cout <<
"ptr mov " << m_copy <<
" ref " << m_copy->
num_ref() << std::endl;
106 return (
nullptr != m_copy);
119 for(
auto it : m_ptr_map) {
120 it.first->drop_copy();
131 template<
typename T,
typename... Args>
136 inline Ptr<std::decay_t<T>>
get_ptr(T&& obj);
146 std::unique_ptr<detail::ptr_impl> m_ptr;
149 template<
typename... Args>
159 : m_ptr(new detail::ptr_impl(copy))
163 return static_cast<copy_type*
>(m_ptr->get_copy());
186 return **
static_cast<copy_type*
>(m_ptr->get_copy());
190 return **
static_cast<copy_type*
>(m_ptr->get_copy());
194 return m_ptr && m_ptr->is_valid();
204 template<
typename Arg>
205 inline auto get_ptr(Arg&& obj) {
209 if (
nullptr != copy) {
210 if (copy->get_ptr() == &obj) {
211 bool is_ready =
true;
215 for (
auto it : copy) {
216 parsec_data_t *data = *it;
217 for (
int i = 0; i < parsec_nb_devices; ++i) {
218 if (
nullptr != data->device_copies[i]) {
231 throw std::runtime_error(
"ttg::get_ptr called on an unknown object!");
235 template<
typename... Args>
236 inline std::pair<bool, std::tuple<ptr<std::decay_t<Args>>...>>
get_ptr(Args&&... args) {
238 throw std::runtime_error(
"ttg::get_ptr called outside of a task!");
242 auto fn = [&](
auto&& arg){
243 auto pair =
get_ptr(std::forward<
decltype(arg)>(arg));
245 return std::move(pair.second);
247 std::tuple<ptr<std::decay_t<Args>>...> tpl = {(fn(std::forward<Args>(args)))...};
248 return {ready, std::move(tpl)};
258 if (
nullptr != copy) {
260 return ptr_type(copy);
267 return ptr_type(copy);
270 template<
typename T,
typename... Args>
ttg_parsec::detail::ttg_data_copy_t * get_copy(ttg_parsec::Ptr< T > &p)
ttg_data_copy_t * create_new_datacopy(Value &&value)
thread_local parsec_ttg_task_base_t * parsec_ttg_caller
this contains PaRSEC-based TTG functionality
Ptr< std::decay_t< T > > get_ptr(T &&obj)
Ptr< T > make_ptr(Args &&... args)
friend Ptr< T > make_ptr(Args &&... args)
friend detail::ttg_data_copy_t * detail::get_copy(Ptr< S > &p)
Ptr & operator=(const Ptr &p)
value_type & operator*() const
friend Ptr< std::decay_t< S > > get_ptr(S &&obj)
value_type & operator->() const
Ptr & operator=(Ptr &&p)=default
std::decay_t< T > value_type
ttg_data_copy_t ** copies
ptr_impl & operator=(ptr_impl &&p)
static void drop_all_ptr()
ptr_impl(copy_type *copy)
copy_type * get_copy() const
ptr_impl(const ptr_impl &p)
ptr_impl & operator=(const ptr_impl &p)
virtual void * get_ptr()=0