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

daisytuner / docc / 22949872003

11 Mar 2026 11:15AM UTC coverage: 63.681% (-0.9%) from 64.6%
22949872003

push

github

web-flow
Merge pull request #569 from daisytuner/HIPtarget

ROCmTarget

191 of 803 new or added lines in 15 files covered. (23.79%)

3 existing lines in 2 files now uncovered.

24700 of 38787 relevant lines covered (63.68%)

370.4 hits per line

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

74.44
/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✔
NEW
31
                            throw InvalidSDFGException("Nested map in GPU kernel has repeated X dimension");
×
NEW
32
                        }
×
33
                        foundX = true;
12✔
34
                    } else if (dim == GPUDimension::Y) {
27✔
35
                        if (foundY) {
12✔
NEW
36
                            throw InvalidSDFGException("Nested map in GPU kernel has repeated Y dimension");
×
NEW
37
                        }
×
38
                        foundY = true;
12✔
39
                    } else if (dim == GPUDimension::Z) {
15✔
40
                        if (foundZ) {
15✔
NEW
41
                            throw InvalidSDFGException("Nested map in GPU kernel has repeated Z dimension");
×
NEW
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✔
NEW
55
                throw InvalidSDFGException("Nested map in GPU kernel not GPU or Sequential");
×
NEW
56
            }
×
57

58
            if (map->schedule_type().value() == structured_control_flow::ScheduleType_Sequential::value()) {
33✔
NEW
59
                continue;
×
NEW
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
    auto& assumptions_analysis = analysis_manager.get<analysis::AssumptionsAnalysis>();
24✔
78

79
    symbolic::Expression init = SymEngine::null;
24✔
80
    symbolic::Expression stride = SymEngine::null;
24✔
81
    symbolic::Expression bound = SymEngine::null;
24✔
82

83
    for (auto loop : loops) {
33✔
84
        if (auto map = dynamic_cast<structured_control_flow::Map*>(loop)) {
33✔
85
            if (map->schedule_type().value() != ScheduleT::value() &&
33✔
86
                map->schedule_type().value() != structured_control_flow::ScheduleType_Sequential::value()) {
33✔
NEW
87
                throw InvalidSDFGException("Nested map in GPU kernel not GPU or Sequential");
×
NEW
88
            }
×
89
            if (map->schedule_type().value() == structured_control_flow::ScheduleType_Sequential::value()) {
33✔
NEW
90
                continue;
×
NEW
91
            }
×
92
            if (ScheduleT::dimension(map->schedule_type()) != dimension) {
33✔
93
                continue;
20✔
94
            }
20✔
95
            if (init != SymEngine::null) {
13✔
NEW
96
                if (symbolic::eq(init, map->init())) {
×
NEW
97
                    throw InvalidSDFGException("Nested map in GPU kernel has repeated dimension with different init");
×
NEW
98
                }
×
NEW
99
            }
×
100

101
            init = map->init();
13✔
102
            if (!symbolic::eq(init, symbolic::zero())) {
13✔
NEW
103
                throw InvalidSDFGException("Init is not zero");
×
NEW
104
            }
×
105

106
            if (stride != SymEngine::null) {
13✔
NEW
107
                if (!symbolic::eq(stride, analysis::LoopAnalysis::stride(map))) {
×
NEW
108
                    throw InvalidSDFGException("Nested map in GPU kernel has repeated dimension with different stride");
×
NEW
109
                }
×
NEW
110
            }
×
111

112
            stride = analysis::LoopAnalysis::stride(map);
13✔
113
            if (!symbolic::eq(stride, symbolic::one())) {
13✔
NEW
114
                throw InvalidSDFGException("Stride is not one");
×
NEW
115
            }
×
116

117
            if (bound != SymEngine::null) {
13✔
NEW
118
                if (!symbolic::eq(bound, analysis::LoopAnalysis::canonical_bound(map, assumptions_analysis))) {
×
NEW
119
                    throw InvalidSDFGException("Nested map in GPU kernel has repeated dimension with different bound");
×
NEW
120
                }
×
NEW
121
            }
×
122

123
            bound = analysis::LoopAnalysis::canonical_bound(map, assumptions_analysis);
13✔
124
            if (bound == SymEngine::null) {
13✔
NEW
125
                throw InvalidSDFGException("Canonical bound is null");
×
NEW
126
            }
×
127
            auto num_iterations = symbolic::div(bound, stride);
13✔
128
            num_iterations = symbolic::sub(num_iterations, init);
13✔
129

130
            return num_iterations;
13✔
131
        }
13✔
132
    }
33✔
133
    return symbolic::one();
11✔
134
}
24✔
135

136
template<typename ScheduleT>
137
bool is_outermost_gpu_map(structured_control_flow::Map& node, analysis::AnalysisManager& analysis_manager) {
16✔
138
    auto& loop_analysis = analysis_manager.get<analysis::LoopAnalysis>();
16✔
139
    auto& loop_tree = loop_analysis.loop_tree();
16✔
140
    structured_control_flow::ControlFlowNode* ancestor = loop_tree.at(&node);
16✔
141
    while (ancestor != nullptr) {
16✔
142
        if (auto map = dynamic_cast<structured_control_flow::Map*>(ancestor)) {
8✔
143
            if (map->schedule_type().value() == ScheduleT::value()) {
8✔
144
                return false;
8✔
145
            }
8✔
146
        }
8✔
NEW
147
        ancestor = loop_tree.at(ancestor);
×
NEW
148
    }
×
149
    return true;
8✔
150
}
16✔
151

152
template<typename ScheduleT>
153
symbolic::SymbolSet get_gpu_indvars(
154
    structured_control_flow::Map& node, analysis::AnalysisManager& analysis_manager, GPUDimension dimension
155
) {
24✔
156
    auto& loop_analysis = analysis_manager.get<analysis::LoopAnalysis>();
24✔
157
    auto loops = loop_analysis.descendants(&node);
24✔
158
    loops.insert(&node);
24✔
159
    symbolic::SymbolSet indvars;
24✔
160
    for (const auto& loop : loops) {
39✔
161
        if (auto map = dynamic_cast<structured_control_flow::Map*>(loop)) {
39✔
162
            if (map->schedule_type().value() == ScheduleT::value()) {
39✔
163
                if (ScheduleT::dimension(map->schedule_type()) == dimension) {
39✔
164
                    indvars.insert(map->indvar());
13✔
165
                }
13✔
166
            }
39✔
167
        }
39✔
168
    }
39✔
169
    return indvars;
24✔
170
}
24✔
171

172
// Explicit template instantiations for CUDA
173
template symbolic::Expression find_nested_gpu_blocksize<cuda::ScheduleType_CUDA>(
174
    structured_control_flow::Map& node, analysis::AnalysisManager& analysis_manager, GPUDimension dimension
175
);
176

177
template symbolic::Expression find_nested_gpu_iterations<cuda::ScheduleType_CUDA>(
178
    structured_control_flow::Map& node, analysis::AnalysisManager& analysis_manager, GPUDimension dimension
179
);
180

181
template bool is_outermost_gpu_map<
182
    cuda::ScheduleType_CUDA>(structured_control_flow::Map& node, analysis::AnalysisManager& analysis_manager);
183

184
template symbolic::SymbolSet get_gpu_indvars<cuda::ScheduleType_CUDA>(
185
    structured_control_flow::Map& node, analysis::AnalysisManager& analysis_manager, GPUDimension dimension
186
);
187

188
// Explicit template instantiations for ROCM
189
template symbolic::Expression find_nested_gpu_blocksize<rocm::ScheduleType_ROCM>(
190
    structured_control_flow::Map& node, analysis::AnalysisManager& analysis_manager, GPUDimension dimension
191
);
192

193
template symbolic::Expression find_nested_gpu_iterations<rocm::ScheduleType_ROCM>(
194
    structured_control_flow::Map& node, analysis::AnalysisManager& analysis_manager, GPUDimension dimension
195
);
196

197
template bool is_outermost_gpu_map<
198
    rocm::ScheduleType_ROCM>(structured_control_flow::Map& node, analysis::AnalysisManager& analysis_manager);
199

200
template symbolic::SymbolSet get_gpu_indvars<rocm::ScheduleType_ROCM>(
201
    structured_control_flow::Map& node, analysis::AnalysisManager& analysis_manager, GPUDimension dimension
202
);
203

204
} // namespace gpu
205
} // namespace sdfg
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