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

daisytuner / docc / 25928236622

15 May 2026 04:10PM UTC coverage: 60.84%. First build
25928236622

Pull #709

github

web-flow
Merge fd5af827f into df89083a8
Pull Request #709: Add support for tenstorrent backend to python front end

12 of 118 new or added lines in 9 files covered. (10.17%)

34996 of 57521 relevant lines covered (60.84%)

11108.56 hits per line

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

52.45
/sdfg/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(
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(
25✔
30
          element_id,
25✔
31
          debug_info,
25✔
32
          vertex,
25✔
33
          parent,
25✔
34
          LibraryNodeType_GEMM,
25✔
35
          {"__C"},
25✔
36
          {"__A", "__B", "__C", "__alpha", "__beta"},
25✔
37
          implementation_type,
25✔
38
          precision
25✔
39
      ),
25✔
40
      layout_(layout), trans_a_(trans_a), trans_b_(trans_b), m_(m), n_(n), k_(k), lda_(lda), ldb_(ldb), ldc_(ldc) {}
25✔
41

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

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

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

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

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

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

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

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

58
symbolic::Expression GEMMNode::ldc() const { return this->ldc_; };
8✔
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 { BLASNode::validate(function); }
8✔
95

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

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

105
    if (trans_a_ == BLAS_Transpose::ConjTrans || trans_b_ == BLAS_Transpose::ConjTrans) {
6✔
106
        return false;
×
107
    }
×
108

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

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

116
    auto in_edges = dataflow.in_edges(*this);
6✔
117
    auto in_edges_it = in_edges.begin();
6✔
118

119
    data_flow::Memlet* iedge_a = nullptr;
6✔
120
    data_flow::Memlet* iedge_b = nullptr;
6✔
121
    data_flow::Memlet* iedge_c = nullptr;
6✔
122
    data_flow::Memlet* alpha_edge = nullptr;
6✔
123
    data_flow::Memlet* beta_edge = nullptr;
6✔
124
    while (in_edges_it != in_edges.end()) {
36✔
125
        auto& edge = *in_edges_it;
30✔
126
        auto dst_conn = edge.dst_conn();
30✔
127
        if (dst_conn == "__A") {
30✔
128
            iedge_a = &edge;
6✔
129
        } else if (dst_conn == "__B") {
24✔
130
            iedge_b = &edge;
6✔
131
        } else if (dst_conn == "__C") {
18✔
132
            iedge_c = &edge;
6✔
133
        } else if (dst_conn == "__alpha") {
12✔
134
            alpha_edge = &edge;
6✔
135
        } else if (dst_conn == "__beta") {
6✔
136
            beta_edge = &edge;
6✔
137
        } else {
6✔
138
            throw InvalidSDFGException("GEMMNode has unexpected input: " + dst_conn);
×
139
        }
×
140
        ++in_edges_it;
30✔
141
    }
30✔
142

143
    auto& oedge = *dataflow.out_edges(*this).begin();
6✔
144

145
    // Checks if legal
146
    auto* input_node_a = static_cast<data_flow::AccessNode*>(&iedge_a->src());
6✔
147
    auto* input_node_b = static_cast<data_flow::AccessNode*>(&iedge_b->src());
6✔
148
    auto* input_node_c = static_cast<data_flow::AccessNode*>(&iedge_c->src());
6✔
149
    auto* output_node = static_cast<data_flow::AccessNode*>(&oedge.dst());
6✔
150
    auto* alpha_node = static_cast<data_flow::AccessNode*>(&alpha_edge->src());
6✔
151
    auto* beta_node = static_cast<data_flow::AccessNode*>(&beta_edge->src());
6✔
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 ||
6✔
155
        dataflow.in_degree(*input_node_b) != 0 || !input_node_c || dataflow.in_degree(*input_node_c) != 0 ||
6✔
156
        !output_node || dataflow.out_degree(*output_node) != 0) {
6✔
157
        return false; // data nodes are not standalone
×
158
    }
×
159
    if (dataflow.in_degree(*alpha_node) != 0 || dataflow.in_degree(*beta_node) != 0) {
6✔
160
        return false; // alpha and beta are not standalone
×
161
    }
×
162
    for (auto* nd : dataflow.data_nodes()) {
36✔
163
        if (nd != input_node_a && nd != input_node_b && nd != input_node_c && nd != output_node &&
36✔
164
            (!alpha_node || nd != alpha_node) && (!beta_node || nd != beta_node)) {
36✔
165
            return false; // there are other nodes in here that we could not preserve correctly
×
166
        }
×
167
    }
