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

daisytuner / sdfglib / 17637380013

11 Sep 2025 07:29AM UTC coverage: 59.755% (+0.6%) from 59.145%
17637380013

push

github

web-flow
New debug info (#210)

* initial draft

* update data structure and construction logic

* finalize DebugInfo draft

* fix tests

* Update serializer and fix tests

* fix append bug

* update data structure

* sdfg builder update

* const ref vectors

* update implementation and partial tests

* compiling state

* update serializer interface

* update dot test

* reset interface to debug_info in json to maintain compatibility with tools

* first review batch

* second batch of changes

* merge fixes

777 of 1111 new or added lines in 46 files covered. (69.94%)

11 existing lines in 11 files now uncovered.

9755 of 16325 relevant lines covered (59.75%)

115.06 hits per line

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

76.0
/src/data_flow/library_nodes/math/ml/maxpool.cpp
1
#include "sdfg/data_flow/library_nodes/math/ml/maxpool.h"
2

3
#include "sdfg/analysis/analysis.h"
4
#include "sdfg/analysis/scope_analysis.h"
5
#include "sdfg/builder/structured_sdfg_builder.h"
6
#include "sdfg/debug_info.h"
7

8
namespace sdfg {
9
namespace math {
10
namespace ml {
11

12
/*************** Constructor ***************/
13
MaxPoolNode::MaxPoolNode(
1✔
14
    size_t element_id,
15
    const DebugInfoRegion &debug_info,
16
    const graph::Vertex vertex,
17
    data_flow::DataFlowGraph &parent,
18
    std::vector<size_t> kernel_shape,
19
    std::vector<size_t> pads,
20
    std::vector<size_t> strides
21
)
22
    : MathNode(
1✔
23
          element_id, debug_info, vertex, parent, LibraryNodeType_MaxPool, {"Y"}, {"X"}, data_flow::ImplementationType_NONE
1✔
24
      ),
25
      kernel_shape_(std::move(kernel_shape)), pads_(std::move(pads)), strides_(std::move(strides)) {}
1✔
26

27
/*************** Accessors ***************/
28
std::vector<size_t> MaxPoolNode::kernel_shape() const { return kernel_shape_; }
×
29
std::vector<size_t> MaxPoolNode::pads() const { return pads_; }
×
30
std::vector<size_t> MaxPoolNode::strides() const { return strides_; }
×
31

32
void MaxPoolNode::validate(const Function &) const { /* TODO */ }
×
33

34
/*************** Expand ***************/
35
bool MaxPoolNode::expand(builder::StructuredSDFGBuilder &builder, analysis::AnalysisManager &analysis_manager) {
1✔
36
    auto &dataflow = this->get_parent();
1✔
37
    auto &block = static_cast<structured_control_flow::Block &>(*dataflow.get_parent());
1✔
38

39
    auto &scope_analysis = analysis_manager.get<analysis::ScopeAnalysis>();
1✔
40
    auto &parent = static_cast<structured_control_flow::Sequence &>(*scope_analysis.parent_scope(&block));
1✔
41
    int index = parent.index(block);
1✔
42
    auto &transition = parent.at(index).second;
1✔
43

44
    // Locate edges
45
    const data_flow::Memlet *iedge_X = nullptr;
1✔
46
    const data_flow::Memlet *oedge_Y = nullptr;
1✔
47
    for (const auto &edge : dataflow.in_edges(*this)) {
2✔
48
        if (edge.dst_conn() == "X") {
1✔
49
            iedge_X = &edge;
1✔
50
        }
1✔
51
    }
52
    for (const auto &edge : dataflow.out_edges(*this)) {
2✔
53
        if (edge.src_conn() == "Y") {
1✔
54
            oedge_Y = &edge;
1✔
55
        }
1✔
56
    }
57
    if (!iedge_X || !oedge_Y) return false;
1✔
58

59
    std::string X_name = static_cast<const data_flow::AccessNode &>(iedge_X->src()).data();
1✔
60
    std::string Y_name = static_cast<const data_flow::AccessNode &>(oedge_Y->dst()).data();
1✔
61

62
    // Create new sequence before
63
    auto &new_sequence = builder.add_sequence_before(
2✔
64
        parent, block, transition.assignments(), builder.debug_info().get_region(block.debug_info().indices())
1✔
65
    );
66
    structured_control_flow::Sequence *last_scope = &new_sequence;
1✔
67

68
    // Create maps over output subset dims (parallel dims)
69
    const auto &begin_Y = oedge_Y->begin_subset();
1✔
70
    const auto &end_Y = oedge_Y->end_subset();
1✔
71
    data_flow::Subset out_subset;
1✔
72
    std::vector<symbolic::Expression> out_syms;
1✔
73
    structured_control_flow::Map *last_map = nullptr;
1✔
74
    for (size_t d = 0; d < begin_Y.size(); ++d) {
5✔
75
        std::string indvar_str = builder.find_new_name("_i");
4✔
76
        builder.add_container(indvar_str, types::Scalar(types::PrimitiveType::UInt64));
4✔
77
        auto indvar = symbolic::symbol(indvar_str);
4✔
78
        auto init = begin_Y[d];
4✔
79
        auto update = symbolic::add(indvar, symbolic::one());
4✔
80
        auto cond = symbolic::Lt(indvar, symbolic::add(end_Y[d], symbolic::one()));
4✔
81
        last_map = &builder.add_map(
8✔
82
            *last_scope,
4✔
83
            indvar,
84
            cond,
85
            init,
86
            update,
87
            structured_control_flow::ScheduleType_Sequential::create(),
4✔
88
            {},
4✔
89
            builder.subject().debug_info().get_region(block.debug_info().indices())
4✔
90
        );
91
        last_scope = &last_map->root();
4✔
92
        out_subset.push_back(indvar);
4✔
93
        out_syms.push_back(indvar);
4✔
94
    }
4✔
95

96
    // Kernel reduction loops
97
    structured_control_flow::For *last_for = nullptr;
1✔
98
    std::vector<symbolic::Expression> kernel_syms;
1✔
99
    for (size_t d = 0; d < kernel_shape_.size(); ++d) {
3✔
100
        std::string indvar_str = builder.find_new_name("_k");
2✔
101
        builder.add_container(indvar_str, types::Scalar(types::PrimitiveType::UInt64));
2✔
102
        auto indvar = symbolic::symbol(indvar_str);
2✔
103
        auto init = symbolic::integer(0);
2✔
104
        auto update = symbolic::add(indvar, symbolic::one());
2✔
105
        auto cond = symbolic::Lt(indvar, symbolic::integer(static_cast<int64_t>(kernel_shape_[d])));
2✔
106
        last_for = &builder.add_for(
4✔
107
            *last_scope,
2✔
108
            indvar,
109
            cond,
110
            init,
2✔
111
            update,
112
            {},
2✔
113
            builder.subject().debug_info().get_region(block.debug_info().indices())
2✔
114
        );
115
        last_scope = &last_for->root();
2✔
116
        kernel_syms.push_back(indvar);
2✔
117
    }
2✔
118

119
    // Build subsets
120
    const auto &begin_X = iedge_X->begin_subset();
1✔
121
    // infer: X dims N,C,H,W => assume same dims as Y except spatial dims with stride/pad
122

123
    auto int_expr = [](size_t v) { return symbolic::integer(static_cast<int64_t>(v)); };
5✔
124
    auto get_stride = [&](size_t idx) -> symbolic::Expression {
3✔
125
        return idx < strides_.size() ? int_expr(strides_[idx]) : symbolic::one();
2✔
126
    };
127
    auto get_pad = [&](size_t idx) -> symbolic::Expression {
3✔
128
        return idx < pads_.size() ? int_expr(pads_[idx]) : symbolic::zero();
2✔
129
    };
130

131
    // Create innermost block
132
    auto &code_block =
1✔
133
        builder.add_block(*last_scope, {}, builder.subject().debug_info().get_region(block.debug_info().indices()));
1✔
134

135
    // Access nodes
136
    const DebugInfos dbg = builder.subject().debug_info().get_region(block.debug_info().indices());
1✔
137
    auto &X_acc = builder.add_access(code_block, X_name, dbg);
1✔
138
    auto &Y_acc_in = builder.add_access(code_block, Y_name, dbg);
1✔
139
    auto &Y_acc_out = builder.add_access(code_block, Y_name, dbg);
1✔
140

141
    // Build X subset using output coords * stride - pad + kernel_idx
142
    data_flow::Subset subset_X;
1✔
143
    // Assume dims: N, C, spatial...
144
    subset_X.push_back(out_syms[0]); // N
1✔
145
    subset_X.push_back(out_syms[1]); // C
1✔
146
    for (size_t d = 0; d < kernel_syms.size(); ++d) {
3✔
147
        auto expr =
148
            symbolic::sub(symbolic::add(symbolic::mul(get_stride(d), out_syms[2 + d]), kernel_syms[d]), get_pad(d));
2✔
149
        subset_X.push_back(expr);
2✔
150
    }
2✔
151

152
    // Y subset is just out_subset
153
    data_flow::Subset subset_Y = out_subset;
1✔
154

155
    // Tasklet max
156
    auto &tasklet = builder.add_tasklet(code_block, data_flow::TaskletCode::max, "_out", {"_in1", "_in2"}, dbg);
1✔
157

158
    builder.add_computational_memlet(code_block, Y_acc_in, tasklet, "_in1", subset_Y, oedge_Y->base_type(), dbg);
1✔
159
    builder.add_computational_memlet(code_block, X_acc, tasklet, "_in2", subset_X, iedge_X->base_type(), dbg);
1✔
160
    builder.add_computational_memlet(code_block, tasklet, "_out", Y_acc_out, subset_Y, oedge_Y->base_type(), dbg);
1✔
161

162
    // Cleanup old block
163
    builder.remove_memlet(block, *iedge_X);
1✔
164
    builder.remove_memlet(block, *oedge_Y);
1✔
165
    builder.remove_node(block, *this);
1✔
166
    builder.remove_child(parent, index + 1);
1✔
167

168
    return true;
1✔
169
}
1✔
170

171
/*************** Clone ***************/
172
std::unique_ptr<data_flow::DataFlowNode> MaxPoolNode::
173
    clone(size_t element_id, const graph::Vertex vertex, data_flow::DataFlowGraph &parent) const {
×
174
    return std::unique_ptr<data_flow::DataFlowNode>(new MaxPoolNode(
×
175
        element_id, this->debug_info(), vertex, parent, this->kernel_shape_, this->pads_, this->strides_
×
176
    ));
177
}
×
178

179
/*************** Serializer ***************/
180
nlohmann::json MaxPoolNodeSerializer::serialize(const data_flow::LibraryNode &library_node) {
×
181
    const MaxPoolNode &node = static_cast<const MaxPoolNode &>(library_node);
×
182
    nlohmann::json j;
×
183
    j["code"] = node.code().value();
×
184
    j["outputs"] = node.outputs();
×
185
    j["inputs"] = node.inputs();
×
186
    j["kernel_shape"] = node.kernel_shape();
×
187
    j["pads"] = node.pads();
×
188
    j["strides"] = node.strides();
×
189
    return j;
×
190
}
×
191

192
data_flow::LibraryNode &MaxPoolNodeSerializer::deserialize(
×
193
    const nlohmann::json &j, builder::StructuredSDFGBuilder &builder, structured_control_flow::Block &parent
194
) {
195
    auto code = j["code"].get<std::string>();
×
196
    if (code != LibraryNodeType_MaxPool.value()) {
×
197
        throw std::runtime_error("Invalid library node code");
×
198
    }
199
    sdfg::serializer::JSONSerializer serializer;
×
NEW
200
    DebugInfoRegion debug_info = serializer.json_to_debug_info_region(j["debug_info"], builder.debug_info());
×
201

202
    auto kernel_shape = j["kernel_shape"].get<std::vector<size_t>>();
×
203
    auto pads = j["pads"].get<std::vector<size_t>>();
×
204
    auto strides = j["strides"].get<std::vector<size_t>>();
×
205

206
    return builder.add_library_node<MaxPoolNode>(parent, debug_info, kernel_shape, pads, strides);
×
207
}
×
208

209
} // namespace ml
210
} // namespace math
211
} // 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