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

daisytuner / sdfglib / 17621055299

10 Sep 2025 05:00PM UTC coverage: 59.755% (+0.6%) from 59.145%
17621055299

Pull #210

github

web-flow
Merge 6e7cc1401 into b8fdeb232
Pull Request #210: New debug info

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

40.18
/src/data_flow/library_nodes/math/blas/dot.cpp
1
#include "sdfg/data_flow/library_nodes/math/blas/dot.h"
2

3
#include "sdfg/analysis/analysis.h"
4
#include "sdfg/builder/structured_sdfg_builder.h"
5

6
#include "sdfg/analysis/scope_analysis.h"
7

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

12
DotNode::DotNode(
1✔
13
    size_t element_id,
14
    const DebugInfoRegion& debug_info,
15
    const graph::Vertex vertex,
16
    data_flow::DataFlowGraph& parent,
17
    const data_flow::ImplementationType& implementation_type,
18
    const BLAS_Precision& precision,
19
    symbolic::Expression n,
20
    symbolic::Expression incx,
21
    symbolic::Expression incy
22
)
23
    : MathNode(element_id, debug_info, vertex, parent, LibraryNodeType_DOT, {"res"}, {"x", "y"}, implementation_type),
1✔
24
      precision_(precision), n_(n), incx_(incx), incy_(incy) {}
1✔
25

26
BLAS_Precision DotNode::precision() const { return this->precision_; };
×
27

28
symbolic::Expression DotNode::n() const { return this->n_; };
×
29

30
symbolic::Expression DotNode::incx() const { return this->incx_; };
×
31

32
symbolic::Expression DotNode::incy() const { return this->incy_; };
×
33

34
void DotNode::validate(const Function& function) const {
×
35
    auto& graph = this->get_parent();
×
36

37
    if (graph.in_degree(*this) != this->inputs_.size()) {
×
38
        throw InvalidSDFGException("DotNode must have " + std::to_string(this->inputs_.size()) + " inputs");
×
39
    }
40
    if (graph.out_degree(*this) != 1) {
×
41
        throw InvalidSDFGException("DotNode must have 1 output");
×
42
    }
43

44
    std::unordered_map<std::string, const data_flow::Memlet*> memlets;
×
45
    for (auto& input : this->inputs_) {
×
46
        bool found = false;
×
47
        for (auto& iedge : graph.in_edges(*this)) {
×
48
            if (iedge.dst_conn() == input) {
×
49
                found = true;
×
50
                memlets[input] = &iedge;
×
51
                break;
×
52
            }
53
        }
54
        if (!found) {
×
55
            throw InvalidSDFGException("DotNode input " + input + " not found");
×
56
        }
57
    }
58

59
    auto& oedge = *graph.out_edges(*this).begin();
×
60
    if (oedge.src_conn() != this->outputs_.at(0)) {
×
61
        throw InvalidSDFGException("DotNode output " + this->outputs_.at(0) + " not found");
×
62
    }
63

64
    auto& x_memlet = memlets.at("x");
×
65
    auto& x_subset_begin = x_memlet->begin_subset();
×
66
    auto& x_subset_end = x_memlet->end_subset();
×
67
    if (x_subset_begin.size() != 1) {
×
68
        throw InvalidSDFGException("DotNode input x must have 1 dimensions");
×
69
    }
70

71
    auto& y_memlet = memlets.at("y");
×
72
    auto& y_subset_begin = y_memlet->begin_subset();
×
73
    auto& y_subset_end = y_memlet->end_subset();
×
74
    if (y_subset_begin.size() != 1) {
×
75
        throw InvalidSDFGException("DotNode input y must have 1 dimensions");
×
76
    }
77
}
×
78

