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

daisytuner / sdfglib / 17656823807

11 Sep 2025 08:42PM UTC coverage: 60.447% (+1.1%) from 59.335%
17656823807

Pull #219

github

web-flow
Merge d5416236f into 6c1992b40
Pull Request #219: stdlib Library Nodes and ConstantNodes

460 of 1635 new or added lines in 81 files covered. (28.13%)

93 existing lines in 35 files now uncovered.

9385 of 15526 relevant lines covered (60.45%)

107.21 hits per line

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

47.13
/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, {"_out"}, {"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

NEW
34
void DotNode::validate(const Function& function) const {}
×
35

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

39
    auto& dataflow = this->get_parent();
1✔
40
    auto& block = static_cast<structured_control_flow::Block&>(*dataflow.get_parent());
1✔
41
    auto& parent = static_cast<structured_control_flow::Sequence&>(*scope_analysis.parent_scope(&block));
1✔
42
    int index = parent.index(block);
1✔
43
    auto& transition = parent.at(index).second;
1✔
44

45
    const data_flow::Memlet* iedge_x = nullptr;
1✔
46
    const data_flow::Memlet* iedge_y = nullptr;
1✔
47
    for (const auto& iedge : dataflow.in_edges(*this)) {
3✔
48
        if (iedge.dst_conn() == "x") {
2✔
49
            iedge_x = &iedge;
1✔
50
        } else if (iedge.dst_conn() == "y") {
2✔
51
            iedge_y = &iedge;
1✔
52
        }
1✔
53
    }
54

55
    const data_flow::Memlet* oedge_res = nullptr;
1✔
56
    for (const auto& oedge : dataflow.out_edges(*this)) {
1✔
57
        if (oedge.src_conn() == "_out") {
1✔
58
            oedge_res = &oedge;
1✔
59
            break;
1✔
60
        }
61
    }
62

63
    // Check if legal
64
    auto& input_node_x = static_cast<const data_flow::AccessNode&>(iedge_x->src());
1✔
65
    auto& input_node_y = static_cast<const data_flow::AccessNode&>(iedge_y->src());
1✔
66
    auto& output_node_res = static_cast<const data_flow::AccessNode&>(oedge_res->dst());
1✔
67
    if (dataflow.in_degree(input_node_x) != 0 || dataflow.in_degree(input_node_y) != 0 ||
1✔
68
        dataflow.out_degree(output_node_res) != 0) {
1✔
69
        return false;
×
70
    }
71

72
    auto& new_sequence = builder.add_sequence_before(parent, block, transition.assignments(), block.debug_info());
1✔
73

74
    std::string loop_var = builder.find_new_name("_i");
1✔
75
    builder.add_container(loop_var, types::Scalar(types::PrimitiveType::UInt64));
1✔
76

77
    auto loop_indvar = symbolic::symbol(loop_var);
1✔
78
    auto loop_init = symbolic::integer(0);
1✔
79
    auto loop_condition = symbolic::Lt(loop_indvar, this->n_);
1✔
80
    auto loop_update = symbolic::add(loop_indvar, symbolic::integer(1));
1✔
81

82
    auto& loop =
1✔
83
        builder.add_for(new_sequence, loop_indvar, loop_condition, loop_init, loop_update, {}, block.debug_info());
1✔
84
    auto& body = loop.root();
1✔
85

86
    auto& new_block = builder.add_block(body);
1✔
87

88
    auto& res_in = builder.add_access(new_block, output_node_res.data());
1✔
89
    auto& res_out = builder.add_access(new_block, output_node_res.data());
1✔
90
    auto& x = builder.add_access(new_block, input_node_x.data());
1✔
91
    auto& y = builder.add_access(new_block, input_node_y.data());
1✔
92

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

95
    builder.add_computational_memlet(
2✔
96
        new_block,
1✔
97
        x,
1✔
98
        tasklet,
1✔
99
        "_in1",
1✔
100
        {symbolic::mul(loop_indvar, this->incx_)},
1✔
101
        iedge_x->base_type(),
1✔
102
        iedge_x->debug_info()
1✔
103
    );
104
    builder.add_computational_memlet(
2✔
105
        new_block,
1✔
106
        y,
1✔
107
        tasklet,
1✔
108
        "_in2",
1✔
109
        {symbolic::mul(loop_indvar, this->incy_)},
1✔
110
        iedge_y->base_type(),
1✔
111
        iedge_y->debug_info()
1✔
112
    );
113
    builder
2✔
114
        .add_computational_memlet(new_block, res_in, tasklet, "_in3", {}, oedge_res->base_type(), oedge_res->debug_info());
1✔
115
    builder.add_computational_memlet(
2✔
116
        new_block, tasklet, "_out", res_out, {}, oedge_res->base_type(), oedge_res->debug_info()
1✔
117
    );
118

119
    // Clean up
120
    builder.remove_memlet(block, *iedge_x);
1✔
121
    builder.remove_memlet(block, *iedge_y);
1✔
122
    builder.remove_memlet(block, *oedge_res);
1✔
123
    builder.remove_node(block, input_node_x);
1✔
124
    builder.remove_node(block, input_node_y);
1✔
125
    builder.remove_node(block, output_node_res);
1✔
126
    builder.remove_node(block, *this);
1✔
127
    builder.remove_child(parent, index + 1);
1✔
128

129
    return true;
1✔
130
}
1✔
131

