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

IntelPython / dpctl / 14754782295

30 Apr 2025 12:39PM UTC coverage: 86.419%. Remained the same
14754782295

Pull #2068

github

web-flow
Merge c8700ceb2 into b7a6b67c7
Pull Request #2068: Correct a path to `cl.cfg` file

3020 of 3716 branches covered (81.27%)

Branch coverage included in aggregate %.

12195 of 13890 relevant lines covered (87.8%)

6998.91 hits per line

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

70.37
/libsyclinterface/helper/source/dpctl_error_handlers.cpp
1
//===-- dpctl_async_error_handler.h - An async error handler     -*-C++-*- ===//
2
//
3
//                      Data Parallel Control (dpctl)
4
//
5
// Copyright 2020-2025 Intel Corporation
6
//
7
// Licensed under the Apache License, Version 2.0 (the "License");
8
// you may not use this file except in compliance with the License.
9
// You may obtain a copy of the License at
10
//
11
//    http://www.apache.org/licenses/LICENSE-2.0
12
//
13
// Unless required by applicable law or agreed to in writing, software
14
// distributed under the License is distributed on an "AS IS" BASIS,
15
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
// See the License for the specific language governing permissions and
17
// limitations under the License.
18
//
19
//===----------------------------------------------------------------------===//
20
///
21
/// \file
22
/// A functor to use for passing an error handler callback function to sycl
23
/// context and queue contructors.
24
//===----------------------------------------------------------------------===//
25

26
#include "dpctl_error_handlers.h"
27
#include "dpctl_service.h"
28
#include <cstring>
29
#include <sstream>
30
#ifdef _WIN32
31
#include <cstdlib>
32
#include <stddef.h>
33
#endif
34
#ifdef ENABLE_GLOG
35
#include <glog/logging.h>
36
#endif
37

38
void DPCTL_AsyncErrorHandler::operator()(const sycl::exception_list &exceptions)
39
{
×
40
    for (std::exception_ptr const &e : exceptions) {
×
41
        try {
×
42
            std::rethrow_exception(e);
×
43
        } catch (sycl::exception const &e) {
×
44
            error_handler(e, __FILE__, __func__, __LINE__);
×
45
            auto err_code = e.code().value();
×
46
            handler_(static_cast<int>(err_code));
×
47
        }
×
48
    }
×
49
}
×
50

51
namespace
52
{
53
int requested_verbosity_level(void)
54
{
3,854✔
55
    char *verbose = nullptr;
3,854✔
56

57
#ifdef _WIN32
58
    size_t len = 0;
59
    _dupenv_s(&verbose, &len, "DPCTL_VERBOSITY");
60
#else
61
    verbose = std::getenv("DPCTL_VERBOSITY");
3,854✔
62
#endif
3,854✔
63

64
    int requested_level = 0;
3,854✔
65

66
    if (verbose) {
3,854✔
67
        if (!std::strncmp(verbose, "none", 4))
1,996!
68
            requested_level = error_level::none;
×
69
        else if (!std::strncmp(verbose, "error", 5))
1,996!
70
            requested_level = error_level::error;
×
71
        else if (!std::strncmp(verbose, "warning", 7))
1,996!
72
            requested_level = error_level::warning;
1,996✔
73
    }
1,996✔
74

75
#ifdef _WIN32
76
    if (verbose)
77
        free(verbose);
78
#endif
79

80
    return requested_level;
3,854✔
81
}
3,854✔
82

83
void output_message(std::string ss_str, error_level error_type)
84
{
1,996✔
85
#ifdef ENABLE_GLOG
86
    switch (error_type) {
87
    case error_level::error:
88
        LOG(ERROR) << "[ERR] " << ss_str;
89
        break;
90
    case error_level::warning:
91
        LOG(WARNING) << "[WARN] " << ss_str;
92
        break;
93
    default:
94
        LOG(FATAL) << "[FATAL] " << ss_str;
95
    }
96
#else
97
    switch (error_type) {
1,996✔
98
    case error_level::error:
1,592!
99
        std::cerr << "[ERR] " << ss_str;
1,592✔
100
        break;
1,592✔
101
    case error_level::warning:
404!
102
        std::cerr << "[WARN] " << ss_str;
404✔
103
        break;
404✔
104
    default:
×
105
        std::cerr << "[FATAL] " << ss_str;
×
106
    }
1,996✔
107
#endif
1,996✔
108
}
1,996✔
109

110
} // namespace
111

112
void error_handler(const std::exception &e,
113
                   const char *file_name,
114
                   const char *func_name,
115
                   int line_num,
116
                   error_level error_type)
117
{
3,414✔
118
    int requested_level = requested_verbosity_level();
3,414✔
119
    int error_level = static_cast<int>(error_type);
3,414✔
120

121
    bool to_output = requested_level >= error_level;
3,414✔
122

123
    if (to_output) {
3,414✔
124
        std::stringstream ss;
1,591✔
125
        ss << e.what() << " in " << func_name << " at " << file_name << ":"
1,591✔
126
           << line_num << std::endl;
1,591✔
127

128
        output_message(ss.str(), error_type);
1,591✔
129
    }
1,591✔
130
}
3,414✔
131

132
void error_handler(const std::string &what,
133
                   const char *file_name,
134
                   const char *func_name,
135
                   int line_num,
136
                   error_level error_type)
137
{
440✔
138
    int requested_level = requested_verbosity_level();
440✔
139
    int error_level = static_cast<int>(error_type);
440✔
140

141
    bool to_output = requested_level >= error_level;
440✔
142

143
    if (to_output) {
440✔
144
        std::stringstream ss;
405✔
145
        ss << what << " in " << func_name << " at " << file_name << ":"
405✔
146
           << line_num << std::endl;
405✔
147

148
        output_message(ss.str(), error_type);
405✔
149
    }
405✔
150
}
440✔
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

© 2025 Coveralls, Inc