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

daisytuner / docc / 27981272983

22 Jun 2026 08:18PM UTC coverage: 61.754% (-0.03%) from 61.782%
27981272983

Pull #781

github

web-flow
Merge bddaa3724 into fe87d162b
Pull Request #781: Extend Segformer benchmarks setup

987 of 1432 new or added lines in 62 files covered. (68.92%)

9 existing lines in 7 files now uncovered.

38121 of 61730 relevant lines covered (61.75%)

993.19 hits per line

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

67.24
/sdfg/src/data_flow/library_nodes/load_const_node.cpp
1
#include "sdfg/data_flow/library_nodes/load_const_node.h"
2

3
#include "daisy_rtl/base64.h"
4

5
namespace sdfg {
6
namespace data_flow {
7

8
LoadConstNode::LoadConstNode(
9
    size_t element_id,
10
    const DebugInfo& debug_info,
11
    const graph::Vertex vertex,
12
    data_flow::DataFlowGraph& parent,
13
    std::unique_ptr<types::IType> type,
14
    std::unique_ptr<ConstSource> data_source
15
)
16
    : LibraryNode(
3✔
17
          element_id,
3✔
18
          debug_info,
3✔
19
          vertex,
3✔
20
          parent,
3✔
21
          LibraryNodeType_LoadConst,
3✔
22
          {"_out"},
3✔
23
          {},
3✔
24
          true,
3✔
25
          data_flow::ImplementationType_NONE
3✔
26
      ),
3✔
27
      type_(std::move(type)), data_source_(std::move(data_source)) {}
3✔
28

29
symbolic::SymbolSet LoadConstNode::symbols() const { return {}; }
×
30

31
const types::IType& LoadConstNode::type() const { return *type_; }
2✔
32

33
ConstSource& LoadConstNode::data_source() const { return *data_source_; }
4✔
34

35
std::string LoadConstNode::toStr() const { return "LoadConst(" + type_->print() + ": " + data_source_->toStr() + ")"; }
1✔
36

37
std::unique_ptr<data_flow::DataFlowNode> LoadConstNode::
38
    clone(size_t element_id, const graph::Vertex vertex, data_flow::DataFlowGraph& parent) const {
×
39
    return std::make_unique<
×
40
        LoadConstNode>(element_id, debug_info_, vertex, parent, type_->clone(), data_source_->clone());
×
41
}
×
42

43
void LoadConstNode::replace(const symbolic::Expression old_expression, const symbolic::Expression new_expression) {}
×
44

NEW
45
void LoadConstNode::replace(const symbolic::ExpressionMapping& replacements) {}
×
46

47
nlohmann::json LoadConstNodeSerializer::serialize(const data_flow::LibraryNode& library_node) {
1✔
48
    const LoadConstNode& node = static_cast<const LoadConstNode&>(library_node);
1✔
49

50
    nlohmann::json j;
1✔
51
    j["code"] = node.code().value();
1✔
52
    serializer::JSONSerializer serializer;
1✔
53
    serializer.type_to_json(j["load_type"], node.type());
1✔
54
    const_source_to_json(j["source"], node.data_source());
1✔
55

56
    return j;
1✔
57
}
1✔
58

59
void LoadConstNodeSerializer::const_source_to_json(nlohmann::json& j, const ConstSource& source) {
1✔
60
    if (auto* inMemSource = dynamic_cast<const InMemoryConstSource*>(&source)) {
1✔
61
        j["source_type"] = "in_memory";
1✔
62
        j["data"] = base64_encode(inMemSource->data_.data(), inMemSource->data_.size());
1✔
63
    } else if (auto* rawFileSource = dynamic_cast<const RawFileConstSource*>(&source)) {
1✔
64
        j["source_type"] = "raw_file";
×
65
        j["filename"] = rawFileSource->filename().string();
×
66
        j["size"] = rawFileSource->num_bytes();
×
67
    } else {
×
68
        throw InvalidSDFGException("Invalid const source type");
×
69
    }
×
70
}
1✔
71

72
std::unique_ptr<ConstSource> LoadConstNodeSerializer::json_to_const_source(const nlohmann::json& j) {
1✔
73
    std::string source_type = j.at("source_type").get<std::string>();
1✔
74

75
    if (source_type == "in_memory") {
1✔
76
        auto decoded = base64_decode(j.at("data").get<std::string>());
1✔
77
        auto ptr = std::make_unique<InMemoryConstSource>(decoded.size());
1✔
78
        ptr->data_ = std::move(decoded);
1✔
79
        return ptr;
1✔
80
    } else if (source_type == "raw_file") {
1✔
81
        auto filename = j.at("filename").get<std::filesystem::path>();
×
82
        auto size = j.at("size").get<size_t>();
×
83
        return std::make_unique<RawFileConstSource>(filename, size);
×
84
    } else {
×
85
        throw InvalidSDFGException("Invalid const source type '" + source_type + "'");
×
86
    }
×
87
}
1✔
88

89
data_flow::LibraryNode& LoadConstNodeSerializer::deserialize(
90
    const nlohmann::json& j, builder::StructuredSDFGBuilder& builder, structured_control_flow::Block& parent
91
) {
1✔
92
    auto code = j.at("code").get<std::string>();
1✔
93
    if (code != LibraryNodeType_LoadConst.value()) {
1✔
94
        throw InvalidSDFGException("Invalid library node code");
×
95
    }
×
96

97
    sdfg::serializer::JSONSerializer serializer;
1✔
98
    DebugInfo debug_info = serializer.json_to_debug_info(j.at("debug_info"));
1✔
99
    std::unique_ptr<types::IType> type = serializer.json_to_type(j.at("load_type"));
1✔
100

101
    std::unique_ptr<ConstSource> data_source = json_to_const_source(j.at("source"));
1✔
102

103
    return builder.add_library_node<LoadConstNode>(parent, debug_info, std::move(type), std::move(data_source));
1✔
104
}
1✔
105

106
LoadConstNodeDispatcher::LoadConstNodeDispatcher(
107
    codegen::LanguageExtension& language_extension,
108
    const Function& function,
109
    const data_flow::DataFlowGraph& data_flow_graph,
110
    const LoadConstNode& node
111
)
112
    : codegen::LibraryNodeDispatcher(language_extension, function, data_flow_graph, node) {}
1✔
113

114
void LoadConstNodeDispatcher::dispatch_code(
115
    codegen::PrettyPrinter& stream,
116
    codegen::PrettyPrinter& globals_stream,
117
    codegen::CodeSnippetFactory& library_snippet_factory
118
) {
1✔
119
    std::string local_ptr = node_.outputs()[0];
1✔
120
    auto& node = static_cast<const LoadConstNode&>(node_);
1✔
121
    auto& src = node.data_source();
1✔
122
    if (auto* inMemSrc = dynamic_cast<const InMemoryConstSource*>(&src)) {
1✔
123
        dispatch_inline_const(stream, globals_stream, library_snippet_factory, *inMemSrc, local_ptr);
1✔
124
    } else if (auto* rawFileSrc = dynamic_cast<const RawFileConstSource*>(&src)) {
1✔
125
        dispatch_runtime_load(stream, globals_stream, library_snippet_factory, *rawFileSrc, local_ptr);
×
126
    } else {
×
127
        throw InvalidSDFGException("Invalid const source type");
×
128
    }
×
129
}
1✔
130

131
void LoadConstNodeDispatcher::dispatch_inline_const(
132
    codegen::PrettyPrinter& stream,
133
    codegen::PrettyPrinter& globals_stream,
134
    codegen::CodeSnippetFactory& library_snippet_factory,
135
    const ConstSource& source,
136
    const std::string& output_container
137
) {
1✔
138
    std::string identifier = "daisy_load_const_" + std::to_string(node_.element_id());
1✔
139
    globals_stream << "static const uint8_t " << identifier << "[] = {";
1✔
140

141
    auto it = source.inline_begin();
1✔
142
    auto end = source.inline_end();
1✔
143
    bool first = true;
1✔
144
    while (it != end) {
97✔
145
        if (first) {
96✔
146
            first = false;
1✔
147
        } else {
95✔
148
            globals_stream << ", ";
95✔
149
        }
95✔
150
        globals_stream << "0x" << std::hex << +*it << std::dec;
96✔
151
        ++it;
96✔
152
    }
96✔
153
    globals_stream << "};" << std::endl;
1✔
154

155
    auto& node = dynamic_cast<const LoadConstNode&>(node_);
1✔
156

157
    auto target_type = language_extension_.declaration("", node.type());
1✔
158
    stream << output_container << " = " << "const_cast<" << target_type << ">(reinterpret_cast<const " << target_type
1✔
159
           << ">(&" + identifier + "[0]));" << std::endl;
1✔
160
}
1✔
161

162
void LoadConstNodeDispatcher::
163
    ensure_arg_capture_dep(codegen::PrettyPrinter& globals_stream, codegen::CodeSnippetFactory& code_snippet_factory) {
×
164
    auto marker = "arg_capture_includes"; // TODO use modern api to require linking of
×
165

166
    if (code_snippet_factory.find(marker) == code_snippet_factory.snippets().end()) {
×
167
        code_snippet_factory.require(marker, "", false);
×
168
        code_snippet_factory.add_global("#include <daisy_rtl/arg_capture_io.h>");
×
169

170
        globals_stream << std::endl;
×
171
    }
×
172
}
×
173

174
void LoadConstNodeDispatcher::dispatch_runtime_load(
175
    codegen::PrettyPrinter& stream,
176
    codegen::PrettyPrinter& globals_stream,
177
    codegen::CodeSnippetFactory& library_snippet_factory,
178
    const RawFileConstSource& source,
179
    const std::string& output_container
180
) {
×
181
    ensure_arg_capture_dep(globals_stream, library_snippet_factory);
×
182

183
    stream << "arg_capture::ArgCaptureIO::read_data_from_raw_file(" << source.filename().string() << ", "
×
184
           << output_container << ", " << source.num_bytes() << ");" << std::endl;
×
185
}
×
186

187
} // namespace data_flow
188
} // 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