36✔
168

169
    auto& A_var = input_node_a->data();
6✔
170
    auto& B_var = input_node_b->data();
6✔
171
    auto& C_in_var = input_node_c->data();
6✔
172
    auto& C_out_var = output_node->data();
6✔
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());
6✔
177

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

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

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

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

196
        auto indvar = symbolic::symbol(indvar_str);
18✔
197
        auto init = dim_begin;
18✔
198
        auto update = symbolic::add(indvar, symbolic::one());
18✔
199
        auto condition = symbolic::Lt(indvar, dim_end);
18✔
200
        if (i < 2) {
18✔
201
            last_map = &builder.add_map(
12✔
202
                *last_scope,
12✔
203
                indvar,
12✔
204
                condition,
12✔
205
                init,
12✔
206
                update,
12✔
207
                structured_control_flow::ScheduleType_Sequential::create(),
12✔
208
                {},
12✔
209
                block.debug_info()
12✔
210
            );
12✔
211
        } else {
12✔
212
            last_map = &builder.add_for(*last_scope, indvar, condition, init, update, {}, block.debug_info());
6✔
213
        }
6✔
214
        last_scope = &last_map->root();
18✔
215

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

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

223

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

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

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

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

243
    // Row-major indexing: address = ld * row + col
244
    // No transpose: A is m×k, access A[i, k] => lda*i + k
245
    // Transpose:    A is k×m stored, access A[k, i] => lda*k + i
246
    symbolic::Expression a_idx = (trans_a_ == BLAS_Transpose::Trans)
6✔
247
                                     ? symbolic::add(symbolic::mul(lda(), new_subset[2]), new_subset[0])
6✔
248
                                     : symbolic::add(symbolic::mul(lda(), new_subset[0]), new_subset[2]);
6✔
249
    builder.add_computational_memlet(
6✔
250
        code_block, input_node_a_new, core_fma, "_in1", {a_idx}, iedge_a->base_type(), iedge_a->debug_info()
6✔
251
    );
6✔
252
    // No transpose: B is k×n, access B[k, j] => ldb*k + j
253
    // Transpose:    B is n×k stored, access B[j, k] => ldb*j + k
254
    symbolic::Expression b_idx = (trans_b_ == BLAS_Transpose::Trans)
6✔
255
                                     ? symbolic::add(symbolic::mul(ldb(), new_subset[1]), new_subset[2])
6✔
256
                                     : symbolic::add(symbolic::mul(ldb(), new_subset[2]), new_subset[1]);
6✔
257
    builder.add_computational_memlet(
6✔
258
        code_block, input_node_b_new, core_fma, "_in2", {b_idx}, iedge_b->base_type(), iedge_b->debug_info()
6✔
259
    );
6✔
260
    builder.add_computational_memlet(code_block, core_fma, "_out", sum_out, {}, oedge.debug_info());
6✔
261

262
    auto& flush_block = builder.add_block_after(output_loop->root(), *last_map, {}, block.debug_info());
6✔
263
    auto& sum_final = builder.add_access(flush_block, sum_var, block.debug_info());
6✔
264
    auto& input_node_c_new = builder.add_access(flush_block, C_in_var, input_node_c->debug_info());
6✔
265
    symbolic::Expression c_idx = symbolic::add(symbolic::mul(ldc(), new_subset[0]), new_subset[1]);
6✔
266

267
    auto& scale_sum_tasklet =
6✔
268
        builder.add_tasklet(flush_block, data_flow::TaskletCode::fp_mul, "_out", {"_in1", "_in2"}, block.debug_info());
6✔
269
    builder.add_computational_memlet(flush_block, sum_final, scale_sum_tasklet, "_in1", {}, block.debug_info());
6✔
270
    if (auto const_node = dynamic_cast<data_flow::ConstantNode*>(alpha_node)) {
6✔
271
        auto& alpha_node_new =
6✔
272
            builder.add_constant(flush_block, const_node->data(), const_node->type(), block.debug_info());
6✔
273
        builder.add_computational_memlet(flush_block, alpha_node_new, scale_sum_tasklet, "_in2", {}, block.debug_info());
6✔
274
    } else {
6✔
275
        auto& alpha_node_new = builder.add_access(flush_block, alpha_node->data(), block.debug_info());
×
276
        builder.add_computational_memlet(flush_block, alpha_node_new, scale_sum_tasklet, "_in2", {}, block.debug_info());
×
277
    }
×
278