132
std::unique_ptr<data_flow::DataFlowNode> DotNode::
133
    clone(size_t element_id, const graph::Vertex vertex, data_flow::DataFlowGraph& parent) const {
×
134
    auto node_clone = std::unique_ptr<DotNode>(new DotNode(
×
135
        element_id,
×
136
        this->debug_info(),
×
137
        vertex,
×
138
        parent,
×
139
        this->implementation_type_,
×
140
        this->precision_,
×
141
        this->n_,
×
142
        this->incx_,
×
143
        this->incy_
×
144
    ));
145
    return std::move(node_clone);
×
146
}
×
147

148
nlohmann::json DotNodeSerializer::serialize(const data_flow::LibraryNode& library_node) {
×
149
    const DotNode& gemm_node = static_cast<const DotNode&>(library_node);
×
150
    nlohmann::json j;
×
151

152
    serializer::JSONSerializer serializer;
×
153
    j["code"] = gemm_node.code().value();
×
154
    j["precision"] = gemm_node.precision();
×
155
    j["n"] = serializer.expression(gemm_node.n());
×
156
    j["incx"] = serializer.expression(gemm_node.incx());
×
157
    j["incy"] = serializer.expression(gemm_node.incy());
×
158

159
    return j;
×
160
}
×
161

162
data_flow::LibraryNode& DotNodeSerializer::deserialize(
×
163
    const nlohmann::json& j, builder::StructuredSDFGBuilder& builder, structured_control_flow::Block& parent
164
) {
165
    // Assertions for required fields
166
    assert(j.contains("element_id"));
×
167
    assert(j.contains("code"));
×
168
    assert(j.contains("debug_info"));
×
169

170
    auto code = j["code"].get<std::string>();
×
171
    if (code != LibraryNodeType_DOT.value()) {
×
172
        throw std::runtime_error("Invalid library node code");
×
173
    }
174

175
    // Extract debug info using JSONSerializer
176
    sdfg::serializer::JSONSerializer serializer;
×
177
    DebugInfo debug_info = serializer.json_to_debug_info(j["debug_info"]);
×
178

179
    auto precision = j.at("precision").get<BLAS_Precision>();
×
180
    auto n = SymEngine::Expression(j.at("n"));
×
181
    auto incx = SymEngine::Expression(j.at("incx"));
×
182
    auto incy = SymEngine::Expression(j.at("incy"));
×
183

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

186
    return builder.add_library_node<DotNode>(parent, debug_info, implementation_type, precision, n, incx, incy);
×
187
}
×
188

189
DotNodeDispatcher_BLAS::DotNodeDispatcher_BLAS(
×
190
    codegen::LanguageExtension& language_extension,
191
    const Function& function,
192
    const data_flow::DataFlowGraph& data_flow_graph,
193
    const DotNode& node
194
)
195
    : codegen::LibraryNodeDispatcher(language_extension, function, data_flow_graph, node) {}
×
196

NEW
197
void DotNodeDispatcher_BLAS::dispatch_code(
×
198
    codegen::PrettyPrinter& stream,
199
    codegen::PrettyPrinter& globals_stream,
200
    codegen::CodeSnippetFactory& library_snippet_factory
201
) {
202
    stream << "{" << std::endl;
×
203
    stream.setIndent(stream.indent() + 4);
×
204

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

207
    sdfg::types::Scalar base_type(types::PrimitiveType::Void);
×
208
    switch (dot_node.precision()) {
×
209
        case BLAS_Precision::h:
210
            base_type = types::Scalar(types::PrimitiveType::Half);
×
211
            break;
×
212
        case BLAS_Precision::s:
213
            base_type = types::Scalar(types::PrimitiveType::Float);
×
214
            break;
×
215
        case BLAS_Precision::d:
216
            base_type = types::Scalar(types::PrimitiveType::Double);
×
217
            break;
×
218
        default:
219
            throw std::runtime_error("Invalid BLAS_Precision value");
×
220
    }
221

NEW
222
    stream << "res = ";
×
223
    stream << "cblas_" << BLAS_Precision_to_string(dot_node.precision()) << "dot(";
×
224
    stream.setIndent(stream.indent() + 4);
×
225
    stream << this->language_extension_.expression(dot_node.n());
×
226
    stream << ", ";
×
227
    stream << "x";
×
228
    stream << ", ";
×
229
    stream << this->language_extension_.expression(dot_node.incx());
×
230
    stream << ", ";
×
231
    stream << "y";
×
232
    stream << ", ";
×
233
    stream << this->language_extension_.expression(dot_node.incy());
×
234
    stream.setIndent(stream.indent() - 4);
×
235
    stream << ");" << std::endl;
×
236

237
    stream.setIndent(stream.indent() - 4);
×
238
    stream << "}" << std::endl;
×
239
}
×
240

241
DotNodeDispatcher_CUBLAS::DotNodeDispatcher_CUBLAS(
×
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

NEW
249
void DotNodeDispatcher_CUBLAS::dispatch_code(
×
250
    codegen::PrettyPrinter& stream,
251
    codegen::PrettyPrinter& globals_stream,
252
    codegen::CodeSnippetFactory& library_snippet_factory
253
) {
254
    throw std::runtime_error("DotNodeDispatcher_CUBLAS not implemented");
×
255
}
×
256

257
} // namespace blas
258
} // namespace math
259
} // 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

© 2025 Coveralls, Inc