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

daisytuner / sdfglib / 20564758202

29 Dec 2025 12:13AM UTC coverage: 40.366% (+1.4%) from 38.976%
20564758202

push

github

web-flow
Merge pull request #409 from daisytuner/lib-nodes-refactor

restructures library nodes

14298 of 45900 branches covered (31.15%)

Branch coverage included in aggregate %.

259 of 388 new or added lines in 19 files covered. (66.75%)

28 existing lines in 2 files now uncovered.

12247 of 19861 relevant lines covered (61.66%)

89.04 hits per line

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

30.82
/src/data_flow/library_nodes/math/blas/gemm_node.cpp
1
#include "sdfg/data_flow/library_nodes/math/blas/gemm_node.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
GEMMNode::GEMMNode(
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
    const BLAS_Layout& layout,
20
    const BLAS_Transpose& trans_a,
21
    const BLAS_Transpose& trans_b,
22
    symbolic::Expression m,
23
    symbolic::Expression n,
24
    symbolic::Expression k,
25
    symbolic::Expression lda,
26
    symbolic::Expression ldb,
27
    symbolic::Expression ldc
28
)
29
    : BLASNode(
1!
30
          element_id,
1✔
31
          debug_info,
1✔
32
          vertex,
1✔
33
          parent,
1✔
34
          LibraryNodeType_GEMM,
35
          {"C"},
1!
36
          {"A", "B", "C", "alpha", "beta"},
1!
37
          implementation_type,
1✔
38
          precision
1✔
39
      ),
40
      layout_(layout), trans_a_(trans_a), trans_b_(trans_b), m_(m), n_(n), k_(k), lda_(lda), ldb_(ldb), ldc_(ldc) {}
1!
41

42
BLAS_Layout GEMMNode::layout() const { return this->layout_; };
×
43

44
BLAS_Transpose GEMMNode::trans_a() const { return this->trans_a_; };
×
45

46
BLAS_Transpose GEMMNode::trans_b() const { return this->trans_b_; };
×
47

48
symbolic::Expression GEMMNode::m() const { return this->m_; };
1✔
49

50
symbolic::Expression GEMMNode::n() const { return this->n_; };
1✔
51

52
symbolic::Expression GEMMNode::k() const { return this->k_; };
1✔
53

54
symbolic::Expression GEMMNode::lda() const { return this->lda_; };
1✔
55

56
symbolic::Expression GEMMNode::ldb() const { return this->ldb_; };
1✔
57

58
symbolic::Expression GEMMNode::ldc() const { return this->ldc_; };
1✔
59

NEW
60
symbolic::SymbolSet GEMMNode::symbols() const {
×
NEW
61
    symbolic::SymbolSet syms;
×
62

NEW
63
    for (auto& atom : symbolic::atoms(this->m_)) {
×
NEW
64
        syms.insert(atom);
×
65
    }
NEW
66
    for (auto& atom : symbolic::atoms(this->n_)) {
×
NEW
67
        syms.insert(atom);
×
68
    }
NEW
69
    for (auto& atom : symbolic::atoms(this->k_)) {
×
NEW
70
        syms.insert(atom);
×
71
    }
NEW
72
    for (auto& atom : symbolic::atoms(this->lda_)) {
×
NEW
73
        syms.insert(atom);
×
74
    }
NEW
75
    for (auto& atom : symbolic::atoms(this->ldb_)) {
×
NEW
76
        syms.insert(atom);
×
77
    }
NEW
78
    for (auto& atom : symbolic::atoms(this->ldc_)) {
×
NEW
79
        syms.insert(atom);
×
80
    }
81

NEW
82
    return syms;
×
NEW
83
};
×
84

NEW
85
void GEMMNode::replace(const symbolic::Expression old_expression, const symbolic::Expression new_expression) {
×
NEW
86
    this->m_ = symbolic::subs(this->m_, old_expression, new_expression);
×
NEW
87
    this->n_ = symbolic::subs(this->n_, old_expression, new_expression);
×
NEW
88
    this->k_ = symbolic::subs(this->k_, old_expression, new_expression);
×
NEW
89
    this->lda_ = symbolic::subs(this->lda_, old_expression, new_expression);
×
NEW
90
    this->ldb_ = symbolic::subs(this->ldb_, old_expression, new_expression);
×
NEW
91
    this->ldc_ = symbolic::subs(this->ldc_, old_expression, new_expression);
×
NEW
92
};
×
93

