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

daisytuner / sdfglib / 15453311876

04 Jun 2025 09:38PM UTC coverage: 58.159% (-0.3%) from 58.435%
15453311876

push

github

web-flow
Merge pull request #53 from daisytuner/element-ids

uses uuid as element id

206 of 236 new or added lines in 26 files covered. (87.29%)

6 existing lines in 6 files now uncovered.

8105 of 13936 relevant lines covered (58.16%)

107.66 hits per line

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

93.28
/src/visualizer/dot_visualizer.cpp
1
#include "sdfg/visualizer/dot_visualizer.h"
2

3
#include <cstddef>
4
#include <string>
5
#include <utility>
6

7
#include "sdfg/data_flow/access_node.h"
8
#include "sdfg/data_flow/memlet.h"
9
#include "sdfg/schedule.h"
10
#include "sdfg/structured_control_flow/control_flow_node.h"
11
#include "sdfg/structured_control_flow/sequence.h"
12
#include "sdfg/structured_sdfg.h"
13

14
namespace sdfg {
15
namespace visualizer {
16

17
void DotVisualizer::visualizeBlock(Schedule& schedule, structured_control_flow::Block& block) {
179✔
18
    this->stream_ << "subgraph cluster_" << block.element_id() << " {" << std::endl;
179✔
19
    this->stream_.setIndent(this->stream_.indent() + 4);
179✔
20
    this->stream_ << "style=filled;shape=box;fillcolor=white;color=black;label=\"\";" << std::endl;
179✔
21
    this->last_comp_name_cluster_ = "cluster_" + block.element_id();
179✔
22
    if (block.dataflow().nodes().empty()) {
179✔
23
        this->stream_ << block.element_id() << " [shape=point,style=invis,label=\"\"];"
4✔
24
                      << std::endl;
2✔
25
        this->stream_.setIndent(this->stream_.indent() - 4);
2✔
26
        this->stream_ << "}" << std::endl;
2✔
27
        this->last_comp_name_ = block.element_id();
2✔
28
        return;
2✔
29
    }
30
    this->last_comp_name_.clear();
177✔
31
    std::list<data_flow::DataFlowNode*> nodes = block.dataflow().topological_sort();
177✔
32
    for (data_flow::DataFlowNode* node : nodes) {
545✔
33
        if (const data_flow::Tasklet* tasklet = dynamic_cast<data_flow::Tasklet*>(node)) {
368✔
34
            this->stream_ << tasklet->element_id() << " [shape=octagon,label=\""
354✔
35
                          << tasklet->output(0).first << " = ";
177✔
36
            this->visualizeTasklet(*tasklet);
177✔
37
            this->stream_ << "\"];" << std::endl;
177✔
38
            for (data_flow::Memlet& iedge : block.dataflow().in_edges(*tasklet)) {
192✔
39
                data_flow::AccessNode const& src =
15✔
40
                    dynamic_cast<data_flow::AccessNode const&>(iedge.src());
15✔
41
                this->stream_ << src.element_id() << " -> " << tasklet->element_id()
30✔
42
                              << " [label=\"   " << iedge.dst_conn() << " = " << src.data();
15✔
43
                if (!symbolic::is_nvptx(symbolic::symbol(src.data()))) {
15✔
44
                    types::IType const& type = schedule.sdfg().type(src.data());
15✔
45
                    this->visualizeSubset(schedule.sdfg(), type, iedge.subset());
15✔
46
                }
15✔
47
                this->stream_ << "   \"];" << std::endl;
15✔
48
            }
49
            for (data_flow::Memlet& oedge : block.dataflow().out_edges(*tasklet)) {
354✔
50
                data_flow::AccessNode const& dst =
177✔
51
                    dynamic_cast<data_flow::AccessNode const&>(oedge.dst());
177✔
52
                types::IType const& type = schedule.sdfg().type(dst.data());
177✔
53
                this->stream_ << tasklet->element_id() << " -> " << dst.element_id()
354✔
54
                              << " [label=\"   " << dst.data();
177✔
55
                this->visualizeSubset(schedule.sdfg(), type, oedge.subset());
177✔
56
                this->stream_ << " = " << oedge.src_conn() << "   \"];" << std::endl;
177✔
57
            }
58
            if (this->last_comp_name_.empty()) this->last_comp_name_ = tasklet->element_id();
177✔
59
        } else if (const data_flow::AccessNode* access_node =
368✔
60
                       dynamic_cast<data_flow::AccessNode*>(node)) {
191✔
61
            bool source = false, sink = false;
190✔
62
            for (data_flow::Memlet& edge : block.dataflow().out_edges(*access_node)) {
190✔
63
                if ((source = (edge.src_conn() == "void"))) break;
14✔
64
            }
65
            for (data_flow::Memlet& edge : block.dataflow().in_edges(*access_node)) {
190✔
66
                if ((sink = (edge.dst_conn() == "void"))) break;
177✔
67
            }
68
            if (!source && !sink) continue;
190✔
69
            this->stream_ << access_node->element_id() << " [";
190✔
70
            if (!schedule.sdfg().is_internal(access_node->data())) this->stream_ << "penwidth=3.0,";
190✔
71
            if (schedule.sdfg().is_transient(access_node->data()))
190✔
72
                this->stream_ << "style=\"dashed,filled\",";
178✔
73
            this->stream_ << "label=\"" << access_node->data() << "\"];" << std::endl;
190✔
74
        } else if (const data_flow::LibraryNode* libnode =
191✔
75
                       dynamic_cast<data_flow::LibraryNode*>(node)) {
1✔
76
            this->stream_ << libnode->element_id() << " [shape=doubleoctagon,label=\"";
1✔
77
            this->visualizeLibraryNode(libnode->call());
1✔
78
            this->stream_ << "\"];" << std::endl;
1✔
79
            if (this->last_comp_name_.empty()) this->last_comp_name_ = libnode->element_id();
1✔
80
        }
1✔
81
    }
82
    this->stream_.setIndent(this->stream_.indent() - 4);
177✔
83
    this->stream_ << "}" << std::endl;
177✔
84
}
179✔
85

86
void DotVisualizer::visualizeSequence(Schedule& schedule,
189✔
87
                                      structured_control_flow::Sequence& sequence) {
88
    std::string last_comp_name_tmp, last_comp_name_cluster_tmp;
189✔
89
    for (size_t i = 0; i < sequence.size(); ++i) {
386✔
90
        std::pair<ControlFlowNode&, Transition&> child = sequence.at(i);
197✔
91
        this->visualizeNode(schedule, child.first);
197✔
92
        if ((i > 0) && !last_comp_name_tmp.empty() && !this->last_comp_name_.empty()) {
197✔
93
            this->stream_ << last_comp_name_tmp << " -> " << this->last_comp_name_ << " [";
8✔
94
            if (!last_comp_name_cluster_tmp.empty())
8✔
95
                this->stream_ << "ltail=\"" << last_comp_name_cluster_tmp << "\",";
8✔
96
            if (!this->last_comp_name_cluster_.empty())
8✔
97
                this->stream_ << "lhead=\"" << this->last_comp_name_cluster_ << "\",";
6✔
98
            this->stream_ << "minlen=3]"
8✔
99
                          << ";" << std::endl;
8✔
100
        }
8✔
101
        last_comp_name_tmp = this->last_comp_name_;
197✔
102
        this->last_comp_name_.clear();
197✔
103
        last_comp_name_cluster_tmp = this->last_comp_name_cluster_;
197✔
104
        this->last_comp_name_cluster_.clear();
197✔
105
    }
197✔
106
}
189✔
107

108
void DotVisualizer::visualizeIfElse(Schedule& schedule, structured_control_flow::IfElse& if_else) {
3✔
109
    this->stream_ << "subgraph cluster_" << if_else.element_id() << " {" << std::endl;
3✔
110
    this->stream_.setIndent(this->stream_.indent() + 4);
3✔
111
    this->stream_ << "style=filled;shape=box;fillcolor=white;color=black;label=\"if:\";"
6✔
112
                  << std::endl
3✔
113
                  << if_else.element_id() << " [shape=point,style=invis,label=\"\"];" << std::endl;
3✔
114
    for (size_t i = 0; i < if_else.size(); ++i) {
9✔
115
        this->stream_ << "subgraph cluster_" << if_else.element_id() << "_" << std::to_string(i)
12✔
116
                      << " {" << std::endl;
6✔
117
        this->stream_.setIndent(this->stream_.indent() + 4);
6✔
118
        this->stream_ << "style=filled;shape=box;fillcolor=white;color=black;label=\""
12✔
119
                      << this->expression(if_else.at(i).second->__str__()) << "\";" << std::endl;
6✔
120
        this->visualizeSequence(schedule, if_else.at(i).first);
6✔
121
        this->stream_.setIndent(this->stream_.indent() - 4);
6✔
122
        this->stream_ << "}" << std::endl;
6✔
123
    }
6✔
124
    this->stream_.setIndent(this->stream_.indent() - 4);
3✔
125
    this->stream_ << "}" << std::endl;
3✔
126
    this->last_comp_name_ = if_else.element_id();
3✔
127
    this->last_comp_name_cluster_ = "cluster_" + if_else.element_id();
3✔
128
}
3✔
129

130
void DotVisualizer::visualizeWhile(Schedule& schedule, structured_control_flow::While& while_loop) {
2✔
131
    this->stream_ << "subgraph cluster_" << while_loop.element_id() << " {" << std::endl;
2✔
132
    this->stream_.setIndent(this->stream_.indent() + 4);
2✔
133
    this->stream_ << "style=filled;shape=box;fillcolor=white;color=black;label=\"while:\";"
4✔
134
                  << std::endl
2✔
135
                  << while_loop.element_id() << " [shape=point,style=invis,label=\"\"];"
2✔
136
                  << std::endl;
2✔
137
    this->visualizeSequence(schedule, while_loop.root());
2✔
138
    this->stream_.setIndent(this->stream_.indent() - 4);
2✔
139
    this->stream_ << "}" << std::endl;
2✔
140
    this->last_comp_name_ = while_loop.element_id();
2✔
141
    this->last_comp_name_cluster_ = "cluster_" + while_loop.element_id();
2✔
142
}
2✔
143

144
void DotVisualizer::visualizeFor(Schedule& schedule, structured_control_flow::For& loop) {
9✔
145
    this->stream_ << "subgraph cluster_" << loop.element_id() << " {" << std::endl;
9✔
146
    this->stream_.setIndent(this->stream_.indent() + 4);
9✔
147
    this->stream_ << "style=filled;shape=box;fillcolor=white;color=black;label=\"for: ";
9✔
148
    this->visualizeForBounds(loop.indvar(), loop.init(), loop.condition(), loop.update());
9✔
149
    LoopSchedule loop_schedule = schedule.loop_schedule(&loop);
9✔
150
    if (loop_schedule == LoopSchedule::VECTORIZATION) this->stream_ << " (vectorized)";
9✔
151
    if (loop_schedule == LoopSchedule::MULTICORE) this->stream_ << " (parallelized)";
9✔
152
    this->stream_ << "\";" << std::endl
18✔
153
                  << loop.element_id() << " [shape=point,style=invis,label=\"\"];" << std::endl;
9✔
154
    this->visualizeSequence(schedule, loop.root());
9✔
155
    this->stream_.setIndent(this->stream_.indent() - 4);
9✔
156
    this->stream_ << "}" << std::endl;
9✔
157
    this->last_comp_name_ = loop.element_id();
9✔
158
    this->last_comp_name_cluster_ = "cluster_" + loop.element_id();
9✔
159
}
9✔
160

161
void DotVisualizer::visualizeReturn(Schedule& schedule,
1✔
162
                                    structured_control_flow::Return& return_node) {
163
    this->stream_ << return_node.element_id() << " [shape=cds,label=\" return  \"];" << std::endl;
1✔
164
    this->last_comp_name_ = return_node.element_id();
1✔
165
    this->last_comp_name_cluster_.clear();
1✔
166
}
1✔
167
void DotVisualizer::visualizeBreak(Schedule& schedule, structured_control_flow::Break& break_node) {
1✔
168
    this->stream_ << break_node.element_id() << " [shape=cds,label=\" break  \"];" << std::endl;
1✔
169
    this->last_comp_name_ = break_node.element_id();
1✔
170
    this->last_comp_name_cluster_.clear();
1✔
171
}
1✔
172

173
void DotVisualizer::visualizeContinue(Schedule& schedule,
1✔
174
                                      structured_control_flow::Continue& continue_node) {
175
    this->stream_ << continue_node.element_id() << " [shape=cds,label=\" continue  \"];"
2✔
176
                  << std::endl;
1✔
177
    this->last_comp_name_ = continue_node.element_id();
1✔
178
    this->last_comp_name_cluster_.clear();
1✔
179
}
1✔
180

181
void DotVisualizer::visualizeKernel(Schedule& schedule,
1✔
182
                                    structured_control_flow::Kernel& kernel_node) {
183
    bool gridDim_x = false;
1✔
184
    bool gridDim_y = false;
1✔
185
    bool gridDim_z = false;
1✔
186
    bool blockDim_x = false;
1✔
187
    bool blockDim_y = false;
1✔
188
    bool blockDim_z = false;
1✔
189
    bool blockIdx_x = false;
1✔
190
    bool blockIdx_y = false;
1✔
191
    bool blockIdx_z = false;
1✔
192
    bool threadIdx_x = false;
1✔
193
    bool threadIdx_y = false;
1✔
194
    bool threadIdx_z = false;
1✔
195

196
    for (std::string const& container : schedule.sdfg().containers()) {
20✔
197
        gridDim_x = gridDim_x || (container == kernel_node.gridDim_x()->get_name());
19✔
198
        gridDim_y = gridDim_y || (container == kernel_node.gridDim_y()->get_name());
19✔
199
        gridDim_z = gridDim_z || (container == kernel_node.gridDim_z()->get_name());
19✔
200
        blockDim_x = blockDim_x || (container == kernel_node.blockDim_x()->get_name());
19✔
201
        blockDim_y = blockDim_y || (container == kernel_node.blockDim_y()->get_name());
19✔
202
        blockDim_z = blockDim_z || (container == kernel_node.blockDim_z()->get_name());
19✔
203
        blockIdx_x = blockIdx_x || (container == kernel_node.blockIdx_x()->get_name());
19✔
204
        blockIdx_y = blockIdx_y || (container == kernel_node.blockIdx_y()->get_name());
19✔
205
        blockIdx_z = blockIdx_z || (container == kernel_node.blockIdx_z()->get_name());
19✔
206
        threadIdx_x = threadIdx_x || (container == kernel_node.threadIdx_x()->get_name());
19✔
207
        threadIdx_y = threadIdx_y || (container == kernel_node.threadIdx_y()->get_name());
19✔
208
        threadIdx_z = threadIdx_z || (container == kernel_node.threadIdx_z()->get_name());
19✔
209
    }
210

211
    size_t replacements_size_before = this->replacements_.size();
1✔
212

213
    if (gridDim_x)
1✔
214
        this->replacements_.push_back(
2✔
215
            {kernel_node.gridDim_x()->get_name(), kernel_node.gridDim_x_init()->__str__()});
1✔
216
    if (gridDim_y)
1✔
217
        this->replacements_.push_back(
2✔
218
            {kernel_node.gridDim_y()->get_name(), kernel_node.gridDim_y_init()->__str__()});
1✔
219
    if (gridDim_z)
1✔
220
        this->replacements_.push_back(
2✔
221
            {kernel_node.gridDim_z()->get_name(), kernel_node.gridDim_z_init()->__str__()});
1✔
222
    if (blockDim_x)
1✔
223
        this->replacements_.push_back(
2✔
224
            {kernel_node.blockDim_x()->get_name(), kernel_node.blockDim_x_init()->__str__()});
1✔
225
    if (blockDim_y)
1✔
226
        this->replacements_.push_back(
2✔
227
            {kernel_node.blockDim_y()->get_name(), kernel_node.blockDim_y_init()->__str__()});
1✔
228
    if (blockDim_z)
1✔
229
        this->replacements_.push_back(
2✔
230
            {kernel_node.blockDim_z()->get_name(), kernel_node.blockDim_z_init()->__str__()});
1✔
231
    if (blockIdx_x)
1✔
232
        this->replacements_.push_back(
2✔
233
            {kernel_node.blockIdx_x()->get_name(), kernel_node.blockIdx_x_init()->__str__()});
1✔
234
    if (blockIdx_y)
1✔
235
        this->replacements_.push_back(
2✔
236
            {kernel_node.blockIdx_y()->get_name(), kernel_node.blockIdx_y_init()->__str__()});
1✔
237
    if (blockIdx_z)
1✔
238
        this->replacements_.push_back(
2✔
239
            {kernel_node.blockIdx_z()->get_name(), kernel_node.blockIdx_z_init()->__str__()});
1✔
240
    if (threadIdx_x)
1✔
241
        this->replacements_.push_back(
2✔
242
            {kernel_node.threadIdx_x()->get_name(), kernel_node.threadIdx_x_init()->__str__()});
1✔
243
    if (threadIdx_y)
1✔
244
        this->replacements_.push_back(
2✔
245
            {kernel_node.threadIdx_y()->get_name(), kernel_node.threadIdx_y_init()->__str__()});
1✔
246
    if (threadIdx_z)
1✔
247
        this->replacements_.push_back(
2✔
248
            {kernel_node.threadIdx_z()->get_name(), kernel_node.threadIdx_z_init()->__str__()});
1✔
249

250
    this->visualizeSequence(schedule, kernel_node.root());
1✔
251

252
    this->replacements_.resize(replacements_size_before);
1✔
253
}
1✔
254

255
void DotVisualizer::visualizeMap(Schedule& schedule, structured_control_flow::Map& map_node) {
×
NEW
256
    this->stream_ << "subgraph cluster_" << map_node.element_id() << " {" << std::endl;
×
257
    this->stream_.setIndent(this->stream_.indent() + 4);
×
258
    this->stream_ << "style=filled;shape=box;fillcolor=white;color=black;label=\"map: ";
×
259
    this->stream_ << map_node.indvar()->get_name() << "[0:";
×
260
    this->stream_ << map_node.num_iterations()->__str__() << "];";
×
261
    LoopSchedule loop_schedule = schedule.loop_schedule(&map_node);
×
262
    if (loop_schedule == LoopSchedule::VECTORIZATION) this->stream_ << " (vectorized)";
×
263
    if (loop_schedule == LoopSchedule::MULTICORE) this->stream_ << " (parallelized)";
×
264
    this->stream_ << "\";" << std::endl
×
NEW
265
                  << map_node.element_id() << " [shape=point,style=invis,label=\"\"];" << std::endl;
×
266
    this->visualizeSequence(schedule, map_node.root());
×
267
    this->stream_.setIndent(this->stream_.indent() - 4);
×
268
    this->stream_ << "}" << std::endl;
×
NEW
269
    this->last_comp_name_ = map_node.element_id();
×
NEW
270
    this->last_comp_name_cluster_ = "cluster_" + map_node.element_id();
×
UNCOV
271
}
×
272

273
void DotVisualizer::visualize() {
171✔
274
    this->stream_.clear();
171✔
275
    this->stream_ << "digraph " << this->schedule_.name() << " {" << std::endl;
171✔
276
    this->stream_.setIndent(4);
171✔
277
    this->stream_ << "graph [compound=true];" << std::endl;
171✔
278
    for (size_t i = 0; i < schedule_.size(); ++i) {
342✔
279
        StructuredSDFG const& sdfg = this->schedule_.schedule(i).sdfg();
171✔
280
        StructuredSDFG& function = this->schedule_.schedule(i).builder().subject();
171✔
281
        this->stream_ << "subgraph cluster_" << sdfg.name() << " {" << std::endl;
171✔
282
        this->stream_.setIndent(8);
171✔
283
        this->stream_ << "node [style=filled,fillcolor=white];" << std::endl
171✔
284
                      << "style=filled;color=lightblue;label=\"";
171✔
285
        std::string condition = this->expression(this->schedule_.condition(i)->__str__());
171✔
286
        if (condition != "True") this->stream_ << condition;
171✔
287
        this->stream_ << "\";" << std::endl;
171✔
288
        this->visualizeSequence(this->schedule_.schedule(i), function.root());
171✔
289
        this->stream_.setIndent(4);
171✔
290
        this->stream_ << "}" << std::endl;
171✔
291
    }
171✔
292
    this->stream_.setIndent(0);
171✔
293
    this->stream_ << "}" << std::endl;
171✔
294
}
171✔
295

296
}  // namespace visualizer
297
}  // 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

© 2025 Coveralls, Inc