DPC++ Runtime
Runtime libraries for oneAPI DPC++
exception.cpp
Go to the documentation of this file.
1
//==---------------- exception.cpp - SYCL exception ------------------------==//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
9
// 4.9.2 Exception Class Interface
10
#include <
sycl/context.hpp
>
11
#include <
sycl/exception.hpp
>
12
13
#include <cstring>
14
15
namespace
sycl
{
16
__SYCL_INLINE_VER_NAMESPACE
(_V1) {
17
18
exception::exception(std::error_code EC,
const
char
*Msg)
19
:
exception
(EC, nullptr, Msg) {}
20
21
exception::exception
(std::error_code EC,
const
std::string &Msg)
22
:
exception
(EC, nullptr, Msg) {}
23
24
// new SYCL 2020 constructors
25
exception::exception
(std::error_code EC) :
exception
(EC, nullptr,
""
) {}
26
27
exception::exception
(
int
EV,
const
std::error_category &ECat,
28
const
std::string &WhatArg)
29
:
exception
({EV, ECat},
nullptr
, WhatArg) {}
30
31
exception::exception
(
int
EV,
const
std::error_category &ECat,
32
const
char
*WhatArg)
33
:
exception
({EV, ECat},
nullptr
, std::string(WhatArg)) {}
34
35
exception::exception
(
int
EV,
const
std::error_category &ECat)
36
:
exception
({EV, ECat},
nullptr
,
""
) {}
37
38
exception::exception
(
context
Ctx, std::error_code EC,
39
const
std::string &WhatArg)
40
:
exception
(EC,
std
::make_shared<
context
>(Ctx), WhatArg) {}
41
42
exception::exception
(
context
Ctx, std::error_code EC,
const
char
*WhatArg)
43
:
exception
(Ctx, EC,
std
::string(WhatArg)) {}
44
45
exception::exception
(
context
Ctx, std::error_code EC)
46
:
exception
(Ctx, EC,
""
) {}
47
48
exception::exception
(
context
Ctx,
int
EV,
const
std::error_category &ECat,
49
const
char
*WhatArg)
50
:
exception
(Ctx, {EV, ECat}, std::string(WhatArg)) {}
51
52
exception::exception
(
context
Ctx,
int
EV,
const
std::error_category &ECat,
53
const
std::string &WhatArg)
54
:
exception
(Ctx, {EV, ECat}, WhatArg) {}
55
56
exception::exception
(
context
Ctx,
int
EV,
const
std::error_category &ECat)
57
:
exception
(Ctx, EV, ECat,
""
) {}
58
59
// protected base constructor for all SYCL 2020 constructors
60
exception::exception
(std::error_code EC, std::shared_ptr<context> SharedPtrCtx,
61
const
std::string &WhatArg)
62
: MMsg(
std
::make_shared<
std
::string>(WhatArg)),
63
MPIErr(PI_ERROR_INVALID_VALUE), MContext(SharedPtrCtx), MErrC(EC) {}
64
65
const
std::error_code &
exception::code
() const noexcept {
66
return
MErrC;
67
}
68
69
const
std::error_category &
exception::category
() const noexcept {
70
return
code
().category();
71
}
72
73
const
char
*
exception::what
() const noexcept {
return
MMsg->c_str(); }
74
75
bool
exception::has_context
() const noexcept {
return
(MContext !=
nullptr
); }
76
77
context
exception::get_context
()
const
{
78
if
(!
has_context
())
79
throw
invalid_object_error();
80
81
return
*MContext;
82
}
83
84
cl_int
exception::get_cl_code
()
const
{
return
MPIErr; }
85
86
const
std::error_category &
sycl_category
() noexcept {
87
static
const
detail::SYCLCategory
SYCLCategoryObj;
88
return
SYCLCategoryObj;
89
}
90
91
std::error_code
make_error_code
(
sycl::errc
Err) noexcept {
92
return
{
static_cast<
int
>
(Err),
sycl_category
()};
93
}
94
95
}
// __SYCL_INLINE_VER_NAMESPACE(_V1)
96
}
// namespace sycl
sycl::_V1::detail::SYCLCategory
Definition:
exception.hpp:54
sycl::_V1::sycl_category
const std::error_category & sycl_category() noexcept
Definition:
exception.cpp:86
sycl::_V1::exception::get_context
context get_context() const
Definition:
exception.cpp:77
sycl::_V1::make_error_code
std::error_code make_error_code(sycl::errc E) noexcept
Constructs an error code using e and sycl_category()
Definition:
exception.cpp:91
__SYCL_INLINE_VER_NAMESPACE
#define __SYCL_INLINE_VER_NAMESPACE(X)
Definition:
defines_elementary.hpp:11
context.hpp
sycl
---— Error handling, matching OpenCL plugin semantics.
Definition:
access.hpp:14
sycl::_V1::exception::has_context
bool has_context() const noexcept
Definition:
exception.cpp:75
sycl::_V1::cl_int
std::int32_t cl_int
Definition:
aliases.hpp:108
sycl::_V1::exception::get_cl_code
cl_int get_cl_code() const
Definition:
exception.cpp:84
sycl::_V1::exception::code
const std::error_code & code() const noexcept
Definition:
exception.cpp:65
sycl::_V1::exception
Definition:
exception.hpp:64
sycl::_V1::errc
errc
Definition:
exception.hpp:28
sycl::_V1::exception::exception
exception(std::error_code, const char *Msg)
Definition:
exception.cpp:18
sycl::_V1::exception::category
const std::error_category & category() const noexcept
Definition:
exception.cpp:69
exception.hpp
std
Definition:
accessor.hpp:3201
sycl::_V1::exception::what
const char * what() const noexcept final
Definition:
exception.cpp:73
sycl::_V1::context
The context class represents a SYCL context on which kernel functions may be executed.
Definition:
context.hpp:41
source
exception.cpp
Generated by
1.8.17