94
void GEMMNode::validate(const Function& function) const {}
1✔
95

96
bool GEMMNode::expand(builder::StructuredSDFGBuilder& builder, analysis::AnalysisManager& analysis_manager) {
1✔
97
    auto& scope_analysis = analysis_manager.get<analysis::ScopeAnalysis>();
1✔
98

99
    auto& dataflow = this->get_parent();
1✔
100
    auto& block = static_cast<structured_control_flow::Block&>(*dataflow.get_parent());
1✔
101
    auto& parent = static_cast<structured_control_flow::Sequence&>(*scope_analysis.parent_scope(&block));
1✔
102
    int index = parent.index(block);
1✔
103
    auto& transition = parent.at(index).second;
1✔
104

105
    if (trans_a_ != BLAS_Transpose::No || trans_b_ != BLAS_Transpose::No) {
1!
106
        return false;
×
107
    }
108

109
    auto primitive_type = scalar_primitive();
1✔
110
    if (primitive_type == types::PrimitiveType::Void) {
1!
111
        return false;
×
112
    }
113

114
    types::Scalar scalar_type(primitive_type);
1✔
115

116
    auto in_edges = dataflow.in_edges(*this);
1!
117
    auto in_edges_it = in_edges.begin();
1!
118

119
    data_flow::Memlet* iedge_a = nullptr;
1✔
120
    data_flow::Memlet* iedge_b = nullptr;
1✔
121
    data_flow::Memlet* iedge_c = nullptr;
1✔
122
    data_flow::Memlet* alpha_edge = nullptr;
1✔
123
    data_flow::Memlet* beta_edge = nullptr;
1✔
124
    while (in_edges_it != in_edges.end()) {
6!
125
        auto& edge = *in_edges_it;
5!
126
        auto dst_conn = edge.dst_conn();
5!
127
        if (dst_conn == "A") {
5!
128
            iedge_a = &edge;
1✔
129
        } else if (dst_conn == "B") {
5!
130
            iedge_b = &edge;
1✔
131
        } else if (dst_conn == "C") {
4!
132
            iedge_c = &edge;
1✔
133
        } else if (dst_conn == "alpha") {
3!
134
            alpha_edge = &edge;
1✔
135
        } else if (dst_conn == "beta") {
2!
136
            beta_edge = &edge;
1✔
137
        } else {
1✔
138
            throw InvalidSDFGException("GEMMNode has unexpected input: " + dst_conn);
×
139
        }
140
        ++in_edges_it;
5!
141
    }
5✔
142

143
    auto& oedge = *dataflow.out_edges(*this).begin();
1!
144

145
    // Checks if legal
146
    auto* input_node_a = static_cast<data_flow::AccessNode*>(&iedge_a->src());
1!
147
    auto* input_node_b = static_cast<data_flow::AccessNode*>(&iedge_b->src());
1!
148
    auto* input_node_c = static_cast<data_flow::AccessNode*>(&iedge_c->src());
1!
149
    auto* output_node = static_cast<data_flow::AccessNode*>(&oedge.dst());
1!
150
    auto* alpha_node = static_cast<data_flow::AccessNode*>(&alpha_edge->src());
1!
151
    auto* beta_node = static_cast<data_flow::AccessNode*>(&beta_edge->src());
1!
152

153
    // we must be the only thing in this block, as we do not support splitting a block into pre, expanded lib-node, post
154
    if (!input_node_a || dataflow.in_degree(*input_node_a) != 0 || !input_node_b ||
2!
155
        dataflow.in_degree(*input_node_b) != 0 || !input_node_c || dataflow.in_degree(*input_node_c) != 0 ||
1!
156
        !output_node || dataflow.out_degree(*output_node) != 0) {
1!
157
        return false; // data nodes are not standalone
×
158
    }
159
    if (dataflow.in_degree(*alpha_node) != 0 || dataflow.in_degree(*beta_node) != 0) {
1!
160
        return false; // alpha and beta are not standalone
×
161
    }
162
    for (auto* nd : dataflow.data_nodes()) {
7!
163
        if (nd != input_node_a && nd != input_node_b && nd != input_node_c && nd != output_node &&
7✔
164
            (!alpha_node || nd != alpha_node) && (!beta_node || nd != beta_node)) {
2!
165
            return false; // there are other nodes in here that we could not preserve correctly
×
166
        }
167
    }
168

169
    auto& A_var = input_node_a->data();
1!
170
    auto& B_var = input_node_b->data();
1!
171
    auto& C_in_var = input_node_c->data();
1!
172
    auto& C_out_var = output_node->data();
1!
173

174

175
    // Add new graph after the current block
176
    auto& new_sequence = builder.add_sequence_before(parent, block, transition.assignments(), block.debug_info());
1!
177

178
    // Add maps
179
    std::vector<symbolic::Expression> indvar_ends{this->m(), this->n(), this->k()};
1!
180
    data_flow::Subset new_subset;
1✔
181
    structured_control_flow::Sequence* last_scope = &new_sequence;
1✔
182
    structured_control_flow::Map* last_map = nullptr;
1✔
183
    structured_control_flow::Map* output_loop = nullptr;
1✔
184
    std::vector<std::string> indvar_names{"_i", "_j", "_k"};
1!
185

186
    std::string sum_var = builder.find_new_name("_sum");
1!
187
    builder.add_container(sum_var, scalar_type);
1!
188

189
    for (size_t i = 0; i < 3; i++) {
4✔
190
        auto dim_begin = symbolic::zero();
3!
191
        auto& dim_end = indvar_ends[i];
3✔
192

193
        std::string indvar_str = builder.find_new_name(indvar_names[i]);
3!
194
        builder.add_container(indvar_str, types::Scalar(types::PrimitiveType::UInt64));
3!
195

196
        auto indvar = symbolic::symbol(indvar_str);
3!
197
        auto init = dim_begin;
3!
198
        auto update = symbolic::add(indvar, symbolic::one());
3!
199
        auto condition = symbolic::Lt(indvar, dim_end);
3!
200
        last_map = &builder.add_map(
6!
201
            *last_scope,
3✔
202
            indvar,
3!
203
            condition,
3!
204
            init,
3!
205
            update,
3!
206
            structured_control_flow::ScheduleType_Sequential::create(),
3!
207
            {},
3✔
208
            block.debug_info()
3!
209
        );
210
        last_scope = &last_map->root();
3!
211

212
        if (i == 1) {
3✔
213
            output_loop = last_map;
1✔
214
        }
1✔
215

216
        new_subset.push_back(indvar);
3!
217
    }
3✔
218

219

220
    // Add code
221
    auto& init_block = builder.add_block_before(output_loop->root(), *last_map, {}, block.debug_info());
1!
222
    auto& sum_init = builder.add_access(init_block, sum_var, block.debug_info());
1!
223

224
    auto& zero_node = builder.add_constant(init_block, "0.0", alpha_edge->base_type(), block.debug_info());
1!
225
    auto& init_tasklet = builder.add_tasklet(init_block, data_flow::assign, "_out", {"_in"}, block.debug_info());
1!
226
    builder.add_computational_memlet(init_block, zero_node, init_tasklet, "_in", {}, block.debug_info());
1!
227
    builder.add_computational_memlet(init_block, init_tasklet, "_out", sum_init, {}, block.debug_info());
1!
228

229
    auto& code_block = builder.add_block(*last_scope, {}, block.debug_info());
1!
230
    auto& input_node_a_new = builder.add_access(code_block, A_var, input_node_a->debug_info());
1!
231
    auto& input_node_b_new = builder.add_access(code_block, B_var, input_node_b->debug_info());
1!
232

233
    auto& core_fma =
1✔
234
        builder.add_tasklet(code_block, data_flow::fp_fma, "_out", {"_in1", "_in2", "_in3"}, block.debug_info());
1!
235
    auto& sum_in = builder.add_access(code_block, sum_var, block.debug_info());
1!
236
    auto& sum_out = builder.add_access(code_block, sum_var, block.debug_info());
1!
237
    builder.add_computational_memlet(code_block, sum_in, core_fma, "_in3", {}, block.debug_info());
1!
238

239
    symbolic::Expression a_idx = symbolic::add(symbolic::mul(lda(), new_subset[0]), new_subset[2]);
1!
240
    builder.add_computational_memlet(
2!
241
        code_block, input_node_a_new, core_fma, "_in1", {a_idx}, iedge_a->base_type(), iedge_a->debug_info()
1!
242
    );
243
    symbolic::Expression b_idx = symbolic::add(symbolic::mul(ldb(), new_subset[2]), new_subset[1]);
1!
244
    builder.add_computational_memlet(
2!
245
        code_block, input_node_b_new, core_fma, "_in2", {b_idx}, iedge_b->base_type(), iedge_b->debug_info()
1!
246
    );
247
    builder.add_computational_memlet(code_block, core_fma, "_out", sum_out, {}, oedge.debug_info());
1!
248

249
    auto& flush_block = builder.add_block_after(output_loop->root(), *last_map, {}, block.debug_info());
1!
250
    auto& sum_final = builder.add_access(flush_block, sum_var, block.debug_info());
1!
251
    auto& input_node_c_new = builder.add_access(flush_block, C_in_var, input_node_c->debug_info());
1!
252
    symbolic::Expression c_idx = symbolic::add(symbolic::mul(ldc(), new_subset[0]), new_subset[1]);
1!
253

254
    auto& scale_sum_tasklet =
1✔
255
        builder.add_tasklet(flush_block, data_flow::TaskletCode::fp_mul, "_out", {"_in1", "_in2"}, block.debug_info());
1!
256
    builder.add_computational_memlet(flush_block, sum_final, scale_sum_tasklet, "_in1", {}, block.debug_info());
1!
257
    if (auto const_node = dynamic_cast<data_flow::ConstantNode*>(alpha_node)) {
1!
258
        auto& alpha_node_new =
1✔
259
            builder.add_constant(flush_block, const_node->data(), const_node->type(), block.debug_info());
1!
260
        builder.add_computational_memlet(flush_block, alpha_node_new, scale_sum_tasklet, "_in2", {}, block.debug_info());
1!
261
    } else {
1✔
262
        auto& alpha_node_new = builder.add_access(flush_block, alpha_node->data(), block.debug_info());
×
263
        builder.add_computational_memlet(flush_block, alpha_node_new, scale_sum_tasklet, "_in2", {}, block.debug_info());
×
264
    }
265

266
    std::string scaled_sum_temp = builder.find_new_name("scaled_sum_temp");
1!
267
    builder.add_container(scaled_sum_temp, scalar_type);
1!
268
    auto& scaled_sum_final = builder.add_access(flush_block, scaled_sum_temp, block.debug_info());
1!
269
    builder.add_computational_memlet(
2!
270
        flush_block, scale_sum_tasklet, "_out", scaled_sum_final, {}, scalar_type, block.debug_info()
1!
271
    );
272

273
    auto& scale_input_tasklet =
1✔
274
        builder.add_tasklet(flush_block, data_flow::TaskletCode::fp_mul, "_out", {"_in1", "_in2"}, block.debug_info());
1!
275
    builder.add_computational_memlet(
2!
276
        flush_block, input_node_c_new, scale_input_tasklet, "_in1", {c_idx}, iedge_c->base_type(), iedge_c->debug_info()
1!
277
    );
278
    if (auto const_node = dynamic_cast<data_flow::ConstantNode*>(beta_node)) {
1!
279
        auto& beta_node_new =
1✔
280
            builder.add_constant(flush_block, const_node->data(), const_node->type(), block.debug_info());
1!
281
        builder
2✔
282
            .add_computational_memlet(flush_block, beta_node_new, scale_input_tasklet, "_in2", {}, block.debug_info());
1!
283
    } else {
1✔
284
        auto& beta_node_new = builder.add_access(flush_block, beta_node->data(), block.debug_info());
×
285
        builder
×
286
            .add_computational_memlet(flush_block, beta_node_new, scale_input_tasklet, "_in2", {}, block.debug_info());
×
287
    }
288

289
    std::string scaled_input_temp = builder.find_new_name("scaled_input_temp");
1!
290
    builder.add_container(scaled_input_temp, scalar_type);
1!
291
    auto& scaled_input_c = builder.add_access(flush_block, scaled_input_temp, block.debug_info());
1!
292
    builder.add_computational_memlet(
2!
293
        flush_block, scale_input_tasklet, "_out", scaled_input_c, {}, scalar_type, block.debug_info()
1!
294
    );
295

296
    auto& flush_add_tasklet =
1✔
297
        builder.add_tasklet(flush_block, data_flow::TaskletCode::fp_add, "_out", {"_in1", "_in2"}, block.debug_info());
1!
298
    auto& output_node_new = builder.add_access(flush_block, C_out_var, output_node->debug_info());
1!
299
    builder.add_computational_memlet(
2!
300
        flush_block, scaled_sum_final, flush_add_tasklet, "_in1", {}, scalar_type, block.debug_info()
1!
301
    );
302
    builder.add_computational_memlet(
2!
303
        flush_block, scaled_input_c, flush_add_tasklet, "_in2", {}, scalar_type, block.debug_info()
1!
304
    );
305
    builder.add_computational_memlet(
2!
306
        flush_block, flush_add_tasklet, "_out", output_node_new, {c_idx}, iedge_c->base_type(), iedge_c->debug_info()
1!
307
    );
308

309

310
    // Clean up block
311
    builder.remove_memlet(block, *iedge_a);
1!
312
    builder.remove_memlet(block, *iedge_b);
1!
313
    builder.remove_memlet(block, *iedge_c);
1!
314
    builder.remove_memlet(block, *alpha_edge);
1!
315
    builder.remove_node(block, *alpha_node);
1!
316
    builder.remove_memlet(block, *beta_edge);
1!
317
    builder.remove_node(block, *beta_node);
1!
318
    builder.remove_memlet(block, oedge);
1!
319
    builder.remove_node(block, *input_node_a);
1!
320
    builder.remove_node(block, *input_node_b);
1!
321
    builder.remove_node(block, *input_node_c);
1!
322
    builder.remove_node(block, *output_node);
1!
323
    builder.remove_node(block, *this);
1!
324
    builder.remove_child(parent, index + 1);
1!
325

326
    return true;
1✔
327
}
1✔
328

