• 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

35.58
/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 DebugInfo& 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(parent, block, transition.assignments(), block.debug_info());
1✔
116

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

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

125
    auto& loop =
1✔
126
        builder.add_for(new_sequence, loop_indvar, loop_condition, loop_init, loop_update, {}, block.debug_info());
1✔
127
    auto& body = loop.root();
1✔
128

129
    auto& new_block = builder.add_block(body);
1✔
130

131
    auto& res_in = builder.add_access(new_block, output_node_res.data());
1✔
132
    auto& res_out = builder.add_access(new_block, output_node_res.data());
1✔
133
    auto& x = builder.add_access(new_block, input_node_x.data());
1✔
134
    auto& y = builder.add_access(new_block, input_node_y.data());
1✔
135

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

138
    builder.add_computational_memlet(
2✔
139
        new_block,
1✔
140
        x,
1✔
141
        tasklet,
1✔
142
        "_in1",
1✔
143
        {symbolic::mul(loop_indvar, this->incx_)},
1✔
144
        iedge_x->base_type(),
1✔
145
        iedge_x->debug_info()
1✔
146
    );
147
    builder.add_computational_memlet(
2✔
148
        new_block,
1✔
149
        y,
1✔
150
        tasklet,
1✔
151
        "_in2",
1✔
152
        {symbolic::mul(loop_indvar, this->incy_)},
1✔
153
        iedge_y->base_type(),
1✔
154
        iedge_y->debug_info()
1✔
155
    );
156
    builder
2✔
157
        .add_computational_memlet(new_block, res_in, tasklet, "_in3", {}, oedge_res->base_type(), oedge_res->debug_info());
1✔
158
    builder.add_computational_memlet(
2✔
159
        new_block, tasklet, "_out", res_out, {}, oedge_res->base_type(), oedge_res->debug_info()
1✔
160
    );
161

162
    // Clean up
163
    builder.remove_memlet(block, *iedge_x);
1✔
164
    builder.remove_memlet(block, *iedge_y);
1✔
165
    builder.remove_memlet(block, *oedge_res);
1✔
166
    builder.remove_node(block, input_node_x);
1✔
167
    builder.remove_node(block, input_node_y);
1✔
168
    builder.remove_node(block, output_node_res);
1✔
169
    builder.remove_node(block, *this);
1✔
170
    builder.remove_child(parent, index + 1);
1✔
171

172
    return true;
1✔
173
}
1✔
174

175
std::unique_ptr<data_flow::DataFlowNode> DotNode::
176
    clone(size_t element_id, const graph::Vertex vertex, data_flow::DataFlowGraph& parent) const {
×
177
    auto node_clone = std::unique_ptr<DotNode>(new DotNode(
×
178
        element_id,
×
179
        this->debug_info(),
×
180
        vertex,
×
181
        parent,
×
182
        this->implementation_type_,
×
183
        this->precision_,
×
184
        this->n_,
×
185
        this->incx_,
×
186
        this->incy_
×
187
    ));
188
    return std::move(node_clone);
×
189
}
×
190

191
nlohmann::json DotNodeSerializer::serialize(const data_flow::LibraryNode& library_node) {
×
192
    const DotNode& gemm_node = static_cast<const DotNode&>(library_node);
×
193
    nlohmann::json j;
×
194

195
    serializer::JSONSerializer serializer;
×
196
    j["code"] = gemm_node.code().value();
×
197
    j["precision"] = gemm_node.precision();
×
198
    j["n"] = serializer.expression(gemm_node.n());
×
199
    j["incx"] = serializer.expression(gemm_node.incx());
×
200
    j["incy"] = serializer.expression(gemm_node.incy());
×
201

202
    return j;
×
203
}
×
204

205
data_flow::LibraryNode& DotNodeSerializer::deserialize(
×
206
    const nlohmann::json& j, builder::StructuredSDFGBuilder& builder, structured_control_flow::Block& parent
207
) {
208
    // Assertions for required fields
209
    assert(j.contains("element_id"));
×
210
    assert(j.contains("code"));
×
211
    assert(j.contains("debug_info"));
×
212

213
    auto code = j["code"].get<std::string>();
×
214
    if (code != LibraryNodeType_DOT.value()) {
×
215
        throw std::runtime_error("Invalid library node code");
×
216
    }
217

218
    // Extract debug info using JSONSerializer
219
    sdfg::serializer::JSONSerializer serializer;
×
NEW
220
    DebugInfo debug_info = serializer.json_to_debug_info(j["debug_info"]);
×
221

222
    auto precision = j.at("precision").get<BLAS_Precision>();
×
223
    auto n = SymEngine::Expression(j.at("n"));
×
224
    auto incx = SymEngine::Expression(j.at("incx"));
×
225
    auto incy = SymEngine::Expression(j.at("incy"));
×
226

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

229
    return builder.add_library_node<DotNode>(parent, debug_info, implementation_type, precision, n, incx, incy);
×
230
}
×
231

