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

daisytuner / docc / 27981272983

22 Jun 2026 08:18PM UTC coverage: 61.754% (-0.03%) from 61.782%
27981272983

Pull #781

github

web-flow
Merge bddaa3724 into fe87d162b
Pull Request #781: Extend Segformer benchmarks setup

987 of 1432 new or added lines in 62 files covered. (68.92%)

9 existing lines in 7 files now uncovered.

38121 of 61730 relevant lines covered (61.75%)

993.19 hits per line

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

43.54
/sdfg/src/data_flow/library_nodes/math/blas/dot_node.cpp
1
#include "sdfg/data_flow/library_nodes/math/blas/dot_node.h"
2
#include <stdexcept>
3
#include <string>
4

5
#include "sdfg/analysis/analysis.h"
6
#include "sdfg/builder/structured_sdfg_builder.h"
7

8
#include "sdfg/symbolic/symbolic.h"
9

10
namespace sdfg {
11
namespace math {
12
namespace blas {
13

14
DotNode::DotNode(
15
    size_t element_id,
16
    const DebugInfo& debug_info,
17
    const graph::Vertex vertex,
18
    data_flow::DataFlowGraph& parent,
19
    const data_flow::ImplementationType& implementation_type,
20
    const BLAS_Precision& precision,
21
    symbolic::Expression n,
22
    symbolic::Expression incx,
23
    symbolic::Expression incy
24
)
25
    : BLASNode(
13✔
26
          element_id,
13✔
27
          debug_info,
13✔
28
          vertex,
13✔
29
          parent,
13✔
30
          LibraryNodeType_DOT,
13✔
31
          {"__out"},
13✔
32
          {"__x", "__y"},
13✔
33
          implementation_type,
13✔
34
          precision
13✔
35
      ),
13✔
36
      n_(n), incx_(incx), incy_(incy) {}
13✔
37

38
symbolic::Expression DotNode::n() const { return this->n_; };
4✔
39

40
symbolic::Expression DotNode::incx() const { return this->incx_; };
2✔
41

42
symbolic::Expression DotNode::incy() const { return this->incy_; };
2✔
43

44
symbolic::SymbolSet DotNode::symbols() const {
×
45
    symbolic::SymbolSet syms;
×
46

47
    for (auto& atom : symbolic::atoms(this->n_)) {
×
48
        syms.insert(atom);
×
49
    }
×
50
    for (auto& atom : symbolic::atoms(this->incx_)) {
×
51
        syms.insert(atom);
×
52
    }
×
53
    for (auto& atom : symbolic::atoms(this->incy_)) {
×
54
        syms.insert(atom);
×
55
    }
×
56

57
    return syms;
×
58
};
×
59

60
void DotNode::replace(const symbolic::Expression old_expression, const symbolic::Expression new_expression) {
×
61
    this->n_ = symbolic::subs(this->n_, old_expression, new_expression);
×
62
    this->incx_ = symbolic::subs(this->incx_, old_expression, new_expression);
×
63
    this->incy_ = symbolic::subs(this->incy_, old_expression, new_expression);
×
64
};
×
65

NEW
66
void DotNode::replace(const symbolic::ExpressionMapping& replacements) {
×
NEW
67
    this->n_ = symbolic::subs(this->n_, replacements);
×
NEW
68
    this->incx_ = symbolic::subs(this->incx_, replacements);
×
NEW
69
    this->incy_ = symbolic::subs(this->incy_, replacements);
×
NEW
70
};
×
71

UNCOV
72
void DotNode::validate(const Function& function) const { BLASNode::validate(function); }
×
73

74
bool DotNode::expand(builder::StructuredSDFGBuilder& builder, analysis::AnalysisManager& analysis_manager) {
5✔
75
    auto& dataflow = this->get_parent();
5✔
76
    auto& block = static_cast<structured_control_flow::Block&>(*dataflow.get_parent());
5✔
77
    auto& parent = static_cast<structured_control_flow::Sequence&>(*block.get_parent());
5✔
78
    int index = parent.index(block);
5✔
79
    auto& transition = parent.at(index).second;
5✔
80

81
    const data_flow::Memlet* iedge_x = nullptr;
5✔
82
    const data_flow::Memlet* iedge_y = nullptr;
5✔
83
    for (const auto& iedge : dataflow.in_edges(*this)) {
10✔
84
        if (iedge.dst_conn() == "__x") {
10✔
85
            iedge_x = &iedge;
5✔
86
        } else if (iedge.dst_conn() == "__y") {
5✔
87
            iedge_y = &iedge;
5✔
88
        }
5✔
89
    }
10✔
90

91
    const data_flow::Memlet* oedge_res = nullptr;
5✔
92
    for (const auto& oedge : dataflow.out_edges(*this)) {
5✔
93
        if (oedge.src_conn() == "__out") {
5✔
94
            oedge_res = &oedge;
5✔
95
            break;
5✔
96
        }
5✔
97
    }
5✔
98

99
    // Check if legal
100
    auto& input_node_x = static_cast<const data_flow::AccessNode&>(iedge_x->src());
5✔
101
    auto& input_node_y = static_cast<const data_flow::AccessNode&>(iedge_y->src());
5✔
102
    auto& output_node_res = static_cast<const data_flow::AccessNode&>(oedge_res->dst());
5✔
103
    if (dataflow.in_degree(input_node_x) != 0 || dataflow.in_degree(input_node_y) != 0 ||
5✔
104
        dataflow.out_degree(output_node_res) != 0) {
5✔
105
        return false;
×
106
    }
×
107

108
    auto& new_sequence = builder.add_sequence_before(parent, block, transition.assignments(), block.debug_info());
5✔
109

110
    std::string loop_var = builder.find_new_name("_i");
5✔
111
    builder.add_container(loop_var, types::Scalar(types::PrimitiveType::UInt64));
5✔
112

113
    auto loop_indvar = symbolic::symbol(loop_var);
5✔
114
    auto loop_init = symbolic::integer(0);
5✔
115
    auto loop_condition = symbolic::Lt(loop_indvar, this->n_);
5✔
116
    auto loop_update = symbolic::add(loop_indvar, symbolic::integer(1));
5✔
117

118
    auto& loop =
5✔
119
        builder.add_for(new_sequence, loop_indvar, loop_condition, loop_init, loop_update, {}, block.debug_info());
5✔
120
    auto& body = loop.root();
5✔
121

122
    auto& new_block = builder.add_block(body);
5✔
123

124
    auto& res_in = builder.add_access(new_block, output_node_res.data());
5✔
125
    auto& res_out = builder.add_access(new_block, output_node_res.data());
5✔
126
    auto& x = builder.add_access(new_block, input_node_x.data());
5✔
127
    auto& y = builder.add_access(new_block, input_node_y.data());
5✔
128

129
    auto& tasklet = builder.add_tasklet(new_block, data_flow::TaskletCode::fp_fma, "__out", {"_in1", "_in2", "_in3"});
5✔
130

131
    builder.add_computational_memlet(
5✔
132
        new_block,
5✔
133
        x,
5✔
134
        tasklet,
5✔
135
        "_in1",
5✔
136
        {symbolic::mul(loop_indvar, this->incx_)},
5✔
137
        iedge_x->base_type(),
5✔
138
        iedge_x->debug_info()
5✔
139
    );
5✔
140
    builder.add_computational_memlet(
5✔
141
        new_block,
5✔
142
        y,
5✔
143
        tasklet,
5✔
144
        "_in2",
5✔
145
        {symbolic::mul(loop_indvar, this->incy_)},
5✔
146
        iedge_y->base_type(),
5✔
147
        iedge_y->debug_info()
5✔
148
    );
5✔
149
    builder
5✔
150
        .add_computational_memlet(new_block, res_in, tasklet, "_in3", {}, oedge_res->base_type(), oedge_res->debug_info());
5✔
151
    builder.add_computational_memlet(
5✔
152
        new_block, tasklet, "__out", res_out, {}, oedge_res->base_type(), oedge_res->debug_info()
5✔
153
    );
5✔
154

155
    // Clean up
156
    builder.remove_memlet(block, *iedge_x);
5✔
157
    builder.remove_memlet(block, *iedge_y);
5✔
158
    builder.remove_memlet(block, *oedge_res);
5✔
159
    builder.remove_node(block, input_node_x);
5✔
160
    builder.remove_node(block, input_node_y);
5✔
161
    builder.remove_node(block, output_node_res);
5✔
162
    builder.remove_node(block, *this);
5✔
163
    builder.remove_child(parent, index + 1);
5✔
164

165
    return true;
5✔
166
}
5✔
167

168
symbolic::Expression DotNode::flop() const {
×
169
    auto muls = this->n_;
×
170
    auto adds = symbolic::sub(this->n_, symbolic::one());
×
171
    return symbolic::add(muls, adds);
×
172
}
×
173

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

190
data_flow::PointerAccessType DotNode::pointer_access_type(int input_idx) const {
×
191
    if (input_idx == 0) {
×
192
        return data_flow::PointerAccessMeta::create_read_only(symbolic::mul(n_, incx_), true);
×
193
    } else if (input_idx == 1) {
×
194
        return data_flow::PointerAccessMeta::create_read_only(symbolic::mul(n_, incy_), true);
×
195
    } else {
×
196
        return BLASNode::pointer_access_type(input_idx);
×
197
    }
×
198
}
×
199

200
nlohmann::json DotNodeSerializer::serialize(const data_flow::LibraryNode& library_node) {
×
201
    const DotNode& gemm_node = static_cast<const DotNode&>(library_node);
×
202
    nlohmann::json j;
×
203

204
    serializer::JSONSerializer serializer;
×
205
    j["code"] = gemm_node.code().value();
×
206
    j["precision"] = gemm_node.precision();
×
207
    j["n"] = serializer.expression(gemm_node.n());
×
208
    j["incx"] = serializer.expression(gemm_node.incx());
×
209
    j["incy"] = serializer.expression(gemm_node.incy());
×
210

211
    return j;
×
212
}
×
213

214
data_flow::LibraryNode& DotNodeSerializer::deserialize(
215
    const nlohmann::json& j, builder::StructuredSDFGBuilder& builder, structured_control_flow::Block& parent
216
) {
×
217
    // Assertions for required fields
218
    assert(j.contains("element_id"));
×
219
    assert(j.contains("code"));
×
220
    assert(j.contains("debug_info"));
×
221

222
    auto code = j["code"].get<std::string>();
×
223
    if (code != LibraryNodeType_DOT.value()) {
×
224
        throw std::runtime_error("Invalid library node code");
×
225
    }
×
226

227
    // Extract debug info using JSONSerializer
228
    sdfg::serializer::JSONSerializer serializer;
×
229
    DebugInfo debug_info = serializer.json_to_debug_info(j["debug_info"]);
×
230

231
    auto precision = j.at("precision").get<BLAS_Precision>();
×
232
    auto n = symbolic::parse(j.at("n"));
×
233
    auto incx = symbolic::parse(j.at("incx"));
×
234
    auto incy = symbolic::parse(j.at("incy"));
×
235

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

238
    return builder.add_library_node<DotNode>(parent, debug_info, implementation_type, precision, n, incx, incy);
×
239
}
×
240

241
DotNodeDispatcher_BLAS::DotNodeDispatcher_BLAS(
242
    codegen::LanguageExtension& language_extension,
243
    const Function& function,
244
    const data_flow::DataFlowGraph& data_flow_graph,
245
    const DotNode& node
246
)
247
    : codegen::LibraryNodeDispatcher(language_extension, function, data_flow_graph, node) {}
×
248

249
void DotNodeDispatcher_BLAS::dispatch_code_with_edges(
250
    codegen::CodegenOutput& out,
251
    std::vector<codegen::DispatchInput>& inputs,
252
    std::vector<codegen::DispatchOutput>& outputs
253
) {
×
254
    auto& dot_node = static_cast<const DotNode&>(this->node_);
×
255

256
    sdfg::types::Scalar base_type(types::PrimitiveType::Void);
×
257
    BLAS_Precision precision = dot_node.precision();
×
258
    switch (precision) {
×
259
        case BLAS_Precision::h:
×
260
            base_type = types::Scalar(types::PrimitiveType::Half);
×
261
            break;
×
262
        case BLAS_Precision::s:
×
263
            base_type = types::Scalar(types::PrimitiveType::Float);
×
264
            break;
×
265
        case BLAS_Precision::d:
×
266
            base_type = types::Scalar(types::PrimitiveType::Double);
×
267
            break;
×
268
        default:
×
269
            throw std::runtime_error("Invalid BLAS_Precision value");
×
270
    }
×
271

272
    out.library_snippet_factory.require_dependency(BLASLibDependency::instance());
×
273

274
    auto& output = outputs.at(0);
×
275
    pre_allocate_output(out, output, dot_node.output(0));
×
276

277
    out.stream << *output.local_name << " = ";
×
278
    out.stream << "cblas_" << BLAS_Precision_to_string(precision) << "dot(";
×
279
    out.stream.changeIndent(+4);
×
280
    out.stream << this->language_extension_.expression(dot_node.n());
×
281
    out.stream << ", ";
×
282
    out.stream << inputs.at(0).expr;
×
283
    out.stream << ", ";
×
284
    out.stream << this->language_extension_.expression(dot_node.incx());
×
285
    out.stream << ", ";
×
286
    out.stream << inputs.at(1).expr;
×
287
    out.stream << ", ";
×
288
    out.stream << this->language_extension_.expression(dot_node.incy());
×
289
    out.stream.changeIndent(-4);
×
290
    out.stream << ");" << std::endl;
×
291
}
×
292

293

294
} // namespace blas
295
} // namespace math
296
} // 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