• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

celerity / celerity-runtime / 11235529684

08 Oct 2024 12:34PM UTC coverage: 95.102% (+0.02%) from 95.087%
11235529684

push

github

fknorr
Update changelog for optional MPI

3017 of 3416 branches covered (88.32%)

Branch coverage included in aggregate %.

6633 of 6731 relevant lines covered (98.54%)

1480223.86 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.65
/src/runtime.cc
1
#include "runtime.h"
2

3
#include <limits>
4
#include <string>
5

6
#ifdef _MSC_VER
7
#include <process.h>
8
#else
9
#include <unistd.h>
10
#endif
11

12
#if CELERITY_USE_MIMALLOC
13
// override default new/delete operators to use the mimalloc memory allocator
14
#include <mimalloc-new-delete.h>
15
#endif
16

17
#include "affinity.h"
18
#include "backend/sycl_backend.h"
19
#include "cgf_diagnostics.h"
20
#include "command_graph_generator.h"
21
#include "device_selection.h"
22
#include "dry_run_executor.h"
23
#include "host_object.h"
24
#include "instruction_graph_generator.h"
25
#include "live_executor.h"
26
#include "log.h"
27
#include "print_graph.h"
28
#include "reduction.h"
29
#include "scheduler.h"
30
#include "system_info.h"
31
#include "task_manager.h"
32
#include "tracy.h"
33
#include "version.h"
34

35
#if CELERITY_ENABLE_MPI
36
#include "mpi_communicator.h"
37
#include <mpi.h>
38
#else
39
#include "local_communicator.h"
40
#endif
41

42

