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

daisytuner / sdfglib / 17653942017

11 Sep 2025 06:34PM UTC coverage: 59.145% (-0.6%) from 59.755%
17653942017

push

github

web-flow
Merge pull request #224 from daisytuner/revert-210-NewDebugInfo

Revert "New debug info"

313 of 466 new or added lines in 44 files covered. (67.17%)

21 existing lines in 4 files now uncovered.

9274 of 15680 relevant lines covered (59.15%)

115.92 hits per line

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

74.79
/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

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

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

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

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

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

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

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

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

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

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

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

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

112
    auto int_expr = [](size_t v) { return symbolic::integer(static_cast<int64_t>(v)); };
5✔
113
    auto get_stride = [&](size_t idx) -> symbolic::Expression {
3✔
114
        return idx < strides_.size() ? int_expr(strides_[idx]) : symbolic::one();
2✔
115
    };
116
    auto get_pad = [&](size_t idx) -> symbolic::Expression {
3✔
117
        return idx < pads_.size() ? int_expr(pads_[idx]) : symbolic::zero();
2✔
118
    };
119

120
    // Create innermost block
121
    auto &code_block = builder.add_block(*last_scope, {}, block.debug_info());
1✔
122

123
    // Access nodes
124
    const DebugInfo dbg = block.debug_info();
1✔
125
    auto &X_acc = builder.add_access(code_block, X_name, dbg);
1✔
126
    auto &Y_acc_in = builder.add_access(code_block, Y_name, dbg);
1✔
127
    auto &Y_acc_out = builder.add_access(code_block, Y_name, dbg);
1✔
128

129
    // Build X subset using output coords * stride - pad + kernel_idx
130
    data_flow::Subset subset_X;
1✔
131
    // Assume dims: N, C, spatial...
132
    subset_X.push_back(out_syms[0]); // N
1✔
133
    subset_X.push_back(out_syms[1]); // C
1✔
134
    for (size_t d = 0; d < kernel_syms.size(); ++d) {
3✔
135
        auto expr =
136
            symbolic::sub(symbolic::add(symbolic::mul(get_stride(d), out_syms[2 + d]), kernel_syms[d]), get_pad(d));
2✔
137
        subset_X.push_back(expr);
2✔
138
    }
2✔
139

140
    // Y subset is just out_subset
141
    data_flow::Subset subset_Y = out_subset;
1✔
142

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

146
    builder.add_computational_memlet(code_block, Y_acc_in, tasklet, "_in1", subset_Y, oedge_Y->base_type(), dbg);
1✔
147
    builder.add_computational_memlet(code_block, X_acc, tasklet, "_in2", subset_X, iedge_X->base_type(), dbg);
1✔
148
    builder.add_computational_memlet(code_block, tasklet, "_out", Y_acc_out, subset_Y, oedge_Y->base_type(), dbg);
1✔
149

150
    // Cleanup old block
151
    builder.remove_memlet(block, *iedge_X);
1✔
152
    builder.remove_memlet(block, *oedge_Y);
1✔
153
    builder.remove_node(block, *this);
1✔
154
    builder.remove_child(parent, index + 1);
1✔
155

156
    return true;
1✔
157
}
1✔
158

159
/*************** Clone ***************/
160
std::unique_ptr<data_flow::DataFlowNode> MaxPoolNode::
161
    clone(size_t element_id, const graph::Vertex vertex, data_flow::DataFlowGraph &parent) const {
×
162
    return std::unique_ptr<data_flow::DataFlowNode>(new MaxPoolNode(
×
163
        element_id, this->debug_info(), vertex, parent, this->kernel_shape_, this->pads_, this->strides_
×
164
    ));
165
}
×
166

167
/*************** Serializer ***************/
168
nlohmann::json MaxPoolNodeSerializer::serialize(const data_flow::LibraryNode &library_node) {
×
169
    const MaxPoolNode &node = static_cast<const MaxPoolNode &>(library_node);
×
170
    nlohmann::json j;
×
171
    j["code"] = node.code().value();
×
172
    j["outputs"] = node.outputs();
×
173
    j["inputs"] = node.inputs();
×
174
    j["kernel_shape"] = node.kernel_shape();
×
175
    j["pads"] = node.pads();
×
176
    j["strides"] = node.strides();
×
177
    return j;
×
178
}
×
179

180
data_flow::LibraryNode &MaxPoolNodeSerializer::deserialize(
×
181
    const nlohmann::json &j, builder::StructuredSDFGBuilder &builder, structured_control_flow::Block &parent
182
) {
183
    auto code = j["code"].get<std::string>();
×
184
    if (code != LibraryNodeType_MaxPool.value()) {
×
185
        throw std::runtime_error("Invalid library node code");
×
186
    }
187
    sdfg::serializer::JSONSerializer serializer;
×
NEW
188
    DebugInfo debug_info = serializer.json_to_debug_info(j["debug_info"]);
×
189

190
    auto kernel_shape = j["kernel_shape"].get<std::vector<size_t>>();
×
191
    auto pads = j["pads"].get<std::vector<size_t>>();
×
192
    auto strides = j["strides"].get<std::vector<size_t>>();
×
193

194
    return builder.add_library_node<MaxPoolNode>(parent, debug_info, kernel_shape, pads, strides);
×
195
}
×
196

197
} // namespace ml
198
} // namespace math
199
} // 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