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

daisytuner / docc / 26295232204

22 May 2026 02:58PM UTC coverage: 60.853% (+0.02%) from 60.837%
26295232204

push

github

web-flow
Activate Einsum pipeline for Python/PyTorch frontend (#720)

- Added Einsum step to compilation (after which the SDFG is also dumped)
- Generate tasklets and cmath library nodes directly instead of tensor nodes if all tensor types are scalar
- Merged the whole "lifting" part of Einsum nodes into one pass: the EinsumDetectionPass that runs in linear time
- Renamed the EinsumExpand transformation to the EinsumPromotion transformation because the name was confusing with expanding Einsum/library nodes
- Fixed a bug where the lifting failed for multiple input edges of the same access node on a tasklet and added unit tests
- Moved Einsum node source files into tensor folder (but the Einsum node is not a tensor node yet)

85 of 115 new or added lines in 13 files covered. (73.91%)

3 existing lines in 2 files now uncovered.

35027 of 57560 relevant lines covered (60.85%)

11105.41 hits per line

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

75.16
/sdfg/src/serializer/json_serializer.cpp
1
#include "sdfg/serializer/json_serializer.h"
2

3
#include <cassert>
4
#include <memory>
5
#include <sdfg/data_flow/library_nodes/load_const_node.h>
6
#include <utility>
7
#include <vector>
8

9
#include "sdfg/data_flow/library_nodes/barrier_local_node.h"
10
#include "sdfg/data_flow/library_nodes/call_node.h"
11
#include "sdfg/data_flow/library_nodes/invoke_node.h"
12
#include "sdfg/data_flow/library_nodes/math/math.h"
13
#include "sdfg/data_flow/library_nodes/math/tensor/elementwise_ops/cmath_node.h"
14
#include "sdfg/data_flow/library_nodes/math/tensor/elementwise_ops/tasklet_node.h"
15
#include "sdfg/data_flow/library_nodes/metadata_node.h"
16
#include "sdfg/data_flow/library_nodes/stdlib/stdlib.h"
17

18
#include "sdfg/analysis/users.h"
19
#include "sdfg/builder/structured_sdfg_builder.h"
20
#include "sdfg/data_flow/library_node.h"
21
#include "sdfg/data_flow/library_nodes/math/tensor/batchnorm_node.h"
22
#include "sdfg/element.h"
23
#include "sdfg/structured_control_flow/block.h"
24
#include "sdfg/structured_control_flow/for.h"
25
#include "sdfg/structured_control_flow/if_else.h"
26
#include "sdfg/structured_control_flow/map.h"
27
#include "sdfg/structured_control_flow/return.h"
28
#include "sdfg/structured_control_flow/sequence.h"
29
#include "sdfg/structured_control_flow/while.h"
30
#include "sdfg/structured_sdfg.h"
31
#include "sdfg/symbolic/symbolic.h"
32
#include "sdfg/types/function.h"
33
#include "sdfg/types/scalar.h"
34
#include "sdfg/types/type.h"
35
#include "symengine/expression.h"
36
#include "symengine/logic.h"
37
#include "symengine/symengine_rcp.h"
38

39
namespace sdfg {
40
namespace serializer {
41

42
FunctionType function_type_from_string(const std::string& str) {
25✔
43
    if (str == FunctionType_CPU.value()) {
25✔
44
        return FunctionType_CPU;
25✔
45
    } else if (str == FunctionType_NV_GLOBAL.value()) {
25✔
46
        return FunctionType_NV_GLOBAL;
×
47
    }
×
48

49
    return FunctionType(str);
×
50
}
25✔
51

52
/*
53
 * * JSONSerializer class
54
 * * Serialization logic
55
 */
56

57
nlohmann::json JSONSerializer::serialize(
58
    const sdfg::StructuredSDFG& sdfg,
59
    analysis::AnalysisManager* analysis_manager,
60
    structured_control_flow::Sequence* root
61
) {
24✔
62
    nlohmann::json j;
24✔
63

64
    j["name"] = sdfg.name();
24✔
65
    j["element_counter"] = sdfg.element_counter();
24✔
66
    j["type"] = std::string(sdfg.type().value());
24✔
67

68
    nlohmann::json return_type_json;
24✔
69
    type_to_json(return_type_json, sdfg.return_type());
24✔
70
    j["return_type"] = return_type_json;
24✔
71

72
    j["structures"] = nlohmann::json::array();
24✔
73
    for (const auto& structure_name : sdfg.structures()) {
24✔
74
        const auto& structure = sdfg.structure(structure_name);
1✔
75
        nlohmann::json structure_json;
1✔
76
        structure_definition_to_json(structure_json, structure);
1✔
77
        j["structures"].push_back(structure_json);
1✔
78
    }
1✔
79

80
    j["containers"] = nlohmann::json::object();
24✔
81
    for (const auto& container : sdfg.containers()) {
133✔
82
        nlohmann::json desc;
133✔
83
        type_to_json(desc, sdfg.type(container));
133✔
84
        j["containers"][container] = desc;
133✔
85
    }
133✔
86

87
    j["arguments"] = nlohmann::json::array();
24✔
88
    for (const auto& argument : sdfg.arguments()) {
24✔
89
        j["arguments"].push_back(argument);
23✔
90
    }
23✔
91

92
    j["externals"] = nlohmann::json::array();
24✔
93
    for (const auto& external : sdfg.externals()) {
24✔
94
        nlohmann::json external_json;
7✔
95
        external_json["name"] = external;
7✔
96
        external_json["linkage_type"] = sdfg.linkage_type(external);
7✔
97
        j["externals"].push_back(external_json);
7✔
98
    }
7✔
99

100
    j["metadata"] = nlohmann::json::object();
24✔
101
    for (const auto& entry : sdfg.metadata()) {
24✔
102
        j["metadata"][entry.first] = entry.second;
1✔
103
    }
1✔
104

105
    // Walk the SDFG
106
    nlohmann::json root_json;
24✔
107
    sequence_to_json(root_json, sdfg.root());
24✔
108
    j["root"] = root_json;
24✔
109

110
    return j;
24✔
111
}
24✔
112

113
void JSONSerializer::dataflow_to_json(nlohmann::json& j, const data_flow::DataFlowGraph& dataflow) {
52✔
114
    j["type"] = "dataflow";
52✔
115
    j["nodes"] = nlohmann::json::array();
52✔
116
    j["edges"] = nlohmann::json::array();
52✔
117

118
    for (auto& node : dataflow.nodes()) {
201✔
119
        nlohmann::json node_json;
201✔
120
        node_json["element_id"] = node.element_id();
201✔
121

122
        node_json["debug_info"] = nlohmann::json::object();
201✔
123
        debug_info_to_json(node_json["debug_info"], node.debug_info());
201✔
124

125
        if (auto tasklet = dynamic_cast<const data_flow::Tasklet*>(&node)) {
201✔
126
            node_json["type"] = "tasklet";
59✔
127
            node_json["code"] = tasklet->code();
59✔
128
            node_json["inputs"] = nlohmann::json::array();
59✔
129
            for (auto& input : tasklet->inputs()) {
99✔
130
                node_json["inputs"].push_back(input);
99✔
131
            }
99✔
132
            node_json["output"] = tasklet->output();
59✔
133
        } else if (auto lib_node = dynamic_cast<const data_flow::LibraryNode*>(&node)) {
142✔
134
            node_json["type"] = "library_node";
8✔
135
            node_json["implementation_type"] = std::string(lib_node->implementation_type().value());
8✔
136
            auto serializer_fn =
8✔
137
                LibraryNodeSerializerRegistry::instance().get_library_node_serializer(lib_node->code().value());
8✔
138
            if (serializer_fn == nullptr) {
8✔
139
                throw std::runtime_error("Unknown library node code: " + std::string(lib_node->code().value()));
×
140
            }
×
141
            auto serializer = serializer_fn();
8✔
142
            auto lib_node_json = serializer->serialize(*lib_node);
8✔
143
            node_json.merge_patch(lib_node_json);
8✔
144
        } else if (auto code_node = dynamic_cast<const data_flow::ConstantNode*>(&node)) {
134✔
145
            node_json["type"] = "constant_node";
×
146
            node_json["data"] = code_node->data();
×
147

148
            nlohmann::json type_json;
×
149
            type_to_json(type_json, code_node->type());
×
150
            node_json["data_type"] = type_json;
×
151
        } else if (auto code_node = dynamic_cast<const data_flow::AccessNode*>(&node)) {
134✔
152
            node_json["type"] = "access_node";
134✔
153
            node_json["data"] = code_node->data();
134✔
154
        } else {
134✔
155
            throw std::runtime_error("Unknown node type");
×
156
        }
×
157

158
        j["nodes"].push_back(node_json);
201✔
159
    }
201✔
160

161
    for (auto& edge : dataflow.edges()) {
179✔
162
        nlohmann::json edge_json;
179✔
163
        edge_json["element_id"] = edge.element_id();
179✔
164

165
        edge_json["debug_info"] = nlohmann::json::object();
179✔
166
        debug_info_to_json(edge_json["debug_info"], edge.debug_info());
179✔
167

168
        edge_json["src"] = edge.src().element_id();
179✔
169
        edge_json["dst"] = edge.dst().element_id();
179✔
170

171
        edge_json["src_conn"] = edge.src_conn();
179✔
172
        edge_json["dst_conn"] = edge.dst_conn();
179✔
173

174
        edge_json["subset"] = nlohmann::json::array();
179✔
175
        for (auto& subset : edge.subset()) {
179✔
176
            edge_json["subset"].push_back(expression(subset));
64✔
177
        }
64✔
178

179
        nlohmann::json base_type_json;
179✔
180
        type_to_json(base_type_json, edge.base_type());
179✔
181
        edge_json["base_type"] = base_type_json;
179✔
182

183
        j["edges"].push_back(edge_json);
179✔
184
    }
179✔
185
}
52✔
186

187
void JSONSerializer::block_to_json(nlohmann::json& j, const structured_control_flow::Block& block) {
49✔
188
    j["type"] = "block";
49✔
189
    j["element_id"] = block.element_id();
49✔
190

191
    j["debug_info"] = nlohmann::json::object();
49✔
192
    debug_info_to_json(j["debug_info"], block.debug_info());
49✔
193

194
    nlohmann::json dataflow_json;
49✔
195
    dataflow_to_json(dataflow_json, block.dataflow());
49✔
196
    j["dataflow"] = dataflow_json;
49✔
197
}
49✔
198

199
void JSONSerializer::for_to_json(nlohmann::json& j, const structured_control_flow::For& for_node) {
18✔
200
    j["type"] = "for";
18✔
201
    j["element_id"] = for_node.element_id();
18✔
202

203
    j["debug_info"] = nlohmann::json::object();
18✔
204
    debug_info_to_json(j["debug_info"], for_node.debug_info());
18✔
205

206
    j["indvar"] = expression(for_node.indvar());
18✔
207
    j["init"] = expression(for_node.init());
18✔
208
    j["condition"] = expression(for_node.condition());
18✔
209
    j["update"] = expression(for_node.update());
18✔
210

211
    nlohmann::json body_json;
18✔
212
    sequence_to_json(body_json, for_node.root());
18✔
213
    j["root"] = body_json;
18✔
214
}
18✔
215

216
void JSONSerializer::if_else_to_json(nlohmann::json& j, const structured_control_flow::IfElse& if_else_node) {
2✔
217
    j["type"] = "if_else";
2✔
218
    j["element_id"] = if_else_node.element_id();
2✔
219

220
    j["debug_info"] = nlohmann::json::object();
2✔
221
    debug_info_to_json(j["debug_info"], if_else_node.debug_info());
2✔
222

223
    j["branches"] = nlohmann::json::array();
2✔
224
    for (size_t i = 0; i < if_else_node.size(); i++) {
6✔
225
        nlohmann::json branch_json;
4✔
226
        branch_json["condition"] = expression(if_else_node.at(i).second);
4✔
227
        nlohmann::json body_json;
4✔
228
        sequence_to_json(body_json, if_else_node.at(i).first);
4✔
229
        branch_json["root"] = body_json;
4✔
230
        j["branches"].push_back(branch_json);
4✔
231
    }
4✔
232
}
2✔
233

234
void JSONSerializer::while_node_to_json(nlohmann::json& j, const structured_control_flow::While& while_node) {
5✔
235
    j["type"] = "while";
5✔
236
    j["element_id"] = while_node.element_id();
5✔
237

238
    j["debug_info"] = nlohmann::json::object();
5✔
239
    debug_info_to_json(j["debug_info"], while_node.debug_info());
5✔
240

241
    nlohmann::json body_json;
5✔
242
    sequence_to_json(body_json, while_node.root());
5✔
243
    j["root"] = body_json;
5✔
244
}
5✔
245

246
void JSONSerializer::break_node_to_json(nlohmann::json& j, const structured_control_flow::Break& break_node) {
2✔
247
    j["type"] = "break";
2✔
248
    j["element_id"] = break_node.element_id();
2✔
249

250
    j["debug_info"] = nlohmann::json::object();
2✔
251
    debug_info_to_json(j["debug_info"], break_node.debug_info());
2✔
252
}
2✔
253

254
void JSONSerializer::continue_node_to_json(nlohmann::json& j, const structured_control_flow::Continue& continue_node) {
2✔
255
    j["type"] = "continue";
2✔
256
    j["element_id"] = continue_node.element_id();
2✔
257

258
    j["debug_info"] = nlohmann::json::object();
2✔
259
    debug_info_to_json(j["debug_info"], continue_node.debug_info());
2✔
260
}
2✔
261

262
void JSONSerializer::map_to_json(nlohmann::json& j, const structured_control_flow::Map& map_node) {
6✔
263
    j["type"] = "map";
6✔
264
    j["element_id"] = map_node.element_id();
6✔
265

266
    j["debug_info"] = nlohmann::json::object();
6✔
267
    debug_info_to_json(j["debug_info"], map_node.debug_info());
6✔
268

269
    j["indvar"] = expression(map_node.indvar());
6✔
270
    j["init"] = expression(map_node.init());
6✔
271
    j["condition"] = expression(map_node.condition());
6✔
272
    j["update"] = expression(map_node.update());
6✔
273

274
    j["schedule_type"] = nlohmann::json::object();
6✔
275
    schedule_type_to_json(j["schedule_type"], map_node.schedule_type());
6✔
276

277
    nlohmann::json body_json;
6✔
278
    sequence_to_json(body_json, map_node.root());
6✔
279
    j["root"] = body_json;
6✔
280
}
6✔
281

282
void JSONSerializer::return_node_to_json(nlohmann::json& j, const structured_control_flow::Return& return_node) {
2✔
283
    j["type"] = "return";
2✔
284
    j["element_id"] = return_node.element_id();
2✔
285
    j["data"] = return_node.data();
2✔
286

287
    if (return_node.is_constant()) {
2✔
288
        nlohmann::json type_json;
×
289
        type_to_json(type_json, return_node.type());
×
290
        j["data_type"] = type_json;
×
291
    }
×
292

293
    j["debug_info"] = nlohmann::json::object();
2✔
294
    debug_info_to_json(j["debug_info"], return_node.debug_info());
2✔
295
}
2✔
296

297
void JSONSerializer::sequence_to_json(nlohmann::json& j, const structured_control_flow::Sequence& sequence) {
61✔
298
    j["type"] = "sequence";
61✔
299
    j["element_id"] = sequence.element_id();
61✔
300

301
    j["debug_info"] = nlohmann::json::object();
61✔
302
    debug_info_to_json(j["debug_info"], sequence.debug_info());
61✔
303

304
    j["children"] = nlohmann::json::array();
61✔
305
    j["transitions"] = nlohmann::json::array();
61✔
306

307
    for (size_t i = 0; i < sequence.size(); i++) {
132✔
308
        nlohmann::json child_json;
71✔
309
        auto& child = sequence.at(i).first;
71✔
310
        auto& transition = sequence.at(i).second;
71✔
311

312
        if (auto block = dynamic_cast<const structured_control_flow::Block*>(&child)) {
71✔
313
            block_to_json(child_json, *block);
47✔
314
        } else if (auto for_node = dynamic_cast<const structured_control_flow::For*>(&child)) {
47✔
315
            for_to_json(child_json, *for_node);
16✔
316
        } else if (auto sequence_node = dynamic_cast<const structured_control_flow::Sequence*>(&child)) {
16✔
317
            sequence_to_json(child_json, *sequence_node);
×
318
        } else if (auto condition_node = dynamic_cast<const structured_control_flow::IfElse*>(&child)) {
8✔
319
            if_else_to_json(child_json, *condition_node);
×
320
        } else if (auto while_node = dynamic_cast<const structured_control_flow::While*>(&child)) {
8✔
321
            while_node_to_json(child_json, *while_node);
×
322
        } else if (auto return_node = dynamic_cast<const structured_control_flow::Return*>(&child)) {
8✔
323
            return_node_to_json(child_json, *return_node);
×
324
        } else if (auto break_node = dynamic_cast<const structured_control_flow::Break*>(&child)) {
8✔
325
            break_node_to_json(child_json, *break_node);
2✔
326
        } else if (auto continue_node = dynamic_cast<const structured_control_flow::Continue*>(&child)) {
6✔
327
            continue_node_to_json(child_json, *continue_node);
2✔
328
        } else if (auto map_node = dynamic_cast<const structured_control_flow::Map*>(&child)) {
4✔
329
            map_to_json(child_json, *map_node);
4✔
330
        } else {
4✔
331
            throw std::runtime_error("Unknown child type");
×
332
        }
×
333

334
        j["children"].push_back(child_json);
71✔
335

336
        // Add transition information
337
        nlohmann::json transition_json;
71✔
338
        transition_json["type"] = "transition";
71✔
339
        transition_json["element_id"] = transition.element_id();
71✔
340

341
        transition_json["debug_info"] = nlohmann::json::object();
71✔
342
        debug_info_to_json(transition_json["debug_info"], transition.debug_info());
71✔
343

344
        transition_json["assignments"] = nlohmann::json::array();
71✔
345
        for (const auto& assignment : transition.assignments()) {
71✔
346
            nlohmann::json assignment_json;
3✔
347
            assignment_json["symbol"] = expression(assignment.first);
3✔
348
            assignment_json["expression"] = expression(assignment.second);
3✔
349
            transition_json["assignments"].push_back(assignment_json);
3✔
350
        }
3✔
351

352
        j["transitions"].push_back(transition_json);
71✔
353
    }
71✔
354
}
61✔
355

356
void JSONSerializer::type_to_json(nlohmann::json& j, const types::IType& type) {
528✔
357
    if (auto scalar_type = dynamic_cast<const types::Scalar*>(&type)) {
528✔
358
        j["type"] = "scalar";
387✔
359
        j["primitive_type"] = scalar_type->primitive_type();
387✔
360
        j["storage_type"] = nlohmann::json::object();
387✔
361
        storage_type_to_json(j["storage_type"], scalar_type->storage_type());
387✔
362
        j["initializer"] = scalar_type->initializer();
387✔
363
        j["alignment"] = scalar_type->alignment();
387✔
364
    } else if (auto array_type = dynamic_cast<const types::Array*>(&type)) {
387✔
365
        j["type"] = "array";
72✔
366
        nlohmann::json element_type_json;
72✔
367
        type_to_json(element_type_json, array_type->element_type());
72✔
368
        j["element_type"] = element_type_json;
72✔
369
        j["num_elements"] = expression(array_type->num_elements());
72✔
370
        j["storage_type"] = nlohmann::json::object();
72✔
371
        storage_type_to_json(j["storage_type"], array_type->storage_type());
72✔
372
        j["initializer"] = array_type->initializer();
72✔
373
        j["alignment"] = array_type->alignment();
72✔
374
    } else if (auto pointer_type = dynamic_cast<const types::Pointer*>(&type)) {
72✔
375
        j["type"] = "pointer";
51✔
376
        if (pointer_type->has_pointee_type()) {
51✔
377
            nlohmann::json pointee_type_json;
50✔
378
            type_to_json(pointee_type_json, pointer_type->pointee_type());
50✔
379
            j["pointee_type"] = pointee_type_json;
50✔
380
        }
50✔
381
        j["storage_type"] = nlohmann::json::object();
51✔
382
        storage_type_to_json(j["storage_type"], pointer_type->storage_type());
51✔
383
        j["initializer"] = pointer_type->initializer();
51✔
384
        j["alignment"] = pointer_type->alignment();
51✔
385
    } else if (auto structure_type = dynamic_cast<const types::Structure*>(&type)) {
51✔
386
        j["type"] = "structure";
5✔
387
        j["name"] = structure_type->name();
5✔
388
        j["storage_type"] = nlohmann::json::object();
5✔
389
        storage_type_to_json(j["storage_type"], structure_type->storage_type());
5✔
390
        j["initializer"] = structure_type->initializer();
5✔
391
        j["alignment"] = structure_type->alignment();
5✔
392
    } else if (auto function_type = dynamic_cast<const types::Function*>(&type)) {
13✔
393
        j["type"] = "function";
5✔
394
        nlohmann::json return_type_json;
5✔
395
        type_to_json(return_type_json, function_type->return_type());
5✔
396
        j["return_type"] = return_type_json;
5✔
397
        j["params"] = nlohmann::json::array();
5✔
398
        for (size_t i = 0; i < function_type->num_params(); i++) {
16✔
399
            nlohmann::json param_json;
11✔
400
            type_to_json(param_json, function_type->param_type(symbolic::integer(i)));
11✔
401
            j["params"].push_back(param_json);
11✔
402
        }
11✔
403
        j["is_var_arg"] = function_type->is_var_arg();
5✔
404
        j["storage_type"] = nlohmann::json::object();
5✔
405
        storage_type_to_json(j["storage_type"], function_type->storage_type());
5✔
406
        j["initializer"] = function_type->initializer();
5✔
407
        j["alignment"] = function_type->alignment();
5✔
408
    } else if (auto reference_type = dynamic_cast<const sdfg::codegen::Reference*>(&type)) {
8✔
409
        j["type"] = "reference";
8✔
410
        nlohmann::json reference_type_json;
8✔
411
        type_to_json(reference_type_json, reference_type->reference_type());
8✔
412
        j["reference_type"] = reference_type_json;
8✔
413
    } else if (auto tensor_type = dynamic_cast<const types::Tensor*>(&type)) {
8✔
414
        j["type"] = "tensor";
×
415
        nlohmann::json element_type_json;
×
416
        type_to_json(element_type_json, tensor_type->element_type());
×
417
        j["element_type"] = element_type_json;
×
418
        j["shape"] = nlohmann::json::array();
×
419
        for (const auto& dim : tensor_type->shape()) {
×
420
            j["shape"].push_back(expression(dim));
×
421
        }
×
422
        j["strides"] = nlohmann::json::array();
×
423
        for (const auto& stride : tensor_type->strides()) {
×
424
            j["strides"].push_back(expression(stride));
×
425
        }
×
426
        j["offset"] = expression(tensor_type->offset());
×
427
        j["storage_type"] = nlohmann::json::object();
×
428
        storage_type_to_json(j["storage_type"], tensor_type->storage_type());
×
429
        j["initializer"] = tensor_type->initializer();
×
430
        j["alignment"] = tensor_type->alignment();
×
431
    } else {
×
432
        throw std::runtime_error("Unknown type");
×
433
    }
×
434
}
528✔
435

436
void JSONSerializer::structure_definition_to_json(nlohmann::json& j, const types::StructureDefinition& definition) {
2✔
437
    j["name"] = definition.name();
2✔
438
    j["members"] = nlohmann::json::array();
2✔
439
    for (size_t i = 0; i < definition.num_members(); i++) {
4✔
440
        nlohmann::json member_json;
2✔
441
        type_to_json(member_json, definition.member_type(symbolic::integer(i)));
2✔
442
        j["members"].push_back(member_json);
2✔
443
    }
2✔
444
    j["is_packed"] = definition.is_packed();
2✔
445
}
2✔
446

447
void JSONSerializer::debug_info_to_json(nlohmann::json& j, const DebugInfo& debug_info) {
598✔
448
    j["has"] = debug_info.has();
598✔
449
    j["filename"] = debug_info.filename();
598✔
450
    j["function"] = debug_info.function();
598✔
451
    j["start_line"] = debug_info.start_line();
598✔
452
    j["start_column"] = debug_info.start_column();
598✔
453
    j["end_line"] = debug_info.end_line();
598✔
454
    j["end_column"] = debug_info.end_column();
598✔
455
}
598✔
456

457

458
void JSONSerializer::schedule_type_to_json(nlohmann::json& j, const ScheduleType& schedule_type) {
8✔
459
    j["value"] = schedule_type.value();
8✔
460
    j["category"] = static_cast<int>(schedule_type.category());
8✔
461
    j["properties"] = nlohmann::json::object();
8✔
462
    for (const auto& prop : schedule_type.properties()) {
8✔
463
        j["properties"][prop.first] = prop.second;
4✔
464
    }
4✔
465
}
8✔
466

467
void JSONSerializer::storage_type_to_json(nlohmann::json& j, const types::StorageType& storage_type) {
520✔
468
    j["value"] = storage_type.value();
520✔
469
    j["allocation"] = storage_type.allocation();
520✔
470
    j["deallocation"] = storage_type.deallocation();
520✔
471
    if (!storage_type.allocation_size().is_null()) {
520✔
472
        j["allocation_size"] = expression(storage_type.allocation_size());
×
473
    }
×
474
    const symbolic::Expression& arg1 = storage_type.arg1();
520✔
475
    if (!arg1.is_null()) {
520✔
476
        auto args = nlohmann::json::array();
×
477
        args.push_back(expression(arg1));
×
478
        j["args"] = args;
×
479
    }
×
480
}
520✔
481

482

483
/*
484
 * * Deserialization logic
485
 */
486

487
std::unique_ptr<StructuredSDFG> JSONSerializer::deserialize(nlohmann::json& j) {
25✔
488
    assert(j.contains("name"));
25✔
489
    assert(j["name"].is_string());
25✔
490
    assert(j.contains("type"));
25✔
491
    assert(j["type"].is_string());
25✔
492
    assert(j.contains("element_counter"));
25✔
493
    assert(j["element_counter"].is_number_integer());
25✔
494

495
    std::unique_ptr<types::IType> return_type;
25✔
496
    if (j.contains("return_type")) {
25✔
497
        return_type = json_to_type(j["return_type"]);
25✔
498
    } else {
25✔
499
        return_type = std::make_unique<types::Scalar>(types::PrimitiveType::Void);
×
500
    }
×
501

502
    FunctionType function_type = function_type_from_string(j["type"].get<std::string>());
25✔
503
    builder::StructuredSDFGBuilder builder(j["name"], function_type, *return_type);
25✔
504

505
    size_t element_counter = j["element_counter"];
25✔
506
    builder.set_element_counter(element_counter);
25✔
507

508
    // deserialize structures
509
    assert(j.contains("structures"));
25✔
510
    assert(j["structures"].is_array());
25✔
511
    for (const auto& structure : j["structures"]) {
25✔
512
        assert(structure.contains("name"));
1✔
513
        assert(structure["name"].is_string());
1✔
514
        json_to_structure_definition(structure, builder);
1✔
515
    }
1✔
516

517
    nlohmann::json& containers = j["containers"];
25✔
518

519
    // deserialize externals
520
    for (const auto& external : j["externals"]) {
25✔
521
        assert(external.contains("name"));
7✔
522
        assert(external["name"].is_string());
7✔
523
        assert(external.contains("linkage_type"));
7✔
524
        assert(external["linkage_type"].is_number_integer());
7✔
525
        auto& type_desc = containers.at(external["name"].get<std::string>());
7✔
526
        auto type = json_to_type(type_desc);
7✔
527
        builder.add_external(external["name"], *type, LinkageType(external["linkage_type"]));
7✔
528
    }
7✔
529

530
    // deserialize arguments
531
    for (const auto& name : j["arguments"]) {
26✔
532
        auto& type_desc = containers.at(name.get<std::string>());
26✔
533
        auto type = json_to_type(type_desc);
26✔
534
        builder.add_container(name, *type, true, false);
26✔
535
    }
26✔
536

537
    // deserialize transients
538
    for (const auto& entry : containers.items()) {
139✔
539
        if (builder.subject().is_argument(entry.key())) {
139✔
540
            continue;
26✔
541
        }
26✔
542
        if (builder.subject().is_external(entry.key())) {
113✔
543
            continue;
7✔
544
        }
7✔
545
        auto type = json_to_type(entry.value());
106✔
546
        builder.add_container(entry.key(), *type, false, false);
106✔
547
    }
106✔
548

549
    // deserialize root node
550
    assert(j.contains("root"));
25✔
551
    auto& root = builder.subject().root();
25✔
552
    json_to_sequence(j["root"], builder, root);
25✔
553

554
    // deserialize metadata
555
    assert(j.contains("metadata"));
25✔
556
    assert(j["metadata"].is_object());
25✔
557
    for (const auto& entry : j["metadata"].items()) {
25✔
558
        builder.subject().add_metadata(entry.key(), entry.value());
1✔
559
    }
1✔
560

561
    builder.set_element_counter(element_counter);
25✔
562

563
    return builder.move();
25✔
564
}
25✔
565

566
void JSONSerializer::json_to_structure_definition(const nlohmann::json& j, builder::StructuredSDFGBuilder& builder) {
2✔
567
    assert(j.contains("name"));
2✔
568
    assert(j["name"].is_string());
2✔
569
    assert(j.contains("members"));
2✔
570
    assert(j["members"].is_array());
2✔
571
    assert(j.contains("is_packed"));
2✔
572
    assert(j["is_packed"].is_boolean());
2✔
573
    auto is_packed = j["is_packed"];
2✔
574
    auto& definition = builder.add_structure(j["name"], is_packed);
2✔
575
    for (const auto& member : j["members"]) {
2✔
576
        nlohmann::json member_json;
2✔
577
        auto member_type = json_to_type(member);
2✔
578
        definition.add_member(*member_type);
2✔
579
    }
2✔
580
}
2✔
581

582
std::vector<std::pair<std::string, types::Scalar>> JSONSerializer::json_to_arguments(const nlohmann::json& j) {
×
583
    std::vector<std::pair<std::string, types::Scalar>> arguments;
×
584
    for (const auto& argument : j) {
×
585
        assert(argument.contains("name"));
×
586
        assert(argument["name"].is_string());
×
587
        assert(argument.contains("type"));
×
588
        assert(argument["type"].is_object());
×
589
        std::string name = argument["name"];
×
590
        auto type = json_to_type(argument["type"]);
×
591
        arguments.emplace_back(name, *dynamic_cast<types::Scalar*>(type.get()));
×
592
    }
×
593
    return arguments;
×
594
}
×
595

596
void JSONSerializer::json_to_dataflow(
597
    const nlohmann::json& j, builder::StructuredSDFGBuilder& builder, structured_control_flow::Block& parent
598
) {
42✔
599
    std::map<size_t, data_flow::DataFlowNode&> nodes_map;
42✔
600

601
    assert(j.contains("nodes"));
42✔
602
    assert(j["nodes"].is_array());
42✔
603
    for (const auto& node : j["nodes"]) {
197✔
604
        assert(node.contains("type"));
197✔
605
        assert(node["type"].is_string());
197✔
606
        assert(node.contains("element_id"));
197✔
607
        assert(node["element_id"].is_number_integer());
197✔
608
        std::string type = node["type"];
197✔
609
        if (type == "tasklet") {
197✔
610
            assert(node.contains("code"));
58✔
611
            assert(node["code"].is_number_integer());
58✔
612
            assert(node.contains("inputs"));
58✔
613
            assert(node["inputs"].is_array());
58✔
614
            assert(node.contains("output"));
58✔
615
            assert(node["output"].is_string());
58✔
616
            auto inputs = node["inputs"].get<std::vector<std::string>>();
58✔
617

618
            auto& tasklet =
58✔
619
                builder
58✔
620
                    .add_tasklet(parent, node["code"], node["output"], inputs, json_to_debug_info(node["debug_info"]));
58✔
621
            tasklet.element_id_ = node["element_id"];
58✔
622
            nodes_map.insert({node["element_id"], tasklet});
58✔
623
        } else if (type == "library_node") {
139✔
624
            assert(node.contains("code"));
8✔
625
            data_flow::LibraryNodeCode code(node["code"].get<std::string>());
8✔
626

627
            auto serializer_fn = LibraryNodeSerializerRegistry::instance().get_library_node_serializer(code.value());
8✔
628
            if (serializer_fn == nullptr) {
8✔
629
                throw std::runtime_error("Unknown library node code: " + std::string(code.value()));
×
630
            }
×
631
            auto serializer = serializer_fn();
8✔
632
            auto& lib_node = serializer->deserialize(node, builder, parent);
8✔
633
            lib_node.implementation_type() =
8✔
634
                data_flow::ImplementationType(node["implementation_type"].get<std::string>());
8✔
635
            lib_node.element_id_ = node["element_id"];
8✔
636
            nodes_map.insert({node["element_id"], lib_node});
8✔
637
        } else if (type == "access_node") {
131✔
638
            assert(node.contains("data"));
131✔
639
            auto& access_node = builder.add_access(parent, node["data"], json_to_debug_info(node["debug_info"]));
131✔
640
            access_node.element_id_ = node["element_id"];
131✔
641
            nodes_map.insert({node["element_id"], access_node});
131✔
642
        } else if (type == "constant_node") {
131✔
643
            assert(node.contains("data"));
×
644
            assert(node.contains("data_type"));
×
645

646
            auto type = json_to_type(node["data_type"]);
×
647

648
            auto& constant_node =
×
649
                builder.add_constant(parent, node["data"], *type, json_to_debug_info(node["debug_info"]));
×
650
            constant_node.element_id_ = node["element_id"];
×
651
            nodes_map.insert({node["element_id"], constant_node});
×
652
        } else {
×
653
            throw std::runtime_error("Unknown node type");
×
654
        }
×
655
    }
197✔
656

657
    assert(j.contains("edges"));
42✔
658
    assert(j["edges"].is_array());
42✔
659
    for (const auto& edge : j["edges"]) {
176✔
660
        assert(edge.contains("src"));
176✔
661
        assert(edge["src"].is_number_integer());
176✔
662
        assert(edge.contains("dst"));
176✔
663
        assert(edge["dst"].is_number_integer());
176✔
664
        assert(edge.contains("src_conn"));
176✔
665
        assert(edge["src_conn"].is_string());
176✔
666
        assert(edge.contains("dst_conn"));
176✔
667
        assert(edge["dst_conn"].is_string());
176✔
668
        assert(edge.contains("subset"));
176✔
669
        assert(edge["subset"].is_array());
176✔
670

671
        assert(nodes_map.find(edge["src"]) != nodes_map.end());
176✔
672
        assert(nodes_map.find(edge["dst"]) != nodes_map.end());
176✔
673
        auto& source = nodes_map.at(edge["src"]);
176✔
674
        auto& target = nodes_map.at(edge["dst"]);
176✔
675

676
        auto base_type = json_to_type(edge["base_type"]);
176✔
677

678
        assert(edge.contains("subset"));
176✔
679
        assert(edge["subset"].is_array());
176✔
680
        std::vector<symbolic::Expression> subset;
176✔
681
        for (const auto& subset_ : edge["subset"]) {
176✔
682
            assert(subset_.is_string());
62✔
683
            std::string subset_str = subset_;
62✔
684
            auto expr = symbolic::parse(subset_str);
62✔
685
            subset.push_back(expr);
62✔
686
        }
62✔
687
        auto& memlet = builder.add_memlet(
176✔
688
            parent,
176✔
689
            source,
176✔
690
            edge["src_conn"],
176✔
691
            target,
176✔
692
            edge["dst_conn"],
176✔
693
            subset,
176✔
694
            *base_type,
176✔
695
            json_to_debug_info(edge["debug_info"])
176✔
696
        );
176✔
697
        memlet.element_id_ = edge["element_id"];
176✔
698
    }
176✔
699
}
42✔
700

701
void JSONSerializer::json_to_sequence(
702
    const nlohmann::json& j, builder::StructuredSDFGBuilder& builder, structured_control_flow::Sequence& sequence
703
) {
54✔
704
    assert(j.contains("type"));
54✔
705
    assert(j["type"].is_string());
54✔
706
    assert(j.contains("children"));
54✔
707
    assert(j["children"].is_array());
54✔
708
    assert(j.contains("transitions"));
54✔
709
    assert(j["transitions"].is_array());
54✔
710
    assert(j["transitions"].size() == j["children"].size());
54✔
711

712
    sequence.element_id_ = j["element_id"];
54✔
713
    sequence.debug_info_ = json_to_debug_info(j["debug_info"]);
54✔
714

715
    std::string type = j["type"];
54✔
716
    if (type == "sequence") {
54✔
717
        for (size_t i = 0; i < j["children"].size(); i++) {
115✔
718
            auto& child = j["children"][i];
61✔
719
            auto& transition = j["transitions"][i];
61✔
720
            assert(child.contains("type"));
61✔
721
            assert(child["type"].is_string());
61✔
722

723
            assert(transition.contains("type"));
61✔
724
            assert(transition["type"].is_string());
61✔
725
            assert(transition.contains("assignments"));
61✔
726
            assert(transition["assignments"].is_array());
61✔
727
            control_flow::Assignments assignments;
61✔
728
            for (const auto& assignment : transition["assignments"]) {
61✔
729
                assert(assignment.contains("symbol"));
2✔
730
                assert(assignment["symbol"].is_string());
2✔
731
                assert(assignment.contains("expression"));
2✔
732
                assert(assignment["expression"].is_string());
2✔
733
                auto expr = symbolic::parse(assignment["expression"].get<std::string>());
2✔
734
                assignments.insert({symbolic::symbol(assignment["symbol"]), expr});
2✔
735
            }
2✔
736

737
            if (child["type"] == "block") {
61✔
738
                json_to_block_node(child, builder, sequence, assignments);
39✔
739
            } else if (child["type"] == "for") {
39✔
740
                json_to_for_node(child, builder, sequence, assignments);
16✔
741
            } else if (child["type"] == "if_else") {
16✔
742
                json_to_if_else_node(child, builder, sequence, assignments);
×
743
            } else if (child["type"] == "while") {
6✔
744
                json_to_while_node(child, builder, sequence, assignments);
×
745
            } else if (child["type"] == "break") {
6✔
746
                json_to_break_node(child, builder, sequence, assignments);
1✔
747
            } else if (child["type"] == "continue") {
5✔
748
                json_to_continue_node(child, builder, sequence, assignments);
1✔
749
            } else if (child["type"] == "return") {
4✔
750
                json_to_return_node(child, builder, sequence, assignments);
×
751
            } else if (child["type"] == "map") {
4✔
752
                json_to_map_node(child, builder, sequence, assignments);
4✔
753
            } else if (child["type"] == "sequence") {
4✔
754
                auto& subseq = builder.add_sequence(sequence, assignments, json_to_debug_info(child["debug_info"]));
×
755
                json_to_sequence(child, builder, subseq);
×
756
            } else {
×
757
                throw std::runtime_error("Unknown child type");
×
758
            }
×
759

760
            sequence.at(i).second.debug_info_ = json_to_debug_info(transition["debug_info"]);
61✔
761
            sequence.at(i).second.element_id_ = transition["element_id"];
61✔
762
        }
61✔
763
    } else {
54✔
764
        throw std::runtime_error("expected sequence type");
×
765
    }
×
766
}
54✔
767

768
void JSONSerializer::json_to_block_node(
769
    const nlohmann::json& j,
770
    builder::StructuredSDFGBuilder& builder,
771
    structured_control_flow::Sequence& parent,
772
    control_flow::Assignments& assignments
773
) {
40✔
774
    assert(j.contains("type"));
40✔
775
    assert(j["type"].is_string());
40✔
776
    assert(j.contains("dataflow"));
40✔
777
    assert(j["dataflow"].is_object());
40✔
778
    auto& block = builder.add_block(parent, assignments, json_to_debug_info(j["debug_info"]));
40✔
779
    block.element_id_ = j["element_id"];
40✔
780
    assert(j["dataflow"].contains("type"));
40✔
781
    assert(j["dataflow"]["type"].is_string());
40✔
782
    std::string type = j["dataflow"]["type"];
40✔
783
    if (type == "dataflow") {
40✔
784
        json_to_dataflow(j["dataflow"], builder, block);
40✔
785
    } else {
40✔
786
        throw std::runtime_error("Unknown dataflow type");
×
787
    }
×
788
}
40✔
789

790
void JSONSerializer::json_to_for_node(
791
    const nlohmann::json& j,
792
    builder::StructuredSDFGBuilder& builder,
793
    structured_control_flow::Sequence& parent,
794
    control_flow::Assignments& assignments
795
) {
17✔
796
    assert(j.contains("type"));
17✔
797
    assert(j["type"].is_string());
17✔
798
    assert(j.contains("indvar"));
17✔
799
    assert(j["indvar"].is_string());
17✔
800
    assert(j.contains("init"));
17✔
801
    assert(j["init"].is_string());
17✔
802
    assert(j.contains("condition"));
17✔
803
    assert(j["condition"].is_string());
17✔
804
    assert(j.contains("update"));
17✔
805
    assert(j["update"].is_string());
17✔
806
    assert(j.contains("root"));
17✔
807
    assert(j["root"].is_object());
17✔
808

809
    symbolic::Symbol indvar = symbolic::symbol(j["indvar"]);
17✔
810
    auto init = symbolic::parse(j["init"].get<std::string>());
17✔
811
    auto update = symbolic::parse(j["update"].get<std::string>());
17✔
812

813
    auto condition_expr = symbolic::parse(j["condition"].get<std::string>());
17✔
814
    symbolic::Condition condition = SymEngine::rcp_dynamic_cast<const SymEngine::Boolean>(condition_expr);
17✔
815
    if (condition.is_null()) {
17✔
816
        throw InvalidSDFGException("For loop condition is not a boolean expression");
×
817
    }
×
818

819
    auto& for_node =
17✔
820
        builder.add_for(parent, indvar, condition, init, update, assignments, json_to_debug_info(j["debug_info"]));
17✔
821
    for_node.element_id_ = j["element_id"];
17✔
822

823
    assert(j["root"].contains("type"));
17✔
824
    assert(j["root"]["type"].is_string());
17✔
825
    assert(j["root"]["type"] == "sequence");
17✔
826
    json_to_sequence(j["root"], builder, for_node.root());
17✔
827
}
17✔
828

829
void JSONSerializer::json_to_if_else_node(
830
    const nlohmann::json& j,
831
    builder::StructuredSDFGBuilder& builder,
832
    structured_control_flow::Sequence& parent,
833
    control_flow::Assignments& assignments
834
) {
1✔
835
    assert(j.contains("type"));
1✔
836
    assert(j["type"].is_string());
1✔
837
    assert(j["type"] == "if_else");
1✔
838
    assert(j.contains("branches"));
1✔
839
    assert(j["branches"].is_array());
1✔
840
    auto& if_else_node = builder.add_if_else(parent, assignments, json_to_debug_info(j["debug_info"]));
1✔
841
    if_else_node.element_id_ = j["element_id"];
1✔
842
    for (const auto& branch : j["branches"]) {
2✔
843
        assert(branch.contains("condition"));
2✔
844
        assert(branch["condition"].is_string());
2✔
845
        assert(branch.contains("root"));
2✔
846
        assert(branch["root"].is_object());
2✔
847

848
        auto condition_expr = symbolic::parse(branch["condition"].get<std::string>());
2✔
849
        symbolic::Condition condition = SymEngine::rcp_dynamic_cast<const SymEngine::Boolean>(condition_expr);
2✔
850
        if (condition.is_null()) {
2✔
851
            throw InvalidSDFGException("If condition is not a boolean expression");
×
852
        }
×
853
        auto& branch_node = builder.add_case(if_else_node, condition);
2✔
854
        assert(branch["root"].contains("type"));
2✔
855
        assert(branch["root"]["type"].is_string());
2✔
856
        std::string type = branch["root"]["type"];
2✔
857
        if (type == "sequence") {
2✔
858
            json_to_sequence(branch["root"], builder, branch_node);
2✔
859
        } else {
2✔
860
            throw std::runtime_error("Unknown child type");
×
861
        }
×
862
    }
2✔
863
}
1✔
864

865
void JSONSerializer::json_to_while_node(
866
    const nlohmann::json& j,
867
    builder::StructuredSDFGBuilder& builder,
868
    structured_control_flow::Sequence& parent,
869
    control_flow::Assignments& assignments
870
) {
3✔
871
    assert(j.contains("type"));
3✔
872
    assert(j["type"].is_string());
3✔
873
    assert(j["type"] == "while");
3✔
874
    assert(j.contains("root"));
3✔
875
    assert(j["root"].is_object());
3✔
876

877
    auto& while_node = builder.add_while(parent, assignments, json_to_debug_info(j["debug_info"]));
3✔
878
    while_node.element_id_ = j["element_id"];
3✔
879

880
    assert(j["root"]["type"] == "sequence");
3✔
881
    json_to_sequence(j["root"], builder, while_node.root());
3✔
882
}
3✔
883

884
void JSONSerializer::json_to_break_node(
885
    const nlohmann::json& j,
886
    builder::StructuredSDFGBuilder& builder,
887
    structured_control_flow::Sequence& parent,
888
    control_flow::Assignments& assignments
889
) {
1✔
890
    assert(j.contains("type"));
1✔
891
    assert(j["type"].is_string());
1✔
892
    assert(j["type"] == "break");
1✔
893
    auto& node = builder.add_break(parent, assignments, json_to_debug_info(j["debug_info"]));
1✔
894
    node.element_id_ = j["element_id"];
1✔
895
}
1✔
896

897
void JSONSerializer::json_to_continue_node(
898
    const nlohmann::json& j,
899
    builder::StructuredSDFGBuilder& builder,
900
    structured_control_flow::Sequence& parent,
901
    control_flow::Assignments& assignments
902
) {
1✔
903
    assert(j.contains("type"));
1✔
904
    assert(j["type"].is_string());
1✔
905
    assert(j["type"] == "continue");
1✔
906
    auto& node = builder.add_continue(parent, assignments, json_to_debug_info(j["debug_info"]));
1✔
907
    node.element_id_ = j["element_id"];
1✔
908
}
1✔
909

910
void JSONSerializer::json_to_map_node(
911
    const nlohmann::json& j,
912
    builder::StructuredSDFGBuilder& builder,
913
    structured_control_flow::Sequence& parent,
914
    control_flow::Assignments& assignments
915
) {
5✔
916
    assert(j.contains("type"));
5✔
917
    assert(j["type"].is_string());
5✔
918
    assert(j["type"] == "map");
5✔
919
    assert(j.contains("indvar"));
5✔
920
    assert(j["indvar"].is_string());
5✔
921
    assert(j.contains("init"));
5✔
922
    assert(j["init"].is_string());
5✔
923
    assert(j.contains("condition"));
5✔
924
    assert(j["condition"].is_string());
5✔
925
    assert(j.contains("update"));
5✔
926
    assert(j["update"].is_string());
5✔
927
    assert(j.contains("root"));
5✔
928
    assert(j["root"].is_object());
5✔
929
    assert(j.contains("schedule_type"));
5✔
930
    assert(j["schedule_type"].is_object());
5✔
931

932
    structured_control_flow::ScheduleType schedule_type = json_to_schedule_type(j["schedule_type"]);
5✔
933

934
    symbolic::Symbol indvar = symbolic::symbol(j["indvar"]);
5✔
935
    auto init = symbolic::parse(j["init"].get<std::string>());
5✔
936
    auto update = symbolic::parse(j["update"].get<std::string>());
5✔
937
    auto condition_expr = symbolic::parse(j["condition"].get<std::string>());
5✔
938
    symbolic::Condition condition = SymEngine::rcp_dynamic_cast<const SymEngine::Boolean>(condition_expr);
5✔
939
    if (condition.is_null()) {
5✔
940
        throw InvalidSDFGException("Map condition is not a boolean expression");
×
941
    }
×
942

943
    auto& map_node = builder.add_map(
5✔
944
        parent, indvar, condition, init, update, schedule_type, assignments, json_to_debug_info(j["debug_info"])
5✔
945
    );
5✔
946
    map_node.element_id_ = j["element_id"];
5✔
947

948
    assert(j["root"].contains("type"));
5✔
949
    assert(j["root"]["type"].is_string());
5✔
950
    assert(j["root"]["type"] == "sequence");
5✔
951
    json_to_sequence(j["root"], builder, map_node.root());
5✔
952
}
5✔
953

954
void JSONSerializer::json_to_return_node(
955
    const nlohmann::json& j,
956
    builder::StructuredSDFGBuilder& builder,
957
    structured_control_flow::Sequence& parent,
958
    control_flow::Assignments& assignments
959
) {
1✔
960
    assert(j.contains("type"));
1✔
961
    assert(j["type"].is_string());
1✔
962
    assert(j["type"] == "return");
1✔
963

964
    std::string data = j["data"];
1✔
965
    std::unique_ptr<types::IType> data_type = nullptr;
1✔
966
    if (j.contains("data_type")) {
1✔
967
        data_type = json_to_type(j["data_type"]);
×
968
    }
×
969

970
    if (data_type == nullptr) {
1✔
971
        auto& node = builder.add_return(parent, data, assignments, json_to_debug_info(j["debug_info"]));
1✔
972
        node.element_id_ = j["element_id"];
1✔
973
    } else {
1✔
974
        auto& node =
×
975
            builder.add_constant_return(parent, data, *data_type, assignments, json_to_debug_info(j["debug_info"]));
×
976
        node.element_id_ = j["element_id"];
×
977
    }
×
978
}
1✔
979

980
std::unique_ptr<types::IType> JSONSerializer::json_to_type(const nlohmann::json& j) {
484✔
981
    if (j.contains("type")) {
484✔
982
        if (j["type"] == "scalar") {
484✔
983
            // Deserialize scalar type
984
            assert(j.contains("primitive_type"));
358✔
985
            types::PrimitiveType primitive_type = j["primitive_type"];
358✔
986
            assert(j.contains("storage_type"));
358✔
987
            types::StorageType storage_type = json_to_storage_type(j["storage_type"]);
358✔
988
            assert(j.contains("initializer"));
358✔
989
            std::string initializer = j["initializer"];
358✔
990
            assert(j.contains("alignment"));
358✔
991
            size_t alignment = j["alignment"];
358✔
992
            return std::make_unique<types::Scalar>(storage_type, alignment, initializer, primitive_type);
358✔
993
        } else if (j["type"] == "array") {
358✔
994
            // Deserialize array type
995
            assert(j.contains("element_type"));
69✔
996
            std::unique_ptr<types::IType> member_type = json_to_type(j["element_type"]);
69✔
997
            assert(j.contains("num_elements"));
69✔
998
            std::string num_elements_str = j["num_elements"];
69✔
999
            // Convert num_elements_str to symbolic::Expression
1000
            auto num_elements = symbolic::parse(num_elements_str);
69✔
1001
            assert(j.contains("storage_type"));
69✔
1002
            types::StorageType storage_type = json_to_storage_type(j["storage_type"]);
69✔
1003
            assert(j.contains("initializer"));
69✔
1004
            std::string initializer = j["initializer"];
69✔
1005
            assert(j.contains("alignment"));
69✔
1006
            size_t alignment = j["alignment"];
69✔
1007
            return std::make_unique<types::Array>(storage_type, alignment, initializer, *member_type, num_elements);
69✔
1008
        } else if (j["type"] == "pointer") {
69✔
1009
            // Deserialize pointer type
1010
            std::optional<std::unique_ptr<types::IType>> pointee_type;
46✔
1011
            if (j.contains("pointee_type")) {
46✔
1012
                assert(j.contains("pointee_type"));
45✔
1013
                pointee_type = json_to_type(j["pointee_type"]);
45✔
1014
            } else {
45✔
1015
                pointee_type = std::nullopt;
1✔
1016
            }
1✔
1017
            assert(j.contains("storage_type"));
46✔
1018
            types::StorageType storage_type = json_to_storage_type(j["storage_type"]);
46✔
1019
            assert(j.contains("initializer"));
46✔
1020
            std::string initializer = j["initializer"];
46✔
1021
            assert(j.contains("alignment"));
46✔
1022
            size_t alignment = j["alignment"];
46✔
1023
            if (pointee_type.has_value()) {
46✔
1024
                return std::make_unique<types::Pointer>(storage_type, alignment, initializer, *pointee_type.value());
45✔
1025
            } else {
45✔
1026
                return std::make_unique<types::Pointer>(storage_type, alignment, initializer);
1✔
1027
            }
1✔
1028
        } else if (j["type"] == "structure") {
46✔
1029
            // Deserialize structure type
1030
            assert(j.contains("name"));
3✔
1031
            std::string name = j["name"];
3✔
1032
            assert(j.contains("storage_type"));
3✔
1033
            types::StorageType storage_type = json_to_storage_type(j["storage_type"]);
3✔
1034
            assert(j.contains("initializer"));
3✔
1035
            std::string initializer = j["initializer"];
3✔
1036
            assert(j.contains("alignment"));
3✔
1037
            size_t alignment = j["alignment"];
3✔
1038
            return std::make_unique<types::Structure>(storage_type, alignment, initializer, name);
3✔
1039
        } else if (j["type"] == "function") {
8✔
1040
            // Deserialize function type
1041
            assert(j.contains("return_type"));
4✔
1042
            std::unique_ptr<types::IType> return_type = json_to_type(j["return_type"]);
4✔
1043
            assert(j.contains("params"));
4✔
1044
            std::vector<std::unique_ptr<types::IType>> params;
4✔
1045
            for (const auto& param : j["params"]) {
10✔
1046
                params.push_back(json_to_type(param));
10✔
1047
            }
10✔
1048
            assert(j.contains("is_var_arg"));
4✔
1049
            bool is_var_arg = j["is_var_arg"];
4✔
1050
            assert(j.contains("storage_type"));
4✔
1051
            types::StorageType storage_type = json_to_storage_type(j["storage_type"]);
4✔
1052
            assert(j.contains("initializer"));
4✔
1053
            std::string initializer = j["initializer"];
4✔
1054
            assert(j.contains("alignment"));
4✔
1055
            size_t alignment = j["alignment"];
4✔
1056
            auto function =
4✔
1057
                std::make_unique<types::Function>(storage_type, alignment, initializer, *return_type, is_var_arg);
4✔
1058
            for (const auto& param : params) {
10✔
1059
                function->add_param(*param);
10✔
1060
            }
10✔
1061
            return function->clone();
4✔
1062
        } else if (j["type"] == "reference") {
4✔
1063
            // Deserialize reference type
1064
            assert(j.contains("reference_type"));
4✔
1065
            std::unique_ptr<types::IType> reference_type = json_to_type(j["reference_type"]);
4✔
1066
            return std::make_unique<sdfg::codegen::Reference>(*reference_type);
4✔
1067
        } else if (j["type"] == "tensor") {
4✔
1068
            // Deserialize tensor type
1069
            assert(j.contains("element_type"));
×
1070
            std::unique_ptr<types::IType> element_type = json_to_type(j["element_type"]);
×
1071
            assert(j.contains("shape"));
×
1072
            std::vector<symbolic::Expression> shape;
×
1073
            for (const auto& dim : j["shape"]) {
×
1074
                assert(dim.is_string());
×
1075
                std::string dim_str = dim;
×
1076
                auto expr = symbolic::parse(dim_str);
×
1077
                shape.push_back(expr);
×
1078
            }
×
1079
            assert(j.contains("strides"));
×
1080
            std::vector<symbolic::Expression> strides;
×
1081
            for (const auto& stride : j["strides"]) {
×
1082
                assert(stride.is_string());
×
1083
                std::string stride_str = stride;
×
1084
                auto expr = symbolic::parse(stride_str);
×
1085
                strides.push_back(expr);
×
1086
            }
×
1087
            assert(j.contains("offset"));
×
1088
            symbolic::Expression offset = symbolic::parse(j["offset"].get<std::string>());
×
1089
            assert(j.contains("storage_type"));
×
1090
            types::StorageType storage_type = json_to_storage_type(j["storage_type"]);
×
1091
            assert(j.contains("initializer"));
×
1092
            std::string initializer = j["initializer"];
×
1093
            assert(j.contains("alignment"));
×
1094
            size_t alignment = j["alignment"];
×
1095
            return std::make_unique<types::Tensor>(
×
1096
                storage_type, alignment, initializer, dynamic_cast<types::Scalar&>(*element_type), shape, strides, offset
×
1097
            );
×
1098
        } else {
×
1099
            throw std::runtime_error("Unknown type");
×
1100
        }
×
1101
    } else {
484✔
1102
        throw std::runtime_error("Type not found");
×
1103
    }
×
1104
}
484✔
1105

1106
DebugInfo JSONSerializer::json_to_debug_info(const nlohmann::json& j) {
557✔
1107
    assert(j.contains("has"));
557✔
1108
    assert(j["has"].is_boolean());
557✔
1109
    if (!j["has"]) {
557✔
1110
        return DebugInfo();
553✔
1111
    }
553✔
1112
    assert(j.contains("filename"));
557✔
1113
    assert(j["filename"].is_string());
4✔
1114
    std::string filename = j["filename"];
4✔
1115
    assert(j.contains("function"));
4✔
1116
    assert(j["function"].is_string());
4✔
1117
    std::string function = j["function"];
4✔
1118
    assert(j.contains("start_line"));
4✔
1119
    assert(j["start_line"].is_number_integer());
4✔
1120
    size_t start_line = j["start_line"];
4✔
1121
    assert(j.contains("start_column"));
4✔
1122
    assert(j["start_column"].is_number_integer());
4✔
1123
    size_t start_column = j["start_column"];
4✔
1124
    assert(j.contains("end_line"));
4✔
1125
    assert(j["end_line"].is_number_integer());
4✔
1126
    size_t end_line = j["end_line"];
4✔
1127
    assert(j.contains("end_column"));
4✔
1128
    assert(j["end_column"].is_number_integer());
4✔
1129
    size_t end_column = j["end_column"];
4✔
1130
    return DebugInfo(filename, function, start_line, start_column, end_line, end_column);
4✔
1131
}
4✔
1132

1133
ScheduleType JSONSerializer::json_to_schedule_type(const nlohmann::json& j) {
6✔
1134
    assert(j.contains("value"));
6✔
1135
    assert(j["value"].is_string());
6✔
1136
    // assert(j.contains("category"));
1137
    // assert(j["category"].is_number_integer());
1138
    assert(j.contains("properties"));
6✔
1139
    assert(j["properties"].is_object());
6✔
1140
    ScheduleTypeCategory category = ScheduleTypeCategory::None;
6✔
1141
    if (j.contains("category")) {
6✔
1142
        category = static_cast<ScheduleTypeCategory>(j["category"].get<int>());
6✔
1143
    }
6✔
1144
    ScheduleType schedule_type(j["value"].get<std::string>(), category);
6✔
1145
    for (const auto& [key, value] : j["properties"].items()) {
6✔
1146
        assert(value.is_string());
3✔
1147
        schedule_type.set_property(key, value.get<std::string>());
3✔
1148
    }
3✔
1149
    return schedule_type;
6✔
1150
}
6✔
1151

1152
types::StorageType JSONSerializer::json_to_storage_type(const nlohmann::json& j) {
480✔
1153
    if (!j.contains("value")) {
480✔
1154
        return types::StorageType::CPU_Stack();
×
1155
    }
×
1156
    std::string value = j["value"].get<std::string>();
480✔
1157

1158
    symbolic::Expression allocation_size = SymEngine::null;
480✔
1159
    if (j.contains("allocation_size")) {
480✔
1160
        allocation_size = symbolic::parse(j["allocation_size"].get<std::string>());
×
1161
    }
×
1162

1163
    types::StorageType::AllocationType allocation = j["allocation"];
480✔
1164
    types::StorageType::AllocationType deallocation = j["deallocation"];
480✔
1165

1166
    auto storageType = types::StorageType(j["value"].get<std::string>(), allocation_size, allocation, deallocation);
480✔
1167

1168
    if (j.contains("args")) {
480✔
1169
        nlohmann::json::array_t args = j["args"];
×
1170
        if (args.size() > 0) {
×
1171
            storageType.arg1(symbolic::parse(args[0].get<std::string>()));
×
1172
        }
×
1173
    }
×
1174
    return storageType;
480✔
1175
}
480✔
1176

1177
std::string JSONSerializer::expression(const symbolic::Expression expr) {
298✔
1178
    JSONSymbolicPrinter printer;
298✔
1179
    return printer.apply(expr);
298✔
1180
};
298✔
1181

1182
void JSONSerializer::writeToFile(const StructuredSDFG& sdfg, const std::filesystem::path& file) {
×
1183
    JSONSerializer ser;
×
1184
    auto json = ser.serialize(sdfg);
×
1185

1186
    auto parent_path = file.parent_path();
×
1187
    if (!parent_path.empty()) {
×
1188
        std::filesystem::create_directories(file.parent_path());
×
1189
    }
×
1190

1191
    std::ofstream out(file, std::ofstream::out);
×
1192
    if (!out.is_open()) {
×
1193
        std::cerr << "Could not open file " << file << " for writing JSON output." << std::endl;
×
1194
    }
×
1195
    out << json << std::endl;
×
1196
    out.close();
×
1197
}
×
1198

1199
void JSONSymbolicPrinter::bvisit(const SymEngine::Equality& x) {
×
1200
    str_ = apply(x.get_args()[0]) + " == " + apply(x.get_args()[1]);
×
1201
    str_ = parenthesize(str_);
×
1202
};
×
1203

1204
void JSONSymbolicPrinter::bvisit(const SymEngine::Unequality& x) {
×
1205
    str_ = apply(x.get_args()[0]) + " != " + apply(x.get_args()[1]);
×
1206
    str_ = parenthesize(str_);
×
1207
};
×
1208

1209
void JSONSymbolicPrinter::bvisit(const SymEngine::LessThan& x) {
2✔
1210
    str_ = apply(x.get_args()[0]) + " <= " + apply(x.get_args()[1]);
2✔
1211
    str_ = parenthesize(str_);
2✔
1212
};
2✔
1213

1214
void JSONSymbolicPrinter::bvisit(const SymEngine::StrictLessThan& x) {
22✔
1215
    str_ = apply(x.get_args()[0]) + " < " + apply(x.get_args()[1]);
22✔
1216
    str_ = parenthesize(str_);
22✔
1217
};
22✔
1218

1219
void JSONSymbolicPrinter::bvisit(const SymEngine::Min& x) {
×
1220
    std::ostringstream s;
×
1221
    auto container = x.get_args();
×
1222
    if (container.size() == 1) {
×
1223
        s << apply(*container.begin());
×
1224
    } else {
×
1225
        s << "min(";
×
1226
        s << apply(*container.begin());
×
1227

1228
        // Recursively apply __daisy_min to the arguments
1229
        SymEngine::vec_basic subargs;
×
1230
        for (auto it = ++(container.begin()); it != container.end(); ++it) {
×
1231
            subargs.push_back(*it);
×
1232
        }
×
1233
        auto submin = SymEngine::min(subargs);
×
1234
        s << ", " << apply(submin);
×
1235

1236
        s << ")";
×
1237
    }
×
1238

1239
    str_ = s.str();
×
1240
};
×
1241

1242
void JSONSymbolicPrinter::bvisit(const SymEngine::Max& x) {
×
1243
    std::ostringstream s;
×
1244
    auto container = x.get_args();
×
1245
    if (container.size() == 1) {
×
1246
        s << apply(*container.begin());
×
1247
    } else {
×
1248
        s << "max(";
×
1249
        s << apply(*container.begin());
×
1250

1251
        // Recursively apply __daisy_max to the arguments
1252
        SymEngine::vec_basic subargs;
×
1253
        for (auto it = ++(container.begin()); it != container.end(); ++it) {
×
1254
            subargs.push_back(*it);
×
1255
        }
×
1256
        auto submax = SymEngine::max(subargs);
×
1257
        s << ", " << apply(submax);
×
1258

1259
        s << ")";
×
1260
    }
×
1261

1262
    str_ = s.str();
×
1263
};
×
1264

1265
void LibraryNodeSerializerRegistry::
1266
    register_library_node_serializer(std::string library_node_code, LibraryNodeSerializerFn fn) {
161✔
1267
    std::lock_guard<std::mutex> lock(mutex_);
161✔
1268
    if (factory_map_.find(library_node_code) != factory_map_.end()) {
161✔
1269
        return;
×
1270
    }
×
1271
    factory_map_[library_node_code] = std::move(fn);
161✔
1272
}
161✔
1273

1274
LibraryNodeSerializerFn LibraryNodeSerializerRegistry::get_library_node_serializer(std::string library_node_code) {
17✔
1275
    auto it = factory_map_.find(library_node_code);
17✔
1276
    if (it != factory_map_.end()) {
17✔
1277
        return it->second;
17✔
1278
    }
17✔
1279
    return nullptr;
×
1280
}
17✔
1281

1282
size_t LibraryNodeSerializerRegistry::size() const { return factory_map_.size(); }
×
1283

1284
void register_default_serializers() {
3✔
1285
    // stdlib
1286
    LibraryNodeSerializerRegistry::instance()
3✔
1287
        .register_library_node_serializer(stdlib::LibraryNodeType_Alloca.value(), []() {
3✔
1288
            return std::make_unique<stdlib::AllocaNodeSerializer>();
×
1289
        });
×
1290
    LibraryNodeSerializerRegistry::instance()
3✔
1291
        .register_library_node_serializer(stdlib::LibraryNodeType_Assert.value(), []() {
3✔
1292
            return std::make_unique<stdlib::AssertNodeSerializer>();
×
1293
        });
×
1294
    LibraryNodeSerializerRegistry::instance()
3✔
1295
        .register_library_node_serializer(stdlib::LibraryNodeType_Calloc.value(), []() {
3✔
1296
            return std::make_unique<stdlib::CallocNodeSerializer>();
×
1297
        });
×
1298
    LibraryNodeSerializerRegistry::instance()
3✔
1299
        .register_library_node_serializer(stdlib::LibraryNodeType_Free.value(), []() {
3✔
1300
            return std::make_unique<stdlib::FreeNodeSerializer>();
×
1301
        });
×
1302
    LibraryNodeSerializerRegistry::instance()
3✔
1303
        .register_library_node_serializer(stdlib::LibraryNodeType_Malloc.value(), []() {
3✔
1304
            return std::make_unique<stdlib::MallocNodeSerializer>();
×
1305
        });
×
1306
    LibraryNodeSerializerRegistry::instance()
3✔
1307
        .register_library_node_serializer(stdlib::LibraryNodeType_Memcpy.value(), []() {
3✔
1308
            return std::make_unique<stdlib::MemcpyNodeSerializer>();
×
1309
        });
×
1310
    LibraryNodeSerializerRegistry::instance()
3✔
1311
        .register_library_node_serializer(stdlib::LibraryNodeType_Memmove.value(), []() {
3✔
1312
            return std::make_unique<stdlib::MemmoveNodeSerializer>();
×
1313
        });
×
1314
    LibraryNodeSerializerRegistry::instance()
3✔
1315
        .register_library_node_serializer(stdlib::LibraryNodeType_Memset.value(), []() {
3✔
1316
            return std::make_unique<stdlib::MemsetNodeSerializer>();
×
1317
        });
×
1318
    LibraryNodeSerializerRegistry::instance()
3✔
1319
        .register_library_node_serializer(stdlib::LibraryNodeType_Trap.value(), []() {
3✔
1320
            return std::make_unique<stdlib::TrapNodeSerializer>();
×
1321
        });
×
1322
    LibraryNodeSerializerRegistry::instance()
3✔
1323
        .register_library_node_serializer(stdlib::LibraryNodeType_Unreachable.value(), []() {
3✔
1324
            return std::make_unique<stdlib::UnreachableNodeSerializer>();
×
1325
        });
×
1326

1327
    // Metadata
1328
    LibraryNodeSerializerRegistry::instance()
3✔
1329
        .register_library_node_serializer(data_flow::LibraryNodeType_Metadata.value(), []() {
3✔
1330
            return std::make_unique<data_flow::MetadataNodeSerializer>();
×
1331
        });
×
1332

1333
    // Barrier
1334
    LibraryNodeSerializerRegistry::instance()
3✔
1335
        .register_library_node_serializer(data_flow::LibraryNodeType_BarrierLocal.value(), []() {
3✔
1336
            return std::make_unique<data_flow::BarrierLocalNodeSerializer>();
1✔
1337
        });
1✔
1338

1339
    // Call Node
1340
    LibraryNodeSerializerRegistry::instance()
3✔
1341
        .register_library_node_serializer(data_flow::LibraryNodeType_Call.value(), []() {
6✔
1342
            return std::make_unique<data_flow::CallNodeSerializer>();
6✔
1343
        });
6✔
1344
    LibraryNodeSerializerRegistry::instance()
3✔
1345
        .register_library_node_serializer(data_flow::LibraryNodeType_Invoke.value(), []() {
3✔
1346
            return std::make_unique<data_flow::InvokeNodeSerializer>();
×
1347
        });
×
1348

1349
    // LoadConst
1350
    LibraryNodeSerializerRegistry::instance()
3✔
1351
        .register_library_node_serializer(data_flow::LibraryNodeType_LoadConst.value(), []() {
3✔
1352
            return std::make_unique<data_flow::LoadConstNodeSerializer>();
2✔
1353
        });
2✔
1354

1355
    // CMath
1356
    LibraryNodeSerializerRegistry::instance()
3✔
1357
        .register_library_node_serializer(math::cmath::LibraryNodeType_CMath.value(), []() {
3✔
1358
            return std::make_unique<math::cmath::CMathNodeSerializer>();
×
1359
        });
×
1360
    // Backward compatibility
1361
    LibraryNodeSerializerRegistry::instance()
3✔
1362
        .register_library_node_serializer(math::cmath::LibraryNodeType_CMath_Deprecated.value(), []() {
3✔
1363
            return std::make_unique<math::cmath::CMathNodeSerializer>();
×
1364
        });
×
1365

1366
    // BLAS
1367
    LibraryNodeSerializerRegistry::instance()
3✔
1368
        .register_library_node_serializer(math::blas::LibraryNodeType_DOT.value(), []() {
3✔
1369
            return std::make_unique<math::blas::DotNodeSerializer>();
×
1370
        });
×
1371
    LibraryNodeSerializerRegistry::instance()
3✔
1372
        .register_library_node_serializer(math::blas::LibraryNodeType_GEMM.value(), []() {
3✔
1373
            return std::make_unique<math::blas::GEMMNodeSerializer>();
×
1374
        });
×
1375

1376
    // Tensor
1377

1378
    LibraryNodeSerializerRegistry::instance()
3✔
1379
        .register_library_node_serializer(math::tensor::LibraryNodeType_Broadcast.value(), []() {
3✔
1380
            return std::make_unique<math::tensor::BroadcastNodeSerializer>();
×
1381
        });
×
1382
    LibraryNodeSerializerRegistry::instance()
3✔
1383
        .register_library_node_serializer(math::tensor::LibraryNodeType_Conv.value(), []() {
3✔
1384
            return std::make_unique<math::tensor::ConvNodeSerializer>();
×
1385
        });
×
1386
    LibraryNodeSerializerRegistry::instance()
3✔
1387
        .register_library_node_serializer(math::tensor::LibraryNodeType_Pooling.value(), []() {
3✔
1388
            return std::make_unique<math::tensor::PoolingNodeSerializer>();
×
1389
        });
×
1390
    LibraryNodeSerializerRegistry::instance()
3✔
1391
        .register_library_node_serializer(math::tensor::LibraryNodeType_Transpose.value(), []() {
3✔
1392
            return std::make_unique<math::tensor::TransposeNodeSerializer>();
×
1393
        });
×
1394
    LibraryNodeSerializerRegistry::instance()
3✔
1395
        .register_library_node_serializer(math::tensor::LibraryNodeType_MatMul.value(), []() {
3✔
1396
            return std::make_unique<math::tensor::MatMulNodeSerializer>();
×
1397
        });
×
1398

1399
    // Elementwise
1400
    LibraryNodeSerializerRegistry::instance()
3✔
1401
        .register_library_node_serializer(math::tensor::LibraryNodeType_Abs.value(), []() {
3✔
1402
            return std::make_unique<math::tensor::AbsNodeSerializer>();
×
1403
        });
×
1404
    LibraryNodeSerializerRegistry::instance()
3✔
1405
        .register_library_node_serializer(math::tensor::LibraryNodeType_Add.value(), []() {
3✔
1406
            return std::make_unique<math::tensor::AddNodeSerializer>();
×
1407
        });
×
1408
    LibraryNodeSerializerRegistry::instance()
3✔
1409
        .register_library_node_serializer(math::tensor::LibraryNodeType_Div.value(), []() {
3✔
1410
            return std::make_unique<math::tensor::DivNodeSerializer>();
×
1411
        });
×
1412
    LibraryNodeSerializerRegistry::instance()
3✔
1413
        .register_library_node_serializer(math::tensor::LibraryNodeType_Elu.value(), []() {
3✔
1414
            return std::make_unique<math::tensor::EluNodeSerializer>();
×
1415
        });
×
1416
    LibraryNodeSerializerRegistry::instance()
3✔
1417
        .register_library_node_serializer(math::tensor::LibraryNodeType_Exp.value(), []() {
3✔
1418
            return std::make_unique<math::tensor::ExpNodeSerializer>();
×
1419
        });
×
1420
    LibraryNodeSerializerRegistry::instance()
3✔
1421
        .register_library_node_serializer(math::tensor::LibraryNodeType_Erf.value(), []() {
3✔
1422
            return std::make_unique<math::tensor::ErfNodeSerializer>();
×
1423
        });
×
1424
    LibraryNodeSerializerRegistry::instance()
3✔
1425
        .register_library_node_serializer(math::tensor::LibraryNodeType_HardSigmoid.value(), []() {
3✔
1426
            return std::make_unique<math::tensor::HardSigmoidNodeSerializer>();
×
1427
        });
×
1428
    LibraryNodeSerializerRegistry::instance()
3✔
1429
        .register_library_node_serializer(math::tensor::LibraryNodeType_LeakyReLU.value(), []() {
3✔
1430
            return std::make_unique<math::tensor::LeakyReLUNodeSerializer>();
×
1431
        });
×
1432
    LibraryNodeSerializerRegistry::instance()
3✔
1433
        .register_library_node_serializer(math::tensor::LibraryNodeType_Mul.value(), []() {
3✔
1434
            return std::make_unique<math::tensor::MulNodeSerializer>();
×
1435
        });
×
1436
    LibraryNodeSerializerRegistry::instance()
3✔
1437
        .register_library_node_serializer(math::tensor::LibraryNodeType_Pow.value(), []() {
3✔
1438
            return std::make_unique<math::tensor::PowNodeSerializer>();
×
1439
        });
×
1440
    LibraryNodeSerializerRegistry::instance()
3✔
1441
        .register_library_node_serializer(math::tensor::LibraryNodeType_ReLU.value(), []() {
3✔
1442
            return std::make_unique<math::tensor::ReLUNodeSerializer>();
×
1443
        });
×
1444
    LibraryNodeSerializerRegistry::instance()
3✔
1445
        .register_library_node_serializer(math::tensor::LibraryNodeType_Sigmoid.value(), []() {
3✔
1446
            return std::make_unique<math::tensor::SigmoidNodeSerializer>();
×
1447
        });
×
1448
    LibraryNodeSerializerRegistry::instance()
3✔
1449
        .register_library_node_serializer(math::tensor::LibraryNodeType_Sqrt.value(), []() {
3✔
1450
            return std::make_unique<math::tensor::SqrtNodeSerializer>();
×
1451
        });
×
1452
    LibraryNodeSerializerRegistry::instance()
3✔
1453
        .register_library_node_serializer(math::tensor::LibraryNodeType_Sub.value(), []() {
3✔
1454
            return std::make_unique<math::tensor::SubNodeSerializer>();
×
1455
        });
×
1456
    LibraryNodeSerializerRegistry::instance()
3✔
1457
        .register_library_node_serializer(math::tensor::LibraryNodeType_Tanh.value(), []() {
3✔
1458
            return std::make_unique<math::tensor::TanhNodeSerializer>();
×
1459
        });
×
1460
    LibraryNodeSerializerRegistry::instance()
3✔
1461
        .register_library_node_serializer(math::tensor::LibraryNodeType_Minimum.value(), []() {
3✔
1462
            return std::make_unique<math::tensor::MinimumNodeSerializer>();
×
1463
        });
×
1464
    LibraryNodeSerializerRegistry::instance()
3✔
1465
        .register_library_node_serializer(math::tensor::LibraryNodeType_Maximum.value(), []() {
3✔
1466
            return std::make_unique<math::tensor::MaximumNodeSerializer>();
×
1467
        });
×
1468
    LibraryNodeSerializerRegistry::instance()
3✔
1469
        .register_library_node_serializer(math::tensor::LibraryNodeType_Fill.value(), []() {
3✔
1470
            return std::make_unique<math::tensor::FillNodeSerializer>();
×
1471
        });
×
1472
    LibraryNodeSerializerRegistry::instance()
3✔
1473
        .register_library_node_serializer(math::tensor::LibraryNodeType_TensorTasklet.value(), []() {
3✔
1474
            return std::make_unique<math::tensor::TaskletTensorNodeSerializer>();
×
1475
        });
×
1476
    LibraryNodeSerializerRegistry::instance()
3✔
1477
        .register_library_node_serializer(math::tensor::LibraryNodeType_TensorCMath.value(), []() {
3✔
1478
            return std::make_unique<math::tensor::CMathTensorNodeSerializer>();
×
1479
        });
×
1480
    LibraryNodeSerializerRegistry::instance()
3✔
1481
        .register_library_node_serializer(math::tensor::LibraryNodeType_Cast.value(), []() {
3✔
1482
            return std::make_unique<math::tensor::CastNodeSerializer>();
×
1483
        });
×
1484

1485
    LibraryNodeSerializerRegistry::instance()
3✔
1486
        .register_library_node_serializer(math::tensor::LibraryNodeType_BatchNorm.value(), [] {
3✔
1487
            return std::make_unique<math::tensor::BatchNormNodeSerializer>();
×
1488
        });
×
1489

1490
    // Reduce
1491
    LibraryNodeSerializerRegistry::instance()
3✔
1492
        .register_library_node_serializer(math::tensor::LibraryNodeType_Sum.value(), []() {
3✔
1493
            return std::make_unique<math::tensor::SumNodeSerializer>();
×
1494
        });
×
1495
    LibraryNodeSerializerRegistry::instance()
3✔
1496
        .register_library_node_serializer(math::tensor::LibraryNodeType_Max.value(), []() {
3✔
1497
            return std::make_unique<math::tensor::MaxNodeSerializer>();
×
1498
        });
×
1499
    LibraryNodeSerializerRegistry::instance()
3✔
1500
        .register_library_node_serializer(math::tensor::LibraryNodeType_Min.value(), []() {
3✔
1501
            return std::make_unique<math::tensor::MinNodeSerializer>();
×
1502
        });
×
1503
    LibraryNodeSerializerRegistry::instance()
3✔
1504
        .register_library_node_serializer(math::tensor::LibraryNodeType_Softmax.value(), []() {
3✔
1505
            return std::make_unique<math::tensor::SoftmaxNodeSerializer>();
×
1506
        });
×
1507
    LibraryNodeSerializerRegistry::instance()
3✔
1508
        .register_library_node_serializer(math::tensor::LibraryNodeType_Mean.value(), []() {
3✔
1509
            return std::make_unique<math::tensor::MeanNodeSerializer>();
×
1510
        });
×
1511
    LibraryNodeSerializerRegistry::instance()
3✔
1512
        .register_library_node_serializer(math::tensor::LibraryNodeType_Std.value(), []() {
3✔
1513
            return std::make_unique<math::tensor::StdNodeSerializer>();
×
1514
        });
×
1515

1516
    // Einsum
1517
    LibraryNodeSerializerRegistry::instance()
3✔
1518
        .register_library_node_serializer(math::tensor::LibraryNodeType_Einsum.value(), []() {
3✔
NEW
1519
            return std::make_unique<math::tensor::EinsumSerializer>();
×
UNCOV
1520
        });
×
1521
}
3✔
1522

1523
} // namespace serializer
1524
} // 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