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

daisytuner / sdfglib / 17266091799

27 Aug 2025 12:02PM UTC coverage: 59.728% (-0.03%) from 59.755%
17266091799

push

github

web-flow
Merge pull request #213 from daisytuner/write-loopnest_index-to-instrumentation

Write loopnest index to instrumentation

1 of 9 new or added lines in 2 files covered. (11.11%)

2 existing lines in 1 file now uncovered.

9357 of 15666 relevant lines covered (59.73%)

116.2 hits per line

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

8.62
/src/codegen/instrumentation/instrumentation_plan.cpp
1
#include "sdfg/codegen/instrumentation/instrumentation_plan.h"
2

3
#include "sdfg/analysis/loop_analysis.h"
4

5
namespace sdfg {
6
namespace codegen {
7

8
void InstrumentationPlan::update(const structured_control_flow::ControlFlowNode& node, InstrumentationEventType event_type) {
×
9
    this->nodes_[&node] = event_type;
×
10
}
×
11

12
bool InstrumentationPlan::should_instrument(const structured_control_flow::ControlFlowNode& node) const {
46✔
13
    return this->nodes_.count(&node);
46✔
14
}
15

16
void InstrumentationPlan::begin_instrumentation(const structured_control_flow::ControlFlowNode& node, PrettyPrinter& stream)
×
17
    const {
18
    std::string region_name = sdfg_.name() + "_" + std::to_string(node.element_id());
×
19
    auto& dbg_info = node.debug_info();
×
20

21
    // Create metadata variable
22
    std::string metdata_var = sdfg_.name() + "_" + std::to_string(node.element_id());
×
23
    stream << "__daisy_metadata_t " << metdata_var << ";" << std::endl;
×
24
    stream << metdata_var << ".region_name = \"" << region_name << "\";" << std::endl;
×
25
    stream << metdata_var << ".function_name = \"" << dbg_info.function() << "\";" << std::endl;
×
26
    stream << metdata_var << ".file_name = \"" << dbg_info.filename() << "\";" << std::endl;
×
27
    stream << metdata_var << ".line_begin = " << dbg_info.start_line() << ";" << std::endl;
×
28
    stream << metdata_var << ".line_end = " << dbg_info.end_line() << ";" << std::endl;
×
29
    stream << metdata_var << ".column_begin = " << dbg_info.start_column() << ";" << std::endl;
×
30
    stream << metdata_var << ".column_end = " << dbg_info.end_column() << ";" << std::endl;
×
NEW
31
    if (!(this->loopnest_indices_.empty())) {
×
NEW
32
        stream << metdata_var << ".loopnest_index = " << this->loopnest_indices_.at(&node) << ";" << std::endl;
×
NEW
33
    }
×
34

35
    if (this->nodes_.at(&node) == InstrumentationEventType::CPU) {
×
36
        stream << "__daisy_instrumentation_enter(__daisy_instrumentation_ctx, &" << metdata_var << ", "
×
37
               << "__DAISY_EVENT_SET_CPU" << ");" << std::endl;
×
38
    } else {
×
39
        stream << "__daisy_instrumentation_enter(__daisy_instrumentation_ctx, &" << metdata_var << ", "
×
40
               << "__DAISY_EVENT_SET_CUDA" << ");" << std::endl;
×
41
    }
42
}
×
43

44
void InstrumentationPlan::end_instrumentation(const structured_control_flow::ControlFlowNode& node, PrettyPrinter& stream)
×
45
    const {
46
    std::string metdata_var = sdfg_.name() + "_" + std::to_string(node.element_id());
×
47
    if (this->nodes_.at(&node) == InstrumentationEventType::CPU) {
×
48
        stream << "__daisy_instrumentation_exit(__daisy_instrumentation_ctx, &" << metdata_var << ", "
×
49
               << "__DAISY_EVENT_SET_CPU" << ");" << std::endl;
×
50
    } else {
×
51
        stream << "__daisy_instrumentation_exit(__daisy_instrumentation_ctx, &" << metdata_var << ", "
×
52
               << "__DAISY_EVENT_SET_CUDA" << ");" << std::endl;
×
53
    }
54
}
×
55

56
std::unique_ptr<InstrumentationPlan> InstrumentationPlan::none(StructuredSDFG& sdfg) {
41✔
57
    return std::make_unique<InstrumentationPlan>(
41✔
58
        sdfg, std::unordered_map<const structured_control_flow::ControlFlowNode*, InstrumentationEventType>{}
41✔
59
    );
60
}
×
61

62
std::unique_ptr<InstrumentationPlan> InstrumentationPlan::outermost_loops_plan(StructuredSDFG& sdfg) {
×
63
    analysis::AnalysisManager analysis_manager(sdfg);
×
64
    auto& loop_tree_analysis = analysis_manager.get<analysis::LoopAnalysis>();
×
65
    auto ols = loop_tree_analysis.outermost_loops();
×
66

67
    std::unordered_map<const structured_control_flow::ControlFlowNode*, InstrumentationEventType> nodes;
×
NEW
68
    std::unordered_map<const structured_control_flow::ControlFlowNode*, size_t> loopnest_indices;
×
NEW
69
    for (size_t i = 0; i < ols.size(); i++) {
×
NEW
70
        auto& loop = ols[i];
×
71
        if (auto map_node = dynamic_cast<const structured_control_flow::Map*>(loop)) {
×
72
            if (map_node->schedule_type().value() == "CUDA") {
×
73
                nodes.insert({loop, InstrumentationEventType::CUDA});
×
74
                continue;
×
75
            }
76
        }
×
NEW
77
        loopnest_indices[loop] = i;
×
UNCOV
78
        nodes.insert({loop, InstrumentationEventType::CPU}); // Default to CPU if not CUDA
×
UNCOV
79
    }
×
NEW
80
    return std::make_unique<InstrumentationPlan>(sdfg, nodes, loopnest_indices);
×
81
}
×
82

83
} // namespace codegen
84
} // 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