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

daisytuner / sdfglib / 20099967441

10 Dec 2025 01:17PM UTC coverage: 40.379% (+0.04%) from 40.342%
20099967441

push

github

web-flow
Merge pull request #371 from daisytuner/CUDACorrelationFix

Cuda correlation fix

13699 of 43883 branches covered (31.22%)

Branch coverage included in aggregate %.

46 of 69 new or added lines in 4 files covered. (66.67%)

2 existing lines in 2 files now uncovered.

11700 of 19019 relevant lines covered (61.52%)

101.75 hits per line

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

61.98
/src/types/utils.cpp
1
#include "sdfg/types/utils.h"
2
#include <memory>
3
#include <string>
4

5
#include "sdfg/codegen/utils.h"
6
#include "sdfg/function.h"
7
#include "sdfg/symbolic/symbolic.h"
8

9
#include "sdfg/types/structure.h"
10
#include "sdfg/types/type.h"
11

12
namespace sdfg {
13
namespace types {
14

15
const types::IType&
16
infer_type_internal(const sdfg::Function& function, const types::IType& type, const data_flow::Subset& subset) {
2,021✔
17
    if (subset.empty()) {
2,021✔
18
        return type;
1,286✔
19
    }
20

21
    if (type.type_id() == TypeID::Scalar) {
735!
22
        if (!subset.empty()) {
×
23
            throw InvalidSDFGException("Scalar type must have no subset");
×
24
        }
25

26
        return type;
×
27
    } else if (type.type_id() == TypeID::Array) {
735✔
28
        auto& array_type = static_cast<const types::Array&>(type);
724✔
29

30
        data_flow::Subset element_subset(subset.begin() + 1, subset.end());
724!
31
        return infer_type_internal(function, array_type.element_type(), element_subset);
724!
32
    } else if (type.type_id() == TypeID::Structure) {
735!
33
        auto& structure_type = static_cast<const types::Structure&>(type);
11✔
34

35
        data_flow::Subset element_subset(subset.begin() + 1, subset.end());
11!
36

37
        auto& definition = function.structure(structure_type.name());
11!
38
        if (definition.is_vector()) {
11!
39
            return infer_type_internal(function, definition.vector_element_type(), element_subset);
10!
40
        }
41
        auto member = SymEngine::rcp_dynamic_cast<const SymEngine::Integer>(subset.at(0));
1!
42
        return infer_type_internal(function, definition.member_type(member), element_subset);
1!
43
    } else if (type.type_id() == TypeID::Pointer) {
11!
44
        throw InvalidSDFGException("Subset references non-contiguous memory");
×
45
    }
46

47
    throw InvalidSDFGException("Type inference failed because of unknown type");
×
48
};
2,021✔
49

50
const types::IType& infer_type(const sdfg::Function& function, const types::IType& type, const data_flow::Subset& subset) {
2,438✔
51
    if (subset.empty()) {
2,438✔
52
        return type;
1,152✔
53
    }
54

55
    if (type.type_id() == TypeID::Pointer) {
1,286✔
56
        auto& pointer_type = static_cast<const types::Pointer&>(type);
891✔
57
        if (!pointer_type.has_pointee_type()) {
891!
58
            throw InvalidSDFGException("Opaque pointer with non-empty subset");
×
59
        }
60

61
        auto& pointee_type = pointer_type.pointee_type();
891✔
62
        data_flow::Subset element_subset(subset.begin() + 1, subset.end());
891!
63
        return infer_type_internal(function, pointee_type, element_subset);
891!
64
    } else {
891✔
65
        return infer_type_internal(function, type, subset);
395✔
66
    }
67
};
2,438✔
68

69
std::unique_ptr<types::IType> recombine_array_type(const types::IType& type, uint depth, const types::IType& inner_type) {
21✔
70
    if (depth == 0) {
21✔
71
        return inner_type.clone();
9✔
72
    } else {
73
        if (auto atype = dynamic_cast<const types::Array*>(&type)) {
12!
74
            return std::make_unique<types::Array>(
12!
75
                atype->storage_type(),
12✔
76
                atype->alignment(),
12!
77
                atype->initializer(),
12!
78
                *recombine_array_type(atype->element_type(), depth - 1, inner_type).get(),
12!
79
                atype->num_elements()
12!
80
            );
81
        } else {
82
            throw std::runtime_error("construct_type: Non array types are not supported yet!");
×
83
        }
84
    }
85
};
21✔
86

87
const IType& peel_to_innermost_element(const IType& type, int follow_ptr) {
13✔
88
    int next_follow = follow_ptr;
13✔
89
    if (follow_ptr == PEEL_TO_INNERMOST_ELEMENT_FOLLOW_ONLY_OUTER_PTR) {
13✔
90
        next_follow = 0; // only follow an outermost pointer
5✔
91
    }
5✔
92

93
    switch (type.type_id()) {
13!
94
        case TypeID::Array:
95
            return peel_to_innermost_element(dynamic_cast<const types::Array&>(type).element_type(), next_follow);
3!
96
        case TypeID::Reference:
97
            return peel_to_innermost_element(dynamic_cast<const codegen::Reference&>(type).reference_type(), next_follow);
×
98
        case TypeID::Pointer:
99
            if (follow_ptr != 0) {
6✔
100
                if (follow_ptr != PEEL_TO_INNERMOST_ELEMENT_FOLLOW_ONLY_OUTER_PTR) {
5!
101
                    next_follow = follow_ptr - 1; // follow one less pointer
×
102
                }
×
103

104
                auto& pointer_type = dynamic_cast<const types::Pointer&>(type);
5!
105
                if (pointer_type.has_pointee_type()) {
5!
106
                    return peel_to_innermost_element(pointer_type.pointee_type(), next_follow);
5✔
107
                } else {
108
                    return type;
×
109
                }
110
            }
111
            // fall back to cut-off if we did not follow the pointer
112
        default:
113
            return type;
5✔
114
    }
115
}
13✔
116

117
symbolic::Expression get_contiguous_element_size(const types::IType& type, bool allow_comp_time_eval) {
5✔
118
    // need to peel explicitly, primitive_type() would follow ALL pointers, even ***, even though this is not contiguous
119
    auto& innermost = peel_to_innermost_element(type, PEEL_TO_INNERMOST_ELEMENT_FOLLOW_ONLY_OUTER_PTR);
5✔
120
    return get_type_size(innermost, allow_comp_time_eval);
5✔
121
}
122

123
symbolic::Expression get_type_size(const types::IType& type, bool allow_comp_time_eval) {
18✔
124
    bool only_symbolic = false;
18✔
125

126
    auto id = type.type_id();
18✔
127
    if (id == TypeID::Pointer || id == TypeID::Reference || id == TypeID::Function) {
18!
128
        return symbolic::integer(8); // assume 64-bit pointers
3✔
129
    } else if (id == TypeID::Structure) {
15✔
130
        // TODO if we have the target definition, we could evaluate the StructureDefinition to a size
131
        only_symbolic = true;
5✔
132
    } else if (id == TypeID::Array) {
15✔
133
        auto& arr = dynamic_cast<const types::Array&>(type);
1!
134
        auto inner_element_size = get_type_size(arr.element_type(), allow_comp_time_eval);
1✔
135
        if (!inner_element_size.is_null()) {
1!
136
            return symbolic::mul(inner_element_size, arr.num_elements());
1!
137
        } else {
138
            return {};
×
139
        }
140
    }
1✔
141

142
    if (only_symbolic) {
14✔
143
        // Could not statically figure out the size
144
        // Could be struct we could evaluate by its definition or sth. we do not understand here
145
        if (allow_comp_time_eval) {
5✔
146
            return symbolic::size_of_type(type);
4✔
147
        } else { // size unknown
148
            return {};
1✔
149
        }
150
    } else { // should just be a primitive type
151
        auto prim_type = type.primitive_type();
9✔
152

153
        long size_of_type = static_cast<long>(types::bit_width(prim_type)) / 8;
9✔
154
        if (size_of_type != 0) {
9!
155
            return symbolic::integer(size_of_type);
9✔
156
        } else {
157
            return {};
×
158
        }
159
    }
160
}
18✔
161

162
const types::IType* peel_to_next_element(const types::IType& type) {
5✔
163
    switch (type.type_id()) {
5!
164
        case TypeID::Array:
165
            return &dynamic_cast<const types::Array&>(type).element_type();
2!
166
        case TypeID::Reference:
NEW
167
            return &dynamic_cast<const codegen::Reference&>(type).reference_type();
×
168
        case TypeID::Pointer: {
169
            auto& pointer_type = dynamic_cast<const types::Pointer&>(type);
2!
170
            if (pointer_type.has_pointee_type()) {
2!
171
                return &pointer_type.pointee_type();
2✔
172
            } else {
NEW
173
                return nullptr;
×
174
            }
175
        }
176
        default:
177
            return &type;
1✔
178
    }
179
}
5✔
180

181
} // namespace types
182
} // 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