7#include <memory_resource>
15#include "ddc/chunk_traits.hpp"
16#include "ddc/discrete_vector.hpp"
21static constexpr PDI_inout_t default_access_v
22 = (std::is_lvalue_reference_v<T> && !std::is_const_v<std::remove_reference_t<T>>)
27static constexpr PDI_inout_t chunk_default_access_v = is_writable_chunk_v<T> ? PDI_INOUT : PDI_OUT;
31 std::string m_event_name;
33 std::vector<std::string> m_names;
36 std::pmr::monotonic_buffer_resource m_metadata;
39 explicit PdiEvent(std::string
const& event_name) : m_event_name(event_name) {}
47 PDI_event(m_event_name.c_str());
48 for (std::string
const& one_name : m_names) {
49 PDI_reclaim(one_name.c_str());
63 std::enable_if_t<is_borrowed_chunk_v<BorrowedChunk>,
int> = 0>
64 PdiEvent&
with(std::string
const& name, BorrowedChunk&& data)
67 !(access & PDI_IN) || (chunk_default_access_v<BorrowedChunk> & PDI_IN),
68 "Invalid access for constant data");
69 auto extents = detail::array(data.domain().extents());
70 std::size_t& rank = *std::pmr::polymorphic_allocator<std::size_t>(&m_metadata).allocate(1);
71 rank = extents.size();
72 PDI_share((name +
"_rank").c_str(), &rank, PDI_OUT);
73 m_names.push_back(name +
"_rank");
75 (name +
"_extents").c_str(),
76 std::pmr::vector<std::size_t>(extents.begin(), extents.end(), &m_metadata).data(),
78 m_names.push_back(name +
"_extents");
81 const_cast<chunk_value_t<BorrowedChunk>*>(data.data_handle()),
83 m_names.push_back(name);
90 std::enable_if_t<std::is_arithmetic_v<std::remove_reference_t<Arithmetic>>,
int> = 0>
91 PdiEvent&
with(std::string
const& name, Arithmetic&& data)
94 !(access & PDI_IN) || (default_access_v<Arithmetic> & PDI_IN),
95 "Invalid access for constant data");
96 using value_type = std::remove_cv_t<std::remove_reference_t<Arithmetic>>;
97 value_type* data_ptr =
const_cast<value_type*>(&data);
99 if constexpr (!(access & PDI_IN)) {
100 data_ptr = std::pmr::polymorphic_allocator<value_type>(&m_metadata).allocate(1);
103 PDI_share(name.c_str(), data_ptr, access);
104 m_names.push_back(name);
108 template <PDI_inout_t access,
class T>
111 return with<access>(name, std::forward<T>(t));
119 template <
class BorrowedChunk, std::enable_if_t<is_borrowed_chunk_v<BorrowedChunk>,
int> = 0>
120 PdiEvent&
with(std::string
const& name, BorrowedChunk&& data)
122 return with<chunk_default_access_v<BorrowedChunk>>(name, std::forward<BorrowedChunk>(data));
128 std::enable_if_t<std::is_arithmetic_v<std::remove_reference_t<Arithmetic>>,
int> = 0>
129 PdiEvent&
with(std::string
const& name, Arithmetic&& data)
131 return with<default_access_v<Arithmetic>>(name, std::forward<Arithmetic>(data));
138 return with(name, std::forward<T>(t));
144template <PDI_inout_t access,
class DataType>
147 PdiEvent(name
).with<access>(name, std::forward<DataType>(data));
150template <
class DataType>
153 PdiEvent(name
).with(name, std::forward<DataType>(data));
PdiEvent(PdiEvent const &rhs)=delete
PdiEvent & and_with(std::string const &name, T &&t)
With synonym.
PdiEvent & and_with(std::string const &name, T &&t)
PdiEvent & operator=(PdiEvent &&rhs) noexcept=delete
PdiEvent & operator=(PdiEvent const &rhs)=delete
PdiEvent(std::string const &event_name)
PdiEvent & with(std::string const &name, Arithmetic &&data)
Arithmetic overload.
PdiEvent & with(std::string const &name, BorrowedChunk &&data)
API with access deduction.
PdiEvent & with(std::string const &name, Arithmetic &&data)
PdiEvent & with(std::string const &name, BorrowedChunk &&data)
PdiEvent(PdiEvent &&rhs) noexcept=delete
The top-level namespace of DDC.
void expose_to_pdi(std::string const &name, DataType &&data)
void expose_to_pdi(std::string const &name, DataType &&data)