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

IntelPython / dpctl / 15248847350

26 May 2025 07:36AM UTC coverage: 84.99% (+0.02%) from 84.967%
15248847350

Pull #2049

github

web-flow
Merge 614587671 into 651929058
Pull Request #2049: Support compilation from SYCL source code

2974 of 3778 branches covered (78.72%)

Branch coverage included in aggregate %.

191 of 218 new or added lines in 4 files covered. (87.61%)

1 existing line in 1 file now uncovered.

12421 of 14336 relevant lines covered (86.64%)

6782.65 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,886✔
55
    char *verbose = nullptr;
3,886✔
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,886✔
62
#endif
3,886✔
63

64
    int requested_level = 0;
3,886✔
65

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

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

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

83
void output_message(std::string ss_str, error_level error_type)
84
{
2,017✔
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) {
2,017✔
98
    case error_level::error:
1,609!
99
        std::cerr << "[ERR] " << ss_str;
1,609✔
100
        break;
1,609✔
101
    case error_level::warning:
408!
102
        std::cerr << "[WARN] " << ss_str;
408✔
103
        break;
408✔
104
    default:
×
105
        std::cerr << "[FATAL] " << ss_str;
×
106
    }
2,017✔
107
#endif
2,017✔
108
}
2,017✔
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,442✔
118
    int requested_level = requested_verbosity_level();
3,442✔
119
    int error_level = static_cast<int>(error_type);
3,442✔
120

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

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

128
        output_message(ss.str(), error_type);
1,608✔
129
    }
1,608✔
130
}
3,442✔
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
{
444✔
138
    int requested_level = requested_verbosity_level();
444✔
139
    int error_level = static_cast<int>(error_type);
444✔
140

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

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

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