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

celerity / celerity-runtime / 11841839434

14 Nov 2024 04:54PM UTC coverage: 95.154% (-0.02%) from 95.176%
11841839434

push

github

fknorr
Update benchmark results for epoch refactoring

3018 of 3414 branches covered (88.4%)

Branch coverage included in aggregate %.

6682 of 6780 relevant lines covered (98.55%)

1298952.13 hits per line

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

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

3
#include <atomic>
4
#include <future>
5
#include <limits>
6
#include <string>
7

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

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

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

40
#if CELERITY_ENABLE_MPI
41
#include "mpi_communicator.h"
42
#include <mpi.h>
43
#else
44
#include "local_communicator.h"
45
#endif
46

47

48
namespace celerity {
49
namespace detail {
50

51
        class epoch_promise final : public task_promise {
52
          public:
53
                std::future<void> get_future() { return m_promise.get_future(); }
555✔
54

55
                void fulfill() override { m_promise.set_value(); }
555✔
56

57
                allocation_id get_user_allocation_id() override { utils::panic("epoch_promise::get_user_allocation_id"); }
×
58

59
          private:
60
                std::promise<void> m_promise;
61
        };
62

63
        std::unique_ptr<runtime> runtime::s_instance = nullptr;
64

65
        void runtime::mpi_initialize_once(int* argc, char*** argv) {
56✔
66
#if CELERITY_ENABLE_MPI
67
                CELERITY_DETAIL_TRACY_ZONE_SCOPED_V("mpi::init", LightSkyBlue, "MPI_Init");
68
                assert(!s_mpi_initialized);
56✔
69
                int provided;
56✔
70
                MPI_Init_thread(argc, argv, MPI_THREAD_MULTIPLE, &provided);
56✔
71
                assert(provided == MPI_THREAD_MULTIPLE);
56✔
72
#endif // CELERITY_ENABLE_MPI
73
                s_mpi_initialized = true;
56✔
74
        }
56✔
75

76
        void runtime::mpi_finalize_once() {
56✔
77
#if CELERITY_ENABLE_MPI
78
                CELERITY_DETAIL_TRACY_ZONE_SCOPED_V("mpi::finalize", LightSkyBlue, "MPI_Finalize");
79
                assert(s_mpi_initialized && !s_mpi_finalized && (!s_test_mode || !s_instance));
56✔
80
                MPI_Finalize();
56✔
81
#endif // CELERITY_ENABLE_MPI
82
                s_mpi_finalized = true;
56✔
83
        }
56✔
84

85
        void runtime::init(int* argc, char** argv[], const devices_or_selector& user_devices_or_selector) {
219✔
86
                assert(!s_instance);
219✔
87
                s_instance = std::unique_ptr<runtime>(new runtime(argc, argv, user_devices_or_selector));
219!
88
                if(!s_test_mode) { atexit(shutdown); }
219✔
89
        }
219✔
90

91
        runtime& runtime::get_instance() {
3,704✔
92
                if(s_instance == nullptr) { throw std::runtime_error("Runtime has not been initialized"); }
3,704!
93
                return *s_instance;
3,704✔
94
        }
95

96
        void runtime::shutdown() { s_instance.reset(); }
49✔
97

98
        static auto get_pid() {
219✔
99
#ifdef _MSC_VER
100
                return _getpid();
101
#else
102
                return getpid();
219✔
103
#endif
104
        }
105

106
        static std::string get_version_string() {
219✔
107
                using namespace celerity::version;
108
                return fmt::format("{}.{}.{} {}{}", major, minor, patch, git_revision, git_dirty ? "-dirty" : "");
438!
109
        }
110

111
        static const char* get_build_type() {
219✔
112
#if CELERITY_DETAIL_ENABLE_DEBUG
113
                return "debug";
219✔
114
#else
115
                return "release";
116
#endif
117
        }
118

119
        static const char* get_mimalloc_string() {
219✔
120
#if CELERITY_USE_MIMALLOC
121
                return "using mimalloc";
122
#else
123
                return "using the default allocator";
219✔
124
#endif
125
        }
126

127
        static std::string get_sycl_version() {
219✔
128
#if CELERITY_SYCL_IS_ACPP
129
                return fmt::format("AdaptiveCpp {}.{}.{}", HIPSYCL_VERSION_MAJOR, HIPSYCL_VERSION_MINOR, HIPSYCL_VERSION_PATCH);
130
#elif CELERITY_SYCL_IS_DPCPP
131
                return "DPC++ / Clang " __clang_version__;
132
#elif CELERITY_SYCL_IS_SIMSYCL
133
                return "SimSYCL " SIMSYCL_VERSION;
657✔
134
#else
135
#error "unknown SYCL implementation"
136
#endif
137
        }
138

139
        static std::string get_mpi_version() {
219✔
140
#if CELERITY_ENABLE_MPI
141
                char version[MPI_MAX_LIBRARY_VERSION_STRING];
219✔
142
                int len = -1;
219✔
143
                MPI_Get_library_version(version, &len);
219✔
144
                // try shortening the human-readable version string (so far tested on OpenMPI)
145
                if(const auto brk = /* find last of */ strpbrk(version, ",;")) { len = static_cast<int>(brk - version); }
219!
146
                return std::string(version, static_cast<size_t>(len));
876✔
147
#else
148
                return "single node";
149
#endif
150
        }
151

152
        static host_config get_mpi_host_config() {
213✔
153
#if CELERITY_ENABLE_MPI
154
                // Determine the "host config", i.e., how many nodes are spawned on this host,
155
                // and what this node's local rank is. We do this by finding all world-ranks
156
                // that can use a shared-memory transport (if running on OpenMPI, use the
157
                // per-host split instead).
158
#ifdef OPEN_MPI
159
#define SPLIT_TYPE OMPI_COMM_TYPE_HOST
160
#else
161
                // TODO: Assert that shared memory is available (i.e. not explicitly disabled)
162
#define SPLIT_TYPE MPI_COMM_TYPE_SHARED
163
#endif
164
                MPI_Comm host_comm = nullptr;
213✔
165
                MPI_Comm_split_type(MPI_COMM_WORLD, SPLIT_TYPE, 0, MPI_INFO_NULL, &host_comm);
213✔
166

167
                int local_rank = 0;
213✔
168
                MPI_Comm_rank(host_comm, &local_rank);
213✔
169

170
                int node_count = 0;
213✔
171
                MPI_Comm_size(host_comm, &node_count);
213✔
172

173
                host_config host_cfg;
213✔
174
                host_cfg.local_rank = local_rank;
213✔
175
                host_cfg.node_count = node_count;
213✔
176

177
                MPI_Comm_free(&host_comm);
213✔
178

179
                return host_cfg;
426✔
180
#else  // CELERITY_ENABLE_MPI
181
                return host_config{1, 0};
182
#endif // CELERITY_ENABLE_MPI
183
        }
184

185
        runtime::runtime(int* argc, char** argv[], const devices_or_selector& user_devices_or_selector) {
219✔
186
                m_application_thread = std::this_thread::get_id();
219✔
187

188
                m_cfg = std::make_unique<config>(argc, argv);
219✔
189

190
                CELERITY_DETAIL_IF_TRACY_SUPPORTED(tracy_detail::g_tracy_mode = m_cfg->get_tracy_mode());
191
                CELERITY_DETAIL_TRACY_ZONE_SCOPED("runtime::startup", DarkGray);
192

193
                if(s_test_mode) {
219✔
194
                        assert(s_test_active && "initializing the runtime from a test without a runtime_fixture");
176✔
195
                        s_test_runtime_was_instantiated = true;
176✔
196
                } else {
197
                        mpi_initialize_once(argc, argv);
43✔
198
                }
199

200
                int world_size = 1;
219✔
201
                int world_rank = 0;
219✔
202
#if CELERITY_ENABLE_MPI
203
                MPI_Comm_size(MPI_COMM_WORLD, &world_size);
219✔
204
                MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
219✔
205
#endif
206

207
                host_config host_cfg;
219✔
208
                if(m_cfg->is_dry_run()) {
219✔
209
                        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!
210
                        m_num_nodes = static_cast<size_t>(m_cfg->get_dry_run_nodes());
6✔
211
                        m_local_nid = 0;
6✔
212
                        host_cfg.node_count = 1;
6✔
213
                        host_cfg.local_rank = 0;
6✔
214
                } else {
215
                        m_num_nodes = static_cast<size_t>(world_size);
213✔
216
                        m_local_nid = static_cast<node_id>(world_rank);
213✔
217
                        host_cfg = get_mpi_host_config();
213✔
218
                }
219

220
                // Do not touch logger settings in tests, where the full (trace) logs are captured
221
                if(!s_test_mode) {
219✔
222
                        spdlog::set_level(m_cfg->get_log_level());
43✔
223
                        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✔
224
                }
225

226
                CELERITY_INFO("Celerity runtime version {} running on {} / {}. PID = {}, build type = {}, {}", get_version_string(), get_sycl_version(),
219✔
227
                    get_mpi_version(), get_pid(), get_build_type(), get_mimalloc_string());
228

229
#ifndef __APPLE__
230
                if(const uint32_t cores = affinity_cores_available(); cores < min_cores_needed) {
219!
231
                        CELERITY_WARN("Celerity has detected that only {} logical cores are available to this process. It is recommended to assign at least {} "
×
232
                                      "logical cores. Performance may be negatively impacted.",
233
                            cores, min_cores_needed);
234
                }
235
#endif
236

237
                if(!s_test_mode && m_cfg->get_tracy_mode() != tracy_mode::off) {
219!
238
                        if constexpr(CELERITY_TRACY_SUPPORT) {
239
                                CELERITY_WARN("Profiling with Tracy is enabled. Performance may be negatively impacted.");
240
                        } else {
241
                                CELERITY_WARN("CELERITY_TRACY is set, but Celerity was compiled without Tracy support. Ignoring.");
×
242
                        }
243
                }
244

245
                cgf_diagnostics::make_available();
219✔
246

247
                std::vector<sycl::device> devices;
219✔
248
                {
249
                        CELERITY_DETAIL_TRACY_ZONE_SCOPED("runtime::pick_devices", PaleVioletRed);
250
                        devices = std::visit([&](const auto& value) { return pick_devices(host_cfg, value, sycl::platform::get_platforms()); }, user_devices_or_selector);
438✔
251
                        assert(!devices.empty()); // postcondition of pick_devices
219✔
252
                }
253

254
                auto backend = make_sycl_backend(select_backend(sycl_backend_enumerator{}, devices), devices, m_cfg->should_enable_device_profiling());
219✔
255
                const auto system = backend->get_system_info(); // backend is about to be moved
219✔
256

257
                if(m_cfg->is_dry_run()) {
219✔
258
                        m_exec = std::make_unique<dry_run_executor>(static_cast<executor::delegate*>(this));
6✔
259
                } else {
260
#if CELERITY_ENABLE_MPI
261
                        auto comm = std::make_unique<mpi_communicator>(collective_clone_from, MPI_COMM_WORLD);
213✔
262
#else
263
                        auto comm = std::make_unique<local_communicator>();
264
#endif
265
                        m_exec = std::make_unique<live_executor>(std::move(backend), std::move(comm), static_cast<executor::delegate*>(this));
213✔
266
                }
213✔
267

268
                if(m_cfg->should_record()) {
219✔
269
                        m_task_recorder = std::make_unique<task_recorder>();
16✔
270
                        m_command_recorder = std::make_unique<command_recorder>();
16✔
271
                        m_instruction_recorder = std::make_unique<instruction_recorder>();
16✔
272
                }
273

274
                task_manager::policy_set task_mngr_policy;
219✔
275
                // 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
276
                // first iteration of a submit-loop. We could get rid of this case by making access-modes a runtime property of accessors (cf
277
                // https://github.com/celerity/meta/issues/74).
278
                task_mngr_policy.uninitialized_read_error = CELERITY_ACCESS_PATTERN_DIAGNOSTICS ? error_policy::log_warning : error_policy::ignore;
219✔
279

280
                m_task_mngr = std::make_unique<task_manager>(m_num_nodes, m_tdag, m_task_recorder.get(), static_cast<task_manager::delegate*>(this), task_mngr_policy);
219✔
281
                if(m_cfg->get_horizon_step()) m_task_mngr->set_horizon_step(m_cfg->get_horizon_step().value());
219!
282
                if(m_cfg->get_horizon_max_parallelism()) m_task_mngr->set_horizon_max_parallelism(m_cfg->get_horizon_max_parallelism().value());
219!
283

284
                scheduler::policy_set schdlr_policy;
219✔
285
                // Any uninitialized read that is observed on CDAG generation was already logged on task generation, unless we have a bug.
286
                schdlr_policy.command_graph_generator.uninitialized_read_error = error_policy::ignore;
219✔
287
                schdlr_policy.instruction_graph_generator.uninitialized_read_error = error_policy::ignore;
219✔
288
                schdlr_policy.command_graph_generator.overlapping_write_error = CELERITY_ACCESS_PATTERN_DIAGNOSTICS ? error_policy::log_error : error_policy::ignore;
219✔
289
                schdlr_policy.instruction_graph_generator.overlapping_write_error =
219✔
290
                    CELERITY_ACCESS_PATTERN_DIAGNOSTICS ? error_policy::log_error : error_policy::ignore;
291
                schdlr_policy.instruction_graph_generator.unsafe_oversubscription_error = error_policy::log_warning;
219✔
292

293
                // The scheduler references tasks by pointer, so we make sure its lifetime is shorter than the task_manager's.
294
                m_schdlr = std::make_unique<scheduler>(m_num_nodes, m_local_nid, system, static_cast<abstract_scheduler::delegate*>(this), m_command_recorder.get(),
876✔
295
                    m_instruction_recorder.get(), schdlr_policy);
657✔
296

297
                // task_manager will pass generated tasks through its delegate, so generate the init epoch only after the scheduler has been initialized
298
                m_task_mngr->generate_epoch_task(epoch_action::init);
219✔
299

300
                m_num_local_devices = system.devices.size();
219✔
301
        }
438✔
302

303
        void runtime::require_call_from_application_thread() const {
6,504✔
304
                if(std::this_thread::get_id() != m_application_thread) {
6,504✔
305
                        utils::panic("Celerity runtime, queue, handler, buffer and host_object types must only be constructed, used, and destroyed from the "
40✔
306
                                     "application thread. Make sure that you did not accidentally capture one of these types in a host_task.");
307
                }
308
        }
6,494✔
309

310
        runtime::~runtime() {
219✔
311
                // LCOV_EXCL_START
312
                if(!is_unreferenced()) {
313
                        // this call might originate from static destruction - we cannot assume spdlog to still be around
314
                        utils::panic("Detected an attempt to destroy runtime while at least one queue, buffer or host_object was still alive. This likely means "
315
                                     "that one of these objects was leaked, or at least its lifetime extended beyond the scope of main(). This is undefined.");
316
                }
317
                // LCOV_EXCL_STOP
318

319
                require_call_from_application_thread();
219✔
320

321
                CELERITY_DETAIL_TRACY_ZONE_SCOPED("runtime::shutdown", DimGray);
322

323
                // Create and await the shutdown epoch
324
                sync(epoch_action::shutdown);
219✔
325

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

330
                // task_manager references the scheduler as its delegate, so we destroy it first.
331
                m_task_mngr.reset();
219✔
332

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

337
                // With scheduler and executor threads gone, all recorders can be safely accessed from the runtime / application thread
338
                if(spdlog::should_log(log_level::info) && m_cfg->should_print_graphs()) {
219!
339
                        if(m_local_nid == 0) { // It's the same across all nodes
16✔
340
                                assert(m_task_recorder.get() != nullptr);
8✔
341
                                const auto tdag_str = detail::print_task_graph(*m_task_recorder);
24✔
342
                                CELERITY_INFO("Task graph:\n\n{}\n", tdag_str);
8!
343
                        }
8✔
344

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

349
                        if(m_local_nid == 0) {
16✔
350
                                // Avoid racing on stdout with other nodes (funneled through mpirun)
351
                                if(!is_dry_run()) { std::this_thread::sleep_for(std::chrono::milliseconds(500)); }
8!
352
                                CELERITY_INFO("Command graph:\n\n{}\n", cdag_str);
8!
353
                        }
354

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

363
                m_instruction_recorder.reset();
219✔
364
                m_command_recorder.reset();
219✔
365
                m_task_recorder.reset();
219✔
366

367
                cgf_diagnostics::teardown();
219✔
368

369
                if(!s_test_mode) { mpi_finalize_once(); }
219✔
370
        }
219✔
371

372
        task_id runtime::fence(buffer_access_map access_map, side_effect_map side_effects, std::unique_ptr<task_promise> fence_promise) {
66✔
373
                require_call_from_application_thread();
66✔
374
                maybe_prune_task_graph();
65✔
375
                return m_task_mngr->generate_fence_task(std::move(access_map), std::move(side_effects), std::move(fence_promise));
65✔
376
        }
377

378
        task_id runtime::sync(epoch_action action) {
556✔
379
                require_call_from_application_thread();
556✔
380

381
                maybe_prune_task_graph();
555✔
382
                auto promise = std::make_unique<epoch_promise>();
555✔
383
                const auto future = promise->get_future();
555✔
384
                const auto epoch = m_task_mngr->generate_epoch_task(action, std::move(promise));
555✔
385
                future.wait();
555✔
386
                return epoch;
555✔
387
        }
555✔
388

389
        void runtime::maybe_prune_task_graph() {
2,445✔
390
                require_call_from_application_thread();
2,445✔
391

392
                const auto current_epoch = m_latest_epoch_reached.load(std::memory_order_relaxed);
2,445✔
393
                if(current_epoch > m_last_epoch_pruned_before) {
2,445✔
394
                        m_tdag.erase_before_epoch(current_epoch);
834✔
395
                        m_last_epoch_pruned_before = current_epoch;
834✔
396
                }
397
        }
2,445✔
398

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

404
                // Send local graph to rank 0 on all other nodes
405
                if(local_nid != 0) {
18✔
406
                        const uint64_t usize = graph_str.size();
9✔
407
                        assert(usize < std::numeric_limits<int32_t>::max());
9✔
408
                        const int32_t size = static_cast<int32_t>(usize);
9✔
409
                        MPI_Send(&size, 1, MPI_INT32_T, 0, tag, comm);
9✔
410
                        if(size > 0) MPI_Send(graph_str.data(), static_cast<int32_t>(size), MPI_BYTE, 0, tag, comm);
9!
411
                        return "";
27✔
412
                }
413
                // On node 0, receive and combine
414
                std::vector<std::string> graphs;
9✔
415
                graphs.push_back(graph_str);
9✔
416
                for(node_id peer = 1; peer < num_nodes; ++peer) {
18✔
417
                        int32_t size = 0;
9✔
418
                        MPI_Recv(&size, 1, MPI_INT32_T, static_cast<int>(peer), tag, comm, MPI_STATUS_IGNORE);
9✔
419
                        if(size > 0) {
9!
420
                                std::string graph;
9✔
421
                                graph.resize(size);
9✔
422
                                MPI_Recv(graph.data(), size, MPI_BYTE, static_cast<int>(peer), tag, comm, MPI_STATUS_IGNORE);
9✔
423
                                graphs.push_back(std::move(graph));
9✔
424
                        }
9✔
425
                }
426
                return combine_command_graphs(graphs);
27✔
427
#else  // CELERITY_ENABLE_MPI
428
                assert(num_nodes == 1 && local_nid == 0);
429
                return graph_str;
430
#endif // CELERITY_ENABLE_MPI
431
        }
9✔
432

433
        // task_manager::delegate
434

435
        void runtime::task_created(const task* tsk) {
3,235✔
436
                assert(m_schdlr != nullptr);
3,235✔
437
                m_schdlr->notify_task_created(tsk);
3,235✔
438
        }
3,235✔
439

440
        // scheduler::delegate
441

442
        void runtime::flush(std::vector<const instruction*> instructions, std::vector<outbound_pilot> pilots) {
3,868✔
443
                // thread-safe
444
                assert(m_exec != nullptr);
3,868✔
445
                m_exec->submit(std::move(instructions), std::move(pilots));
3,868✔
446
        }
3,868✔
447

448
        // executor::delegate
449

450
        void runtime::horizon_reached(const task_id horizon_tid) {
582✔
451
                assert(!m_latest_horizon_reached || *m_latest_horizon_reached < horizon_tid);
582✔
452
                assert(m_latest_epoch_reached.load(std::memory_order::relaxed) < horizon_tid); // relaxed: written only by this thread
1,164✔
453

454
                if(m_latest_horizon_reached.has_value()) {
582✔
455
                        m_latest_epoch_reached.store(*m_latest_horizon_reached, std::memory_order_relaxed);
553✔
456
                        m_schdlr->notify_epoch_reached(*m_latest_horizon_reached);
553✔
457
                }
458
                m_latest_horizon_reached = horizon_tid;
582✔
459
        }
582✔
460

461
        void runtime::epoch_reached(const task_id epoch_tid) {
774✔
462
                // m_latest_horizon_reached does not need synchronization (see definition), all other accesses are implicitly synchronized.
463
                assert(!m_latest_horizon_reached || *m_latest_horizon_reached < epoch_tid);
774✔
464
                assert(epoch_tid == 0 || m_latest_epoch_reached.load(std::memory_order_relaxed) < epoch_tid);
1,329✔
465

466
                m_latest_epoch_reached.store(epoch_tid, std::memory_order_relaxed);
774✔
467
                m_schdlr->notify_epoch_reached(epoch_tid);
774✔
468
                m_latest_horizon_reached = std::nullopt; // Any non-applied horizon is now behind the epoch and will therefore never become an epoch itself
774✔
469
        }
774✔
470

471
        void runtime::create_queue() {
220✔
472
                require_call_from_application_thread();
220✔
473
                ++m_num_live_queues;
219✔
474
        }
219✔
475

476
        void runtime::destroy_queue() {
220✔
477
                require_call_from_application_thread();
220✔
478

479
                assert(m_num_live_queues > 0);
219✔
480
                --m_num_live_queues;
219✔
481
        }
219✔
482

483
        allocation_id runtime::create_user_allocation(void* const ptr) {
110✔
484
                require_call_from_application_thread();
110✔
485
                const auto aid = allocation_id(user_memory_id, m_next_user_allocation_id++);
109✔
486
                m_exec->track_user_allocation(aid, ptr);
109✔
487
                return aid;
109✔
488
        }
489

490
        buffer_id runtime::create_buffer(const range<3>& range, const size_t elem_size, const size_t elem_align, const allocation_id user_aid) {
343✔
491
                require_call_from_application_thread();
343✔
492

493
                const auto bid = m_next_buffer_id++;
342✔
494
                m_live_buffers.emplace(bid);
342✔
495
                m_task_mngr->notify_buffer_created(bid, range, user_aid != null_allocation_id);
342✔
496
                m_schdlr->notify_buffer_created(bid, range, elem_size, elem_align, user_aid);
342✔
497
                return bid;
684✔
498
        }
499

500
        void runtime::set_buffer_debug_name(const buffer_id bid, const std::string& debug_name) {
23✔
501
                require_call_from_application_thread();
23✔
502

503
                assert(utils::contains(m_live_buffers, bid));
23✔
504
                m_task_mngr->notify_buffer_debug_name_changed(bid, debug_name);
23✔
505
                m_schdlr->notify_buffer_debug_name_changed(bid, debug_name);
23✔
506
        }
23✔
507

508
        void runtime::destroy_buffer(const buffer_id bid) {
343✔
509
                require_call_from_application_thread();
343✔
510

511
                assert(utils::contains(m_live_buffers, bid));
342✔
512
                m_schdlr->notify_buffer_destroyed(bid);
342✔
513
                m_task_mngr->notify_buffer_destroyed(bid);
342✔
514
                m_live_buffers.erase(bid);
342✔
515
        }
342✔
516

517
        host_object_id runtime::create_host_object(std::unique_ptr<host_object_instance> instance) {
34✔
518
                require_call_from_application_thread();
34✔
519

520
                const auto hoid = m_next_host_object_id++;
33✔
521
                m_live_host_objects.emplace(hoid);
33✔
522
                const bool owns_instance = instance != nullptr;
33✔
523
                if(owns_instance) { m_exec->track_host_object_instance(hoid, std::move(instance)); }
33✔
524
                m_task_mngr->notify_host_object_created(hoid);
33✔
525
                m_schdlr->notify_host_object_created(hoid, owns_instance);
33✔
526
                return hoid;
66✔
527
        }
528

529
        void runtime::destroy_host_object(const host_object_id hoid) {
34✔
530
                require_call_from_application_thread();
34✔
531

532
                assert(utils::contains(m_live_host_objects, hoid));
33✔
533
                m_schdlr->notify_host_object_destroyed(hoid);
33✔
534
                m_task_mngr->notify_host_object_destroyed(hoid);
33✔
535
                m_live_host_objects.erase(hoid);
33✔
536
        }
33✔
537

538

539
        reduction_id runtime::create_reduction(std::unique_ptr<reducer> reducer) {
65✔
540
                require_call_from_application_thread();
65✔
541

542
                const auto rid = m_next_reduction_id++;
65✔
543
                m_exec->track_reducer(rid, std::move(reducer));
65✔
544
                return rid;
130✔
545
        }
546

547
        bool runtime::is_unreferenced() const { return m_num_live_queues == 0 && m_live_buffers.empty() && m_live_host_objects.empty(); }
219!
548

549
} // namespace detail
550
} // 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