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

daisytuner / docc / 28106147644

24 Jun 2026 02:32PM UTC coverage: 61.922% (+0.1%) from 61.779%
28106147644

Pull #806

github

web-flow
Merge 2be414d54 into 57cc1db99
Pull Request #806: Map Collapse for Multiple targets in a neste sequence

165 of 185 new or added lines in 2 files covered. (89.19%)

419 existing lines in 30 files now uncovered.

37705 of 60891 relevant lines covered (61.92%)

1004.4 hits per line

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

55.7
/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) {
20✔
17
    if (!OffloadTransform::can_be_applied(builder, analysis_manager)) {
20✔
18
        return false;
×
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();
20✔
24
    if (!num_iters.is_null() && SymEngine::is_a<SymEngine::Integer>(*num_iters)) {
20✔
25
        int64_t iters = SymEngine::down_cast<const SymEngine::Integer&>(*num_iters).as_int();
4✔
26
        int64_t block = static_cast<int64_t>(block_size_);
4✔
27
        int64_t grid_size = (iters + block - 1) / block;
4✔
28

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

35
    return true;
20✔
36
}
20✔
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
) {
19✔
44
    // Allocate device pointer
45
    auto& sdfg = builder.subject();
19✔
46
    auto& type = sdfg.type(host_arg_name);
19✔
47
    auto new_type = type.clone();
19✔
48
    new_type->storage_type(global_device_storage_type(arg_size));
19✔
49
    builder.add_container(device_arg_name, *new_type);
19✔
50
}
19✔
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
) {
2✔
99
    auto& free_type = builder.subject().type(device_arg_name);
2✔
100
    offloading::add_offloading_node<CUDADataOffloadingNode>(
2✔
101
        builder,
2✔
102
        dealloc_block,
2✔
103
        device_arg_name,
2✔
104
        device_arg_name,
2✔
105
        offloading::DataTransferDirection::NONE,
2✔
106
        offloading::BufferLifecycle::FREE,
2✔
107
        free_type,
2✔
108
        free_type,
2✔
109
        this->map_.debug_info(),
2✔
110
        arg_size,
2✔
111
        symbolic::zero()
2✔
112
    );
2✔
113
}
2✔
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
) {
19✔
146
    offloading::add_offloading_node<CUDADataOffloadingNode>(
19✔
147
        builder,
19✔
148
        copy_block,
19✔
149
        host_arg_name,
19✔
150
        device_arg_name,
19✔
151
        offloading::DataTransferDirection::H2D,
19✔
152
        offloading::BufferLifecycle::ALLOC,
19✔
153
        builder.subject().type(host_arg_name),
19✔
154
        builder.subject().type(device_arg_name),
19✔
155
        this->map_.debug_info(),
19✔
156
        size,
19✔
157
        symbolic::integer(0)
19✔
158
    );
19✔
159
}
19✔
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
) {
17✔
192
    offloading::add_offloading_node<CUDADataOffloadingNode>(
17✔
193
        builder,
17✔
194
        copy_out_block,
17✔
195
        host_arg_name,
17✔
196
        device_arg_name,
17✔
197
        offloading::DataTransferDirection::D2H,
17✔
198
        offloading::BufferLifecycle::FREE,
17✔
199
        builder.subject().type(host_arg_name),
17✔
200
        builder.subject().type(device_arg_name),
17✔
201
        this->map_.debug_info(),
17✔
202
        size,
17✔
203
        symbolic::integer(0)
17✔
204
    );
17✔
205
}
17✔
206

207
void CUDATransform::to_json(nlohmann::json& j) const {
1✔
208
    j["transformation_type"] = this->name();
1✔
209
    j["parameters"] = nlohmann::json::object();
1✔
210
    j["parameters"]["block_size"] = block_size_;
1✔
211

212
    serializer::JSONSerializer ser_flat(false);
1✔
213
    j["subgraph"] = nlohmann::json::object();
1✔
214
    j["subgraph"]["0"] = nlohmann::json::object();
1✔
215
    ser_flat.serialize_node(j["subgraph"]["0"], map_);
1✔
216
};
1✔
217

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

228
    return CUDATransform(*map, block_size);
1✔
229
};
1✔
230

231

232
} // namespace cuda
233
} // 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