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

daisytuner / docc / 28851442347

07 Jul 2026 08:09AM UTC coverage: 62.959% (+1.3%) from 61.644%
28851442347

Pull #810

github

web-flow
Merge 768a26f80 into e7f8bfb2e
Pull Request #810: Add DOCC_REUSE_SOURCES envar to recompile the shared library from locally edited sources

37 of 46 new or added lines in 1 file covered. (80.43%)

3687 existing lines in 112 files now uncovered.

40560 of 64423 relevant lines covered (62.96%)

963.15 hits per line

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

85.12
/opt/src/targets/gpu/gpu_map_utils.cpp
1
#include "sdfg/targets/gpu/gpu_map_utils.h"
2

3
#include "sdfg/analysis/assumptions_analysis.h"
4
#include "sdfg/analysis/loop_analysis.h"
5
#include "sdfg/targets/cuda/cuda.h"
6
#include "sdfg/targets/rocm/rocm.h"
7

8
namespace sdfg {
9
namespace gpu {
10

11
template<typename ScheduleT>
12
symbolic::Expression find_nested_gpu_blocksize(
13
    structured_control_flow::Map& node, analysis::AnalysisManager& analysis_manager, GPUDimension dimension
14
) {
24✔
15
    auto& loop_analysis = analysis_manager.get<analysis::LoopAnalysis>();
24✔
16
    auto loops = loop_analysis.descendants(&node);
24✔
17
    loops.insert(&node);
24✔
18

19
    // Check for repeated dimensions in loop tree paths
20
    auto loop_tree_paths = loop_analysis.loop_tree_paths(&node);
24✔
21
    for (auto& path : loop_tree_paths) {
24✔
22
        bool foundX = false;
24✔
23
        bool foundY = false;
24✔
24
        bool foundZ = false;
24✔
25
        for (auto& loop : path) {
39✔
26
            if (auto map = dynamic_cast<structured_control_flow::Map*>(loop)) {
39✔
27
                if (map->schedule_type().value() == ScheduleT::value()) {
39✔
28
                    auto dim = ScheduleT::dimension(map->schedule_type());
39✔
29
                    if (dim == GPUDimension::X) {
39✔
30
                        if (foundX) {
12✔
31
                            throw InvalidSDFGException("Nested map in GPU kernel has repeated X dimension");
×
32
                        }
×
33
                        foundX = true;
12✔
34
                    } else if (dim == GPUDimension::Y) {
27✔
35
                        if (foundY) {
12✔
36
                            throw InvalidSDFGException("Nested map in GPU kernel has repeated Y dimension");
×
37
                        }
×
38
                        foundY = true;
12✔
39
                    } else if (dim == GPUDimension::Z) {
15✔
40
                        if (foundZ) {
15✔
41
                            throw InvalidSDFGException("Nested map in GPU kernel has repeated Z dimension");
×
42
                        }
×
43
                        foundZ = true;
15✔
44
                    }
15✔
45
                }
39✔
46
            }
39✔
47
        }
39✔
48
    }
24✔
49

50
    // Find block size for the requested dimension
51
    for (auto loop : loops) {
33✔
52
        if (auto map = dynamic_cast<structured_control_flow::Map*>(loop)) {
33✔
53
            if (map->schedule_type().value() != ScheduleT::value() &&
33✔
54
                map->schedule_type().value() != structured_control_flow::ScheduleType_Sequential::value()) {
33✔
55
                throw InvalidSDFGException("Nested map in GPU kernel not GPU or Sequential");
×
56
            }
×
57

58
            if (map->schedule_type().value() == structured_control_flow::ScheduleType_Sequential::value()) {
33✔
59
                continue;
×
60
            }
×
61

62
            if (ScheduleT::dimension(map->schedule_type()) == dimension) {
33✔
63
                return ScheduleT::block_size(map->schedule_type());
13✔
64
            }
13✔
65
        }
33✔
66
    }
33✔
67
    return symbolic::one();
11✔
68
}
24✔
69

70
template<typename ScheduleT>
71
symbolic::Expression find_nested_gpu_iterations(
72
    structured_control_flow::Map& node, analysis::AnalysisManager& analysis_manager, GPUDimension dimension
73
) {
24✔
74
    auto& loop_analysis = analysis_manager.get<analysis::LoopAnalysis>();
24✔
75
    auto loops = loop_analysis.descendants(&node);
24✔
76
    loops.insert(&node);
24✔
77

78
    symbolic::Expression max_num_iterations = symbolic::one();
24✔
79

80
    for (auto loop : loops) {
39✔
81
        if (auto map = dynamic_cast<structured_control_flow::Map*>(loop)) {
39✔
82
            if (map->schedule_type().value() != ScheduleT::value() &&
39✔
83
                map->schedule_type().value() != structured_control_flow::ScheduleType_Sequential::value()) {
39✔
UNCOV
84
                throw InvalidSDFGException("Nested map in GPU kernel not GPU or Sequential");
×
85
            }
×
86
            if (map->schedule_type().value() == structured_control_flow::ScheduleType_Sequential::value()) {
39✔
UNCOV
87
                continue;
×
UNCOV
88
            }
×
89
            if (ScheduleT::dimension(map->schedule_type()) != dimension) {
39✔
90
                continue;
26✔
91
            }
26✔
92

93
            // Note: arbitrary `init` and `stride` are permitted here; the
94
            // dispatcher emits `indvar = init + thread_flat_id * stride` so
95
            // the body sees the natural strided value. `num_iterations()`
96
            // already accounts for both.
97
            auto num_iterations = map->num_iterations();
13✔
98
            if (num_iterations.is_null()) {
13✔
UNCOV
99
                throw InvalidSDFGException("Cannot determine number of iterations for nested map in GPU kernel");
×
UNCOV
100
            }
×
101
            max_num_iterations = symbolic::max(max_num_iterations, num_iterations);
13✔
102
        }
13✔
103
    }
39✔
104
    return max_num_iterations;
24✔
105
}
24✔
106

107
template<typename ScheduleT>
108
bool is_outermost_gpu_map(structured_control_flow::Map& node, analysis::AnalysisManager& analysis_manager) {
16✔
109
    auto& loop_analysis = analysis_manager.get<analysis::LoopAnalysis>();
16✔
110
    auto& loop_tree = loop_analysis.loop_tree();
16✔
111
    structured_control_flow::ControlFlowNode* ancestor = loop_tree.at(&node);
16✔
112
    while (ancestor != nullptr) {
16✔
113
        if (auto map = dynamic_cast<structured_control_flow::Map*>(ancestor)) {
8✔
114
            if (map->schedule_type().value() == ScheduleT::value()) {
8✔
115
                return false;
8✔
116
            }
8✔
117
        }
8✔
UNCOV
118
        ancestor = loop_tree.at(ancestor);
×
UNCOV
119
    }
×
120
    return true;
8✔
121
}
16✔
122

123
template<typename ScheduleT>
124
symbolic::SymbolSet get_gpu_indvars(
125
    structured_control_flow::Map& node, analysis::AnalysisManager& analysis_manager, GPUDimension dimension
126
) {
24✔
127
    auto& loop_analysis = analysis_manager.get<analysis::LoopAnalysis>();
24✔
128
    auto loops = loop_analysis.descendants(&node);
24✔
129
    loops.insert(&node);
24✔
130
    symbolic::SymbolSet indvars;
24✔
131
    for (const auto& loop : loops) {
39✔
132
        if (auto map = dynamic_cast<structured_control_flow::Map*>(loop)) {
39✔
133
            if (map->schedule_type().value() == ScheduleT::value()) {
39✔
134
                if (ScheduleT::dimension(map->schedule_type()) == dimension) {
39✔
135
                    indvars.insert(map->indvar());
13✔
136
                }
13✔
137
            }
39✔
138
        }
39✔
139
    }
39✔
140
    return indvars;
24✔
141
}
24✔
142

143
template<typename ScheduleT>
144
std::vector<structured_control_flow::Map*>
145
get_gpu_maps(structured_control_flow::Map& node, analysis::AnalysisManager& analysis_manager, GPUDimension dimension) {
12✔
146
    auto& loop_analysis = analysis_manager.get<analysis::LoopAnalysis>();
12✔
147
    auto loops = loop_analysis.descendants(&node);
12✔
148
    loops.insert(&node);
12✔
149
    std::vector<structured_control_flow::Map*> maps;
12✔
150
    for (const auto& loop : loops) {
24✔
151
        if (auto map = dynamic_cast<structured_control_flow::Map*>(loop)) {
24✔
152
            if (map->schedule_type().value() == ScheduleT::value()) {
24✔
153
                if (ScheduleT::dimension(map->schedule_type()) == dimension) {
24✔
154
                    maps.push_back(map);
8✔
155
                }
8✔
156
            }
24✔
157
        }
24✔
158
    }
24✔
159
    return maps;
12✔
160
}
12✔
161

162
// Explicit template instantiations for CUDA
163
template symbolic::Expression find_nested_gpu_blocksize<cuda::ScheduleType_CUDA>(
164
    structured_control_flow::Map& node, analysis::AnalysisManager& analysis_manager, GPUDimension dimension
165
);
166

167
template symbolic::Expression find_nested_gpu_iterations<cuda::ScheduleType_CUDA>(
168
    structured_control_flow::Map& node, analysis::AnalysisManager& analysis_manager, GPUDimension dimension
169
);
170

171
template bool is_outermost_gpu_map<
172
    cuda::ScheduleType_CUDA>(structured_control_flow::Map& node, analysis::AnalysisManager& analysis_manager);
173

174
template symbolic::SymbolSet get_gpu_indvars<cuda::ScheduleType_CUDA>(
175
    structured_control_flow::Map& node, analysis::AnalysisManager& analysis_manager, GPUDimension dimension
176
);
177

178
template std::vector<structured_control_flow::Map*> get_gpu_maps<cuda::ScheduleType_CUDA>(
179
    structured_control_flow::Map& node, analysis::AnalysisManager& analysis_manager, GPUDimension dimension
180
);
181

182
// Explicit template instantiations for ROCM
183
template symbolic::Expression find_nested_gpu_blocksize<rocm::ScheduleType_ROCM>(
184
    structured_control_flow::Map& node, analysis::AnalysisManager& analysis_manager, GPUDimension dimension
185
);
186

187
template symbolic::Expression find_nested_gpu_iterations<rocm::ScheduleType_ROCM>(
188
    structured_control_flow::Map& node, analysis::AnalysisManager& analysis_manager, GPUDimension dimension
189
);
190

191
template bool is_outermost_gpu_map<
192
    rocm::ScheduleType_ROCM>(structured_control_flow::Map& node, analysis::AnalysisManager& analysis_manager);
193

194
template symbolic::SymbolSet get_gpu_indvars<rocm::ScheduleType_ROCM>(
195
    structured_control_flow::Map& node, analysis::AnalysisManager& analysis_manager, GPUDimension dimension
196
);
197

198
template std::vector<structured_control_flow::Map*> get_gpu_maps<rocm::ScheduleType_ROCM>(
199
    structured_control_flow::Map& node, analysis::AnalysisManager& analysis_manager, GPUDimension dimension
200
);
201

202
} // namespace gpu
203
} // namespace sdfg
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc