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

daisytuner / sdfglib / 17539274729

05 Sep 2025 11:40AM UTC coverage: 59.145% (+0.09%) from 59.057%
17539274729

push

github

web-flow
Schedule type extension (#221)

* Initial Draft

* Simplify schedule type class for serialization

* string ref

* fix and = operator

60 of 72 new or added lines in 19 files covered. (83.33%)

4 existing lines in 2 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

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 DebugInfo &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
75
    auto &new_sequence = builder.add_sequence_before(parent, block, transition.assignments(), block.debug_info());
×
76
    structured_control_flow::Sequence *last_scope = &new_sequence;
×
77

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

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

113
    // Create innermost block
114
    auto &code_block = builder.add_block(*last_scope);
×
115
    auto &tasklet =
×
116
        builder
×
117
            .add_tasklet(code_block, data_flow::TaskletCode::fma, "_out", {"_in1", "_in2", "_in3"}, block.debug_info());
×
118

119
    auto &A_in = builder.add_access(code_block, A_name, block.debug_info());
×
120
    auto &B_in = builder.add_access(code_block, B_name, block.debug_info());
×
121
    auto &C_in = builder.add_access(code_block, has_C_in ? C_in_name : C_out_name, block.debug_info());
×
122
    auto &C_out = builder.add_access(code_block, C_out_name, block.debug_info());
×
123

124
    data_flow::Subset subset_A;
×
125
    if (trans_a_) {
×
126
        subset_A = {out_syms[1], out_syms[0]};
×
127
    } else {
×
128
        subset_A = {out_syms[0], out_syms[1]};
×
129
    }
130
    data_flow::Subset subset_B;
×
131
    if (trans_b_) {
×
132
        subset_B = {out_syms[1], out_syms[0]};
×
133
    } else {
×
134
        subset_B = {out_syms[0], out_syms[1]};
×
135
    }
136
    data_flow::Subset subset_C = {out_syms[0], out_syms[1]};
×
137

138
    builder
×
139
        .add_computational_memlet(code_block, A_in, tasklet, "_in1", subset_A, iedge_A->base_type(), block.debug_info());
×
140
    builder
×
141
        .add_computational_memlet(code_block, B_in, tasklet, "_in2", subset_B, iedge_B->base_type(), block.debug_info());
×
142
    builder
×
143
        .add_computational_memlet(code_block, C_in, tasklet, "_in3", subset_C, oedge_Y->base_type(), block.debug_info());
×
144
    builder
×
145
        .add_computational_memlet(code_block, tasklet, "_out", C_out, subset_C, oedge_Y->base_type(), block.debug_info());
×
146

147
    // Cleanup old block
148
    builder.remove_memlet(block, *iedge_A);
×
149
    builder.remove_memlet(block, *iedge_B);
×
150
    if (has_C_in) {
×
151
        builder.remove_memlet(block, *iedge_C);
×
152
    }
×
153
    builder.remove_memlet(block, *oedge_Y);
×
154
    builder.remove_node(block, *this);
×
155
    builder.remove_child(parent, index + 1);
×
156

157
    return true;
×
158
}
×
159

160
std::unique_ptr<data_flow::DataFlowNode> GemmNode::
161
    clone(size_t element_id, const graph::Vertex vertex, data_flow::DataFlowGraph &parent) const {
×
162
    return std::unique_ptr<data_flow::DataFlowNode>(
×
163
        new GemmNode(element_id, this->debug_info(), vertex, parent, alpha_, beta_, trans_a_, trans_b_)
×
164
    );
165
}
×
166

167
nlohmann::json GemmNodeSerializer::serialize(const data_flow::LibraryNode &library_node) {
×
168
    const GemmNode &node = static_cast<const GemmNode &>(library_node);
×
169
    nlohmann::json j;
×
170

171
    j["code"] = node.code().value();
×
172
    j["alpha"] = node.alpha();
×
173
    j["beta"] = node.beta();
×
174
    j["trans_a"] = node.trans_a();
×
175
    j["trans_b"] = node.trans_b();
×
176

177
    return j;
×
178
}
×
179

180
data_flow::LibraryNode &GemmNodeSerializer::deserialize(
×
181
    const nlohmann::json &j, builder::StructuredSDFGBuilder &builder, structured_control_flow::Block &parent
182
) {
183
    auto code = j["code"].get<std::string>();
×
184
    if (code != LibraryNodeType_Gemm.value()) {
×
185
        throw std::runtime_error("Invalid library node code");
×
186
    }
187

188
    sdfg::serializer::JSONSerializer serializer;
×
189
    DebugInfo debug_info = serializer.json_to_debug_info(j["debug_info"]);
×
190

191
    auto alpha = j["alpha"].get<std::string>();
×
192
    auto beta = j["beta"].get<std::string>();
×
193
    auto trans_a = j["trans_a"].get<bool>();
×
194
    auto trans_b = j["trans_b"].get<bool>();
×
195

196
    return builder.add_library_node<GemmNode>(parent, debug_info, alpha, beta, trans_a, trans_b);
×
197
}
×
198

199
} // namespace ml
200
} // namespace math
201
} // 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