• 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_transform.cpp
1
#include "sdfg/transformations/offloading/rocm_transform.h"
2

3
#include <unordered_set>
4

5
#include "sdfg/structured_control_flow/block.h"
6
#include "sdfg/symbolic/symbolic.h"
7
#include "sdfg/targets/rocm/rocm_data_offloading_node.h"
8
#include "sdfg/transformations/transformation.h"
9
#include "symengine/symengine_rcp.h"
10

11
namespace sdfg {
12
namespace rocm {
13

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

NEW
16
bool ROCMTransform::can_be_applied(builder::StructuredSDFGBuilder& builder, analysis::AnalysisManager& analysis_manager) {
×
NEW
17
    if (!OffloadTransform::can_be_applied(builder, analysis_manager)) {
×
NEW
18
        return false;
×
NEW
19
    }
×
20

21
    // Condition: Resulting ROCm grid X-dimension must not exceed hardware limits.
22
    // X grid dimension is limited to 2^31 - 1.
NEW
23
    auto num_iters = this->map_.num_iterations();
×
NEW
24
    if (!num_iters.is_null() && SymEngine::is_a<SymEngine::Integer>(*num_iters)) {
×
NEW
25
        int64_t iters = SymEngine::down_cast<const SymEngine::Integer&>(*num_iters).as_int();
×
NEW
26
        int64_t block = static_cast<int64_t>(block_size_);
×
NEW
27
        int64_t grid_size = (iters + block - 1) / block;
×
28

NEW
29
        constexpr int64_t max_grid_dim_x = 2147483647; // 2^31 - 1
×
NEW
30
        if (grid_size > max_grid_dim_x) {
×
NEW
31
            return false;
×
NEW
32
        }
×
NEW
33
    }
×
34

NEW
35
    return true;
×
NEW
36
}
×
37

38
void ROCMTransform::add_device_buffer(
39
    builder::StructuredSDFGBuilder& builder,
40
    std::string host_arg_name,
41
    std::string device_arg_name,
42
    symbolic::Expression arg_size
43
) {
×
44
    // Allocate device pointer
45
    auto& sdfg = builder.subject();
×
46
    auto& type = sdfg.type(host_arg_name);
×
47
    auto new_type = type.clone();
×
48
    new_type->storage_type(global_device_storage_type(arg_size));
×
49
    builder.add_container(device_arg_name, *new_type);
×
50
}
×
51

52
void ROCMTransform::allocate_device_arg(
53
    builder::StructuredSDFGBuilder& builder,
54
    Block& alloc_block,
55
    std::string host_arg_name,
56
    std::string device_arg_name,
57
    symbolic::Expression arg_size,
58
    symbolic::Expression page_size
59
) {
×
60
    auto& sdfg = builder.subject();
×
61
    if (!builder.subject().exists(device_arg_name)) {
×
62
        auto& type = sdfg.type(host_arg_name);
×
63
        auto new_type = type.clone();
×
64
        new_type->storage_type(global_device_storage_type(arg_size));
×
65
        new_type->storage_type().allocation(types::StorageType::AllocationType::Unmanaged);
×
66
        new_type->storage_type().deallocation(types::StorageType::AllocationType::Unmanaged);
×
67
        new_type->storage_type().allocation_size(SymEngine::null);
×
68

69
        std::unordered_set<std::string> container_set(sdfg.containers().begin(), sdfg.containers().end());
×
70
        if (container_set.find(device_arg_name) == container_set.end()) {
×
71
            builder.add_container(device_arg_name, *new_type);
×
72
        }
×
73
    }
×
74
    auto& out_type = builder.subject().type(device_arg_name);
×
75

76
    offloading::add_offloading_node<ROCMDataOffloadingNode>(
×
77
        builder,
×
78
        alloc_block,
×
79
        host_arg_name,
×
80
        device_arg_name,
×
81
        offloading::DataTransferDirection::NONE,
×
82
        offloading::BufferLifecycle::ALLOC,
×
83
        out_type,
×
84
        out_type,
×
85
        this->map_.debug_info(),
×
86
        arg_size,
×
87
        symbolic::zero()
×
88
    );
×
89
}
×
90

91
void ROCMTransform::deallocate_device_arg(
92
    builder::StructuredSDFGBuilder& builder,
93
    Block& dealloc_block,
94
    std::string device_arg_name,
95
    symbolic::Expression arg_size,
96
    symbolic::Expression page_size
97
) {
×
98
    auto& free_type = builder.subject().type(device_arg_name);
×
99
    offloading::add_offloading_node<ROCMDataOffloadingNode>(
×
100
        builder,
×
101
        dealloc_block,
×
102
        device_arg_name,
×
103
        device_arg_name,
×
104
        offloading::DataTransferDirection::NONE,
×
105
        offloading::BufferLifecycle::FREE,
×
106
        free_type,
×
107
        free_type,
×
108
        this->map_.debug_info(),
×
109
        arg_size,
×
110
        symbolic::zero()
×
111
    );
×
112
}
×
113

114
void ROCMTransform::copy_to_device(
115
    builder::StructuredSDFGBuilder& builder,
116
    const std::string host_arg_name,
117
    std::string device_arg_name,
118
    symbolic::Expression size,
119
    symbolic::Expression page_size,
120
    Block& copy_block
121
) {
×
122
    offloading::add_offloading_node<ROCMDataOffloadingNode>(
×
123
        builder,
×
124
        copy_block,
×
125
        host_arg_name,
×
126
        device_arg_name,
×
127
        offloading::DataTransferDirection::H2D,
×
128
        offloading::BufferLifecycle::NO_CHANGE,
×
129
        builder.subject().type(host_arg_name),
×
130
        builder.subject().type(device_arg_name),
×
131
        this->map_.debug_info(),
×
132
        size,
×
133
        symbolic::integer(0)
×
134
    );
×
135
}
×
136

137
void ROCMTransform::copy_to_device_with_allocation(
138
    builder::StructuredSDFGBuilder& builder,
139
    const std::string host_arg_name,
140
    std::string device_arg_name,
141
    symbolic::Expression size,
142
    symbolic::Expression page_size,
143
    Block& copy_block
144
) {
×
145
    offloading::add_offloading_node<ROCMDataOffloadingNode>(
×
146
        builder,
×
147
        copy_block,
×
148
        host_arg_name,
×
149
        device_arg_name,
×
150
        offloading::DataTransferDirection::H2D,
×
151
        offloading::BufferLifecycle::ALLOC,
×
152
        builder.subject().type(host_arg_name),
×
153
        builder.subject().type(device_arg_name),
×
154
        this->map_.debug_info(),
×
155
        size,
×
156
        symbolic::integer(0)
×
157
    );
×
158
}
×
159

160
void ROCMTransform::copy_from_device(
161
    builder::StructuredSDFGBuilder& builder,
162
    Block& copy_out_block,
163
    const std::string host_arg_name,
164
    std::string device_arg_name,
165
    symbolic::Expression size,
166
    symbolic::Expression page_size
167
) {
×
168
    offloading::add_offloading_node<ROCMDataOffloadingNode>(
×
169
        builder,
×
170
        copy_out_block,
×
171
        host_arg_name,
×
172
        device_arg_name,
×
173
        offloading::DataTransferDirection::D2H,
×
174
        offloading::BufferLifecycle::NO_CHANGE,
×
175
        builder.subject().type(host_arg_name),
×
176
        builder.subject().type(device_arg_name),
×
177
        this->map_.debug_info(),
×
178
        size,
×
179
        symbolic::integer(0)
×
180
    );
×
181
}
×
182

183
void ROCMTransform::copy_from_device_with_free(
184
    builder::StructuredSDFGBuilder& builder,
185
    Block& copy_out_block,
186
    const std::string host_arg_name,
187
    std::string device_arg_name,
188
    symbolic::Expression size,
189
    symbolic::Expression page_size
190
) {
×
191
    offloading::add_offloading_node<ROCMDataOffloadingNode>(
×
192
        builder,
×
193
        copy_out_block,
×
194
        host_arg_name,
×
195
        device_arg_name,
×
196
        offloading::DataTransferDirection::D2H,
×
197
        offloading::BufferLifecycle::FREE,
×
198
        builder.subject().type(host_arg_name),
×
199
        builder.subject().type(device_arg_name),
×
200
        this->map_.debug_info(),
×
201
        size,
×
202
        symbolic::integer(0)
×
203
    );
×
204
}
×
205

206
void ROCMTransform::to_json(nlohmann::json& j) const {
×
207
    std::string loop_type;
×
208
    if (dynamic_cast<structured_control_flow::Map*>(&map_)) {
×
209
        loop_type = "map";
×
210
    } else {
×
211
        throw std::runtime_error("Unsupported loop type for serialization of loop: " + map_.indvar()->get_name());
×
212
    }
×
213

214
    j["transformation_type"] = this->name();
×
215
    j["subgraph"] = {{"0", {{"element_id", this->map_.element_id()}, {"type", loop_type}}}};
×
216
    j["parameters"] = {{"block_size", block_size_}};
×
217
};
×
218

219
ROCMTransform ROCMTransform::from_json(builder::StructuredSDFGBuilder& builder, const nlohmann::json& desc) {
×
220
    auto loop_id = desc["subgraph"]["0"]["element_id"].get<size_t>();
×
221
    size_t block_size = desc["parameters"]["block_size"].get<size_t>();
×
222
    auto element = builder.find_element_by_id(loop_id);
×
223
    if (!element) {
×
224
        throw transformations::
×
225
            InvalidTransformationDescriptionException("Element with ID " + std::to_string(loop_id) + " not found.");
×
226
    }
×
227
    auto map = dynamic_cast<structured_control_flow::Map*>(element);
×
228

229
    return ROCMTransform(*map, block_size);
×
230
};
×
231

232

233
} // namespace rocm
234
} // 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