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

daisytuner / docc / 24408034210

14 Apr 2026 03:32PM UTC coverage: 64.413% (-0.06%) from 64.469%
24408034210

Pull #679

github

web-flow
Merge 7f86463c3 into 505b640ce
Pull Request #679: Single GPU BLAS Handle Instantiation

9 of 92 new or added lines in 15 files covered. (9.78%)

14 existing lines in 7 files now uncovered.

30559 of 47442 relevant lines covered (64.41%)

583.53 hits per line

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

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

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

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

54
    return j;
1✔
55
}
1✔
56

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

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

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

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

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

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

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

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

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

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

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

153
    auto& node = dynamic_cast<const LoadConstNode&>(node_);
1✔
154

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

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

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

168
        globals_stream << std::endl;
×
169
    }
×
170
}
×
171

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

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

185
} // namespace data_flow
186
} // 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