1 #ifndef TTG_PARSEC_PTR_H
2 #define TTG_PARSEC_PTR_H
4 #include <unordered_map>
19 template <
typename Value>
26 static inline std::unordered_map<ptr_impl*, bool> m_ptr_map;
27 static inline std::mutex m_ptr_map_mtx;
32 std::cout <<
"ptr drop_copy " << m_copy <<
" ref " << m_copy->
num_ref() << std::endl;
33 if (
nullptr != m_copy && 1 == m_copy->
drop_ref()) {
39 void register_self() {
41 std::lock_guard _{m_ptr_map_mtx};
42 m_ptr_map.insert(std::pair{
this,
true});
45 void deregister_self() {
47 std::lock_guard _{m_ptr_map_mtx};
48 if (m_ptr_map.contains(
this)) {
49 m_ptr_map.erase(
this);
59 std::cout <<
"ptr copy_obj ref " << m_copy->
num_ref() << std::endl;
71 std::cout <<
"ptr cpy " << m_copy <<
" ref " << m_copy->
num_ref() << std::endl;
79 std::cout <<
"ptr mov " << m_copy <<
" ref " << m_copy->
num_ref() << std::endl;
92 std::cout <<
"ptr cpy " << m_copy <<
" ref " << m_copy->
num_ref() << std::endl;
100 std::cout <<
"ptr mov " << m_copy <<
" ref " << m_copy->
num_ref() << std::endl;
105 return (
nullptr != m_copy);
118 for(
auto it : m_ptr_map) {
119 it.first->drop_copy();
130 template<
typename T,
typename... Args>
135 inline Ptr<std::decay_t<T>>
get_ptr(T&& obj);
145 std::unique_ptr<detail::ptr_impl> m_ptr;
148 template<
typename... Args>
158 : m_ptr(new detail::ptr_impl(copy))
161 copy_type* get_copy()
const {
162 return static_cast<copy_type*
>(m_ptr->get_copy());
185 return **
static_cast<copy_type*
>(m_ptr->get_copy());
189 return **
static_cast<copy_type*
>(m_ptr->get_copy());
193 return m_ptr && m_ptr->is_valid();
203 template<
typename Arg>
204 inline auto get_ptr(Arg&& obj) {
208 if (
nullptr != copy) {
209 if (copy->get_ptr() == &obj) {
210 bool is_ready =
true;
214 for (
auto it : copy) {
215 parsec_data_t *
data = *it;
216 for (
int i = 0; i < parsec_nb_devices; ++i) {
217 if (
nullptr !=
data->device_copies[i]) {
230 throw std::runtime_error(
"ttg::get_ptr called on an unknown object!");
234 template<
typename... Args>
235 inline std::pair<bool, std::tuple<ptr<std::decay_t<Args>>...>>
get_ptr(Args&&... args) {
237 throw std::runtime_error(
"ttg::get_ptr called outside of a task!");
241 auto fn = [&](
auto&& arg){
242 auto pair =
get_ptr(std::forward<decltype(arg)>(arg));
244 return std::move(pair.second);
246 std::tuple<ptr<std::decay_t<Args>>...> tpl = {(fn(std::forward<Args>(args)))...};
247 return {ready, std::move(tpl)};
257 if (
nullptr != copy) {
259 return ptr_type(copy);
266 return ptr_type(copy);
269 template<
typename T,
typename... Args>
constexpr auto data(C &c) -> decltype(c.data())
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)
value_type & operator*() const
friend Ptr< std::decay_t< S > > get_ptr(S &&obj)
value_type & operator->() const
Ptr & operator=(const Ptr &p)
Ptr & operator=(Ptr &&p)=default
friend Ptr< T > make_ptr(Args &&... args)
std::decay_t< T > value_type
ttg_data_copy_t ** copies
static void drop_all_ptr()
ptr_impl(copy_type *copy)
ptr_impl(const ptr_impl &p)
ptr_impl & operator=(const ptr_impl &p)
copy_type * get_copy() const
ptr_impl & operator=(ptr_impl &&p)
virtual void * get_ptr()=0