• 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

0.0
/src/data_flow/library_nodes/math/ml/gemm.cpp
1
#include "sdfg/data_flow/library_nodes/math/ml/gemm.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
GemmNode::GemmNode(
×
12
    size_t element_id,
13
    const DebugInfoRegion &debug_info,
14
    const graph::Vertex vertex,
15
    data_flow::DataFlowGraph &parent,
16
    const std::string &alpha,
17
    const std::string &beta,
18
    bool trans_a,
19
    bool trans_b
20
)
21
    : MathNode(
×
22
          element_id,
×
23
          debug_info,
×
24
          vertex,
×
25
          parent,
×
26
          LibraryNodeType_Gemm,
27
          {"Y"},
×
28
          {"A", "B", "C"},
×
29
          data_flow::ImplementationType_NONE
30
      ),
31
      alpha_(alpha), beta_(beta), trans_a_(trans_a), trans_b_(trans_b) {}
×
32

33
void GemmNode::validate(const Function &) const { /* TODO */ }
×
34

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

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

44
    // Locate edges
45
    const data_flow::Memlet *iedge_A = nullptr;
×
46
    const data_flow::Memlet *iedge_B = nullptr;
×
47
    const data_flow::Memlet *iedge_C = nullptr;
×
48
    const data_flow::Memlet *oedge_Y = nullptr;
×
49
    for (const auto &edge : dataflow.in_edges(*this)) {
×
50
        if (edge.dst_conn() == "A") {
×
51
            iedge_A = &edge;
×
52
        }
×
53
        if (edge.dst_conn() == "B") {
×
54
            iedge_B = &edge;
×
55
        }
×
56
        if (edge.dst_conn() == "C") {
×
57
            iedge_C = &edge;
×
58
        }
×
59
    }
60
    for (const auto &edge : dataflow.out_edges(*this)) {
×
61
        if (edge.src_conn() == "Y") {
×
62
            oedge_Y = &edge;
×
63
        }
×
64
    }
65
    if (!iedge_A || !iedge_B || !oedge_Y) return false;
×
66

67
    bool has_C_in = iedge_C != nullptr;
×
68

69
    std::string A_name = static_cast<const data_flow::AccessNode &>(iedge_A->src()).data();
×
70
    std::string B_name = static_cast<const data_flow::AccessNode &>(iedge_B->src()).data();
×
71
    std::string C_in_name = has_C_in ? static_cast<const data_flow::AccessNode &>(iedge_C->src()).data() : "";
×
72
    std::string C_out_name = static_cast<const data_flow::AccessNode &>(oedge_Y->dst()).data();
×
73

74
    // Create new sequence before
NEW
75
    auto &new_sequence = builder.add_sequence_before(
×
NEW
76
        parent, block, transition.assignments(), builder.debug_info().get_region(block.debug_info().indices())
×
77
    );
UNCOV
78
    structured_control_flow::Sequence *last_scope = &new_sequence;
×
79

80
    // Create maps over output subset dims (parallel dims)
81
    data_flow::Subset domain_begin = {
×
82
        symbolic::integer(0),
×
83
        symbolic::integer(0),
×
84
        symbolic::integer(0),
×
85
    };
86
    data_flow::Subset domain_end = {
×
87
        oedge_Y->end_subset()[0],
×
88
        oedge_Y->end_subset()[1],
×
89
        trans_a_ ? iedge_A->end_subset()[1] : iedge_A->end_subset()[0],
×
90
    };
91

92
    std::vector<symbolic::Expression> out_syms;
×
93
    structured_control_flow::Map *last_map = nullptr;
×
94
    for (size_t d = 0; d < domain_begin.size(); ++d) {
×
95
        std::string indvar_str = builder.find_new_name("_i");
×
96
        builder.add_container(indvar_str, types::Scalar(types::PrimitiveType::UInt64));
×
97
        auto indvar = symbolic::symbol(indvar_str);
×
98
        auto init = domain_begin[d];
×
99
        auto update = symbolic::add(indvar, symbolic::one());
×
100
        auto cond = symbolic::Lt(indvar, symbolic::add(domain_end[d], symbolic::one()));
×
101
        last_map = &builder.add_map(
×
102
            *last_scope,
×
103
            indvar,
104
            cond,
105
            init,
106
            update,
107
            structured_control_flow::ScheduleType_Sequential::create(),
×
108
            {},
×
NEW
109
            builder.debug_info().get_region(block.debug_info().indices())
×
110
        );
111
        last_scope = &last_map->root();
×
112
        out_syms.push_back(indvar);
×
113
    }
×
114

115
    // Create innermost block
116
    auto &code_block = builder.add_block(*last_scope);
×
NEW
117
    auto &tasklet = builder.add_tasklet(
×
NEW
118
        code_block,
×
119
        data_flow::TaskletCode::fma,
NEW
120
        "_out",
×
NEW
121
        {"_in1", "_in2", "_in3"},
×
NEW
122
        builder.debug_info().get_region(block.debug_info().indices())
×
123
    );
124

NEW
125
    auto &A_in = builder.add_access(code_block, A_name, builder.debug_info().get_region(block.debug_info().indices()));