279
    std::string scaled_sum_temp = builder.find_new_name("scaled_sum_temp");
6✔
280
    builder.add_container(scaled_sum_temp, scalar_type);
6✔
281
    auto& scaled_sum_final = builder.add_access(flush_block, scaled_sum_temp, block.debug_info());
6✔
282
    builder.add_computational_memlet(
6✔
283
        flush_block, scale_sum_tasklet, "_out", scaled_sum_final, {}, scalar_type, block.debug_info()
6✔
284
    );
6✔
285

286
    auto& scale_input_tasklet =
6✔
287
        builder.add_tasklet(flush_block, data_flow::TaskletCode::fp_mul, "_out", {"_in1", "_in2"}, block.debug_info());
6✔
288
    builder.add_computational_memlet(
6✔
289
        flush_block, input_node_c_new, scale_input_tasklet, "_in1", {c_idx}, iedge_c->base_type(), iedge_c->debug_info()
6✔
290
    );
6✔
291
    if (auto const_node = dynamic_cast<data_flow::ConstantNode*>(beta_node)) {
6✔
292
        auto& beta_node_new =
6✔
293
            builder.add_constant(flush_block, const_node->data(), const_node->type(), block.debug_info());
6✔
294
        builder
6✔
295
            .add_computational_memlet(flush_block, beta_node_new, scale_input_tasklet, "_in2", {}, block.debug_info());
6✔
296
    } else {
6✔
297
        auto& beta_node_new = builder.add_access(flush_block, beta_node->data(), block.debug_info());
×
298
        builder
×
299
            .add_computational_memlet(flush_block, beta_node_new, scale_input_tasklet, "_in2", {}, block.debug_info());
×
300
    }
×
301

302
    std::string scaled_input_temp = builder.find_new_name("scaled_input_temp");
6✔
303
    builder.add_container(scaled_input_temp, scalar_type);
6✔
304
    auto& scaled_input_c = builder.add_access(flush_block, scaled_input_temp, block.debug_info());
6✔
305
    builder.add_computational_memlet(
6✔
306
        flush_block, scale_input_tasklet, "_out", scaled_input_c, {}, scalar_type, block.debug_info()
6✔
307
    );
6✔
308

309
    auto& flush_add_tasklet =
6✔
310
        builder.add_tasklet(flush_block, data_flow::TaskletCode::fp_add, "_out", {"_in1", "_in2"}, block.debug_info());
6✔
311
    auto& output_node_new = builder.add_access(flush_block, C_out_var, output_node->debug_info());
6✔
312
    builder.add_computational_memlet(
6✔
313
        flush_block, scaled_sum_final, flush_add_tasklet, "_in1", {}, scalar_type, block.debug_info()
6✔
314
    );
6✔
315
    builder.add_computational_memlet(
6✔
316
        flush_block, scaled_input_c, flush_add_tasklet, "_in2", {}, scalar_type, block.debug_info()
6✔
317
    );
6✔
318
    builder.add_computational_memlet(
6✔
319
        flush_block, flush_add_tasklet, "_out", output_node_new, {c_idx}, iedge_c->base_type(), iedge_c->debug_info()
6✔
320
    );
6✔
321

322

323
    // Clean up block
324
    builder.remove_memlet(block, *iedge_a);
6✔
325
    builder.remove_memlet(block, *iedge_b);
6✔
326
    builder.remove_memlet(block, *iedge_c);
6✔
327
    builder.remove_memlet(block, *alpha_edge);
6✔
328
    builder.remove_node(block, *alpha_node);
6✔
329
    builder.remove_memlet(block, *beta_edge);
6✔
330
    builder.remove_node(block, *beta_node);
6✔
331
    builder.remove_memlet(block, oedge);
6✔
332
    builder.remove_node(block, *input_node_a);
6✔
333
    builder.remove_node(block, *input_node_b);
6✔
334
    builder.remove_node(block, *input_node_c);
6✔
335
    builder.remove_node(block, *output_node);
6✔
336
    builder.remove_node(block, *this);
6✔
337
    builder.remove_child(parent, index + 1);
6✔
338

339
    return true;
6✔
340
}
6✔
341

342
symbolic::Expression GEMMNode::flop() const {
×
343
    return flops(symbolic::__true__(), symbolic::__true__(), symbolic::__true__(), symbolic::__true__());
×
344
}
×
345

