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

celerity / celerity-runtime / 9945915519

15 Jul 2024 08:07PM UTC coverage: 93.077% (-1.3%) from 94.362%
9945915519

push

github

fknorr
Rename existing backend / executor -> legacy_backend / legacy_executor

Names 'backend' and 'executor' will be re-used, but we want to keep the
old APIs around in the meantime to keep changesets small.

3188 of 3687 branches covered (86.47%)

Branch coverage included in aggregate %.

17 of 23 new or added lines in 6 files covered. (73.91%)

95 existing lines in 8 files now uncovered.

7232 of 7508 relevant lines covered (96.32%)

169246.64 hits per line

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

85.0
/include/async_event.h
1
#pragma once
2

3
#include <cassert>
4
#include <chrono>
5
#include <memory>
6
#include <optional>
7
#include <type_traits>
8

9
namespace celerity::detail {
10

11
/// Abstract base class for `async_event` implementations.
12
class async_event_impl {
13
  public:
14
        async_event_impl() = default;
5,275✔
15
        async_event_impl(const async_event_impl&) = delete;
16
        async_event_impl(async_event_impl&&) = delete;
17
        async_event_impl& operator=(const async_event_impl&) = delete;
18
        async_event_impl& operator=(async_event_impl&&) = delete;
19
        virtual ~async_event_impl() = default;
5,275✔
20

21
        /// If this function returns true once, the implementation must guarantee that it will always do so in the future.
22
        /// The event is expected to be cheap to poll repeatedly, and the operation must proceed in the background even while not being polled.
23
        virtual bool is_complete() = 0;
24

25
        /// There is only one instruction type which returns a result, namely alloc_instruction returning a pointer to the allocated memory, i.e. a void*. Having a
26
        /// void* return type on async_event_impl is somewhat leaky, but we don't gain much by wrapping it in a std::any.
UNCOV
27
        virtual void* get_result() { return nullptr; }
×
28

29
        /// Returns the time execution time as measured if profiling was enabled in the issuing component. Requires `is_complete()` to be true.
UNCOV
30
        virtual std::optional<std::chrono::nanoseconds> get_native_execution_time() { return std::nullopt; }
×
31
};
32

33
/// `async_event` implementation that is immediately complete. Used to report synchronous completion of some operations within an otherwise asynchronous
34
/// context.
35
class complete_event final : public async_event_impl {
36
  public:
37
        complete_event() = default;
1,185✔
38
        explicit complete_event(void* const result) : m_result(result) {}
39
        bool is_complete() override { return true; }
1,185✔
UNCOV
40
        void* get_result() override { return m_result; }
×
41

42
  private:
43
        void* m_result = nullptr;
44
};
45

46
/// Type-erased event signalling completion of events at the executor layer. These may wrap SYCL events, asynchronous MPI requests, or similar.
47
class [[nodiscard]] async_event {
48
  public:
49
        async_event() = default;
50
        async_event(std::unique_ptr<async_event_impl> impl) noexcept : m_impl(std::move(impl)) {}
5,275✔
51

52
        /// Polls the underlying event operation to check if it has completed. This function is cheap to call repeatedly.
53
        bool is_complete() const {
411,296✔
54
                assert(m_impl != nullptr);
411,296✔
55
                return m_impl->is_complete();
411,296✔
56
        }
57

58
        void* get_result() const {
7✔
59
                assert(m_impl != nullptr);
7✔
60
                return m_impl->get_result();
7✔
61
        }
62

63
        std::optional<std::chrono::nanoseconds> get_native_execution_time() const {
6✔
64
                assert(m_impl != nullptr);
6✔
65
                return m_impl->get_native_execution_time();
6✔
66
        }
67

68
  private:
69
        std::unique_ptr<async_event_impl> m_impl;
70
};
71

72
/// Shortcut to create an `async_event` using an `async_event_impl`-derived type `Event`.
73
template <typename Event, typename... CtorParams>
74
async_event make_async_event(CtorParams&&... ctor_args) {
5,275✔
75
        static_assert(std::is_base_of_v<async_event_impl, Event>);
76
        return async_event(std::make_unique<Event>(std::forward<CtorParams>(ctor_args)...));
5,275✔
77
}
78

79
/// Shortcut to create an `async_event(complete_event)`.
80
inline async_event make_complete_event() { return make_async_event<complete_event>(); }
1,185✔
81
inline async_event make_complete_event(void* const result) { return make_async_event<complete_event>(result); }
82

83
} // namespace celerity::detail
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

© 2026 Coveralls, Inc