329
symbolic::Expression GEMMNode::flop() const {
×
330
    return flops(symbolic::__true__(), symbolic::__true__(), symbolic::__true__(), symbolic::__true__());
×
331
}
×
332

333
symbolic::Expression GEMMNode::flops(
×
334
    symbolic::Condition alpha_non_zero,
335
    symbolic::Condition alpha_non_ident,
336
    symbolic::Condition beta_non_zero,
337
    symbolic::Condition beta_non_ident
338
) const {
339
    auto res_elems = symbolic::mul(this->m_, this->n_);
×
340

341
    // conditional on alpha != 0.0
342
    auto mm_mul_ops = symbolic::mul(symbolic::mul(res_elems, this->k_), alpha_non_zero);
×
343
    auto mm_sum_ops = symbolic::mul(symbolic::mul(res_elems, symbolic::sub(this->k_, symbolic::one())), alpha_non_zero);
×
344
    // conditional on alpha != 1.0 && alpha != 0.0
345
    auto mm_alpha_scale_ops = symbolic::mul(res_elems, symbolic::And(alpha_non_ident, alpha_non_zero));
×
346
    // conditional on beta != 1.0 && beta != 0.0
347
    auto mm_beta_scale_ops = symbolic::mul(res_elems, symbolic::And(beta_non_ident, beta_non_zero));
×
348
    auto mm_beta_scaled_sum_ops = symbolic::mul(res_elems, beta_non_zero);
×
349
    auto mul_ops = symbolic::add(mm_mul_ops, symbolic::add(mm_alpha_scale_ops, mm_beta_scale_ops));
×
350
    auto add_ops = symbolic::add(mm_sum_ops, mm_beta_scaled_sum_ops);
×
351
    return symbolic::add(mul_ops, add_ops);
×
352
}
×
353

