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

daisytuner / docc / 27471076166

13 Jun 2026 03:33PM UTC coverage: 61.254% (-0.02%) from 61.274%
27471076166

Pull #760

github

web-flow
Merge d6c6a15bd into db7d71ecc
Pull Request #760: Add hardware limit checks for gpu

20 of 52 new or added lines in 4 files covered. (38.46%)

13 existing lines in 2 files now uncovered.

36267 of 59208 relevant lines covered (61.25%)

1122.95 hits per line

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

0.0
/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) {}
×
13

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

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

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

25
    // Condition: Check if parent loop exists
26
    auto parent = loop_analysis.parent_loop(&loop_);
×
27
    if (parent == nullptr) {
×
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)) {
×
33
        if (map->schedule_type().value() != rocm::ScheduleType_ROCM::value()) {
×
34
            return false;
×
35
        }
×
36
        if (rocm::ScheduleType_ROCM::dimension(map->schedule_type()) == rocm::ROCMDimension::Z) {
×
37
            return false;
×
38
        }
×
39
        auto parent_indvar = map->indvar();
×
40
        auto ancestor = parent;
×
41
        while (ancestor) {
×
42
            if (auto map_ancestor = dynamic_cast<structured_control_flow::Map*>(ancestor)) {
×
43
                parent_indvar = map_ancestor->indvar();
×
44
                for (auto& arg : symbolic::atoms(loop_.condition())) {
×
45
                    if (symbolic::eq(arg, parent_indvar)) {
×
46
                        return false;
×
47
                    }
×
48
                }
×
49
            }
×
50
            ancestor = loop_analysis.parent_loop(ancestor);
×
51
        }
×
52
    } else {
×
53
        return false;
×
54
    }
×
55

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

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

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

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

81
    return true;
×
82
}
×
83

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) {
×
93
        child_dim = rocm::ROCMDimension::Y;
×
94
    } else if (parent_dim == rocm::ROCMDimension::Y) {
×
95
        child_dim = rocm::ROCMDimension::Z;
×
96
    } else {
×
97
        throw InvalidSDFGException("Parent loop is Z dimension, cannot parallelize nested map.");
×
98
    }
×
99

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

107
void ROCMParallelizeNestedMap::to_json(nlohmann::json& j) const {
×
108
    if (dynamic_cast<structured_control_flow::For*>(&loop_)) {
×
109
        throw std::runtime_error("ROCMParallelizeNestedMap transformation does not support for-loops.");
×
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

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

119
    j["loop"] = loop_.element_id();
×
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")) {
×
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
    }
×
146
    auto loop = dynamic_cast<structured_control_flow::Map*>(element);
×
147
    if (!loop) {
×
148
        throw InvalidTransformationDescriptionException("Element with ID " + std::to_string(loop_id) + " is not a loop.");
×
149
    }
×
150
    return ROCMParallelizeNestedMap(*loop, block_size);
×
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