79
bool DotNode::expand(builder::StructuredSDFGBuilder& builder, analysis::AnalysisManager& analysis_manager) {
1✔
80
    auto& scope_analysis = analysis_manager.get<analysis::ScopeAnalysis>();
1✔
81

82
    auto& dataflow = this->get_parent();
1✔
83
    auto& block = static_cast<structured_control_flow::Block&>(*dataflow.get_parent());
1✔
84
    auto& parent = static_cast<structured_control_flow::Sequence&>(*scope_analysis.parent_scope(&block));
1✔
85
    int index = parent.index(block);
1✔
86
    auto& transition = parent.at(index).second;
1✔
87

88
    const data_flow::Memlet* iedge_x = nullptr;
1✔
89
    const data_flow::Memlet* iedge_y = nullptr;
1✔
90
    for (const auto& iedge : dataflow.in_edges(*this)) {
3✔
91
        if (iedge.dst_conn() == "x") {
2✔
92
            iedge_x = &iedge;
1✔
93
        } else if (iedge.dst_conn() == "y") {
2✔
94
            iedge_y = &iedge;
1✔
95
        }
1✔
96
    }
97

98
    const data_flow::Memlet* oedge_res = nullptr;
1✔
99
    for (const auto& oedge : dataflow.out_edges(*this)) {
1✔
100
        if (oedge.src_conn() == "res") {
1✔
101
            oedge_res = &oedge;
1✔
102
            break;
1✔
103
        }
104
    }
105

106
    // Check if legal
107
    auto& input_node_x = static_cast<const data_flow::AccessNode&>(iedge_x->src());
1✔
108
    auto& input_node_y = static_cast<const data_flow::AccessNode&>(iedge_y->src());
1✔
109
    auto& output_node_res = static_cast<const data_flow::AccessNode&>(oedge_res->dst());
1✔
110
    if (dataflow.in_degree(input_node_x) != 0 || dataflow.in_degree(input_node_y) != 0 ||
1✔
111
        dataflow.out_degree(output_node_res) != 0) {
1✔
112
        return false;
×
113
    }
114

115
    auto& new_sequence = builder.add_sequence_before(
1✔
116
        parent, block, transition.assignments(), builder.debug_info().get_region(block.debug_info().indices())
1✔
117
    );
118

119
    std::string loop_var = builder.find_new_name("_i");
1✔
120
    builder.add_container(loop_var, types::Scalar(types::PrimitiveType::UInt64));
1✔
121

122
    auto loop_indvar = symbolic::symbol(loop_var);
1✔
123
    auto loop_init = symbolic::integer(0);
1✔
124
    auto loop_condition = symbolic::Lt(loop_indvar, this->n_);
1✔
125
    auto loop_update = symbolic::add(loop_indvar, symbolic::integer(1));
1✔
126

127
    auto& loop = builder.add_for(
2✔
128
        new_sequence,
1✔
129
        loop_indvar,
130
        loop_condition,
131
        loop_init,
1✔
132
        loop_update,
133
        {},
1✔
134
        builder.subject().debug_info().get_region(block.debug_info().indices())
1✔
135
    );
136
    auto& body = loop.root();
1✔
137

138
    auto& new_block = builder.add_block(body);
1✔
139

140
    auto& res_in = builder.add_access(new_block, output_node_res.data());
1✔
141
    auto& res_out = builder.add_access(new_block, output_node_res.data());
1✔
142
    auto& x = builder.add_access(new_block, input_node_x.data());
1✔
143
    auto& y = builder.add_access(new_block, input_node_y.data());
1✔
144

145
    auto& tasklet = builder.add_tasklet(new_block, data_flow::TaskletCode::fma, "_out", {"_in1", "_in2", "_in3"});
1✔
146

147
    builder.add_computational_memlet(
2✔
148
        new_block,
1✔
149
        x,
1✔
150
        tasklet,
1✔
151
        "_in1",
1✔
152
        {symbolic::mul(loop_indvar, this->incx_)},
1✔
153
        iedge_x->base_type(),
1✔
154
        builder.subject().debug_info().get_region(iedge_x->debug_info().indices())
1✔
155
    );
156
    builder.add_computational_memlet(
2✔
157
        new_block,
1✔
158
        y,
1✔
159
        tasklet,
1✔
160
        "_in2",
1✔
161
        {symbolic::mul(loop_indvar, this->incy_)},
1✔
162
        iedge_y->base_type(),
1✔
163
        builder.subject().debug_info().get_region(iedge_y->debug_info().indices())
1✔
164
    );
165
    builder.add_computational_memlet(
2✔
166
        new_block,
1✔
167
        res_in,
1✔
168
        tasklet,
1✔
169
        "_in3",
1✔
170
        {},
1✔
171
        oedge_res->base_type(),
1✔
172
        builder.subject().debug_info().get_region(oedge_res->debug_info().indices())
1✔
173
    );
174
    builder.add_computational_memlet(
2✔
175
        new_block,
1✔
176
        tasklet,
1✔
177
        "_out",
1✔
178
        res_out,
1✔
179
        {},
1✔
180
        oedge_res->base_type(),
1✔
181
        builder.subject().debug_info().get_region(oedge_res->debug_info().indices())
1✔
182
    );
183

184
    // Clean up
185
    builder.remove_memlet(block, *iedge_x);
1✔
186
    builder.remove_memlet(block, *iedge_y);
1✔
187
    builder.remove_memlet(block, *oedge_res);
1✔
188
    builder.remove_node(block, input_node_x);
1✔
189
    builder.remove_node(block, input_node_y);
1✔
190
    builder.remove_node(block, output_node_res);
1✔
191
    builder.remove_node(block, *this);
1✔
192
    builder.remove_child(parent, index + 1);
1✔
193

194
    return true;
1✔
195
}
1✔
196

