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

daisytuner / sdfglib / 16371692169

18 Jul 2025 01:24PM UTC coverage: 65.106% (+0.1%) from 65.002%
16371692169

Pull #152

github

web-flow
Merge 55d25a916 into f93fe77be
Pull Request #152: adds validate method to all elements

87 of 97 new or added lines in 24 files covered. (89.69%)

10 existing lines in 7 files now uncovered.

8790 of 13501 relevant lines covered (65.11%)

176.82 hits per line

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

84.11
/src/function.cpp
1
#include "sdfg/function.h"
2

3
#include "sdfg/symbolic/symbolic.h"
4

5
using json = nlohmann::json;
6

7
namespace sdfg {
8

9
const std::unique_ptr<types::Scalar> Function::NVPTX_SYMBOL_TYPE =
10
    std::make_unique<types::Scalar>(types::PrimitiveType::UInt32);
2✔
11
const std::unique_ptr<types::Pointer> Function::CONST_POINTER_TYPE =
2✔
12
    std::make_unique<types::Pointer>(types::Scalar(types::PrimitiveType::Void));
2✔
13

14
Function::Function(const std::string& name, FunctionType type) : element_counter_(0), name_(name), type_(type) {
558✔
15
    if (this->type_ == FunctionType_NV_GLOBAL) {
558✔
16
        this->assumptions_[symbolic::threadIdx_x()] =
8✔
17
            symbolic::Assumption::create(symbolic::threadIdx_x(), *NVPTX_SYMBOL_TYPE);
8✔
18
        this->assumptions_[symbolic::threadIdx_y()] =
8✔
19
            symbolic::Assumption::create(symbolic::threadIdx_y(), *NVPTX_SYMBOL_TYPE);
8✔
20
        this->assumptions_[symbolic::threadIdx_z()] =
8✔
21
            symbolic::Assumption::create(symbolic::threadIdx_z(), *NVPTX_SYMBOL_TYPE);
8✔
22
        this->assumptions_[symbolic::blockIdx_x()] =
8✔
23
            symbolic::Assumption::create(symbolic::blockIdx_x(), *NVPTX_SYMBOL_TYPE);
8✔
24
        this->assumptions_[symbolic::blockIdx_y()] =
8✔
25
            symbolic::Assumption::create(symbolic::blockIdx_y(), *NVPTX_SYMBOL_TYPE);
8✔
26
        this->assumptions_[symbolic::blockIdx_z()] =
8✔
27
            symbolic::Assumption::create(symbolic::blockIdx_z(), *NVPTX_SYMBOL_TYPE);
8✔
28
        this->assumptions_[symbolic::blockDim_x()] =
8✔
29
            symbolic::Assumption::create(symbolic::blockDim_x(), *NVPTX_SYMBOL_TYPE);
8✔
30
        this->assumptions_[symbolic::blockDim_y()] =
8✔
31
            symbolic::Assumption::create(symbolic::blockDim_y(), *NVPTX_SYMBOL_TYPE);
8✔
32
        this->assumptions_[symbolic::blockDim_z()] =
8✔
33
            symbolic::Assumption::create(symbolic::blockDim_z(), *NVPTX_SYMBOL_TYPE);
8✔
34
        this->assumptions_[symbolic::gridDim_x()] =
8✔
35
            symbolic::Assumption::create(symbolic::gridDim_x(), *NVPTX_SYMBOL_TYPE);
8✔
36
        this->assumptions_[symbolic::gridDim_y()] =
8✔
37
            symbolic::Assumption::create(symbolic::gridDim_y(), *NVPTX_SYMBOL_TYPE);
8✔
38
        this->assumptions_[symbolic::gridDim_z()] =
8✔
39
            symbolic::Assumption::create(symbolic::gridDim_z(), *NVPTX_SYMBOL_TYPE);
8✔
40
    }
8✔
41
};
558✔
42

43
const std::string& Function::name() const { return this->name_; };
357✔
44

45
std::string& Function::name() { return this->name_; };
388✔
46

47
FunctionType Function::type() const { return this->type_; };
30✔
48

49
void Function::validate() const {
486✔
50
    // Function type
51
    if (this->type_ != FunctionType_CPU && this->type_ != FunctionType_NV_GLOBAL) {
486✔
NEW
52
        throw InvalidSDFGException("Function type must be CPU or NV_GLOBAL");
×
53
    }
54
};
486✔
55

56
bool Function::exists(const std::string& name) const {
836✔
57
    return this->containers_.find(name) != this->containers_.end() || symbolic::is_pointer(symbolic::symbol(name)) ||
852✔
58
           helpers::is_number(name) || symbolic::is_nv(symbolic::symbol(name));
16✔
UNCOV
59
};
×
60

61
const types::IType& Function::type(const std::string& name) const {
1,680✔
62
    if (symbolic::is_nv(symbolic::symbol(name))) {
1,680✔
63
        return *NVPTX_SYMBOL_TYPE;
×
64
    }
65
    if (symbolic::is_pointer(symbolic::symbol(name)) || helpers::is_number(name)) {
1,680✔
66
        return *CONST_POINTER_TYPE;
×
67
    }
68

69
    auto entry = this->containers_.find(name);
1,680✔
70
    if (entry == this->containers_.end()) {
1,680✔
71
        throw InvalidSDFGException("Type: Container " + name + " not found");
×
72
    }
73
    return *entry->second;
1,680✔
74
};
1,680✔
75

76
const types::StructureDefinition& Function::structure(const std::string& name) const {
26✔
77
    auto entry = this->structures_.find(name);
26✔
78
    if (entry == this->structures_.end()) {
26✔
79
        throw InvalidSDFGException("Structure: " + name + " not found");
×
80
    }
81
    return *entry->second;
26✔
82
};
×
83

84
const std::vector<std::string>& Function::arguments() const { return this->arguments_; };
24✔
85

86
const std::vector<std::string>& Function::externals() const { return this->externals_; };
33✔
87

88
bool Function::is_argument(const std::string& name) const {
889✔
89
    return std::find(this->arguments_.begin(), this->arguments_.end(), name) != this->arguments_.end();
889✔
90
};
91

92
bool Function::is_external(const std::string& name) const {
636✔
93
    return std::find(this->externals_.begin(), this->externals_.end(), name) != this->externals_.end();
636✔
94
};
95

96
bool Function::is_internal(const std::string& name) const {
820✔
97
    return helpers::endswith(name, external_suffix) &&
820✔
98
           is_external(name.substr(0, name.length() - external_suffix.length()));
×
99
};
×
100

101
bool Function::is_transient(const std::string& name) const {
877✔
102
    return !this->is_argument(name) && !this->is_external(name) && !this->is_internal(name);
877✔
103
};
104

105
symbolic::SymbolSet Function::parameters() const {
8✔
106
    symbolic::SymbolSet params;
8✔
107
    for (auto& arg : this->arguments_) {
27✔
108
        auto& arg_type = this->type(arg);
19✔
109
        if (auto scalar_type = dynamic_cast<const types::Scalar*>(&arg_type)) {
19✔
110
            if (scalar_type->is_symbol()) {
5✔
111
                params.insert(symbolic::symbol(arg));
5✔
112
            }
5✔
113
        }
5✔
114
    }
115
    for (auto& ext : this->externals_) {
14✔
116
        auto& ext_type = this->type(ext);
6✔
117
        if (auto scalar_type = dynamic_cast<const types::Scalar*>(&ext_type)) {
6✔
118
            if (scalar_type->is_symbol()) {
3✔
119
                params.insert(symbolic::symbol(ext));
3✔
120
            }
3✔
121
        }
3✔
122
    }
123
    return params;
8✔
124
};
8✔
125

126
bool Function::has_assumption(const symbolic::Symbol& symbol) const {
1✔
127
    return this->assumptions_.find(symbol) != this->assumptions_.end();
1✔
128
};
129

130
const symbolic::Assumption& Function::assumption(const symbolic::Symbol& symbol) const {
×
131
    auto entry = this->assumptions_.find(symbol);
×
132
    if (entry == this->assumptions_.end()) {
×
133
        throw InvalidSDFGException("Assumption does not exist in SDFG");
×
134
    }
135
    return entry->second;
×
136
};
×
137

138
symbolic::Assumption& Function::assumption(const symbolic::Symbol& symbol) {
3✔
139
    auto entry = this->assumptions_.find(symbol);
3✔
140
    if (entry == this->assumptions_.end()) {
3✔
141
        throw InvalidSDFGException("Assumption does not exist in SDFG");
×
142
    }
143
    return entry->second;
3✔
144
};
×
145

146
const symbolic::Assumptions& Function::assumptions() const { return this->assumptions_; };
658✔
147

148
void Function::add_metadata(const std::string& key, const std::string& value) { this->metadata_[key] = value; };
6✔
149

150
void Function::remove_metadata(const std::string& key) { this->metadata_.erase(key); };
2✔
151

152
const std::string& Function::metadata(const std::string& key) const { return this->metadata_.at(key); };
7✔
153

154
const std::unordered_map<std::string, std::string>& Function::metadata() const { return this->metadata_; };
4✔
155

156
} // 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