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

daisytuner / docc / 27480689803

13 Jun 2026 10:14PM UTC coverage: 61.318%. First build
27480689803

Pull #760

github

web-flow
Merge 01073dcd3 into 9754c0592
Pull Request #760: Add hardware limit checks for gpu

32 of 52 new or added lines in 4 files covered. (61.54%)

36305 of 59208 relevant lines covered (61.32%)

1122.86 hits per line

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

44.37
/opt/src/transformations/offloading/cuda_transform.cpp
1
#include "sdfg/transformations/offloading/cuda_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/cuda/cuda_data_offloading_node.h"
8
#include "sdfg/transformations/transformation.h"
9
#include "symengine/symengine_rcp.h"
10

11
namespace sdfg {
12
namespace cuda {
13

14
std::string CUDATransform::name() const { return "CUDATransform"; }
3✔
15

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

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

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

35
    return true;
7✔
36
}
7✔
37

38
void CUDATransform::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
) {
3✔
44
    // Allocate device pointer
45
    auto& sdfg = builder.subject();
3✔
46
    auto& type = sdfg.type(host_arg_name);
3✔
47
    auto new_type = type.clone();
3✔
48
    new_type->storage_type(global_device_storage_type(arg_size));
3✔
49
    builder.add_container(device_arg_name, *new_type);
3✔
50
}
3✔
51

52
void CUDATransform::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

75
    auto& out_type = builder.subject().type(device_arg_name);
×
76

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

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

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

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

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

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

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

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

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

230
    return CUDATransform(*map, block_size);
1✔
231
};
1✔
232

233

234
} // namespace cuda
235
} // 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