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

celerity / celerity-runtime / 10213354420

02 Aug 2024 09:31AM UTC coverage: 94.7% (+1.8%) from 92.884%
10213354420

Pull #265

github

web-flow
Merge 27912c121 into b431cd83c
Pull Request #265: [IDAG] Switch to Instruction-Graph Scheduling

2978 of 3376 branches covered (88.21%)

Branch coverage included in aggregate %.

368 of 368 new or added lines in 19 files covered. (100.0%)

1 existing line in 1 file now uncovered.

6564 of 6700 relevant lines covered (97.97%)

1522958.6 hits per line

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

92.06
/src/task.cc
1
#include "task.h"
2

3
#include "access_modes.h"
4
#include "utils.h"
5

6

7
namespace celerity {
8
namespace detail {
9

10
        std::unordered_set<buffer_id> buffer_access_map::get_accessed_buffers() const {
37,285✔
11
                std::unordered_set<buffer_id> result;
37,285✔
12
                for(const auto& [bid, _] : m_accesses) {
69,450✔
13
                        result.emplace(bid);
32,167✔
14
                }
15
                return result;
37,285✔
16
        }
×
17

18
        std::unordered_set<cl::sycl::access::mode> buffer_access_map::get_access_modes(buffer_id bid) const {
32,968✔
19
                std::unordered_set<cl::sycl::access::mode> result;
32,968✔
20
                for(const auto& [b, rm] : m_accesses) {
77,692✔
21
                        if(b == bid) { result.insert(rm->get_access_mode()); }
44,722✔
22
                }
23
                return result;
32,968✔
24
        }
×
25

26
        template <int KernelDims>
27
        subrange<3> apply_range_mapper(const range_mapper_base* rm, const chunk<KernelDims>& chnk) {
46,331✔
28
                switch(rm->get_buffer_dimensions()) {
46,331!
29
                case 0: return subrange_cast<3>(subrange<0>());
22,908✔
30
                case 1: return subrange_cast<3>(rm->map_1(chnk));
36,552✔
31
                case 2: return subrange_cast<3>(rm->map_2(chnk));
31,159✔
32
                case 3: return rm->map_3(chnk);
1,018✔
UNCOV
33
                default: assert(false); return subrange<3>{};
×
34
                }
35
        }
36

37
        subrange<3> apply_range_mapper(const range_mapper_base* rm, const chunk<3>& chnk, int kernel_dims) {
46,332✔
38
                switch(kernel_dims) {
46,332!
39
                case 0: return apply_range_mapper<0>(rm, chunk_cast<0>(chnk));
50,928✔
40
                case 1: return apply_range_mapper<1>(rm, chunk_cast<1>(chnk));
18,151✔
41
                case 2: return apply_range_mapper<2>(rm, chunk_cast<2>(chnk));
22,233✔
42
                case 3: return apply_range_mapper<3>(rm, chunk_cast<3>(chnk));
1,343✔
43
                default: assert(!"Unreachable"); return subrange<3>{};
×
44
                }
45
        }
46

47
        region<3> buffer_access_map::get_mode_requirements(
80,431✔
48
            const buffer_id bid, const access_mode mode, const int kernel_dims, const subrange<3>& sr, const range<3>& global_size) const {
49
                box_vector<3> boxes;
80,431✔
50
                for(size_t i = 0; i < m_accesses.size(); ++i) {
181,336✔
51
                        if(m_accesses[i].first != bid || m_accesses[i].second->get_access_mode() != mode) continue;
100,902✔
52
                        boxes.push_back(get_requirements_for_nth_access(i, kernel_dims, sr, global_size));
38,379✔
53
                }
54
                return region(std::move(boxes));
160,851✔
55
        }
80,429✔
56

57
        box<3> buffer_access_map::get_requirements_for_nth_access(const size_t n, const int kernel_dims, const subrange<3>& sr, const range<3>& global_size) const {
42,326✔
58
                return apply_range_mapper(m_accesses[n].second.get(), chunk<3>{sr.offset, sr.range, global_size}, kernel_dims);
84,646✔
59
        }
60

61
        box_vector<3> buffer_access_map::get_required_contiguous_boxes(
4,162✔
62
            const buffer_id bid, const int kernel_dims, const subrange<3>& sr, const range<3>& global_size) const {
63
                box_vector<3> boxes;
4,162✔
64
                for(const auto& [a_bid, a_rm] : m_accesses) {
9,610✔
65
                        if(a_bid == bid) {
5,448✔
66
                                const auto accessed_box = box(apply_range_mapper(a_rm.get(), chunk<3>{sr.offset, sr.range, global_size}, kernel_dims));
4,006✔
67
                                if(!accessed_box.empty()) { boxes.push_back(accessed_box); }
4,006✔
68
                        }
69
                }
70
                return boxes;
4,162✔
71
        }
×
72

73
        void side_effect_map::add_side_effect(const host_object_id hoid, const experimental::side_effect_order order) {
228✔
74
                // TODO for multiple side effects on the same hoid, find the weakest order satisfying all of them
75
                emplace(hoid, order);
228✔
76
        }
228✔
77

78
        std::string print_task_debug_label(const task& tsk, bool title_case) {
32✔
79
                return utils::make_task_debug_label(tsk.get_type(), tsk.get_id(), tsk.get_debug_name(), title_case);
32✔
80
        }
81

82
        std::unordered_map<buffer_id, region<3>> detect_overlapping_writes(const task& tsk, const box_vector<3>& chunks) {
9,076✔
83
                const box<3> scalar_reduction_box({0, 0, 0}, {1, 1, 1});
9,076✔
84

85
                auto& bam = tsk.get_buffer_access_map();
9,076✔
86

87
                // track the union of writes we have checked so far in order to detect an overlap between that union and the next write
88
                std::unordered_map<buffer_id, region<3>> buffer_write_accumulators;
9,076✔
89
                // collect overlapping writes in order to report all of them before throwing
90
                std::unordered_map<buffer_id, region<3>> overlapping_writes;
9,076✔
91

92
                for(const auto bid : bam.get_accessed_buffers()) {
16,365✔
93
                        for(const auto& ck : chunks) {
16,444✔
94
                                region<3> writes;
9,155✔
95
                                for(const auto mode : bam.get_access_modes(bid)) {
18,642✔
96
                                        if(access::mode_traits::is_producer(mode)) {
9,487✔
97
                                                const auto req = bam.get_mode_requirements(bid, mode, tsk.get_dimensions(), ck.get_subrange(), tsk.get_global_size());
6,893✔
98
                                                writes = region_union(writes, req);
6,893✔
99
                                        }
6,893✔
100
                                }
9,155✔
101
                                if(!writes.empty()) {
9,155✔
102
                                        auto& write_accumulator = buffer_write_accumulators[bid]; // allow default-insert
6,840✔
103
                                        if(const auto overlap = region_intersection(write_accumulator, writes); !overlap.empty()) {
6,840✔
104
                                                auto& full_overlap = overlapping_writes[bid]; // allow default-insert
23✔
105
                                                full_overlap = region_union(full_overlap, overlap);
23✔
106
                                        }
6,840✔
107
                                        write_accumulator = region_union(write_accumulator, writes);
6,840✔
108
                                }
109
                        }
9,155✔
110
                }
9,076✔
111

112
                // we already check for accessor-reduction overlaps on task generation, but we still repeat the sanity-check here
113
                for(const auto& rinfo : tsk.get_reductions()) {
9,336✔
114
                        auto& write_accumulator = buffer_write_accumulators[rinfo.bid]; // allow default-insert
260✔
115
                        if(const auto overlap = region_intersection(write_accumulator, scalar_reduction_box); !overlap.empty()) {
260!
116
                                auto& full_overlap = overlapping_writes[rinfo.bid]; // allow default-insert
×
117
                                full_overlap = region_union(full_overlap, overlap);
×
118
                        }
260✔
119
                        write_accumulator = region_union(write_accumulator, scalar_reduction_box);
260✔
120
                }
121

122
                return overlapping_writes;
9,076✔
123
        }
9,076✔
124

125
} // namespace detail
126
} // 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