232
DotNodeDispatcher_BLAS::DotNodeDispatcher_BLAS(
×
233
    codegen::LanguageExtension& language_extension,
234
    const Function& function,
235
    const data_flow::DataFlowGraph& data_flow_graph,
236
    const DotNode& node
237
)
238
    : codegen::LibraryNodeDispatcher(language_extension, function, data_flow_graph, node) {}
×
239

240
void DotNodeDispatcher_BLAS::dispatch(
×
241
    codegen::PrettyPrinter& stream,
242
    codegen::PrettyPrinter& globals_stream,
243
    codegen::CodeSnippetFactory& library_snippet_factory
244
) {
245
    stream << "{" << std::endl;
×
246
    stream.setIndent(stream.indent() + 4);
×
247

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

250
    sdfg::types::Scalar base_type(types::PrimitiveType::Void);
×
251
    switch (dot_node.precision()) {
×
252
        case BLAS_Precision::h:
253
            base_type = types::Scalar(types::PrimitiveType::Half);
×
254
            break;
×
255
        case BLAS_Precision::s:
256
            base_type = types::Scalar(types::PrimitiveType::Float);
×
257
            break;
×
258
        case BLAS_Precision::d:
259
            base_type = types::Scalar(types::PrimitiveType::Double);
×
260
            break;
×
261
        default:
262
            throw std::runtime_error("Invalid BLAS_Precision value");
×
263
    }
264

265
    auto& graph = this->node_.get_parent();
×
266
    for (auto& iedge : graph.in_edges(this->node_)) {
×
267
        auto& access_node = static_cast<const data_flow::AccessNode&>(iedge.src());
×
268
        std::string name = access_node.data();
×
269
        auto& type = this->function_.type(name);
×
270

271
        stream << this->language_extension_.declaration(iedge.dst_conn(), type);
×
272
        stream << " = " << name << ";" << std::endl;
×
273
    }
×
274
    for (auto& oedge : graph.out_edges(this->node_)) {
×
275
        auto& access_node = static_cast<const data_flow::AccessNode&>(oedge.dst());
×
276
        std::string name = access_node.data();
×
277
        auto& type = this->function_.type(name);
×
278

279
        stream << this->language_extension_.declaration(oedge.src_conn(), type);
×
280
        stream << ";" << std::endl;
×
281
    }
×
282

283
    std::string res_name = this->node_.outputs().at(0);
×
284
    stream << res_name << " = ";
×
285
    stream << "cblas_" << BLAS_Precision_to_string(dot_node.precision()) << "dot(";
×
286
    stream.setIndent(stream.indent() + 4);
×
287
    stream << this->language_extension_.expression(dot_node.n());
×
288
    stream << ", ";
×
289
    stream << "x";
×
290
    stream << ", ";
×
291
    stream << this->language_extension_.expression(dot_node.incx());
×
292
    stream << ", ";
×
293
    stream << "y";
×
294
    stream << ", ";
×
295
    stream << this->language_extension_.expression(dot_node.incy());
×
296
    stream.setIndent(stream.indent() - 4);
×
297
    stream << ");" << std::endl;
×
298

299
    for (auto& oedge : graph.out_edges(this->node_)) {
×
300
        auto& access_node = static_cast<const data_flow::AccessNode&>(oedge.dst());
×
301
        std::string name = access_node.data();
×
302
        auto& type = this->function_.type(name);
×
303
        stream << name << " = " << oedge.src_conn() << ";" << std::endl;
×
304
    }
×
305

306
    stream.setIndent(stream.indent() - 4);
×
307
    stream << "}" << std::endl;
×
308
}
×
309

310
DotNodeDispatcher_CUBLAS::DotNodeDispatcher_CUBLAS(
×
311
    codegen::LanguageExtension& language_extension,
312
    const Function& function,
313
    const data_flow::DataFlowGraph& data_flow_graph,
314
    const DotNode& node
315
)
316
    : codegen::LibraryNodeDispatcher(language_extension, function, data_flow_graph, node) {}
×
317

318
void DotNodeDispatcher_CUBLAS::dispatch(
×
319
    codegen::PrettyPrinter& stream,
320
    codegen::PrettyPrinter& globals_stream,
321
    codegen::CodeSnippetFactory& library_snippet_factory
322
) {
323
    throw std::runtime_error("DotNodeDispatcher_CUBLAS not implemented");
×
324
}
×
325

326
} // namespace blas
327
} // namespace math
328
} // 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