13#include <dr/detail/sycl_utils.hpp>
14#include <dr/mp/sycl_support.hpp>
24 if (comm_.rank() == 0) {
25 root_scratchpad_.resize(scratchpad_size_);
26 data = root_scratchpad_.data();
27 size = rng::size(root_scratchpad_) *
sizeof(root_scratchpad_[0]);
29 root_win_.create(comm_, data, size);
39#ifdef SYCL_LANGUAGE_VERSION
41 : sycl_queue_(q), sycl_mem_kind_(kind), dpl_policy_(q), use_sycl_(
true) {
45 sycl::queue sycl_queue_;
46 sycl::usm::alloc sycl_mem_kind_;
47 decltype(oneapi::dpl::execution::make_device_policy(
48 std::declval<sycl::queue>())) dpl_policy_;
51 static constexpr std::size_t scratchpad_size_ = 1000000;
52 bool use_sycl_ =
false;
55 std::set<MPI_Win> wins_;
57 std::vector<char> root_scratchpad_;
62inline bool finalized_ =
false;
63inline bool we_initialized_mpi_ =
false;
65inline auto gcontext() {
66 assert(global_context_ &&
"Call mp::init() after MPI_Init()");
67 return global_context_;
71inline void initialize_mpi() {
73 MPI_Initialized(&initialized);
75 DRLOG(
"initializing MPI");
76 MPI_Init(
nullptr,
nullptr);
77 we_initialized_mpi_ =
true;
79 DRLOG(
"initializing MPI skipped - already initialized");
83 DRLOG(
"calling ishmem_init()");
89inline void finalize_mpi() {
91 MPI_Finalized(&finalized);
93 if (we_initialized_mpi_ && !finalized) {
98 DRLOG(
"calling ishmem_finalize()");
105inline auto root_win() {
return __detail::gcontext()->root_win_; }
106inline dr::communicator &default_comm() {
return __detail::gcontext()->comm_; }
108inline bool finalized() {
return __detail::finalized_; }
109inline std::size_t rank() {
return default_comm().rank(); }
110inline std::size_t nprocs() {
return default_comm().size(); }
112inline std::set<MPI_Win> &active_wins() {
return __detail::gcontext()->wins_; }
114inline void barrier() { __detail::gcontext()->comm_.barrier(); }
115inline auto use_sycl() {
return __detail::gcontext()->use_sycl_; }
119 DRLOG(
"global fence in ISHMEM");
121 DRLOG(
"global fence in ISHMEM finished");
123 for (
auto win : __detail::gcontext()->wins_) {
124 DRLOG(
"global fence, for window:{}", win);
125 MPI_Win_fence(0, win);
127 DRLOG(
"global fence finished");
131 __detail::initialize_mpi();
132 assert(__detail::global_context_ ==
nullptr &&
133 "Do not call mp::init() more than once");
134 __detail::global_context_ =
new __detail::global_context;
137inline void finalize() {
138 assert(__detail::global_context_ !=
nullptr);
139 delete __detail::global_context_;
140 __detail::global_context_ =
nullptr;
141 __detail::finalize_mpi();
142 __detail::finalized_ =
true;
145inline std::string hostname() {
146 constexpr std::size_t MH = 2048;
148 gethostname(buf, MH);
149 return std::string(buf);
152#ifdef SYCL_LANGUAGE_VERSION
153inline sycl::queue &sycl_queue() {
return __detail::gcontext()->sycl_queue_; }
154inline auto sycl_mem_kind() {
return __detail::gcontext()->sycl_mem_kind_; }
155inline auto dpl_policy() {
return __detail::gcontext()->dpl_policy_; }
157inline sycl::queue select_queue(
bool check_different_devices =
false) {
158 std::vector<sycl::device> devices;
160 auto root_devices = sycl::platform().get_devices();
162 for (
auto &&root_device : root_devices) {
163 dr::drlog.debug(
"Root device: {}\n",
164 root_device.get_info<sycl::info::device::name>());
165 if (dr::__detail::partitionable(root_device)) {
166 auto subdevices = root_device.create_sub_devices<
167 sycl::info::partition_property::partition_by_affinity_domain>(
168 sycl::info::partition_affinity_domain::numa);
169 assert(rng::size(subdevices) > 0);
171 for (
auto &&subdevice : subdevices) {
172 dr::drlog.debug(
" add subdevice: {}\n",
173 subdevice.get_info<sycl::info::device::name>());
174 devices.push_back(subdevice);
177 dr::drlog.debug(
" add root device: {}\n",
178 root_device.get_info<sycl::info::device::name>());
179 devices.push_back(root_device);
183 assert(rng::size(devices) > 0);
185 assert(!check_different_devices || my_rank < rng::size(devices));
188 return sycl::queue(devices[my_rank % rng::size(devices)]);
191inline void init(sycl::queue q,
192 sycl::usm::alloc kind = sycl::usm::alloc::shared) {
193 __detail::initialize_mpi();
194 assert(__detail::global_context_ ==
nullptr &&
195 "Do not call mp::init() more than once");
196 __detail::global_context_ =
new __detail::global_context(q, kind);
199template <
typename Selector = decltype(sycl::default_selector_v)>
200inline void init(Selector &&selector = sycl::default_selector_v) {
201 __detail::initialize_mpi();
202 sycl::queue q = mp::select_queue();
207inline auto sycl_queue() {
211inline const auto &dpl_policy() {
213 return std::execution::seq;
Definition: communicator.hpp:13
Definition: communicator.hpp:242
Definition: global.hpp:20