×
NEW
126
    auto &B_in = builder.add_access(code_block, B_name, builder.debug_info().get_region(block.debug_info().indices()));
×
NEW
127
    auto &C_in = builder.add_access(
×
NEW
128
        code_block, has_C_in ? C_in_name : C_out_name, builder.debug_info().get_region(block.debug_info().indices())
×
129
    );
NEW
130
    auto &C_out =
×
NEW
131
        builder.add_access(code_block, C_out_name, builder.debug_info().get_region(block.debug_info().indices()));
×
132

133
    data_flow::Subset subset_A;
×
134
    if (trans_a_) {
×
135
        subset_A = {out_syms[1], out_syms[0]};
×
136
    } else {
×
137
        subset_A = {out_syms[0], out_syms[1]};
×
138
    }
139
    data_flow::Subset subset_B;
×
140
    if (trans_b_) {
×
141
        subset_B = {out_syms[1], out_syms[0]};
×
142
    } else {
×
143
        subset_B = {out_syms[0], out_syms[1]};
×
144
    }
145
    data_flow::Subset subset_C = {out_syms[0], out_syms[1]};
×
146

NEW
147
    builder.add_computational_memlet(
×
NEW
148
        code_block,
×
NEW
149
        A_in,
×
NEW
150
        tasklet,
×
NEW
151
        "_in1",
×
152
        subset_A,
NEW
153
        iedge_A->base_type(),
×
NEW
154
        builder.debug_info().get_region(block.debug_info().indices())
×
155
    );
NEW
156
    builder.add_computational_memlet(
×
NEW
157
        code_block,
×
NEW
158
        B_in,
×
NEW
159
        tasklet,
×
NEW
160
        "_in2",
×
161
        subset_B,
NEW
162
        iedge_B->base_type(),
×
NEW
163
        builder.debug_info().get_region(block.debug_info().indices())
×
164
    );
NEW
165
    builder.add_computational_memlet(
×
NEW
166
        code_block,
×
NEW
167
        C_in,
×
NEW
168
        tasklet,
×
NEW
169
        "_in3",
×
170
        subset_C,
NEW
171
        oedge_Y->base_type(),
×
NEW
172
        builder.debug_info().get_region(block.debug_info().indices())
×
173
    );
NEW
174
    builder.add_computational_memlet(
×
NEW
175
        code_block,
×
NEW
176
        tasklet,
×
NEW
177
        "_out",
×
NEW
178
        C_out,
×
179
        subset_C,
NEW
180
        oedge_Y->base_type(),
×
NEW
181
        builder.debug_info().get_region(block.debug_info().indices())
×
182
    );
183

184
    // Cleanup old block
185
    builder.remove_memlet(block, *iedge_A);
×
186
    builder.remove_memlet(block, *iedge_B);
×
187
    if (has_C_in) {
×
188
        builder.remove_memlet(block, *iedge_C);
×
189
    }
×
190
    builder.remove_memlet(block, *oedge_Y);
×
191
    builder.remove_node(block, *this);
×
192
    builder.remove_child(parent, index + 1);
×
193

194
    return true;
×
195
}
×
196

197
std::unique_ptr<data_flow::DataFlowNode> GemmNode::
198
    clone(size_t element_id, const graph::Vertex vertex, data_flow::DataFlowGraph &parent) const {
×
199
    return std::unique_ptr<data_flow::DataFlowNode>(
×
200
        new GemmNode(element_id, this->debug_info(), vertex, parent, alpha_, beta_, trans_a_, trans_b_)
×
201
    );
202
}
×
203

204
nlohmann::json GemmNodeSerializer::serialize(const data_flow::LibraryNode &library_node) {
×
205
    const GemmNode &node = static_cast<const GemmNode &>(library_node);
×
206
    nlohmann::json j;
×
207

208
    j["code"] = node.code().value();
×
209
    j["alpha"] = node.alpha();
×
210
    j["beta"] = node.beta();
×
211
    j["trans_a"] = node.trans_a();
×
212
    j["trans_b"] = node.trans_b();
×
213

214
    return j;
×
215
}
×
216

217
data_flow::LibraryNode &GemmNodeSerializer::deserialize(
×
218
    const nlohmann::json &j, builder::StructuredSDFGBuilder &builder, structured_control_flow::Block &parent
219
) {
220
    auto code = j["code"].get<std::string>();
×
221
    if (code != LibraryNodeType_Gemm.value()) {
×
222
        throw std::runtime_error("Invalid library node code");
×
223
    }
224

225
    sdfg::serializer::JSONSerializer serializer;
×
NEW
226
    DebugInfoRegion debug_info = serializer.json_to_debug_info_region(j["debug_info"], builder.debug_info());
×
227

228
    auto alpha = j["alpha"].get<std::string>();
×
229
    auto beta = j["beta"].get<std::string>();
×
230
    auto trans_a = j["trans_a"].get<bool>();
×
231
    auto trans_b = j["trans_b"].get<bool>();
×
232

233
    return builder.add_library_node<GemmNode>(parent, debug_info, alpha, beta, trans_a, trans_b);
×
234
}
×
235

236
} // namespace ml
237
} // namespace math
238
} // 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