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

celerity / celerity-runtime / 12009901531

25 Nov 2024 12:20PM UTC coverage: 94.92% (+0.009%) from 94.911%
12009901531

push

github

fknorr
Add missing includes and consistently order them

We can't add the misc-include-cleaner lint because it causes too many
false positives with "interface headers" such as sycl.hpp.

3190 of 3626 branches covered (87.98%)

Branch coverage included in aggregate %.

7049 of 7161 relevant lines covered (98.44%)

1242183.17 hits per line

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

90.54
/src/affinity.cc
1
// non-platform-specific code for thread pinning
2

3
#include "affinity.h"
4

5
#include <cstddef>
6
#include <cstdint>
7
#include <string>
8
#include <string_view>
9
#include <vector>
10

11
#include <fmt/format.h>
12
#include <libenvpp/env.hpp>
13

14

15
namespace celerity::detail::thread_pinning {
16

17
std::string thread_type_to_string(const thread_type t_type) {
691✔
18
        switch(t_type) {
691✔
19
        case thread_type::application: return "application";
696✔
20
        case thread_type::scheduler: return "scheduler";
690✔
21
        case thread_type::executor: return "executor";
672✔
22
        default: break;
5✔
23
        }
24
        if(t_type >= thread_type::first_device_submitter && t_type < thread_type::first_host_queue) {
5!
25
                return fmt::format("device_submitter_{}", t_type - thread_type::first_device_submitter);
4✔
26
        }
27
        if(t_type >= thread_type::first_host_queue && t_type < thread_type::max) { return fmt::format("host_queue_{}", t_type - thread_type::first_host_queue); }
5!
28
        return fmt::format("unknown({})", static_cast<uint32_t>(t_type));
2✔
29
}
30

31
namespace {
32
        // When we no longer need to support compilers without a working std::views::split, get rid of this function
33
        std::vector<std::string> split(const std::string_view str, const char delim) {
3✔
34
                std::vector<std::string> result;
3✔
35
                size_t start = 0;
3✔
36
                size_t end = str.find(delim);
3✔
37
                while(end != std::string::npos) {
7✔
38
                        result.push_back(std::string(str.substr(start, end - start)));
12✔
39
                        start = end + 1;
4✔
40
                        end = str.find(delim, start);
4✔
41
                }
42
                if(start < str.size()) result.push_back(std::string(str.substr(start)));
9!
43
                return result;
3✔
44
        }
×
45
} // namespace
46

47
environment_configuration parse_validate_env(const std::string_view str) {
13✔
48
        using namespace std::string_view_literals;
49
        constexpr const char* error_msg =
13✔
50
            "Cannot parse CELERITY_THREAD_PINNING setting, needs to be either 'auto', 'from:#', comma-separated core list, or bool: {}";
51

52
        if(str.empty()) return {};
13✔
53

54
        // "auto" case
55
        constexpr uint32_t auto_start_from_core = 1;
12✔
56
        if(str == "auto") { return {true, auto_start_from_core, {}}; }
12✔
57

58
        // "from:" case
59
        constexpr auto from_prefix = "from:"sv;
9✔
60
        if(str.starts_with(from_prefix)) {
9✔
61
                try {
62
                        const auto from = env::default_parser<uint32_t>{}(std::string(str.substr(from_prefix.size())));
9✔
63
                        return {true, from, {}};
1✔
64
                } catch(const env::parser_error& e) { throw env::parser_error{fmt::format(error_msg, e.what())}; }
2!
65
        }
66

67
        // core list case
68
        if(str.find(',') != std::string::npos) {
7✔
69
                std::vector<uint32_t> core_ids;
3✔
70
                for(auto cs : split(str, ',')) {
9✔
71
                        try {
72
                                core_ids.push_back(env::default_parser<uint32_t>{}(std::string(cs.begin(), cs.end())));
24✔
73
                        } catch(const env::parser_error& e) { throw env::parser_error{fmt::format(error_msg, e.what())}; }
2!
74
                }
10✔
75
                return {true, 0, core_ids};
2✔
76
        }
3✔
77

78
        // if all else fails, assume we have a boolean
79
        try {
80
                return {env::default_parser<bool>{}(str), auto_start_from_core, {}};
7✔
81
        } catch(const env::parser_error& e) { throw env::parser_error{fmt::format(error_msg, e.what())}; }
2!
82
}
9✔
83

84
} // namespace celerity::detail::thread_pinning
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