197
std::unique_ptr<data_flow::DataFlowNode> DotNode::
198
    clone(size_t element_id, const graph::Vertex vertex, data_flow::DataFlowGraph& parent) const {
×
199
    auto node_clone = std::unique_ptr<DotNode>(new DotNode(
×
200
        element_id,
×
201
        this->debug_info(),
×
202
        vertex,
×
203
        parent,
×
204
        this->implementation_type_,
×
205
        this->precision_,
×
206
        this->n_,
×
207
        this->incx_,
×
208
        this->incy_
×
209
    ));
210
    return std::move(node_clone);
×
211
}
×
212

213
nlohmann::json DotNodeSerializer::serialize(const data_flow::LibraryNode& library_node) {
×
214
    const DotNode& gemm_node = static_cast<const DotNode&>(library_node);
×
215
    nlohmann::json j;
×
216

217
    serializer::JSONSerializer serializer;
×
218
    j["code"] = gemm_node.code().value();
×
219
    j["precision"] = gemm_node.precision();
×
220
    j["n"] = serializer.expression(gemm_node.n());
×
221
    j["incx"] = serializer.expression(gemm_node.incx());
×
222
    j["incy"] = serializer.expression(gemm_node.incy());
×
223

224
    return j;
×
225
}
×
226

227
data_flow::LibraryNode& DotNodeSerializer::deserialize(
×
228
    const nlohmann::json& j, builder::StructuredSDFGBuilder& builder, structured_control_flow::Block& parent
229
) {
230
    // Assertions for required fields
231
    assert(j.contains("element_id"));
×
232
    assert(j.contains("code"));
×
233
    assert(j.contains("debug_info"));
×
234

235
    auto code = j["code"].get<std::string>();
×
236
    if (code != LibraryNodeType_DOT.value()) {
×
237
        throw std::runtime_error("Invalid library node code");
×
238
    }
239

240
    // Extract debug info using JSONSerializer
241
    sdfg::serializer::JSONSerializer serializer;
×
NEW
242
    DebugInfoRegion debug_info = serializer.json_to_debug_info_region(j["debug_info"], builder.debug_info());
×
243

244
    auto precision = j.at("precision").get<BLAS_Precision>();
×
245
    auto n = SymEngine::Expression(j.at("n"));
×
246
    auto incx = SymEngine::Expression(j.at("incx"));
×
247
    auto incy = SymEngine::Expression(j.at("incy"));
×
248

249
    auto implementation_type = j.at("implementation_type").get<std::string>();
×
250

251
    return builder.add_library_node<DotNode>(parent, debug_info, implementation_type, precision, n, incx, incy);
×
252
}
×
253

254
DotNodeDispatcher_BLAS::DotNodeDispatcher_BLAS(
×
255
    codegen::LanguageExtension& language_extension,
256
    const Function& function,
257
    const data_flow::DataFlowGraph& data_flow_graph,
258
    const DotNode& node
259
)
260
    : codegen::LibraryNodeDispatcher(language_extension, function, data_flow_graph, node) {}
