• 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

15.7
/sdfg/src/data_flow/library_nodes/math/tensor/spatial_tensor_node.cpp
1
#include "sdfg/data_flow/library_nodes/math/tensor/spatial_tensor_node.h"
2

3
namespace sdfg::math::tensor {
4

5

6
SpatialTensorNode::SpatialTensorNode(
7
    size_t element_id,
8
    const DebugInfo& debug_info,
9
    const graph::Vertex vertex,
10
    data_flow::DataFlowGraph& parent,
11
    const data_flow::LibraryNodeCode& code,
12
    const std::vector<std::string>& outputs,
13
    const std::vector<std::string>& inputs,
14
    const data_flow::ImplementationType& impl_type,
15
    QuantizationType quantization,
16
    const std::vector<symbolic::Expression>& shape,
17
    const std::vector<symbolic::Expression>& kernel_shape,
18
    const std::vector<symbolic::Expression>& strides,
19
    const std::vector<symbolic::Expression>& pads,
20
    const std::vector<symbolic::Expression>& dilations
21
)
22
    : TensorNode(element_id, debug_info, vertex, parent, code, outputs, inputs, impl_type), shape_(shape),
62✔
23
      kernel_shape_(kernel_shape), strides_(strides), pads_(pads), dilations_(dilations),
62✔
24
      fixed_quantization_(quantization) {}
62✔
25

26
QuantizationType SpatialTensorNode::fixed_quantization() const { return fixed_quantization_; }
×
27

28
QuantizationType SpatialTensorNode::quantization(const data_flow::DataFlowGraph& data_flow_graph) const {
×
29
    if (fixed_quantization_ != QUANTIZATION_MATCH_INPUTS) {
×
30
        return fixed_quantization_;
×
31
    } else {
×
32
        return this->primitive_type(data_flow_graph);
×
33
    }
×
34
}
×
35

36
std::optional<QuantizationType> SpatialTensorNode::uniform_quantization(const data_flow::DataFlowGraph& data_flow_graph
37
) const {
×
38
    if (fixed_quantization_ != QUANTIZATION_MATCH_INPUTS) {
×
39
        auto inferred = this->primitive_type(data_flow_graph);
×
40
        if (inferred == fixed_quantization_) {
×
41
            return fixed_quantization_;
×
42
        } else {
×
43
            return std::nullopt;
×
44
        }
×
45
    } else {
×
46
        return this->primitive_type(data_flow_graph);
×
47
    }
×
48
}
×
49

50
void SpatialTensorNode::set_fixed_quantization(const QuantizationType quant) { fixed_quantization_ = quant; }
×
51

52
symbolic::SymbolSet SpatialTensorNode::symbols() const {
16✔
53
    symbolic::SymbolSet syms;
16✔
54
    for (auto& expr : shape_) {
64✔
55
        for (auto& atom : symbolic::atoms(expr)) {
64✔
56
            syms.insert(atom);
6✔
57
        }
6✔
58
    }
64✔
59
    for (auto& expr : kernel_shape_) {
32✔
60
        for (auto& atom : symbolic::atoms(expr)) {
32✔
61
            syms.insert(atom);
×
62
        }
×
63
    }
32✔
64
    for (auto& expr : strides_) {
28✔
65
        for (auto& atom : symbolic::atoms(expr)) {
28✔
66
            syms.insert(atom);
×
67
        }
×
68
    }
28✔
69
    for (auto& expr : pads_) {
52✔
70
        for (auto& atom : symbolic::atoms(expr)) {
52✔
71
            syms.insert(atom);
×
72
        }
×
73
    }
52✔
74
    for (auto& expr : dilations_) {
26✔
75
        for (auto& atom : symbolic::atoms(expr)) {
26✔
76
            syms.insert(atom);
×
77
        }
×
78
    }
26✔
79
    return syms;
16✔
80
}
16✔
81

82
void SpatialTensorNode::replace(const symbolic::Expression old_expression, const symbolic::Expression new_expression) {
1✔
83
    for (auto& expr : shape_) {
4✔
84
        expr = symbolic::subs(expr, old_expression, new_expression);
4✔
85
    }
4✔
86
    for (auto& expr : kernel_shape_) {
2✔
87
        expr = symbolic::subs(expr, old_expression, new_expression);
2✔
88
    }
2✔
89
    for (auto& expr : strides_) {
1✔
90
        expr = symbolic::subs(expr, old_expression, new_expression);
×
91
    }
×
92
    for (auto& expr : pads_) {
1✔
93
        expr = symbolic::subs(expr, old_expression, new_expression);
×
94
    }
×
95
    for (auto& expr : dilations_) {
1✔
96
        expr = symbolic::subs(expr, old_expression, new_expression);
×
97
    }
×
98
}
1✔
99

NEW
100
void SpatialTensorNode::replace(const symbolic::ExpressionMapping& replacements) {
×
NEW
101
    for (auto& expr : shape_) {
×
NEW
102
        expr = symbolic::subs(expr, replacements);
×
NEW
103
    }
×
NEW
104
    for (auto& expr : kernel_shape_) {
×
NEW
105
        expr = symbolic::subs(expr, replacements);
×
NEW
106
    }
×
NEW
107
    for (auto& expr : strides_) {
×
NEW
108
        expr = symbolic::subs(expr, replacements);
×
NEW
109
    }
×
NEW
110
    for (auto& expr : pads_) {
×
NEW
111
        expr = symbolic::subs(expr, replacements);
×
NEW
112
    }
×
NEW
113
    for (auto& expr : dilations_) {
×
NEW
114
        expr = symbolic::subs(expr, replacements);
×
NEW
115
    }
×
NEW
116
}
×
117

118
size_t SpatialTensorNode::num_spatial_dims() const {
×
119
    auto& s = shape_;
×
120
    assert(s.size() >= 2);
×
121
    return s.size() - 2;
×
122
}
×
123

124
symbolic::Expression SpatialTensorNode::output_spatial_dim(size_t i) const {
×
125
    size_t n_spatial = num_spatial_dims();
×
126
    assert(i < n_spatial);
×
127

128
    auto& s = shape_;
×
129
    auto& ks = kernel_shape_;
×
130
    auto& st = strides_;
×
131
    auto& pa = pads_;
×
132
    auto& di = dilations_;
×
133

134
    auto d_in = s[2 + i];
×
135
    auto k = ks[i];
×
136

137
    symbolic::Expression stride = st.empty() ? symbolic::Expression(symbolic::one()) : st[i];
×
138
    symbolic::Expression dilation = di.empty() ? symbolic::Expression(symbolic::one()) : di[i];
×
139

140
    // pads layout: [begin_d0, begin_d1, …, end_d0, end_d1, …]
141
    symbolic::Expression pad_begin = pa.empty() ? symbolic::Expression(symbolic::zero()) : pa[i];
×
142
    symbolic::Expression pad_end = pa.empty() ? symbolic::Expression(symbolic::zero()) : pa[n_spatial + i];
×
143

144
    // numerator = D_i + pad_begin + pad_end - dilation * (k - 1) - 1
145
    auto numerator = symbolic::
×
146
        sub(symbolic::add(symbolic::add(d_in, pad_begin), pad_end),
×
147
            symbolic::add(symbolic::mul(dilation, symbolic::sub(k, symbolic::one())), symbolic::one()));
×
148

149
    return symbolic::add(symbolic::div(numerator, stride), symbolic::one());
×
150
}
×
151

152
symbolic::Expression SpatialTensorNode::output_spatial_volume() const {
×
153
    size_t n_spatial = num_spatial_dims();
×
154
    symbolic::Expression result = symbolic::Expression(symbolic::one());
×
155
    for (size_t i = 0; i < n_spatial; ++i) {
×
156
        result = symbolic::mul(result, output_spatial_dim(i));
×
157
    }
×
158
    return result;
×
159
}
×
160

161
symbolic::Expression SpatialTensorNode::kernel_volume() const {
×
162
    auto& ks = kernel_shape_;
×
163
    return SymEngine::mul(ks);
×
164
}
×
165

166
std::basic_ostream<char>& SpatialTensorNode::operator<<(std::basic_ostream<char>& os) const {
×
167
    os << "shape=[";
×
168
    for (size_t i = 0; i < shape_.size(); ++i) {
×
169
        if (i > 0) os << ", ";
×
170
        os << shape_[i]->__str__();
×
171
    }
×
172
    os << "], kernel_shape=[";
×
173
    for (size_t i = 0; i < kernel_shape_.size(); ++i) {
×
174
        if (i > 0) os << ", ";
×
175
        os << kernel_shape_[i]->__str__();
×
176
    }
×
177
    os << "], strides=[";
×
178
    for (size_t i = 0; i < strides_.size(); ++i) {
×
179
        if (i > 0) os << ", ";
×
180
        os << strides_[i]->__str__();
×
181
    }
×
182
    os << "], pads=[";
×
183
    for (size_t i = 0; i < pads_.size(); ++i) {
×
184
        if (i > 0) os << ", ";
×
185
        os << pads_[i]->__str__();
×
186
    }
×
187
    os << "], dilations=[";
×
188
    for (size_t i = 0; i < dilations_.size(); ++i) {
×
189
        if (i > 0) os << ", ";
×
190
        os << dilations_[i]->__str__();
×
191
    }
×
192
    os << "], ";
×
193
    os << "quant=" << types::primitive_type_to_string(fixed_quantization_);
×
194
    return os;
×
195
}
×
196

197
void SpatialTensorNodeBaseSerializer::fill_base_values(const SpatialTensorNode& node, nlohmann::json& j) {
×
198
    j["code"] = node.code().value();
×
199

200
    serializer::JSONSerializer serializer;
×
201

202
    j["shape"] = nlohmann::json::array();
×
203
    for (auto& dim : node.shape()) {
×
204
        j["shape"].push_back(serializer.expression(dim));
×
205
    }
×
206

207
    j["kernel_shape"] = nlohmann::json::array();
×
208
    for (auto& dim : node.kernel_shape()) {
×
209
        j["kernel_shape"].push_back(serializer.expression(dim));
×
210
    }
×
211

212
    j["strides"] = nlohmann::json::array();
×
213
    for (auto& stride : node.strides()) {
×
214
        j["strides"].push_back(serializer.expression(stride));
×
215
    }
×
216

217
    j["pads"] = nlohmann::json::array();
×
218
    for (auto& pad : node.pads()) {
×
219
        j["pads"].push_back(serializer.expression(pad));
×
220
    }
×
221

222
    j["dilations"] = nlohmann::json::array();
×
223
    for (auto& dilation : node.dilations()) {
×
224
        j["dilations"].push_back(serializer.expression(dilation));
×
225
    }
×
226

227
    j["result_quant"] = node.quantization();
×
228
}
×
229

230
SpatialTensorNodeBaseSerializer::BaseDeser SpatialTensorNodeBaseSerializer::deserialize_base_values(const nlohmann::json&
231
                                                                                                        j) {
×
232
    assert(j.contains("element_id"));
×
233
    assert(j.contains("code"));
×
234
    assert(j.contains("debug_info"));
×
235
    assert(j.contains("kernel_shape"));
×
236

237
    std::vector<symbolic::Expression> shape;
×
238
    if (j.contains("shape")) {
×
239
        for (const auto& dim : j["shape"]) {
×
240
            shape.push_back(symbolic::parse(dim.get<std::string>()));
×
241
        }
×
242
    }
×
243

244
    std::vector<symbolic::Expression> kernel_shape;
×
245
    for (const auto& dim : j["kernel_shape"]) {
×
246
        kernel_shape.push_back(symbolic::parse(dim.get<std::string>()));
×
247
    }
×
248

249
    std::vector<symbolic::Expression> strides;
×
250
    if (j.contains("strides")) {
×
251
        for (const auto& stride : j["strides"]) {
×
252
            strides.push_back(symbolic::parse(stride.get<std::string>()));
×
253
        }
×
254
    }
×
255

256
    std::vector<symbolic::Expression> pads;
×
257
    if (j.contains("pads")) {
×
258
        for (const auto& pad : j["pads"]) {
×
259
            pads.push_back(symbolic::parse(pad.get<std::string>()));
×
260
        }
×
261
    }
×
262

263
    std::vector<symbolic::Expression> dilations;
×
264
    if (j.contains("dilations")) {
×
265
        for (const auto& dilation : j["dilations"]) {
×
266
            dilations.push_back(symbolic::parse(dilation.get<std::string>()));
×
267
        }
×
268
    }
×
269

270
    sdfg::serializer::JSONSerializer serializer;
×
271
    DebugInfo debug_info = serializer.json_to_debug_info(j["debug_info"]);
×
272

273
    return {
×
274
        .shape = shape,
×
275
        .kernel_shape = kernel_shape,
×
276
        .strides = strides,
×
277
        .pads = pads,
×
278
        .dilations = dilations,
×
279
        .quantization = deserialize_quantization(j, "result_quant", QUANTIZATION_MATCH_INPUTS),
×
280
        .debug_info = debug_info
×
281
    };
×
282
}
×
283

284
} // namespace sdfg::math::tensor
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