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

celerity / celerity-runtime / 12047884020

27 Nov 2024 09:58AM UTC coverage: 94.956% (-0.02%) from 94.972%
12047884020

push

github

fknorr
Do not disable CGF disagnostics in test_utils::add_*_task

This eliminates dead code from an earlier incomplete refactoring.

The CGF teardown / reinit was only required by a single test, which was
coincidentally also broken and didn't test the feature advertised. This
commit splits up the test between runtime_ and runtime_deprecation_tests
and also moves runtime-independent sibling tests to task_graph_tests.

3202 of 3633 branches covered (88.14%)

Branch coverage included in aggregate %.

7151 of 7270 relevant lines covered (98.36%)

1224689.38 hits per line

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

81.08
/include/task.h
1
#pragma once
2

3
#include "cgf.h"
4
#include "graph.h"
5
#include "grid.h"
6
#include "hint.h"
7
#include "intrusive_graph.h"
8
#include "ranges.h"
9
#include "reduction.h"
10
#include "sycl_wrappers.h"
11
#include "types.h"
12
#include "utils.h"
13

14
#include <cassert>
15
#include <cstddef>
16
#include <memory>
17
#include <string>
18
#include <unordered_map>
19
#include <unordered_set>
20
#include <utility>
21
#include <vector>
22

23