354
std::unique_ptr<data_flow::DataFlowNode> GEMMNode::
355
    clone(size_t element_id, const graph::Vertex vertex, data_flow::DataFlowGraph& parent) const {
×
356
    auto node_clone = std::unique_ptr<GEMMNode>(new GEMMNode(
×
357
        element_id,
×
358
        this->debug_info(),
×
359
        vertex,
×
360
        parent,
×
361
        this->implementation_type_,
×
362
        this->precision_,
×
363
        this->layout_,
×
364
        this->trans_a_,
×
365
        this->trans_b_,
×
366
        this->m_,
×
367
        this->n_,
×
368
        this->k_,
×
369
        this->lda_,
×
370
        this->ldb_,
×
371
        this->ldc_
×
372
    ));
373
    return std::move(node_clone);
×
374
}
×
375

376
std::string GEMMNode::toStr() const {
×
377
    return LibraryNode::toStr() + "(" + static_cast<char>(precision_) + ", " +
×
378
           std::string(BLAS_Layout_to_short_string(layout_)) + ", " + BLAS_Transpose_to_char(trans_a_) +
×
379
           BLAS_Transpose_to_char(trans_b_) + ", " + m_->__str__() + ", " + n_->__str__() + ", " + k_->__str__() +
×
380
           ", " + lda_->__str__() + ", " + ldb_->__str__() + ", " + ldc_->__str__() + ")";
×
381
}
×
382