×
261

262
void DotNodeDispatcher_BLAS::dispatch(
×
263
    codegen::PrettyPrinter& stream,
264
    codegen::PrettyPrinter& globals_stream,
265
    codegen::CodeSnippetFactory& library_snippet_factory
266
) {
267
    stream << "{" << std::endl;
×
268
    stream.setIndent(stream.indent() + 4);
×
269

270
    auto& dot_node = static_cast<const DotNode&>(this->node_);
×
271

272
    sdfg::types::Scalar base_type(types::PrimitiveType::Void);
×
273
    switch (dot_node.precision()) {
×
274
        case BLAS_Precision::h:
275
            base_type = types::Scalar(types::PrimitiveType::Half);
×
276
            break;
×
277
        case BLAS_Precision::s:
278
            base_type = types::Scalar(types::PrimitiveType::Float);
×
279
            break;
×
280
        case BLAS_Precision::d:
281
            base_type = types::Scalar(types::PrimitiveType::Double);
×
282
            break;
×
283
        default:
284
            throw std::runtime_error("Invalid BLAS_Precision value");
×
285
    }
286

287
    auto& graph = this->node_.get_parent();
×
288
    for (auto& iedge : graph.in_edges(this->node_)) {
×
289
        auto& access_node = static_cast<const data_flow::AccessNode&>(iedge.src());
×
290
        std::string name = access_node.data();
×
291
        auto& type = this->function_.type(name);
×
292

293
        stream << this->language_extension_.declaration(iedge.dst_conn(), type);
×
294
        stream << " = " << name << ";" << std::endl;
×
295
    }
×
296
    for (auto& oedge : graph.out_edges(this->node_)) {
×
297
        auto& access_node = static_cast<const data_flow::AccessNode&>(oedge.dst());
×
298
        std::string name = access_node.data();
×
299
        auto& type = this->function_.type(name);
×
300

301
        stream << this->language_extension_.declaration(oedge.src_conn(), type);
×
302
        stream << ";" << std::endl;
×
303
    }
×
304

305
    std::string res_name = this->node_.outputs().at(0);
×
306
    stream << res_name << " = ";
×
307
    stream << "cblas_" << BLAS_Precision_to_string(dot_node.precision()) << "dot(";
×
308
    stream.setIndent(stream.indent() + 4);
×
309
    stream << this->language_extension_.expression(dot_node.n());
×
310
    stream << ", ";
×
311
    stream << "x";
×
312
    stream << ", ";
×
313
    stream << this->language_extension_.expression(dot_node.incx());
×
314
    stream << ", ";
×
315
    stream << "y";
×
316
    stream << ", ";
×
317
    stream << this->language_extension_.expression(dot_node.incy());
×
318
    stream.setIndent(stream.indent() - 4);
×
319
    stream << ");" << std::endl;
×
320

321
    for (auto& oedge : graph.out_edges(this->node_)) {
×
322
        auto& access_node = static_cast<const data_flow::AccessNode&>(oedge.dst());
×
323
        std::string name = access_node.data();
×
324
        auto& type = this->function_.type(name);
×
325
        stream << name << " = " << oedge.src_conn() << ";" << std::endl;
×
326
    }
×
327

328
    stream.setIndent(stream.indent() - 4);
×
329
    stream << "}" << std::endl;
×
330
}
×
331

332
DotNodeDispatcher_CUBLAS::DotNodeDispatcher_CUBLAS(
×
333
    codegen::LanguageExtension& language_extension,
334
    const Function& function,
335
    const data_flow::DataFlowGraph& data_flow_graph,
336
    const DotNode& node
337
)
338
    : codegen::LibraryNodeDispatcher(language_extension, function, data_flow_graph, node) {}
×
339

340
void DotNodeDispatcher_CUBLAS::dispatch(
×
341
    codegen::PrettyPrinter& stream,
342
    codegen::PrettyPrinter& globals_stream,
343
    codegen::CodeSnippetFactory& library_snippet_factory
344
) {
345
    throw std::runtime_error("DotNodeDispatcher_CUBLAS not implemented");
×
346
}
×
347

348
} // namespace blas
349
} // namespace math
350
} // 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