346
symbolic::Expression GEMMNode::flops(
347
    symbolic::Condition alpha_non_zero,
348
    symbolic::Condition alpha_non_ident,
349
    symbolic::Condition beta_non_zero,
350
    symbolic::Condition beta_non_ident
351
) const {
×
352
    auto res_elems = symbolic::mul(this->m_, this->n_);
×
353

354
    // conditional on alpha != 0.0
355
    auto mm_mul_ops = symbolic::mul(symbolic::mul(res_elems, this->k_), alpha_non_zero);
×
356
    auto mm_sum_ops = symbolic::mul(symbolic::mul(res_elems, symbolic::sub(this->k_, symbolic::one())), alpha_non_zero);
×
357
    // conditional on alpha != 1.0 && alpha != 0.0
358
    auto mm_alpha_scale_ops = symbolic::mul(res_elems, symbolic::And(alpha_non_ident, alpha_non_zero));
×
359
    // conditional on beta != 1.0 && beta != 0.0
360
    auto mm_beta_scale_ops = symbolic::mul(res_elems, symbolic::And(beta_non_ident, beta_non_zero));
×
361
    auto mm_beta_scaled_sum_ops = symbolic::mul(res_elems, beta_non_zero);
×
362
    auto mul_ops = symbolic::add(mm_mul_ops, symbolic::add(mm_alpha_scale_ops, mm_beta_scale_ops));
×
363
    auto add_ops = symbolic::add(mm_sum_ops, mm_beta_scaled_sum_ops);
×
364
    return symbolic::add(mul_ops, add_ops);
×
365
}
×
366

367
std::unique_ptr<data_flow::DataFlowNode> GEMMNode::
368
    clone(size_t element_id, const graph::Vertex vertex, data_flow::DataFlowGraph& parent) const {
×
369
    auto node_clone = std::unique_ptr<GEMMNode>(new GEMMNode(
×
370
        element_id,
×
371
        this->debug_info(),
×
372
        vertex,
×
373
        parent,
×
374
        this->implementation_type_,
×
375
        this->precision_,
×
376
        this->layout_,
×
377
        this->trans_a_,
×
378
        this->trans_b_,
×
379
        this->m_,
×
380
        this->n_,
×
381
        this->k_,
×
382
        this->lda_,
×
383
        this->ldb_,
×
384
        this->ldc_
×
385
    ));
×
386
    return std::move(node_clone);
×
387
}
×
388

389
std::string GEMMNode::toStr() const {
×
390
    return LibraryNode::toStr() + "(" + static_cast<char>(precision_) + ", " +
×
391
           std::string(BLAS_Layout_to_short_string(layout_)) + ", " + BLAS_Transpose_to_char(trans_a_) +
×
392
           BLAS_Transpose_to_char(trans_b_) + ", " + m_->__str__() + ", " + n_->__str__() + ", " + k_->__str__() +
×
393
           ", " + lda_->__str__() + ", " + ldb_->__str__() + ", " + ldc_->__str__() + ")";
×
394
}
×
395

396
nlohmann::json GEMMNodeSerializer::serialize(const data_flow::LibraryNode& library_node) {
×
397
    const GEMMNode& gemm_node = static_cast<const GEMMNode&>(library_node);
×
398
    nlohmann::json j;
×
399

400
    serializer::JSONSerializer serializer;
×
401
    j["code"] = gemm_node.code().value();
×
402
    j["precision"] = gemm_node.precision();
×
403
    j["layout"] = gemm_node.layout();
×
404
    j["trans_a"] = gemm_node.trans_a();
×
405
    j["trans_b"] = gemm_node.trans_b();
×
406
    j["m"] = serializer.expression(gemm_node.m());
×
407
    j["n"] = serializer.expression(gemm_node.n());
×
408
    j["k"] = serializer.expression(gemm_node.k());
×
409
    j["lda"] = serializer.expression(gemm_node.lda());
×
410
    j["ldb"] = serializer.expression(gemm_node.ldb());
×
411
    j["ldc"] = serializer.expression(gemm_node.ldc());
×
412

413
    return j;
×
414
}
×
415