383
nlohmann::json GEMMNodeSerializer::serialize(const data_flow::LibraryNode& library_node) {
×
384
    const GEMMNode& gemm_node = static_cast<const GEMMNode&>(library_node);
×
385
    nlohmann::json j;
×
386

387
    serializer::JSONSerializer serializer;
×
388
    j["code"] = gemm_node.code().value();
×
389
    j["precision"] = gemm_node.precision();
×
390
    j["layout"] = gemm_node.layout();
×
391
    j["trans_a"] = gemm_node.trans_a();
×
392
    j["trans_b"] = gemm_node.trans_b();
×
393
    j["m"] = serializer.expression(gemm_node.m());
×
394
    j["n"] = serializer.expression(gemm_node.n());
×
395
    j["k"] = serializer.expression(gemm_node.k());
×
396
    j["lda"] = serializer.expression(gemm_node.lda());
×
397
    j["ldb"] = serializer.expression(gemm_node.ldb());
×
398
    j["ldc"] = serializer.expression(gemm_node.ldc());
×
399

400
    return j;
×
401
}
×
402

403
data_flow::LibraryNode& GEMMNodeSerializer::deserialize(
×
404
    const nlohmann::json& j, builder::StructuredSDFGBuilder& builder, structured_control_flow::Block& parent
405
) {
406
    // Assertions for required fields
407
    assert(j.contains("element_id"));
×
408
    assert(j.contains("code"));
×
409
    assert(j.contains("debug_info"));
×
410

411
    auto code = j["code"].get<std::string>();
×
412
    if (code != LibraryNodeType_GEMM.value()) {
×
413
        throw std::runtime_error("Invalid library node code");
×
414
    }
415

416
    // Extract debug info using JSONSerializer
417
    sdfg::serializer::JSONSerializer serializer;
×
418
    DebugInfo debug_info = serializer.json_to_debug_info(j["debug_info"]);
×
419

420
    auto precision = j.at("precision").get<BLAS_Precision>();
×
421
    auto layout = j.at("layout").get<BLAS_Layout>();
×
422
    auto trans_a = j.at("trans_a").get<BLAS_Transpose>();
×
423
    auto trans_b = j.at("trans_b").get<BLAS_Transpose>();
×
424
    auto m = symbolic::parse(j.at("m"));
×
425
    auto n = symbolic::parse(j.at("n"));
×
426
    auto k = symbolic::parse(j.at("k"));
×
427
    auto lda = symbolic::parse(j.at("lda"));
×
428
    auto ldb = symbolic::parse(j.at("ldb"));
×
429
    auto ldc = symbolic::parse(j.at("ldc"));
×
430

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

433
    return builder.add_library_node<
×
434
        GEMMNode>(parent, debug_info, implementation_type, precision, layout, trans_a, trans_b, m, n, k, lda, ldb, ldc);
×
435
}
×
436

