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

daisytuner / sdfglib / 15852980623

24 Jun 2025 02:16PM UTC coverage: 64.412% (+0.3%) from 64.145%
15852980623

push

github

web-flow
Merge pull request #72 from daisytuner/capture-instrumentation

Capture instrumentation

363 of 446 new or added lines in 19 files covered. (81.39%)

100 existing lines in 5 files now uncovered.

8389 of 13024 relevant lines covered (64.41%)

116.79 hits per line

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

80.65
/src/codegen/code_generator.cpp
1
#include "sdfg/codegen/code_generator.h"
2
#include <symengine/constants.h>
3
#include <symengine/dict.h>
4
#include <symengine/number.h>
5
#include "sdfg/codegen/instrumentation/capture_var_plan.h"
6
#include "sdfg/analysis/analysis.h"
7
#include "sdfg/analysis/mem_access_range_analysis.h"
8
#include "sdfg/symbolic/symbolic.h"
9
#include "sdfg/types/structure.h"
10

11
namespace sdfg {
12
namespace codegen {
13

14
std::tuple<int, types::PrimitiveType> CodeGenerator::analyze_type_rec(
7✔
15
    symbolic::Expression* dims,
16
    int maxDim,
17
    int dimIdx,
18
    const types::IType& type,
19
    int argIdx,
20
    const analysis::MemAccessRange* range
21
) {
22
    if (dimIdx >= maxDim) {
7✔
NEW
23
        std::cerr << "In '" << sdfg_.name() << "', arg" << argIdx << ": data nesting deeper than " << maxDim << ", ignoring" << std::endl;
×
NEW
24
        return std::make_tuple(-1, types::Void);
×
25
    }
26

27
    if (auto* scalarType = dynamic_cast<const types::Scalar*>(&type)) {
7✔
28
        // std::cerr << "In '" << sdfg_.name() << "', arg" << argIdx << " dim" << dimIdx << ": scalar" << std::endl;
29
        return std::make_tuple(dimIdx, scalarType->primitive_type());
4✔
30
    } else if (auto structureType = dynamic_cast<const sdfg::types::Structure*>(&type)) {
3✔
31
        // std::cerr << "In '" << sdfg_.name() << "', arg" << argIdx << " dim" << dimIdx << ": struct" << std::endl;
NEW
32
        return std::make_tuple(dimIdx, types::Void);
×
33
    } else if (auto* arrayType = dynamic_cast<const types::Array*>(&type)) {
3✔
34
        dims[dimIdx] = arrayType->num_elements();
1✔
35
        auto& inner = arrayType->element_type();
1✔
36

37
        // std::cerr << "In '" << sdfg_.name() << "', arg" << argIdx << " dim" << dimIdx << ": " << language_extension_.expression(dims[dimIdx]) << std::endl;
38

39
        return analyze_type_rec(dims, maxDim, dimIdx+1, inner, argIdx, range);
1✔
40
    } else if (auto* ptrType = dynamic_cast<const types::Pointer*>(&type)) {
2✔
41
        if (range && !range->is_undefined()) {
2✔
42
            
43
            const auto& dim = range->dims()[dimIdx];
2✔
44

45
            if (symbolic::eq(symbolic::zero(), dim.first)) {
2✔
46
                dims[dimIdx] = symbolic::add(dim.second, symbolic::one());
2✔
47
            
48
                auto& inner = ptrType->pointee_type();
2✔
49

50
                return analyze_type_rec(dims, maxDim, dimIdx+1, inner, argIdx, range);
2✔
51
            } else {
NEW
52
                std::cerr << "In '" << sdfg_.name() << "', arg" << argIdx << " dim" << dimIdx << ": has upper bound " << dim.second->__str__() << ", but does not start at 0, cannot capture"  << std::endl;
×
NEW
53
                return std::make_tuple(-2, types::Void);
×
54
            }
55
        } else {
NEW
56
            std::cerr << "In '" << sdfg_.name() << "', arg" << argIdx << " dim" << dimIdx << ": missing range, cannot capture!" << std::endl;
×
NEW
57
            return std::make_tuple(-2, types::Void);
×
58
        }
59
    } else {
NEW
60
        std::cerr << "In '" << sdfg_.name() << "', arg" << argIdx << ": unsupported type " << type.print() << ", cannot capture!" << std::endl;
×
NEW
61
        return std::make_tuple(-1, types::Void);
×
62
    }
63
}
7✔
64

65
bool CodeGenerator::add_capture_plan(
4✔
66
    const std::string& varName,
67
    int argIdx,
68
    bool isExternal,
69
    std::vector<CaptureVarPlan>& plan,
70
    const analysis::MemAccessRanges& ranges
71
) {
72

73
        auto& type = sdfg_.type(varName);
4✔
74

75
        const auto* range = ranges.get(varName);
4✔
76

77
        symbolic::Expression dims[3];
12✔
78

79
        int dimCount;
80
        types::PrimitiveType innerPrim;
81
        std::tie(dimCount, innerPrim) = analyze_type_rec(dims, 3, 0, type, argIdx, range);
4✔
82

83
        bool isRead = range? range->saw_read() : true;
4✔
84
        bool isWritten = range? range->saw_write() : true;
4✔
85

86
        if (dimCount == 0) {
4✔
87
            plan.emplace_back(isRead, false, CaptureVarType::CapRaw, argIdx, isExternal, innerPrim);
2✔
88
        } else if (dimCount == 1) {
4✔
89
            plan.emplace_back(isRead, isWritten, CaptureVarType::Cap1D, argIdx, isExternal, innerPrim, dims[0]);
1✔
90
        } else if (dimCount == 2) {
2✔
91
            plan.emplace_back(isRead, isWritten, CaptureVarType::Cap2D, argIdx, isExternal, innerPrim, dims[0], dims[1]);
1✔
92
        } else if (dimCount == 3) {
1✔
NEW
93
            plan.emplace_back(isRead, isWritten, CaptureVarType::Cap3D, argIdx, isExternal, innerPrim, dims[0], dims[1], dims[2]);
×
NEW
94
        } else {
×
NEW
95
            return false;
×
96
        }
97

98
        return true;
4✔
99
}
4✔
100

101
std::unique_ptr<std::vector<CaptureVarPlan>> CodeGenerator::create_capture_plans() {
1✔
102
    auto name = sdfg_.name();
1✔
103

104
    analysis::AnalysisManager analysis_manager(sdfg_);
1✔
105
    const auto& args = sdfg_.arguments();
1✔
106
    auto& exts = sdfg_.externals();
1✔
107
    const auto& ranges = analysis_manager.get<analysis::MemAccessRanges>();
1✔
108

109
    auto plan = std::make_unique<std::vector<CaptureVarPlan>>();
1✔
110
    
111
    bool working = true;
1✔
112

113
    int argIdx = -1;
1✔
114
    for (auto& argName : args) {
3✔
115
        ++argIdx;
2✔
116

117
        working &= add_capture_plan(argName, argIdx, false, *plan.get(), ranges);
2✔
118
    }
119

120
    for (auto& argName : exts) {
3✔
121
        ++argIdx;
2✔
122

123
        working &= add_capture_plan(argName, argIdx, true, *plan.get(), ranges);
2✔
124
    }
125

126
    return plan;
1✔
127
}
1✔
128

129
}
130
}
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