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

daisytuner / docc / 27500480732

14 Jun 2026 01:33PM UTC coverage: 61.642% (+0.1%) from 61.54%
27500480732

Pull #764

github

web-flow
Merge 3432db11b into 6b2e310be
Pull Request #764: Deprecates monolithic GPU transformations in favor of composable transformations

202 of 224 new or added lines in 2 files covered. (90.18%)

81 existing lines in 6 files now uncovered.

36559 of 59309 relevant lines covered (61.64%)

1132.66 hits per line

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

33.96
/opt/src/transformations/offloading/rocm_parallelize_nested_map.cpp
1
#include "sdfg/transformations/offloading/rocm_parallelize_nested_map.h"
2

3
#include <sdfg/analysis/loop_analysis.h>
4
#include "sdfg/exceptions.h"
5
#include "sdfg/symbolic/symbolic.h"
6
#include "sdfg/targets/rocm/rocm.h"
7

8
namespace sdfg {
9
namespace transformations {
10

11
ROCMParallelizeNestedMap::ROCMParallelizeNestedMap(structured_control_flow::Map& loop, size_t block_size)
12
    : loop_(loop), block_size_(block_size) {}
2✔
13

14
std::string ROCMParallelizeNestedMap::name() const { return "ROCMParallelizeNestedMap"; }
×
15

16
bool ROCMParallelizeNestedMap::
17
    can_be_applied(builder::StructuredSDFGBuilder& builder, analysis::AnalysisManager& analysis_manager) {
2✔
18
    auto& loop_analysis = analysis_manager.get<analysis::LoopAnalysis>();
2✔
19

20
    // Condition: Check if map is not yet parallelized with ROCM
21
    if (loop_.schedule_type().value() != ScheduleType_Sequential::value()) {
2✔
22
        return false;
×
23
    }
×
24

25
    // Condition: Check if parent loop exists
26
    auto parent = loop_analysis.parent_loop(&loop_);
2✔
27
    if (parent == nullptr) {
2✔
28
        return false;
×
29
    }
×
30

31
    // Condition: Check if parent loop is a ROCM map, and not Z dimension (final dimension)
32
    if (auto map = dynamic_cast<structured_control_flow::Map*>(parent)) {
2✔
33
        if (map->schedule_type().value() != rocm::ScheduleType_ROCM::value()) {
2✔
34
            return false;
×
35
        }
×
36
        if (rocm::ScheduleType_ROCM::dimension(map->schedule_type()) == rocm::ROCMDimension::Z) {
2✔
37
            return false;
×
38
        }
×
39
        auto parent_indvar = map->indvar();
2✔
40
        auto ancestor = parent;
2✔
41
        while (ancestor) {
4✔
42
            if (auto map_ancestor = dynamic_cast<structured_control_flow::Map*>(ancestor)) {
2✔
43
                parent_indvar = map_ancestor->indvar();
2✔
44
                for (auto& arg : symbolic::atoms(loop_.condition())) {
2✔
45
                    if (symbolic::eq(arg, parent_indvar)) {
2✔
46
                        return false;
×
47
                    }
×
48
                }
2✔
49
            }
2✔
50
            ancestor = loop_analysis.parent_loop(ancestor);
2✔
51
        }
2✔
52
    } else {
2✔
53
        return false;
×
54
    }
×
55

56
    // Condition: Check if current loop starts from 0
57
    if (!symbolic::eq(loop_.init(), symbolic::zero())) {
2✔
58
        return false;
×
59
    }
×
60

61
    // Condition: Loop has a stride of 1
62
    auto stride = loop_.stride();
2✔
63
    if (!symbolic::eq(stride, symbolic::one())) {
2✔
UNCOV
64
        return false;
×
UNCOV
65
    }
×
66

67
    // Condition: Resulting ROCm grid dimension must not exceed hardware limits.
68
    // Y and Z grid dimensions are limited to 65535.
69
    auto num_iters = loop_.num_iterations();
2✔
70
    if (!num_iters.is_null() && SymEngine::is_a<SymEngine::Integer>(*num_iters)) {
2✔
71
        int64_t iters = SymEngine::down_cast<const SymEngine::Integer&>(*num_iters).as_int();
2✔
72
        int64_t block = static_cast<int64_t>(block_size_);
2✔
73
        int64_t grid_size = (iters + block - 1) / block;
2✔
74

75
        constexpr int64_t max_grid_dim_yz = 65535;
2✔
76
        if (grid_size > max_grid_dim_yz) {
2✔
77
            return false;
1✔
78
        }
1✔
79
    }
2✔
80

81
    return true;
1✔
82
}
2✔
83

UNCOV
84
void ROCMParallelizeNestedMap::apply(builder::StructuredSDFGBuilder& builder, analysis::AnalysisManager& analysis_manager) {
×
85
    auto& loop_analysis = analysis_manager.get<analysis::LoopAnalysis>();
×
86
    auto parent = loop_analysis.parent_loop(&loop_);
×
87

88
    auto parent_dim =
×
89
        rocm::ScheduleType_ROCM::dimension(static_cast<structured_control_flow::Map*>(parent)->schedule_type());
×
90

91
    rocm::ROCMDimension child_dim;
×
92
    if (parent_dim == rocm::ROCMDimension::X) {
×
UNCOV
93
        child_dim = rocm::ROCMDimension::Y;
×
94
    } else if (parent_dim == rocm::ROCMDimension::Y) {
×
95
        child_dim = rocm::ROCMDimension::Z;
×
96
    } else {
×
UNCOV
97
        throw InvalidSDFGException("Parent loop is Z dimension, cannot parallelize nested map.");
×
98
    }
×
99

UNCOV
100
    auto new_schedule = rocm::ScheduleType_ROCM::create();
×
101
    rocm::ScheduleType_ROCM::dimension(new_schedule, child_dim);
×
102
    rocm::ScheduleType_ROCM::block_size(new_schedule, symbolic::integer(block_size_));
×
103

104
    builder.update_schedule_type(loop_, new_schedule);
×
105
}
×
106

UNCOV
107
void ROCMParallelizeNestedMap::to_json(nlohmann::json& j) const {
×
UNCOV
108
    if (dynamic_cast<structured_control_flow::For*>(&loop_)) {
×
109
        throw std::runtime_error("ROCMParallelizeNestedMap transformation does not support for-loops.");
×
UNCOV
110
    }
×
111
    j["transformation_type"] = this->name();
×
112

113
    // Describe the subgraph in a form compatible with EmbeddingRecorder/EmbeddingReplayer.
114
    // Keep the existing "loop" and "block_size" fields for backward compatibility.
115
    j["subgraph"] = {{"0", {{"element_id", loop_.element_id()}, {"type", "map"}}}};
×
116

UNCOV
117
    j["parameters"] = {{"block_size", block_size_}};
×
118

UNCOV
119
    j["loop"] = loop_.element_id();
×
UNCOV
120
    j["block_size"] = block_size_;
×
121
}
×
122

123
ROCMParallelizeNestedMap ROCMParallelizeNestedMap::
124
    from_json(builder::StructuredSDFGBuilder& builder, const nlohmann::json& j) {
×
125
    // Prefer the embedding-compatible representation (subgraph/parameters),
126
    // but fall back to legacy fields (loop/block_size) if needed.
127
    size_t loop_id;
×
128
    if (j.contains("subgraph")) {
×
UNCOV
129
        const auto& subgraph = j.at("subgraph");
×
130
        const auto& node_desc = subgraph.at("0");
×
131
        loop_id = node_desc.at("element_id").get<size_t>();
×
132
    } else {
×
133
        loop_id = j.at("loop").get<size_t>();
×
134
    }
×
135

136
    size_t block_size;
×
137
    if (j.contains("parameters") && j.at("parameters").contains("block_size")) {
×
138
        block_size = j.at("parameters").at("block_size").get<size_t>();
×
139
    } else {
×
140
        block_size = j.at("block_size").get<size_t>();
×
141
    }
×
142
    auto element = builder.find_element_by_id(loop_id);
×
143
    if (!element) {
×
144
        throw InvalidTransformationDescriptionException("Element with ID " + std::to_string(loop_id) + " not found.");
×
145
    }
×
UNCOV
146
    auto loop = dynamic_cast<structured_control_flow::Map*>(element);
×
UNCOV
147
    if (!loop) {
×
UNCOV
148
        throw InvalidTransformationDescriptionException("Element with ID " + std::to_string(loop_id) + " is not a loop.");
×
UNCOV
149
    }
×
UNCOV
150
    return ROCMParallelizeNestedMap(*loop, block_size);
×
UNCOV
151
}
×
152

153
} // namespace transformations
154
} // 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