437
GEMMNodeDispatcher_BLAS::GEMMNodeDispatcher_BLAS(
×
438
    codegen::LanguageExtension& language_extension,
439
    const Function& function,
440
    const data_flow::DataFlowGraph& data_flow_graph,
441
    const GEMMNode& node
442
)
443
    : codegen::LibraryNodeDispatcher(language_extension, function, data_flow_graph, node) {}
×
444

445
void GEMMNodeDispatcher_BLAS::dispatch_code(
×
446
    codegen::PrettyPrinter& stream,
447
    codegen::PrettyPrinter& globals_stream,
448
    codegen::CodeSnippetFactory& library_snippet_factory
449
) {
450
    stream << "{" << std::endl;
×
451
    stream.setIndent(stream.indent() + 4);
×
452

453
    auto& gemm_node = static_cast<const GEMMNode&>(this->node_);
×
454

455
    sdfg::types::Scalar base_type(types::PrimitiveType::Void);
×
456
    switch (gemm_node.precision()) {
×
457
        case BLAS_Precision::h:
458
            base_type = types::Scalar(types::PrimitiveType::Half);
×
459
            break;
×
460
        case BLAS_Precision::s:
461
            base_type = types::Scalar(types::PrimitiveType::Float);
×
462
            break;
×
463
        case BLAS_Precision::d:
464
            base_type = types::Scalar(types::PrimitiveType::Double);
×
465
            break;
×
466
        default:
467
            throw std::runtime_error("Invalid BLAS_Precision value");
×
468
    }
469

470
    stream << "cblas_" << BLAS_Precision_to_string(gemm_node.precision()) << "gemm(";
×
471
    stream.setIndent(stream.indent() + 4);
×
472
    stream << BLAS_Layout_to_string(gemm_node.layout());
×
473
    stream << ", ";
×
474
    stream << BLAS_Transpose_to_string(gemm_node.trans_a());
×
475
    stream << ", ";
×
476
    stream << BLAS_Transpose_to_string(gemm_node.trans_b());
×
477
    stream << ", ";
×
478
    stream << this->language_extension_.expression(gemm_node.m());
×
479
    stream << ", ";
×
480
    stream << this->language_extension_.expression(gemm_node.n());
×
481
    stream << ", ";
×
482
    stream << this->language_extension_.expression(gemm_node.k());
×
483
    stream << ", ";
×
484
    stream << "alpha";
×
485
    stream << ", ";
×
486
    stream << "A";
×
487
    stream << ", ";
×
488
    stream << this->language_extension_.expression(gemm_node.lda());
×
489
    stream << ", ";
×
490
    stream << "B";
×
491
    stream << ", ";
×
492
    stream << this->language_extension_.expression(gemm_node.ldb());
×
493
    stream << ", ";
×
494
    stream << "beta";
×
495
    stream << ", ";
×
496
    stream << "C";
×
497
    stream << ", ";
×
498
    stream << this->language_extension_.expression(gemm_node.ldc());
×
499

500
    stream.setIndent(stream.indent() - 4);
×
501
    stream << ");" << std::endl;
×
502

503
    stream.setIndent(stream.indent() - 4);
×
504
    stream << "}" << std::endl;
×
505
}
×
506

507
GEMMNodeDispatcher_CUBLASWithTransfers::GEMMNodeDispatcher_CUBLASWithTransfers(
×
508
    codegen::LanguageExtension& language_extension,
509
    const Function& function,
510
    const data_flow::DataFlowGraph& data_flow_graph,
511
    const GEMMNode& node
512
)
513
    : codegen::LibraryNodeDispatcher(language_extension, function, data_flow_graph, node) {}
×
514

515
void GEMMNodeDispatcher_CUBLASWithTransfers::dispatch_code(
×
516
    codegen::PrettyPrinter& stream,
517
    codegen::PrettyPrinter& globals_stream,
518
    codegen::CodeSnippetFactory& library_snippet_factory
519
) {
520
    throw std::runtime_error("GEMMNodeDispatcher_CUBLAS not implemented");
×
521
}
×
522

523
GEMMNodeDispatcher_CUBLASWithoutTransfers::GEMMNodeDispatcher_CUBLASWithoutTransfers(
×
524
    codegen::LanguageExtension& language_extension,
525
    const Function& function,
526
    const data_flow::DataFlowGraph& data_flow_graph,
527
    const GEMMNode& node
528
)
529
    : codegen::LibraryNodeDispatcher(language_extension, function, data_flow_graph, node) {}
×
530

531
void GEMMNodeDispatcher_CUBLASWithoutTransfers::dispatch_code(
×
532
    codegen::PrettyPrinter& stream,
533
    codegen::PrettyPrinter& globals_stream,
534
    codegen::CodeSnippetFactory& library_snippet_factory
535
) {
536
    throw std::runtime_error("GEMMNodeDispatcher_CUBLAS not implemented");
×
537
}
×
538

539
} // namespace blas
540
} // namespace math
541
} // 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