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

IntelPython / dpctl / 6620553462

24 Oct 2023 12:17AM UTC coverage: 85.718% (+0.02%) from 85.701%
6620553462

push

github

web-flow
Merge pull request #1452 from IntelPython/improve-exception-parent-device

Use partition_type_property descriptor in DPCTLDevice_GetParentDevice

2472 of 2923 branches covered (0.0%)

Branch coverage included in aggregate %.

9 of 12 new or added lines in 1 file covered. (75.0%)

130 existing lines in 4 files now uncovered.

8799 of 10226 relevant lines covered (86.05%)

8009.21 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-2022 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,627✔
54
    char *verbose = nullptr;
3,627✔
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,627✔
61
#endif
3,627✔
62

63
    int requested_level = 0;
3,627✔
64

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

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

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

82
void output_message(std::string ss_str, error_level error_type)
83
{
1,871✔
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,871✔
97
    case error_level::error:
1,465✔
98
        std::cerr << "[ERR] " << ss_str;
1,465✔
99
        break;
1,465✔
100
    case error_level::warning:
406✔
101
        std::cerr << "[WARN] " << ss_str;
406✔
102
        break;
406✔
103
    default:
×
104
        std::cerr << "[FATAL] " << ss_str;
×
105
    }
1,871✔
106
#endif
1,871✔
107
}
1,871✔
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,184✔
117
    int requested_level = requested_verbosity_level();
3,184✔
118
    int error_level = static_cast<int>(error_type);
3,184✔
119

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

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

127
        output_message(ss.str(), error_type);
1,465✔
128
    }
1,465✔
129
}
3,184✔
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
{
443✔
137
    int requested_level = requested_verbosity_level();
443✔
138
    int error_level = static_cast<int>(error_type);
443✔
139

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

142
    if (to_output) {
443✔
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
}
443✔
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