416
data_flow::LibraryNode& GEMMNodeSerializer::deserialize(
417
    const nlohmann::json& j, builder::StructuredSDFGBuilder& builder, structured_control_flow::Block& parent
418
) {
×
419
    // Assertions for required fields
420
    assert(j.contains("element_id"));
×
421
    assert(j.contains("code"));
×
422
    assert(j.contains("debug_info"));
×
423

424
    auto code = j["code"].get<std::string>();
×
425
    if (code != LibraryNodeType_GEMM.value()) {
×
426
        throw std::runtime_error("Invalid library node code");
×
427
    }
×
428

429
    // Extract debug info using JSONSerializer
430
    sdfg::serializer::JSONSerializer serializer;
×
431
    DebugInfo debug_info = serializer.json_to_debug_info(j["debug_info"]);
×
432

433
    auto precision = j.at("precision").get<BLAS_Precision>();
×
434
    auto layout = j.at("layout").get<BLAS_Layout>();
×
435
    auto trans_a = j.at("trans_a").get<BLAS_Transpose>();
×
436
    auto trans_b = j.at("trans_b").get<BLAS_Transpose>();
×
437
    auto m = symbolic::parse(j.at("m"));
×
438
    auto n = symbolic::parse(j.at("n"));
×
439
    auto k = symbolic::parse(j.at("k"));
×
440
    auto lda = symbolic::parse(j.at("lda"));
×
441
    auto ldb = symbolic::parse(j.at("ldb"));
×
442
    auto ldc = symbolic::parse(j.at("ldc"));
×
443

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

446
    return builder.add_library_node<
×
447
        GEMMNode>(parent, debug_info, implementation_type, precision, layout, trans_a, trans_b, m, n, k, lda, ldb, ldc);
×
448
}
×
449

450
GEMMNodeDispatcher_BLAS::GEMMNodeDispatcher_BLAS(
451
    codegen::LanguageExtension& language_extension,
452
    const Function& function,
453
    const data_flow::DataFlowGraph& data_flow_graph,
454
    const GEMMNode& node
455
)
456
    : codegen::LibraryNodeDispatcher(language_extension, function, data_flow_graph, node) {}
×
457

458
void GEMMNodeDispatcher_BLAS::dispatch_code(
459
    codegen::PrettyPrinter& stream,
460
    codegen::PrettyPrinter& globals_stream,
461
    codegen::CodeSnippetFactory& library_snippet_factory
462
) {
×
463
    stream << "{" << std::endl;
×
464
    stream.setIndent(stream.indent() + 4);
×
465

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

468
    sdfg::types::Scalar base_type(types::PrimitiveType::Void);
×
469
    switch (gemm_node.precision()) {
×
470
        case BLAS_Precision::h:
×
471
            base_type = types::Scalar(types::PrimitiveType::Half);
×
472
            break;
×
473
        case BLAS_Precision::s:
×
474
            base_type = types::Scalar(types::PrimitiveType::Float);
×
475
            break;
×
476
        case BLAS_Precision::d:
×
477
            base_type = types::Scalar(types::PrimitiveType::Double);
×
478
            break;
×
479
        default:
×
480
            throw std::runtime_error("Invalid BLAS_Precision value");
×
481
    }
×
482

NEW
483
    library_snippet_factory.require_dependency(BLASLibDependency::instance());
×
484

485
    stream << "cblas_" << BLAS_Precision_to_string(gemm_node.precision()) << "gemm(";
×
486
    stream.setIndent(stream.indent() + 4);
×
487
    stream << BLAS_Layout_to_string(gemm_node.layout());
×
488
    stream << ", ";
×
489
    stream << BLAS_Transpose_to_string(gemm_node.trans_a());
×
490
    stream << ", ";
×
491
    stream << BLAS_Transpose_to_string(gemm_node.trans_b());
×
492
    stream << ", ";
×
493
    stream << this->language_extension_.expression(gemm_node.m());
×
494
    stream << ", ";
×
495
    stream << this->language_extension_.expression(gemm_node.n());
×
496
    stream << ", ";
×
497
    stream << this->language_extension_.expression(gemm_node.k());
×
498
    stream << ", ";
×
499
    stream << "__alpha";
×
500
    stream << ", ";
×
501
    stream << "__A";
×
502
    stream << ", ";
×
503
    stream << this->language_extension_.expression(gemm_node.lda());
×
504
    stream << ", ";
×
505
    stream << "__B";
×
506
    stream << ", ";
×
507
    stream << this->language_extension_.expression(gemm_node.ldb());
×
508
    stream << ", ";
×
509
    stream << "__beta";
×
510
    stream << ", ";
×
511
    stream << "__C";
×
512
    stream << ", ";
×
513
    stream << this->language_extension_.expression(gemm_node.ldc());
×
514

515
    stream.setIndent(stream.indent() - 4);
×
516
    stream << ");" << std::endl;
×
517

518
    stream.setIndent(stream.indent() - 4);
×
519
    stream << "}" << std::endl;
×
520
}
×
521

522
} // namespace blas
523
} // namespace math
524
} // 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