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

daisytuner / sdfglib / 16326799612

16 Jul 2025 06:00PM UTC coverage: 64.705% (-0.3%) from 65.036%
16326799612

Pull #144

github

web-flow
Merge 8a7bd93ba into 7d86181a7
Pull Request #144: adds maxpool math instrinsic

0 of 68 new or added lines in 1 file covered. (0.0%)

8653 of 13373 relevant lines covered (64.71%)

176.75 hits per line

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

0.0
/src/data_flow/library_nodes/math/ml/maxpool.cpp
1
#include "sdfg/data_flow/library_nodes/math/ml/maxpool.h"
2

3
#include "sdfg/analysis/analysis.h"
4
#include "sdfg/builder/structured_sdfg_builder.h"
5

6
#include "sdfg/analysis/scope_analysis.h"
7

8
namespace sdfg {
9
namespace math {
10
namespace ml {
11

NEW
12
MaxPoolNode::MaxPoolNode(
×
13
    size_t element_id,
14
    const DebugInfo& debug_info,
15
    const graph::Vertex vertex,
16
    data_flow::DataFlowGraph& parent,
17
    const std::string& output,
18
    const std::string& input,
19
    const std::vector<int>& kernel_shape,
20
    const std::vector<int>& pads,
21
    const std::vector<int>& strides
22
)
NEW
23
    : MathNode(element_id, debug_info, vertex, parent, LibraryNodeType_MaxPool, {output}, {input}),
×
NEW
24
      kernel_shape_(kernel_shape), pads_(pads), strides_(strides) {}
×
25

NEW
26
bool MaxPoolNode::expand(builder::StructuredSDFGBuilder& builder, analysis::AnalysisManager& analysis_manager) {
×
NEW
27
    auto& sdfg = builder.subject();
×
NEW
28
    auto& dataflow = this->get_parent();
×
NEW
29
    auto& block = static_cast<structured_control_flow::Block&>(*dataflow.get_parent());
×
NEW
30
    if (dataflow.in_degree(*this) != 1 || dataflow.out_degree(*this) != 1) {
×
NEW
31
        return false;
×
32
    }
NEW
33
    auto& scope_analyisis = analysis_manager.get<analysis::ScopeAnalysis>();
×
NEW
34
    auto& parent = static_cast<structured_control_flow::Sequence&>(*scope_analyisis.parent_scope(&block));
×
35

NEW
36
    auto& input = this->inputs_.at(0);
×
NEW
37
    auto& output = this->outputs_.at(0);
×
38

NEW
39
    auto& type = sdfg.type(input);
×
NEW
40
    types::Scalar scalar_type(type.primitive_type());
×
41

NEW
42
    auto& iedge = *dataflow.in_edges(*this).begin();
×
NEW
43
    auto& oedge = *dataflow.out_edges(*this).begin();
×
44

45
    // Checks if legal
NEW
46
    auto& input_node = iedge.src();
×
NEW
47
    auto& output_node = oedge.dst();
×
NEW
48
    if (dataflow.in_degree(input_node) != 0 || dataflow.out_degree(output_node) != 0) {
×
NEW
49
        return false;
×
50
    }
51

52
    // Add new graph after the current block
NEW
53
    auto& new_sequence = builder.add_sequence_before(parent, block, block.debug_info()).first;
×
54

55
    // Add output maps
NEW
56
    auto& begin_subsets_out = oedge.begin_subset();
×
NEW
57
    auto& end_subsets_out = oedge.end_subset();
×
NEW
58
    data_flow::Subset new_subset;
×
NEW
59
    structured_control_flow::Sequence* last_scope = &new_sequence;
×
NEW
60
    structured_control_flow::StructuredLoop* last_loop = nullptr;
×
NEW
61
    for (size_t i = 0; i < begin_subsets_out.size(); i++) {
×
NEW
62
        auto& dim_begin = begin_subsets_out[i];
×
NEW
63
        auto& dim_end = end_subsets_out[i];
×
64

NEW
65
        std::string indvar_str = builder.find_new_name("_i");
×
NEW
66
        builder.add_container(indvar_str, types::Scalar(types::PrimitiveType::UInt64));
×
67

NEW
68
        auto indvar = symbolic::symbol(indvar_str);
×
NEW
69
        auto init = dim_begin;
×
NEW
70
        auto update = symbolic::add(indvar, symbolic::one());
×
NEW
71
        auto condition = symbolic::Lt(indvar, symbolic::add(dim_end, symbolic::one()));
×
NEW
72
        last_loop = &builder.add_map(
×
NEW
73
            *last_scope,
×
74
            indvar,
75
            condition,
76
            init,
77
            update,
78
            structured_control_flow::ScheduleType_Sequential,
NEW
79
            {},
×
NEW
80
            block.debug_info()
×
81
        );
NEW
82
        last_scope = &last_loop->root();
×
83

NEW
84
        new_subset.push_back(indvar);
×
NEW
85
    }
×
86

87
    // Add kernel loops
NEW
88
    for (size_t i = 0; i < kernel_shape_.size(); i++) {
×
NEW
89
        auto& kernel_shape = kernel_shape_[i];
×
NEW
90
        auto& pad = pads_[i];
×
NEW
91
        auto& stride = strides_[i];
×
NEW
92
    }
×
93

94
    // Clean up block
NEW
95
    builder.remove_memlet(block, iedge);
×
NEW
96
    builder.remove_memlet(block, oedge);
×
NEW
97
    builder.remove_node(block, input_node);
×
NEW
98
    builder.remove_node(block, output_node);
×
NEW
99
    builder.remove_node(block, *this);
×
NEW
100
    builder.remove_child(parent, block);
×
101

NEW
102
    return true;
×
NEW
103
}
×
104

105
std::unique_ptr<data_flow::DataFlowNode> MaxPoolNode::
NEW
106
    clone(size_t element_id, const graph::Vertex vertex, data_flow::DataFlowGraph& parent) const {
×
NEW
107
    return std::unique_ptr<data_flow::DataFlowNode>(new MaxPoolNode(
×
NEW
108
        element_id,
×
NEW
109
        this->debug_info(),
×
NEW
110
        vertex,
×
NEW
111
        parent,
×
NEW
112
        this->outputs_.at(0),
×
NEW
113
        this->inputs_.at(0),
×
NEW
114
        this->kernel_shape_,
×
NEW
115
        this->pads_,
×
NEW
116
        this->strides_
×
117
    ));
NEW
118
}
×
119

120
} // namespace ml
121
} // namespace math
122
} // 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