43
namespace celerity {
44
namespace detail {
45

46
        std::unique_ptr<runtime> runtime::s_instance = nullptr;
47

48
        void runtime::mpi_initialize_once(int* argc, char*** argv) {
56✔
49
#if CELERITY_ENABLE_MPI
50
                CELERITY_DETAIL_TRACY_ZONE_SCOPED_V("mpi::init", LightSkyBlue, "MPI_Init");
51
                assert(!s_mpi_initialized);
56✔
52
                int provided;
56✔
53
                MPI_Init_thread(argc, argv, MPI_THREAD_MULTIPLE, &provided);
56✔
54
                assert(provided == MPI_THREAD_MULTIPLE);
56✔
55
#endif // CELERITY_ENABLE_MPI
56
                s_mpi_initialized = true;
56✔
57
        }
56✔
58

59
        void runtime::mpi_finalize_once() {
56✔
60
#if CELERITY_ENABLE_MPI
61
                CELERITY_DETAIL_TRACY_ZONE_SCOPED_V("mpi::finalize", LightSkyBlue, "MPI_Finalize");
62
                assert(s_mpi_initialized && !s_mpi_finalized && (!s_test_mode || !s_instance));
56✔
63
                MPI_Finalize();
56✔
64
#endif // CELERITY_ENABLE_MPI
65
                s_mpi_finalized = true;
56✔
66
        }
56✔
67

68
        void runtime::init(int* argc, char** argv[], const devices_or_selector& user_devices_or_selector) {
223✔
69
                assert(!s_instance);
223✔
70
                s_instance = std::unique_ptr<runtime>(new runtime(argc, argv, user_devices_or_selector));
223!
71
        }
223✔
72

73
        runtime& runtime::get_instance() {
5,493✔
74
                if(s_instance == nullptr) { throw std::runtime_error("Runtime has not been initialized"); }
5,493!
75
                return *s_instance;
5,493✔
76
        }
77

78
        static auto get_pid() {
223✔
79
#ifdef _MSC_VER
80
                return _getpid();
81
#else
82
                return getpid();
223✔
83
#endif
84
        }
85

86
        static std::string get_version_string() {
223✔
87
                using namespace celerity::version;
88
                return fmt::format("{}.{}.{} {}{}", major, minor, patch, git_revision, git_dirty ? "-dirty" : "");
446!
89
        }
90

91
        static const char* get_build_type() {
223✔
92
#if CELERITY_DETAIL_ENABLE_DEBUG
93
                return "debug";
223✔
94
#else
95
                return "release";
96
#endif
97
        }
98

99
        static const char* get_mimalloc_string() {
223✔
100
#if CELERITY_USE_MIMALLOC
101
                return "using mimalloc";
102
#else
103
                return "using the default allocator";
223✔
104
#endif
105
        }
106

107
        static std::string get_sycl_version() {
223✔
108
#if CELERITY_SYCL_IS_ACPP
109
                return fmt::format("AdaptiveCpp {}.{}.{}", HIPSYCL_VERSION_MAJOR, HIPSYCL_VERSION_MINOR, HIPSYCL_VERSION_PATCH);
110
#elif CELERITY_SYCL_IS_DPCPP
111
                return "DPC++ / Clang " __clang_version__;
112
#elif CELERITY_SYCL_IS_SIMSYCL
113
                return "SimSYCL " SIMSYCL_VERSION;
669✔
114
#else
115
#error "unknown SYCL implementation"
116
#endif
117
        }
118

119
        static std::string get_mpi_version() {
223✔
120
#if CELERITY_ENABLE_MPI
121
                char version[MPI_MAX_LIBRARY_VERSION_STRING];
223✔
122
                int len = -1;
223✔
123
                MPI_Get_library_version(version, &len);
223✔
124
                // try shortening the human-readable version string (so far tested on OpenMPI)
125
                if(const auto brk = /* find last of */ strpbrk(version, ",;")) { len = static_cast<int>(brk - version); }
223!
126
                return std::string(version, static_cast<size_t>(len));
892✔
127
#else
128
                return "single node";
129
#endif
130
        }
131

132
        static host_config get_mpi_host_config() {
217✔
133
#if CELERITY_ENABLE_MPI
134
                // Determine the "host config", i.e., how many nodes are spawned on this host,
135
                // and what this node's local rank is. We do this by finding all world-ranks
136
                // that can use a shared-memory transport (if running on OpenMPI, use the
137
                // per-host split instead).
138
#ifdef OPEN_MPI
139
#define SPLIT_TYPE OMPI_COMM_TYPE_HOST
140
#else
141
                // TODO: Assert that shared memory is available (i.e. not explicitly disabled)
142
#define SPLIT_TYPE MPI_COMM_TYPE_SHARED
143
#endif
144
                MPI_Comm host_comm = nullptr;
217✔
145
                MPI_Comm_split_type(MPI_COMM_WORLD, SPLIT_TYPE, 0, MPI_INFO_NULL, &host_comm);
217✔
146

147
                int local_rank = 0;
217✔
148
                MPI_Comm_rank(host_comm, &local_rank);
217✔
149

150
                int node_count = 0;
217✔
151
                MPI_Comm_size(host_comm, &node_count);
217✔
152

153
                host_config host_cfg;
217✔
154
                host_cfg.local_rank = local_rank;
217✔
155
                host_cfg.node_count = node_count;
217✔
156

157
                MPI_Comm_free(&host_comm);
217✔
158

159
                return host_cfg;
434✔
160
#else  // CELERITY_ENABLE_MPI
161
                return host_config{1, 0};
162
#endif // CELERITY_ENABLE_MPI
163
        }
164

165
        runtime::runtime(int* argc, char** argv[], const devices_or_selector& user_devices_or_selector) {
223✔
166
                m_application_thread = std::this_thread::get_id();
223✔
167

168
                m_cfg = std::make_unique<config>(argc, argv);
223✔
169

170
                CELERITY_DETAIL_IF_TRACY_SUPPORTED(tracy_detail::g_tracy_mode = m_cfg->get_tracy_mode());
171
                CELERITY_DETAIL_TRACY_ZONE_SCOPED("runtime::startup", DarkGray);
172

173
                if(s_test_mode) {
223✔
174
                        assert(s_test_active && "initializing the runtime from a test without a runtime_fixture");
180✔
175
                        s_test_runtime_was_instantiated = true;
180✔
176
                } else {
177
                        mpi_initialize_once(argc, argv);
43✔
178
                }
179

180
                int world_size = 1;
223✔
181
                int world_rank = 0;
223✔
182
#if CELERITY_ENABLE_MPI
183
                MPI_Comm_size(MPI_COMM_WORLD, &world_size);
223✔
184
                MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
223✔
185
#endif
186

187
                host_config host_cfg;
223✔
188
                if(m_cfg->is_dry_run()) {
223✔
189
                        if(world_size != 1) throw std::runtime_error("In order to run with CELERITY_DRY_RUN_NODES a single MPI process/rank must be used.");
6!
190
                        m_num_nodes = static_cast<size_t>(m_cfg->get_dry_run_nodes());
6✔
191
                        m_local_nid = 0;
6✔
192
                        host_cfg.node_count = 1;
6✔
193
                        host_cfg.local_rank = 0;
6✔
194
                } else {
195
                        m_num_nodes = static_cast<size_t>(world_size);
217✔
196
                        m_local_nid = static_cast<node_id>(world_rank);
217✔
197
                        host_cfg = get_mpi_host_config();
217✔
198
                }
199

200
                // Do not touch logger settings in tests, where the full (trace) logs are captured
201
                if(!s_test_mode) {
223✔
202
                        spdlog::set_level(m_cfg->get_log_level());
43✔
203
                        spdlog::set_pattern(fmt::format("[%Y-%m-%d %H:%M:%S.%e] [{:0{}}] [%^%l%$] %v", m_local_nid, int(ceil(log10(double(m_num_nodes))))));
86✔
204
                }
205

206
                CELERITY_INFO("Celerity runtime version {} running on {} / {}. PID = {}, build type = {}, {}", get_version_string(), get_sycl_version(),
223✔
207
                    get_mpi_version(), get_pid(), get_build_type(), get_mimalloc_string());
208

209
#ifndef __APPLE__
210
                if(const uint32_t cores = affinity_cores_available(); cores < min_cores_needed) {
223!
211
                        CELERITY_WARN("Celerity has detected that only {} logical cores are available to this process. It is recommended to assign at least {} "
×
212
                                      "logical cores. Performance may be negatively impacted.",
213
                            cores, min_cores_needed);
214
                }
215
#endif
216

217
                if(!s_test_mode && m_cfg->get_tracy_mode() != tracy_mode::off) {
223!
218
                        if constexpr(CELERITY_TRACY_SUPPORT) {
219
                                CELERITY_WARN("Profiling with Tracy is enabled. Performance may be negatively impacted.");
220
                        } else {
221
                                CELERITY_WARN("CELERITY_TRACY is set, but Celerity was compiled without Tracy support. Ignoring.");
×
222
                        }
223
                }
224

225
                cgf_diagnostics::make_available();
223✔
226

227
                std::vector<sycl::device> devices;
223✔
228
                {
229
                        CELERITY_DETAIL_TRACY_ZONE_SCOPED("runtime::pick_devices", PaleVioletRed);
230
                        devices = std::visit([&](const auto& value) { return pick_devices(host_cfg, value, sycl::platform::get_platforms()); }, user_devices_or_selector);
446✔
231
                        assert(!devices.empty()); // postcondition of pick_devices
223✔
232
                }
233

234
                auto backend = make_sycl_backend(select_backend(sycl_backend_enumerator{}, devices), devices, m_cfg->should_enable_device_profiling());
223✔
235
                const auto system = backend->get_system_info(); // backend is about to be moved
223✔
236

237
                if(m_cfg->is_dry_run()) {
223✔
238
                        m_exec = std::make_unique<dry_run_executor>(static_cast<executor::delegate*>(this));
6✔
239
                } else {
240
#if CELERITY_ENABLE_MPI
241
                        auto comm = std::make_unique<mpi_communicator>(collective_clone_from, MPI_COMM_WORLD);
217✔
242
#else
243
                        auto comm = std::make_unique<local_communicator>();
244
#endif
245
                        m_exec = std::make_unique<live_executor>(std::move(backend), std::move(comm), static_cast<executor::delegate*>(this));
217✔
246
                }
217✔
247

248
                if(m_cfg->should_record()) {
223✔
249
                        m_task_recorder = std::make_unique<task_recorder>();
16✔
250
                        m_command_recorder = std::make_unique<command_recorder>();
16✔
251
                        m_instruction_recorder = std::make_unique<instruction_recorder>();
16✔
252
                }
253

254
                task_manager::policy_set task_mngr_policy;
223✔
255
                // Merely _declaring_ an uninitialized read is legitimate as long as the kernel does not actually perform the read at runtime - this might happen in the
256
                // first iteration of a submit-loop. We could get rid of this case by making access-modes a runtime property of accessors (cf
257
                // https://github.com/celerity/meta/issues/74).
258
                task_mngr_policy.uninitialized_read_error = CELERITY_ACCESS_PATTERN_DIAGNOSTICS ? error_policy::log_warning : error_policy::ignore;
223✔
259

260
                m_task_mngr = std::make_unique<task_manager>(m_num_nodes, m_task_recorder.get(), task_mngr_policy);
223✔
261
                if(m_cfg->get_horizon_step()) m_task_mngr->set_horizon_step(m_cfg->get_horizon_step().value());
223!
262
                if(m_cfg->get_horizon_max_parallelism()) m_task_mngr->set_horizon_max_parallelism(m_cfg->get_horizon_max_parallelism().value());
223!
263

264
                scheduler::policy_set schdlr_policy;
223✔
265
                // Any uninitialized read that is observed on CDAG generation was already logged on task generation, unless we have a bug.
266
                schdlr_policy.command_graph_generator.uninitialized_read_error = error_policy::ignore;
223✔
267
                schdlr_policy.instruction_graph_generator.uninitialized_read_error = error_policy::ignore;
223✔
268
                schdlr_policy.command_graph_generator.overlapping_write_error = CELERITY_ACCESS_PATTERN_DIAGNOSTICS ? error_policy::log_error : error_policy::ignore;
223✔
269
                schdlr_policy.instruction_graph_generator.overlapping_write_error =
223✔
270
                    CELERITY_ACCESS_PATTERN_DIAGNOSTICS ? error_policy::log_error : error_policy::ignore;
271
                schdlr_policy.instruction_graph_generator.unsafe_oversubscription_error = error_policy::log_warning;
223✔
272

273
                m_schdlr = std::make_unique<scheduler>(m_num_nodes, m_local_nid, system, *m_task_mngr, static_cast<abstract_scheduler::delegate*>(this),
892✔
274
                    m_command_recorder.get(), m_instruction_recorder.get(), schdlr_policy);
669✔
275
                m_task_mngr->register_task_callback([this](const task* tsk) { m_schdlr->notify_task_created(tsk); });
5,302✔
276

277
                m_num_local_devices = system.devices.size();
223✔
278
        }
446✔
279

280
        void runtime::require_call_from_application_thread() const {
5,864✔
281
                if(std::this_thread::get_id() != m_application_thread) {
5,864✔
282
                        utils::panic("Celerity runtime, distr_queue, handler, buffer and host_object types must only be constructed, used, and destroyed from the "
40✔
283
                                     "application thread. Make sure that you did not accidentally capture one of these types in a host_task.");
284
                }
285
        }
5,854✔
286

287
        runtime::~runtime() {
223✔
288
                // LCOV_EXCL_START
289
                if(!is_unreferenced()) {
290
                        // this call might originate from static destruction - we cannot assume spdlog to still be around
291
                        utils::panic("Detected an attempt to destroy runtime while at least one distr_queue, buffer or host_object was still alive. This likely means "
292
                                     "that one of these objects was leaked, or at least its lifetime extended beyond the scope of main(). This is undefined.");
293
                }
294
                // LCOV_EXCL_STOP
295

296
                require_call_from_application_thread();
223✔
297

298
                CELERITY_DETAIL_TRACY_ZONE_SCOPED("runtime::shutdown", DimGray);
299

300
                // Create and await the shutdown epoch
301
                sync(epoch_action::shutdown);
223✔
302

303
                // The shutdown epoch is, by definition, the last task (and command / instruction) issued. Since it has now completed, no more scheduler -> executor
304
                // traffic will occur, and `runtime` can stop functioning as a scheduler_delegate (which would require m_exec to be live).
305
                m_exec.reset();
223✔
306

307
                // ~executor() joins its thread after notifying the scheduler that the shutdown epoch has been reached, which means that this notification is
308
                // sequenced-before the destructor return, and `runtime` can now stop functioning as an executor_delegate (which would require m_schdlr to be live).
309
                m_schdlr.reset();
223✔
310

311
                // Since scheduler and executor threads are gone, task_manager::epoch_monitor is not shared across threads anymore
312
                m_task_mngr.reset();
223✔
313

314
                // With scheduler and executor threads gone, all recorders can be safely accessed from the runtime / application thread
315
                if(spdlog::should_log(log_level::info) && m_cfg->should_print_graphs()) {
223!
316
                        if(m_local_nid == 0) { // It's the same across all nodes
16✔
317
                                assert(m_task_recorder.get() != nullptr);
8✔
318
                                const auto tdag_str = detail::print_task_graph(*m_task_recorder);
24✔
319
                                CELERITY_INFO("Task graph:\n\n{}\n", tdag_str);
8!
320
                        }
8✔
321

322
                        assert(m_command_recorder.get() != nullptr);
16✔
323
                        auto cdag_str = print_command_graph(m_local_nid, *m_command_recorder);
48✔
324
                        if(!is_dry_run()) { cdag_str = gather_command_graph(cdag_str, m_num_nodes, m_local_nid); } // must be called on all nodes
16!
325

326
                        if(m_local_nid == 0) {
16✔
327
                                // Avoid racing on stdout with other nodes (funneled through mpirun)
328
                                if(!is_dry_run()) { std::this_thread::sleep_for(std::chrono::milliseconds(500)); }
8!
329
                                CELERITY_INFO("Command graph:\n\n{}\n", cdag_str);
8!
330
                        }
331

332
                        // IDAGs become unreadable when all nodes print them at the same time - TODO attempt gathering them as well?
333
                        if(m_local_nid == 0) {
16✔
334
                                // we are allowed to deref m_instruction_recorder / m_command_recorder because the scheduler thread has exited at this point
335
                                const auto idag_str = detail::print_instruction_graph(*m_instruction_recorder, *m_command_recorder, *m_task_recorder);
24✔
336
                                CELERITY_INFO("Instruction graph on node 0:\n\n{}\n", idag_str);
8!
337
                        }
8✔
338
                }
16✔
339

340
                m_instruction_recorder.reset();
223✔
341
                m_command_recorder.reset();
223✔
342
                m_task_recorder.reset();
223✔
343

344
                cgf_diagnostics::teardown();
223✔
345

346
                if(!s_test_mode) { mpi_finalize_once(); }
223✔
347
        }
223✔
348

349
        task_id runtime::sync(epoch_action action) {
297✔
350
                require_call_from_application_thread();
297✔
351

352
                const auto epoch = m_task_mngr->generate_epoch_task(action);
296✔
353
                m_task_mngr->await_epoch(epoch);
296✔
354
                return epoch;
296✔
355
        }
356

357
        task_manager& runtime::get_task_manager() const {
3,975✔
358
                require_call_from_application_thread();
3,975✔
359
                return *m_task_mngr;
3,973✔
360
        }
361

362
        std::string gather_command_graph(const std::string& graph_str, const size_t num_nodes, const node_id local_nid) {
18✔
363
#if CELERITY_ENABLE_MPI
364
                const auto comm = MPI_COMM_WORLD;
18✔
365
                const int tag = 0xCDA6; // aka 'CDAG' - Celerity does not perform any other peer-to-peer communication over MPI_COMM_WORLD
18✔
366

367
                // Send local graph to rank 0 on all other nodes
368
                if(local_nid != 0) {
18✔
369
                        const uint64_t usize = graph_str.size();
9✔
370
                        assert(usize < std::numeric_limits<int32_t>::max());
9✔
371
                        const int32_t size = static_cast<int32_t>(usize);
9✔
372
                        MPI_Send(&size, 1, MPI_INT32_T, 0, tag, comm);
9✔
373
                        if(size > 0) MPI_Send(graph_str.data(), static_cast<int32_t>(size), MPI_BYTE, 0, tag, comm);
9!
374
                        return "";
27✔
375
                }
376
                // On node 0, receive and combine
377
                std::vector<std::string> graphs;
9✔
378
                graphs.push_back(graph_str);
9✔
379
                for(node_id peer = 1; peer < num_nodes; ++peer) {
18✔
380
                        int32_t size = 0;
9✔
381
                        MPI_Recv(&size, 1, MPI_INT32_T, static_cast<int>(peer), tag, comm, MPI_STATUS_IGNORE);
9✔
382
                        if(size > 0) {
9!
383
                                std::string graph;
9✔
384
                                graph.resize(size);
9✔
385
                                MPI_Recv(graph.data(), size, MPI_BYTE, static_cast<int>(peer), tag, comm, MPI_STATUS_IGNORE);
9✔
386
                                graphs.push_back(std::move(graph));
9✔
387
                        }
9✔
388
                }
389
                return combine_command_graphs(graphs);
27✔
390
#else  // CELERITY_ENABLE_MPI
391
                assert(num_nodes == 1 && local_nid == 0);
392
                return graph_str;
393
#endif // CELERITY_ENABLE_MPI
394
        }
9✔
395

396
        // scheduler::delegate
397

398
        void runtime::flush(std::vector<const instruction*> instructions, std::vector<outbound_pilot> pilots) {
6,120✔
399
                // thread-safe
400
                assert(m_exec != nullptr);
6,120✔
401
                m_exec->submit(std::move(instructions), std::move(pilots));
6,120✔
402
        }
6,120✔
403

404
        // executor::delegate
405

406
        void runtime::horizon_reached(const task_id horizon_tid) {
839✔
407
                assert(m_task_mngr != nullptr);
839✔
408
                m_task_mngr->notify_horizon_reached(horizon_tid); // thread-safe
839✔
409

410
                // The two-horizon logic is duplicated from task_manager::notify_horizon_reached. TODO move epoch_monitor from task_manager to runtime.
411
                assert(m_schdlr != nullptr);
839✔
412
                if(m_latest_horizon_reached.has_value()) { m_schdlr->notify_epoch_reached(*m_latest_horizon_reached); }
839✔
413
                m_latest_horizon_reached = horizon_tid;
839✔
414
        }
839✔
415

416
        void runtime::epoch_reached(const task_id epoch_tid) {
296✔
417
                assert(m_task_mngr != nullptr);
296✔
418
                m_task_mngr->notify_epoch_reached(epoch_tid); // thread-safe
296✔
419

420
                assert(m_schdlr != nullptr);
296✔
421
                m_schdlr->notify_epoch_reached(epoch_tid);
296✔
422
                m_latest_horizon_reached = std::nullopt; // Any non-applied horizon is now behind the epoch and will therefore never become an epoch itself
296✔
423
        }
296✔
424

425
        void runtime::create_queue() {
213✔
426
                require_call_from_application_thread();
213✔
427

428
                if(m_has_live_queue) { throw std::runtime_error("Only one celerity::distr_queue can be created per process (but it can be copied!)"); }
212✔
429
                m_has_live_queue = true;
211✔
430
        }
211✔
431

432
        void runtime::destroy_queue() {
212✔
433
                require_call_from_application_thread();
212✔
434

435
                assert(m_has_live_queue);
211✔
436
                m_has_live_queue = false;
211✔
437
                destroy_instance_if_unreferenced();
211✔
438
        }
211✔
439

440
        allocation_id runtime::create_user_allocation(void* const ptr) {
108✔
441
                require_call_from_application_thread();
108✔
442
                const auto aid = allocation_id(user_memory_id, m_next_user_allocation_id++);
107✔
443
                m_exec->track_user_allocation(aid, ptr);
107✔
444
                return aid;
107✔
445
        }
446

447
        buffer_id runtime::create_buffer(const range<3>& range, const size_t elem_size, const size_t elem_align, const allocation_id user_aid) {
340✔
448
                require_call_from_application_thread();
340✔
449

450
                const auto bid = m_next_buffer_id++;
339✔
451
                m_live_buffers.emplace(bid);
339✔
452
                m_task_mngr->notify_buffer_created(bid, range, user_aid != null_allocation_id);
339✔
453
                m_schdlr->notify_buffer_created(bid, range, elem_size, elem_align, user_aid);
339✔
454
                return bid;
678✔
455
        }
456

457
        void runtime::set_buffer_debug_name(const buffer_id bid, const std::string& debug_name) {
23✔
458
                require_call_from_application_thread();
23✔
459

460
                assert(utils::contains(m_live_buffers, bid));
23✔
461
                m_task_mngr->notify_buffer_debug_name_changed(bid, debug_name);
23✔
462
                m_schdlr->notify_buffer_debug_name_changed(bid, debug_name);
23✔
463
        }
23✔
464

465
        void runtime::destroy_buffer(const buffer_id bid) {
340✔
466
                require_call_from_application_thread();
340✔
467

468
                assert(utils::contains(m_live_buffers, bid));
339✔
469
                m_schdlr->notify_buffer_destroyed(bid);
339✔
470
                m_task_mngr->notify_buffer_destroyed(bid);
339✔
471
                m_live_buffers.erase(bid);
339✔
472
                destroy_instance_if_unreferenced();
339✔
473
        }
339✔
474

475
        host_object_id runtime::create_host_object(std::unique_ptr<host_object_instance> instance) {
34✔
476
                require_call_from_application_thread();
34✔
477

478
                const auto hoid = m_next_host_object_id++;
33✔
479
                m_live_host_objects.emplace(hoid);
33✔
480
                const bool owns_instance = instance != nullptr;
33✔
481
                if(owns_instance) { m_exec->track_host_object_instance(hoid, std::move(instance)); }
33✔
482
                m_task_mngr->notify_host_object_created(hoid);
33✔
483
                m_schdlr->notify_host_object_created(hoid, owns_instance);
33✔
484
                return hoid;
66✔
485
        }
486

487
        void runtime::destroy_host_object(const host_object_id hoid) {
34✔
488
                require_call_from_application_thread();
34✔
489

490
                assert(utils::contains(m_live_host_objects, hoid));
33✔
491
                m_schdlr->notify_host_object_destroyed(hoid);
33✔
492
                m_task_mngr->notify_host_object_destroyed(hoid);
33✔
493
                m_live_host_objects.erase(hoid);
33✔
494
                destroy_instance_if_unreferenced();
33✔
495
        }
33✔
496

497

498
        reduction_id runtime::create_reduction(std::unique_ptr<reducer> reducer) {
65✔
499
                require_call_from_application_thread();
65✔
500

501
                const auto rid = m_next_reduction_id++;
65✔
502
                m_exec->track_reducer(rid, std::move(reducer));
65✔
503
                return rid;
130✔
504
        }
505

506
        bool runtime::is_unreferenced() const { return !m_has_live_queue && m_live_buffers.empty() && m_live_host_objects.empty(); }
806✔
507

508
        void runtime::destroy_instance_if_unreferenced() {
583✔
509
                if(s_instance == nullptr) return;
583!
510
                if(s_instance->is_unreferenced()) { s_instance.reset(); }
583✔
511
        }
512

513
} // namespace detail
514
} // namespace celerity
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc