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

daisytuner / sdfglib / 20603090460

30 Dec 2025 06:20PM UTC coverage: 39.276% (-0.3%) from 39.581%
20603090460

push

github

web-flow
Merge pull request #414 from daisytuner/blas-connectors

renames connectors of blas nodes

14694 of 48687 branches covered (30.18%)

Branch coverage included in aggregate %.

85 of 250 new or added lines in 11 files covered. (34.0%)

18 existing lines in 1 file now uncovered.

12557 of 20696 relevant lines covered (60.67%)

86.4 hits per line

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

31.19
/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

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

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

82
    return syms;
×
83
};
×
84

85
void GEMMNode::replace(const symbolic::Expression old_expression, const symbolic::Expression new_expression) {
×
86
    this->m_ = symbolic::subs(this->m_, old_expression, new_expression);
×
87
    this->n_ = symbolic::subs(this->n_, old_expression, new_expression);
×
88
    this->k_ = symbolic::subs(this->k_, old_expression, new_expression);
×
89
    this->lda_ = symbolic::subs(this->lda_, old_expression, new_expression);
×
90
    this->ldb_ = symbolic::subs(this->ldb_, old_expression, new_expression);
×
91
    this->ldc_ = symbolic::subs(this->ldc_, old_expression, new_expression);
×
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::StructuredLoop* last_map = nullptr;
1✔
183
    structured_control_flow::StructuredLoop* 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
        if (i < 2) {
3✔
201
            last_map = &builder.add_map(
4!
202
                *last_scope,
2✔
203
                indvar,
2!
204
                condition,
2!
205
                init,
2!
206
                update,
2!
207
                structured_control_flow::ScheduleType_Sequential::create(),
2!
208
                {},
2✔
209
                block.debug_info()
2!
210
            );
211
        } else {
2✔
212
            last_map = &builder.add_for(*last_scope, indvar, condition, init, update, {}, block.debug_info());
1!
213
        }
214
        last_scope = &last_map->root();
3!
215

216
        if (i == 1) {
3✔
217
            output_loop = last_map;
1✔
218
        }
1✔
219

220
        new_subset.push_back(indvar);
3!
221
    }
3✔
222

223

224
    // Add code
225
    auto& init_block = builder.add_block_before(output_loop->root(), *last_map, {}, block.debug_info());
1!
226
    auto& sum_init = builder.add_access(init_block, sum_var, block.debug_info());
1!
227

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

233
    auto& code_block = builder.add_block(*last_scope, {}, block.debug_info());
1!
234
    auto& input_node_a_new = builder.add_access(code_block, A_var, input_node_a->debug_info());
1!
235
    auto& input_node_b_new = builder.add_access(code_block, B_var, input_node_b->debug_info());
1!
236

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

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

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

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

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

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

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

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

313

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

330
    return true;
1✔
331
}
1✔
332

333
symbolic::Expression GEMMNode::flop() const {
×
334
    return flops(symbolic::__true__(), symbolic::__true__(), symbolic::__true__(), symbolic::__true__());
×
335
}
×
336

337
symbolic::Expression GEMMNode::flops(
×
338
    symbolic::Condition alpha_non_zero,
339
    symbolic::Condition alpha_non_ident,
340
    symbolic::Condition beta_non_zero,
341
    symbolic::Condition beta_non_ident
342
) const {
343
    auto res_elems = symbolic::mul(this->m_, this->n_);
×
344

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

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

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

387
nlohmann::json GEMMNodeSerializer::serialize(const data_flow::LibraryNode& library_node) {
×
388
    const GEMMNode& gemm_node = static_cast<const GEMMNode&>(library_node);
×
389
    nlohmann::json j;
×
390

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

404
    return j;
×
405
}
×
406

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

415
    auto code = j["code"].get<std::string>();
×
416
    if (code != LibraryNodeType_GEMM.value()) {
×
417
        throw std::runtime_error("Invalid library node code");
×
418
    }
419

420
    // Extract debug info using JSONSerializer
421
    sdfg::serializer::JSONSerializer serializer;
×
422
    DebugInfo debug_info = serializer.json_to_debug_info(j["debug_info"]);
×
423

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

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

437
    return builder.add_library_node<
×
438
        GEMMNode>(parent, debug_info, implementation_type, precision, layout, trans_a, trans_b, m, n, k, lda, ldb, ldc);
×
439
}
×
440

441
GEMMNodeDispatcher_BLAS::GEMMNodeDispatcher_BLAS(
×
442
    codegen::LanguageExtension& language_extension,
443
    const Function& function,
444
    const data_flow::DataFlowGraph& data_flow_graph,
445
    const GEMMNode& node
446
)
447
    : codegen::LibraryNodeDispatcher(language_extension, function, data_flow_graph, node) {}
×
448

449
void GEMMNodeDispatcher_BLAS::dispatch_code(
×
450
    codegen::PrettyPrinter& stream,
451
    codegen::PrettyPrinter& globals_stream,
452
    codegen::CodeSnippetFactory& library_snippet_factory
453
) {
454
    stream << "{" << std::endl;
×
455
    stream.setIndent(stream.indent() + 4);
×
456

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

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

474
    stream << "cblas_" << BLAS_Precision_to_string(gemm_node.precision()) << "gemm(";
×
475
    stream.setIndent(stream.indent() + 4);
×
476
    stream << BLAS_Layout_to_string(gemm_node.layout());
×
477
    stream << ", ";
×
478
    stream << BLAS_Transpose_to_string(gemm_node.trans_a());
×
479
    stream << ", ";
×
480
    stream << BLAS_Transpose_to_string(gemm_node.trans_b());
×
481
    stream << ", ";
×
482
    stream << this->language_extension_.expression(gemm_node.m());
×
483
    stream << ", ";
×
484
    stream << this->language_extension_.expression(gemm_node.n());
×
485
    stream << ", ";
×
486
    stream << this->language_extension_.expression(gemm_node.k());
×
487
    stream << ", ";
×
NEW
488
    stream << "__alpha";
×
489
    stream << ", ";
×
NEW
490
    stream << "__A";
×
491
    stream << ", ";
×
492
    stream << this->language_extension_.expression(gemm_node.lda());
×
493
    stream << ", ";
×
NEW
494
    stream << "__B";
×
495
    stream << ", ";
×
496
    stream << this->language_extension_.expression(gemm_node.ldb());
×
497
    stream << ", ";
×
NEW
498
    stream << "__beta";
×
499
    stream << ", ";
×
NEW
500
    stream << "__C";
×
501
    stream << ", ";
×
502
    stream << this->language_extension_.expression(gemm_node.ldc());
×
503

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

507
    stream.setIndent(stream.indent() - 4);
×
508
    stream << "}" << std::endl;
×
509
}
×
510

511
GEMMNodeDispatcher_CUBLASWithTransfers::GEMMNodeDispatcher_CUBLASWithTransfers(
×
512
    codegen::LanguageExtension& language_extension,
513
    const Function& function,
514
    const data_flow::DataFlowGraph& data_flow_graph,
515
    const GEMMNode& node
516
)
517
    : codegen::LibraryNodeDispatcher(language_extension, function, data_flow_graph, node) {}
×
518

519
void GEMMNodeDispatcher_CUBLASWithTransfers::dispatch_code(
×
520
    codegen::PrettyPrinter& stream,
521
    codegen::PrettyPrinter& globals_stream,
522
    codegen::CodeSnippetFactory& library_snippet_factory
523
) {
524
    throw std::runtime_error("GEMMNodeDispatcher_CUBLAS not implemented");
×
525
}
×
526

527
GEMMNodeDispatcher_CUBLASWithoutTransfers::GEMMNodeDispatcher_CUBLASWithoutTransfers(
×
528
    codegen::LanguageExtension& language_extension,
529
    const Function& function,
530
    const data_flow::DataFlowGraph& data_flow_graph,
531
    const GEMMNode& node
532
)
533
    : codegen::LibraryNodeDispatcher(language_extension, function, data_flow_graph, node) {}
×
534

535
void GEMMNodeDispatcher_CUBLASWithoutTransfers::dispatch_code(
×
536
    codegen::PrettyPrinter& stream,
537
    codegen::PrettyPrinter& globals_stream,
538
    codegen::CodeSnippetFactory& library_snippet_factory
539
) {
540
    throw std::runtime_error("GEMMNodeDispatcher_CUBLAS not implemented");
×
541
}
×
542

543
} // namespace blas
544
} // namespace math
545
} // 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