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

daisytuner / sdfglib / 20896124135

11 Jan 2026 01:43PM UTC coverage: 62.33% (-0.07%) from 62.402%
20896124135

push

github

web-flow
Merge pull request #423 from daisytuner/copilot/extend-tensor-nodes-conv

Add ConvNode compatible with ONNX Conv operator with n-dimensional expansion and custom validation

329 of 554 new or added lines in 21 files covered. (59.39%)

2 existing lines in 2 files now uncovered.

15413 of 24728 relevant lines covered (62.33%)

88.61 hits per line

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

0.0
/src/data_flow/library_nodes/invoke_node.cpp
1
#include "sdfg/data_flow/library_nodes/invoke_node.h"
2

3
namespace sdfg {
4
namespace data_flow {
5

6
InvokeNode::InvokeNode(
7
    size_t element_id,
8
    const DebugInfo& debug_info,
9
    const graph::Vertex vertex,
10
    data_flow::DataFlowGraph& parent,
11
    const std::string& callee_name,
12
    const std::vector<std::string>& outputs,
13
    const std::vector<std::string>& inputs
14
)
15
    : LibraryNode(
×
16
          element_id,
×
17
          debug_info,
×
18
          vertex,
×
19
          parent,
×
20
          LibraryNodeType_Invoke,
×
21
          outputs,
×
22
          inputs,
×
23
          true,
×
24
          data_flow::ImplementationType_NONE
×
25
      ),
×
26
      callee_name_(callee_name) {
×
27
    this->outputs_.push_back("_unwind"); // Add unwind output
×
28
}
×
29

30
const std::string& InvokeNode::callee_name() const { return this->callee_name_; }
×
31

32
bool InvokeNode::is_void(const Function& sdfg) const { return outputs_.size() == 1 || outputs_.at(0) != "_ret"; }
×
33

34
bool InvokeNode::is_indirect_call(const Function& sdfg) const {
×
35
    auto& type = sdfg.type(this->callee_name_);
×
36
    return dynamic_cast<const types::Pointer*>(&type) != nullptr;
×
37
}
×
38

39
void InvokeNode::validate(const Function& function) const {
×
NEW
40
    LibraryNode::validate(function);
×
41

42
    if (!function.exists(this->callee_name_)) {
×
43
        throw InvalidSDFGException("InvokeNode: Function '" + this->callee_name_ + "' does not exist.");
×
44
    }
×
45
    auto& type = function.type(this->callee_name_);
×
46
    if (!dynamic_cast<const types::Function*>(&type) && !dynamic_cast<const types::Pointer*>(&type)) {
×
47
        throw InvalidSDFGException("InvokeNode: '" + this->callee_name_ + "' is not a function or pointer.");
×
48
    }
×
49

50
    if (auto func_type = dynamic_cast<const types::Function*>(&type)) {
×
51
        if (!function.is_external(this->callee_name_)) {
×
52
            throw InvalidSDFGException("InvokeNode: Function '" + this->callee_name_ + "' must be declared.");
×
53
        }
×
54
        if (!func_type->is_var_arg() && inputs_.size() != func_type->num_params()) {
×
55
            throw InvalidSDFGException(
×
56
                "InvokeNode: Number of inputs does not match number of function parameters. Expected " +
×
57
                std::to_string(func_type->num_params()) + ", got " + std::to_string(inputs_.size())
×
58
            );
×
59
        }
×
60
        if (!this->is_void(function) && outputs_.size() < 1) {
×
61
            throw InvalidSDFGException(
×
62
                "CallNode: Non-void function must have at least one output to store the return value."
×
63
            );
×
64
        }
×
65
    }
×
66
}
×
67

68
symbolic::SymbolSet InvokeNode::symbols() const { return {symbolic::symbol(this->callee_name_)}; }
×
69

70
std::unique_ptr<data_flow::DataFlowNode> InvokeNode::
71
    clone(size_t element_id, const graph::Vertex vertex, data_flow::DataFlowGraph& parent) const {
×
72
    return std::make_unique<InvokeNode>(element_id, debug_info_, vertex, parent, callee_name_, outputs_, inputs_);
×
73
}
×
74

75
void InvokeNode::replace(const symbolic::Expression old_expression, const symbolic::Expression new_expression) {}
×
76

77
nlohmann::json InvokeNodeSerializer::serialize(const data_flow::LibraryNode& library_node) {
×
78
    const InvokeNode& node = static_cast<const InvokeNode&>(library_node);
×
79

80
    nlohmann::json j;
×
81
    j["code"] = node.code().value();
×
82
    j["callee_name"] = node.callee_name();
×
83
    j["outputs"] = node.outputs();
×
84
    j["inputs"] = node.inputs();
×
85

86
    return j;
×
87
}
×
88

89
data_flow::LibraryNode& InvokeNodeSerializer::deserialize(
90
    const nlohmann::json& j, builder::StructuredSDFGBuilder& builder, structured_control_flow::Block& parent
91
) {
×
92
    assert(j.contains("code"));
×
93
    assert(j.contains("callee_name"));
×
94
    assert(j.contains("outputs"));
×
95
    assert(j.contains("inputs"));
×
96
    assert(j.contains("debug_info"));
×
97

98
    auto code = j["code"].get<std::string>();
×
99
    if (code != LibraryNodeType_Invoke.value()) {
×
100
        throw InvalidSDFGException("Invalid library node code");
×
101
    }
×
102

103
    sdfg::serializer::JSONSerializer serializer;
×
104
    DebugInfo debug_info = serializer.json_to_debug_info(j["debug_info"]);
×
105

106
    std::string callee_name = j["callee_name"].get<std::string>();
×
107
    auto outputs = j["outputs"].get<std::vector<std::string>>();
×
108
    auto inputs = j["inputs"].get<std::vector<std::string>>();
×
109

110
    return builder.add_library_node<InvokeNode>(parent, debug_info, callee_name, outputs, inputs);
×
111
}
×
112

113
InvokeNodeDispatcher::InvokeNodeDispatcher(
114
    codegen::LanguageExtension& language_extension,
115
    const Function& function,
116
    const data_flow::DataFlowGraph& data_flow_graph,
117
    const InvokeNode& node
118
)
119
    : codegen::LibraryNodeDispatcher(language_extension, function, data_flow_graph, node) {}
×
120

121
void InvokeNodeDispatcher::dispatch_code(
122
    codegen::PrettyPrinter& stream,
123
    codegen::PrettyPrinter& globals_stream,
124
    codegen::CodeSnippetFactory& library_snippet_factory
125
) {
×
126
    auto& node = static_cast<const InvokeNode&>(node_);
×
127

128
    stream << "try {" << std::endl;
×
129
    stream.setIndent(stream.indent() + 4);
×
130

131
    if (!node.is_void(function_)) {
×
132
        stream << node.outputs().at(0) << " = ";
×
133
    }
×
134
    if (node.is_indirect_call(function_)) {
×
135
        auto& graph = node.get_parent();
×
136

137
        // Collect return memlet
138
        const data_flow::Memlet* ret_memlet = nullptr;
×
139
        for (auto& oedge : graph.out_edges(node)) {
×
140
            if (oedge.src_conn() == "_ret") {
×
141
                ret_memlet = &oedge;
×
142
                break;
×
143
            }
×
144
        }
×
145

146
        // Collect input memlets
147
        std::unordered_map<std::string, const data_flow::Memlet*> input_memlets;
×
148
        for (auto& iedge : graph.in_edges(node)) {
×
149
            input_memlets[iedge.dst_conn()] = &iedge;
×
150
        }
×
151

152
        // Cast callee to function pointer type
153
        std::string func_ptr_type;
×
154

155
        // Return type
156
        if (ret_memlet) {
×
157
            auto& ret_type = ret_memlet->result_type(function_);
×
158
            func_ptr_type = language_extension_.declaration("", ret_type) + " (*)";
×
159
        } else {
×
160
            func_ptr_type = "void (*)";
×
161
        }
×
162

163
        // Parameters
164
        func_ptr_type += "(";
×
165
        for (size_t i = 0; i < node.inputs().size(); i++) {
×
166
            auto memlet_in = input_memlets.find(node.inputs().at(i));
×
167
            assert(memlet_in != input_memlets.end());
×
168
            auto& in_type = memlet_in->second->result_type(function_);
×
169
            func_ptr_type += language_extension_.declaration("", in_type);
×
170
            if (i < node.inputs().size() - 1) {
×
171
                func_ptr_type += ", ";
×
172
            }
×
173
        }
×
174
        func_ptr_type += ")";
×
175

176
        if (this->language_extension_.language() == "C") {
×
177
            stream << "((" << func_ptr_type << ") " << node.callee_name() << ")" << "(";
×
178
        } else if (this->language_extension_.language() == "C++") {
×
179
            stream << "reinterpret_cast<" << func_ptr_type << ">(" << node.callee_name() << ")" << "(";
×
180
        }
×
181
    } else {
×
182
        stream << this->language_extension_.external_prefix() << node.callee_name() << "(";
×
183
    }
×
184
    for (size_t i = 0; i < node.inputs().size(); ++i) {
×
185
        stream << node.inputs().at(i);
×
186
        if (i < node.inputs().size() - 1) {
×
187
            stream << ", ";
×
188
        }
×
189
    }
×
190
    stream << ")" << ";";
×
191
    stream << std::endl;
×
192

193
    stream << node_.outputs().at(node.outputs().size() - 1) << " = false;" << std::endl;
×
194
    stream.setIndent(stream.indent() - 4);
×
195
    stream << "} catch (...) {" << std::endl;
×
196
    stream.setIndent(stream.indent() + 4);
×
197
    stream << node_.outputs().at(node.outputs().size() - 1) << " = true;" << std::endl;
×
198
    stream.setIndent(stream.indent() - 4);
×
199
    stream << "}" << std::endl;
×
200
}
×
201

202
} // namespace data_flow
203
} // 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