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

daisytuner / sdfglib / 20781520363

07 Jan 2026 10:50AM UTC coverage: 61.994% (-0.2%) from 62.168%
20781520363

Pull #438

github

web-flow
Merge af6583671 into 0c34ccd02
Pull Request #438: Cuda tiling

8 of 51 new or added lines in 6 files covered. (15.69%)

2 existing lines in 1 file now uncovered.

14904 of 24041 relevant lines covered (61.99%)

88.13 hits per line

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

83.16
/src/transformations/loop_tiling.cpp
1
#include "sdfg/transformations/loop_tiling.h"
2

3
#include "sdfg/analysis/assumptions_analysis.h"
4
#include "sdfg/analysis/loop_analysis.h"
5
#include "sdfg/analysis/scope_analysis.h"
6
#include "sdfg/builder/structured_sdfg_builder.h"
7
#include "sdfg/structured_control_flow/structured_loop.h"
8
#include "sdfg/symbolic/symbolic.h"
9

10
namespace sdfg {
11
namespace transformations {
12

13
LoopTiling::LoopTiling(structured_control_flow::StructuredLoop& loop, size_t tile_size)
14
    : loop_(loop), tile_size_(tile_size) {};
14✔
15

16
std::string LoopTiling::name() const { return "LoopTiling"; };
7✔
17

18
bool LoopTiling::can_be_applied(builder::StructuredSDFGBuilder& builder, analysis::AnalysisManager& analysis_manager) {
14✔
19
    if (this->tile_size_ <= 1) {
14✔
20
        return false;
4✔
21
    }
4✔
22
    // Criterion contiguous loop
23
    auto& assumptions_analysis = analysis_manager.get<analysis::AssumptionsAnalysis>();
10✔
24
    return analysis::LoopAnalysis::is_contiguous(&loop_, assumptions_analysis);
10✔
25
};
14✔
26

27
void LoopTiling::apply(builder::StructuredSDFGBuilder& builder, analysis::AnalysisManager& analysis_manager) {
10✔
28
    auto& sdfg = builder.subject();
10✔
29

30
    auto& scope_analysis = analysis_manager.get<analysis::ScopeAnalysis>();
10✔
31
    auto parent = static_cast<structured_control_flow::Sequence*>(scope_analysis.parent_scope(&loop_));
10✔
32
    size_t index = parent->index(loop_);
10✔
33
    auto& transition = parent->at(index).second;
10✔
34

35
    auto indvar = loop_.indvar();
10✔
36

37
    // Step 1: Define new outer loop
38
    auto outer_indvar_str = builder.find_new_name(indvar->get_name() + "_tile");
10✔
39
    builder.add_container(outer_indvar_str, sdfg.type(loop_.indvar()->get_name()));
10✔
40

41
    auto outer_indvar = symbolic::symbol(outer_indvar_str);
10✔
42
    auto outer_condition = symbolic::subs(loop_.condition(), indvar, outer_indvar);
10✔
43
    auto outer_update = symbolic::add(outer_indvar, symbolic::integer(this->tile_size_));
10✔
44

45
    structured_control_flow::StructuredLoop* outer_loop = nullptr;
10✔
46
    if (auto map = dynamic_cast<structured_control_flow::Map*>(&loop_)) {
10✔
47
        outer_loop = &builder.add_map_before(
6✔
48
            *parent,
6✔
49
            loop_,
6✔
50
            outer_indvar,
6✔
51
            outer_condition,
6✔
52
            loop_.init(),
6✔
53
            outer_update,
6✔
54
            map->schedule_type(),
6✔
55
            transition.assignments(),
6✔
56
            loop_.debug_info()
6✔
57
        );
6✔
58
    } else {
6✔
59
        outer_loop = &builder.add_for_before(
4✔
60
            *parent,
4✔
61
            loop_,
4✔
62
            outer_indvar,
4✔
63
            outer_condition,
4✔
64
            loop_.init(),
4✔
65
            outer_update,
4✔
66
            transition.assignments(),
4✔
67
            loop_.debug_info()
4✔
68
        );
4✔
69
    }
4✔
70

71
    // Step 2: Redefine inner loop
72
    auto inner_indvar = indvar;
10✔
73
    auto inner_init = outer_indvar;
10✔
74
    auto inner_condition_tile =
10✔
75
        symbolic::Lt(inner_indvar, symbolic::add(outer_indvar, symbolic::integer(this->tile_size_)));
10✔
76

77
    symbolic::Condition inner_condition = symbolic::And(inner_condition_tile, loop_.condition());
10✔
78

79
    auto inner_update = symbolic::add(inner_indvar, symbolic::integer(1));
10✔
80
    builder.update_loop(loop_, inner_indvar, inner_condition, inner_init, inner_update);
10✔
81

82
    // Step 3: Move loop into tiling loop
83
    transition.assignments().clear();
10✔
84
    builder.move_child(*parent, index + 1, outer_loop->root());
10✔
85

86
    analysis_manager.invalidate_all();
10✔
87
    applied_ = true;
10✔
88
    inner_loop_ = &loop_;
10✔
89
    outer_loop_ = outer_loop;
10✔
90
};
10✔
91

92
void LoopTiling::to_json(nlohmann::json& j) const {
4✔
93
    std::string loop_type;
4✔
94
    if (dynamic_cast<structured_control_flow::For*>(&loop_)) {
4✔
95
        loop_type = "for";
2✔
96
    } else if (dynamic_cast<structured_control_flow::Map*>(&loop_)) {
2✔
97
        loop_type = "map";
2✔
98
    } else {
2✔
NEW
99
        throw InvalidSDFGException("Unsupported loop type for serialization of loop: " + loop_.indvar()->get_name());
×
100
    }
×
101

102
    j["transformation_type"] = this->name();
4✔
103
    j["subgraph"] = {{"0", {{"element_id", this->loop_.element_id()}, {"type", loop_type}}}};
4✔
104
    j["parameters"] = {{"tile_size", tile_size_}};
4✔
105
};
4✔
106

107
LoopTiling LoopTiling::from_json(builder::StructuredSDFGBuilder& builder, const nlohmann::json& desc) {
7✔
108
    auto loop_id = desc["subgraph"]["0"]["element_id"].get<size_t>();
7✔
109
    size_t tile_size = desc["parameters"]["tile_size"].get<size_t>();
7✔
110
    auto element = builder.find_element_by_id(loop_id);
7✔
111
    if (!element) {
7✔
112
        throw InvalidTransformationDescriptionException("Element with ID " + std::to_string(loop_id) + " not found.");
×
113
    }
×
114
    auto loop = dynamic_cast<structured_control_flow::StructuredLoop*>(element);
7✔
115

116
    return LoopTiling(*loop, tile_size);
7✔
117
};
7✔
118

NEW
119
structured_control_flow::StructuredLoop* LoopTiling::inner_loop() {
×
NEW
120
    if (!applied_) {
×
NEW
121
        throw InvalidSDFGException("Accessing tiled loop before their creation.");
×
NEW
122
    }
×
123

NEW
124
    return inner_loop_;
×
NEW
125
}
×
126

NEW
127
structured_control_flow::StructuredLoop* LoopTiling::outer_loop() {
×
NEW
128
    if (!applied_) {
×
NEW
129
        throw InvalidSDFGException("Accessing tiled loop before their creation.");
×
NEW
130
    }
×
131

NEW
132
    return outer_loop_;
×
NEW
133
}
×
134

135
} // namespace transformations
136
} // 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