24
namespace celerity {
25
namespace detail {
26

27
        class buffer_access_map {
28
          public:
29
                /// Default ctor for tasks w/o buffer accesses
30
                buffer_access_map() = default;
2,262✔
31

32
                buffer_access_map(std::vector<buffer_access>&& accesses, const task_geometry& geometry);
33

34
                const std::unordered_set<buffer_id>& get_accessed_buffers() const& { return m_accessed_buffers; }
29,167✔
35

36
                size_t get_num_accesses() const { return m_accesses.size(); }
21,034✔
37

38
                std::pair<buffer_id, access_mode> get_nth_access(const size_t n) const {
7,152✔
39
                        const auto& [bid, mode, _] = m_accesses[n];
7,152✔
40
                        return {bid, mode};
7,152✔
41
                }
42

43
                region<3> get_requirements_for_nth_access(const size_t n, const box<3>& execution_range) const;
44

45
                /// Returns the union of all consumer accesses made across the entire task (conceptually, the
46
                /// union of the set of regions obtained by calling get_consumed_region for each chunk).
47
                region<3> get_task_consumed_region(const buffer_id bid) const {
8,004✔
48
                        if(auto it = m_task_consumed_regions.find(bid); it != m_task_consumed_regions.end()) { return it->second; }
8,004✔
49
                        return {};
753✔
50
                }
51

52
                /// Returns the union of all producer accesses made across the entire task (conceptually, the
53
                /// union of the set of regions obtained by calling get_produced_region for each chunk).
54
                region<3> get_task_produced_region(const buffer_id bid) const {
6,951✔
55
                        if(auto it = m_task_produced_regions.find(bid); it != m_task_produced_regions.end()) { return it->second; }
6,951✔
56
                        return {};
133✔
57
                };
58

59
                /// Computes the union of all consumed regions (across multiple accesses) for a given execution range.
60
                region<3> compute_consumed_region(const buffer_id bid, const box<3>& execution_range) const;
61

62
                /// Computes the union of all produced regions (across multiple accesses) for a given execution range.
63
                region<3> compute_produced_region(const buffer_id bid, const box<3>& execution_range) const;
64

65
                /// Returns a set of bounding boxes, one for each accessed region, that must be allocated contiguously.
66
                box_vector<3> compute_required_contiguous_boxes(const buffer_id bid, const box<3>& execution_range) const;
67

68
          private:
69
                std::vector<buffer_access> m_accesses;
70
                std::unordered_set<buffer_id> m_accessed_buffers; ///< Cached set of buffer ids found in m_accesses
71
                task_geometry m_task_geometry;
72
                std::unordered_map<buffer_id, region<3>> m_task_consumed_regions;
73
                std::unordered_map<buffer_id, region<3>> m_task_produced_regions;
74
        };
75

76
        using reduction_set = std::vector<reduction_info>;
77

78
        class side_effect_map : private std::unordered_map<host_object_id, experimental::side_effect_order> {
79
          private:
80
                using map_base = std::unordered_map<host_object_id, experimental::side_effect_order>;
81

82
          public:
83
                using typename map_base::const_iterator, map_base::value_type, map_base::key_type, map_base::mapped_type, map_base::const_reference,
84
                    map_base::const_pointer;
85
                using iterator = const_iterator;
86
                using reference = const_reference;
87
                using pointer = const_pointer;
88

89
                side_effect_map() = default;
3,924✔
90

91
                side_effect_map(const std::vector<host_object_effect>& side_effects) {
1,840✔
92
                        map_base::reserve(side_effects.size());
1,840✔
93
                        for(const auto& [hoid, order] : side_effects) {
2,065✔
94
                                map_base::emplace(hoid, order);
225✔
95
                        }
96
                }
1,840✔
97

98
                using map_base::size, map_base::count, map_base::empty, map_base::cbegin, map_base::cend, map_base::at;
99

100
                iterator begin() const { return cbegin(); }
8,380✔
101
                iterator end() const { return cend(); }
8,361✔
102
        };
103

104
        // TODO refactor into an inheritance hierarchy
105
        class task : public intrusive_graph_node<task> {
106
          public:
107
                task_type get_type() const { return m_type; }
39,662✔
108

109
                task_id get_id() const { return m_tid; }
41,800✔
110

111
                collective_group_id get_collective_group_id() const { return m_cgid; }
17,506✔
112

113
                const buffer_access_map& get_buffer_access_map() const { return m_access_map; }
46,898✔
114

115
                const side_effect_map& get_side_effect_map() const { return m_side_effects; }
16,058✔
116

117
                const task_geometry& get_geometry() const { return m_geometry; }
2,213✔
118

119
                int get_dimensions() const { return m_geometry.dimensions; }
1✔
120

121
                range<3> get_global_size() const { return m_geometry.global_size; }
23,986✔
122

123
                id<3> get_global_offset() const { return m_geometry.global_offset; }
11,706✔
124

125
                range<3> get_granularity() const { return m_geometry.granularity; }
12,713✔
126

127
                void set_debug_name(const std::string& debug_name) { m_debug_name = debug_name; }
1,284✔
128
                const std::string& get_debug_name() const { return m_debug_name; }
9,071✔
129

130
                bool has_variable_split() const { return m_type == task_type::host_compute || m_type == task_type::device_compute; }
7,444✔
131

132
                execution_target get_execution_target() const {
16,649✔
133
                        switch(m_type) {
16,649!
134
                        case task_type::epoch: return execution_target::none;
×
135
                        case task_type::device_compute: return execution_target::device;
8,959✔
136
                        case task_type::host_compute:
7,690✔
137
                        case task_type::collective:
138
                        case task_type::master_node: return execution_target::host;
7,690✔
139
                        case task_type::horizon:
×
140
                        case task_type::fence: return execution_target::none;
×
141
                        default: utils::unreachable(); // LCOV_EXCL_LINE
142
                        }
143
                }
144

145
                const reduction_set& get_reductions() const { return m_reductions; }
78,666✔
146

147
                epoch_action get_epoch_action() const { return m_epoch_action; }
4,178✔
148

149
                task_promise* get_task_promise() const { return m_promise.get(); }
1,334✔
150

151
                template <typename Launcher>
152
                Launcher get_launcher() const {
3,276✔
153
                        return std::get<Launcher>(m_launcher);
3,276✔
154
                }
155

156
                void add_hint(std::unique_ptr<hint_base>&& h) { m_hints.emplace_back(std::move(h)); }
142✔
157

158
                template <typename Hint>
159
                const Hint* get_hint() const {
12,145✔
160
                        static_assert(std::is_base_of_v<hint_base, Hint>, "Hint must extend hint_base");
161
                        for(auto& h : m_hints) {
12,532✔
162
                                if(auto* ptr = dynamic_cast<Hint*>(h.get()); ptr != nullptr) { return ptr; }
667!
163
                        }
164
                        return nullptr;
11,865✔
165
                }
166

167
                static std::unique_ptr<task> make_epoch(task_id tid, detail::epoch_action action, std::unique_ptr<task_promise> promise) {
1,389✔
168
                        return std::unique_ptr<task>(new task(tid, task_type::epoch, non_collective_group_id, task_geometry{}, {}, {}, {}, {}, action, std::move(promise)));
1,389!
169
                }
170

171
                static std::unique_ptr<task> make_host_compute(task_id tid, task_geometry geometry, host_task_launcher launcher, buffer_access_map access_map,
362✔
172
                    side_effect_map side_effect_map, reduction_set reductions) {
173
                        return std::unique_ptr<task>(new task(tid, task_type::host_compute, non_collective_group_id, geometry, std::move(launcher), std::move(access_map),
724✔
174
                            std::move(side_effect_map), std::move(reductions), {}, nullptr));
1,086!
175
                }
176

177
                static std::unique_ptr<task> make_device_compute(
1,615✔
178
                    task_id tid, task_geometry geometry, device_kernel_launcher launcher, buffer_access_map access_map, reduction_set reductions) {
179
                        return std::unique_ptr<task>(new task(tid, task_type::device_compute, non_collective_group_id, geometry, std::move(launcher), std::move(access_map),
3,230✔
180
                            {}, std::move(reductions), {}, nullptr));
4,845!
181
                }
182

183
                static std::unique_ptr<task> make_collective(task_id tid, task_geometry geometry, collective_group_id cgid, size_t num_collective_nodes,
68✔
184
                    host_task_launcher launcher, buffer_access_map access_map, side_effect_map side_effect_map) {
185
                        // The geometry is required to construct the buffer_access_map, so we pass it in here even though it has to have a specific shape
186
                        assert(geometry.dimensions == 1 && geometry.global_size == detail::range_cast<3>(range(num_collective_nodes)) && geometry.global_offset == zeros);
68✔
187
                        return std::unique_ptr<task>(
188
                            new task(tid, task_type::collective, cgid, geometry, std::move(launcher), std::move(access_map), std::move(side_effect_map), {}, {}, nullptr));
68!
189
                }
190

191
                static std::unique_ptr<task> make_master_node(task_id tid, host_task_launcher launcher, buffer_access_map access_map, side_effect_map side_effect_map) {
1,390✔
192
                        return std::unique_ptr<task>(new task(tid, task_type::master_node, non_collective_group_id, task_geometry{}, std::move(launcher),
1,390✔
193
                            std::move(access_map), std::move(side_effect_map), {}, {}, nullptr));
2,780!
194
                }
195

196
                static std::unique_ptr<task> make_horizon(task_id tid) {
850✔
197
                        return std::unique_ptr<task>(new task(tid, task_type::horizon, non_collective_group_id, task_geometry{}, {}, {}, {}, {}, {}, nullptr));
850!
198
                }
199

200
                static std::unique_ptr<task> make_fence(
90✔
201
                    task_id tid, buffer_access_map access_map, side_effect_map side_effect_map, std::unique_ptr<task_promise> promise) {
202
                        return std::unique_ptr<task>(new task(tid, task_type::fence, non_collective_group_id, task_geometry{}, {}, std::move(access_map),
90✔
203
                            std::move(side_effect_map), {}, {}, std::move(promise)));
180!
204
                }
205

206
          private:
207
                task_id m_tid;
208
                task_type m_type;
209
                collective_group_id m_cgid;
210
                task_geometry m_geometry;
211
                command_group_launcher m_launcher;
212
                buffer_access_map m_access_map;
213
                detail::side_effect_map m_side_effects;
214
                reduction_set m_reductions;
215
                std::string m_debug_name;
216
                detail::epoch_action m_epoch_action;
217
                std::unique_ptr<task_promise> m_promise; // TODO keep user_allocation_id in struct task instead of inside task_promise
218
                std::vector<std::unique_ptr<hint_base>> m_hints;
219

220
                task(task_id tid, task_type type, collective_group_id cgid, task_geometry geometry, command_group_launcher launcher, buffer_access_map access_map,
5,764✔
221
                    detail::side_effect_map side_effects, reduction_set reductions, detail::epoch_action epoch_action, std::unique_ptr<task_promise> promise)
222
                    : m_tid(tid), m_type(type), m_cgid(cgid), m_geometry(geometry), m_launcher(std::move(launcher)), m_access_map(std::move(access_map)),
5,764✔
223
                      m_side_effects(std::move(side_effects)), m_reductions(std::move(reductions)), m_epoch_action(epoch_action), m_promise(std::move(promise)) {
11,528✔
224
                        assert(type == task_type::host_compute || type == task_type::device_compute || get_granularity().size() == 1);
5,764✔
225
                        // Only host tasks can have side effects
226
                        assert(this->m_side_effects.empty() || type == task_type::host_compute || type == task_type::collective || type == task_type::master_node
5,764✔
227
                               || type == task_type::fence);
228
                }
5,764✔
229
        };
230

231
        std::unique_ptr<detail::task> make_command_group_task(const detail::task_id tid, const size_t num_collective_nodes, raw_command_group&& cg);
232

233
        [[nodiscard]] std::string print_task_debug_label(const task& tsk, bool title_case = false);
234

235
        /// Determines which overlapping regions appear between write accesses when the iteration space of `tsk` is split into `chunks`.
236
        std::unordered_map<buffer_id, region<3>> detect_overlapping_writes(const task& tsk, const box_vector<3>& chunks);
237

238
        /// The task graph (TDAG) represents all cluster-wide operations, such as command group submissions and fences, and their interdependencies.
239
        class task_graph : public graph<task> {}; // inheritance instead of type alias so we can forward declare task_graph
240

241
} // namespace detail
242
} // 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