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

IntelPython / dpctl / 12303791715

12 Dec 2024 07:55PM UTC coverage: 87.659%. Remained the same
12303791715

Pull #1932

github

web-flow
Merge 63c19472a into 0bcd63568
Pull Request #1932: Speed up custom reductions

3120 of 3640 branches covered (85.71%)

Branch coverage included in aggregate %.

11810 of 13392 relevant lines covered (88.19%)

7079.71 hits per line

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

74.07
/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-2024 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
#endif
33
#ifdef ENABLE_GLOG
34
#include <glog/logging.h>
35
#endif
36

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

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

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

63
    int requested_level = 0;
3,814✔
64

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

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

79
    return requested_level;
3,814✔
80
}
3,814✔
81

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

109
} // namespace
110

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

120
    bool to_output = requested_level >= error_level;
3,373✔
121

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

127
        output_message(ss.str(), error_type);
1,552✔
128
    }
1,552✔
129
}
3,373✔
130

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

140
    bool to_output = requested_level >= error_level;
441✔
141

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

147
        output_message(ss.str(), error_type);
406✔
148
    }
406✔
149
}
441✔
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