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
11 #include <sycl/context.hpp>
12 #include <sycl/exception.hpp>
13 
14 #include <cstring>
15 #include <sstream>
16 
17 namespace sycl {
18 inline namespace _V1 {
19 
21  : exception(EC, nullptr, Msg) {}
22 
23 // new SYCL 2020 constructors
25 
26 exception::exception(int EV, const std::error_category &ECat,
27  const char *WhatArg)
28  : exception({EV, ECat}, nullptr, std::string(WhatArg)) {}
29 
30 exception::exception(int EV, const std::error_category &ECat)
31  : exception({EV, ECat}, nullptr, "") {}
32 
33 // protected base constructor for all SYCL 2020 constructors
34 exception::exception(std::error_code EC, std::shared_ptr<context> SharedPtrCtx,
35  const char *WhatArg)
36  : MMsg(std::make_shared<detail::string>(WhatArg)),
37  MErr(UR_RESULT_ERROR_INVALID_VALUE), MContext(SharedPtrCtx), MErrC(EC) {
39 }
40 
42 
43 const std::error_code &exception::code() const noexcept { return MErrC; }
44 
45 const std::error_category &exception::category() const noexcept {
46  return code().category();
47 }
48 
49 const char *exception::what() const noexcept { return MMsg->c_str(); }
50 
51 bool exception::has_context() const noexcept { return (MContext != nullptr); }
52 
54  if (!has_context())
55  throw sycl::exception(sycl::errc::invalid);
56 
57  return *MContext;
58 }
59 
60 const std::error_category &sycl_category() noexcept {
61  static const detail::SYCLCategory SYCLCategoryObj;
62  return SYCLCategoryObj;
63 }
64 
66  return {static_cast<int>(Err), sycl_category()};
67 }
68 
69 namespace detail {
70 __SYCL_EXPORT const char *stringifyErrorCode(int32_t error) {
71  switch (error) {
72 #define _UR_ERRC(NAME) \
73  case NAME: \
74  return #NAME;
75  // TODO: bring back old code specific messages?
76 #define _UR_ERRC_WITH_MSG(NAME, MSG) \
77  case NAME: \
78  return MSG;
79  _UR_ERRC(UR_RESULT_SUCCESS)
80  _UR_ERRC(UR_RESULT_ERROR_INVALID_OPERATION)
81  _UR_ERRC(UR_RESULT_ERROR_INVALID_QUEUE_PROPERTIES)
82  _UR_ERRC(UR_RESULT_ERROR_INVALID_QUEUE)
83  _UR_ERRC(UR_RESULT_ERROR_INVALID_VALUE)
84  _UR_ERRC(UR_RESULT_ERROR_INVALID_CONTEXT)
85  _UR_ERRC(UR_RESULT_ERROR_INVALID_PLATFORM)
86  _UR_ERRC(UR_RESULT_ERROR_INVALID_BINARY)
87  _UR_ERRC(UR_RESULT_ERROR_INVALID_PROGRAM)
88  _UR_ERRC(UR_RESULT_ERROR_INVALID_SAMPLER)
89  _UR_ERRC(UR_RESULT_ERROR_INVALID_BUFFER_SIZE)
90  _UR_ERRC(UR_RESULT_ERROR_INVALID_MEM_OBJECT)
91  _UR_ERRC(UR_RESULT_ERROR_INVALID_EVENT)
92  _UR_ERRC(UR_RESULT_ERROR_INVALID_EVENT_WAIT_LIST)
93  _UR_ERRC(UR_RESULT_ERROR_MISALIGNED_SUB_BUFFER_OFFSET)
94  _UR_ERRC(UR_RESULT_ERROR_INVALID_WORK_GROUP_SIZE)
95  _UR_ERRC(UR_RESULT_ERROR_COMPILER_NOT_AVAILABLE)
96  _UR_ERRC(UR_RESULT_ERROR_PROFILING_INFO_NOT_AVAILABLE)
97  _UR_ERRC(UR_RESULT_ERROR_DEVICE_NOT_FOUND)
98  _UR_ERRC(UR_RESULT_ERROR_INVALID_DEVICE)
99  _UR_ERRC(UR_RESULT_ERROR_DEVICE_LOST)
100  _UR_ERRC(UR_RESULT_ERROR_DEVICE_REQUIRES_RESET)
101  _UR_ERRC(UR_RESULT_ERROR_DEVICE_IN_LOW_POWER_STATE)
102  _UR_ERRC(UR_RESULT_ERROR_DEVICE_PARTITION_FAILED)
103  _UR_ERRC(UR_RESULT_ERROR_INVALID_DEVICE_PARTITION_COUNT)
104  _UR_ERRC(UR_RESULT_ERROR_INVALID_WORK_ITEM_SIZE)
105  _UR_ERRC(UR_RESULT_ERROR_INVALID_WORK_DIMENSION)
106  _UR_ERRC(UR_RESULT_ERROR_INVALID_KERNEL_ARGS)
107  _UR_ERRC(UR_RESULT_ERROR_INVALID_KERNEL)
108  _UR_ERRC(UR_RESULT_ERROR_INVALID_KERNEL_NAME)
109  _UR_ERRC(UR_RESULT_ERROR_INVALID_KERNEL_ARGUMENT_INDEX)
110  _UR_ERRC(UR_RESULT_ERROR_INVALID_KERNEL_ARGUMENT_SIZE)
111  _UR_ERRC(UR_RESULT_ERROR_INVALID_KERNEL_ATTRIBUTE_VALUE)
112  _UR_ERRC(UR_RESULT_ERROR_INVALID_IMAGE_SIZE)
113  _UR_ERRC(UR_RESULT_ERROR_INVALID_IMAGE_FORMAT_DESCRIPTOR)
114  _UR_ERRC(UR_RESULT_ERROR_MEM_OBJECT_ALLOCATION_FAILURE)
115  _UR_ERRC(UR_RESULT_ERROR_INVALID_PROGRAM_EXECUTABLE)
116  _UR_ERRC(UR_RESULT_ERROR_UNINITIALIZED)
117  _UR_ERRC(UR_RESULT_ERROR_OUT_OF_HOST_MEMORY)
118  _UR_ERRC(UR_RESULT_ERROR_OUT_OF_DEVICE_MEMORY)
119  _UR_ERRC(UR_RESULT_ERROR_OUT_OF_RESOURCES)
120  _UR_ERRC(UR_RESULT_ERROR_PROGRAM_BUILD_FAILURE)
121  _UR_ERRC(UR_RESULT_ERROR_PROGRAM_LINK_FAILURE)
122  _UR_ERRC(UR_RESULT_ERROR_UNSUPPORTED_VERSION)
123  _UR_ERRC(UR_RESULT_ERROR_UNSUPPORTED_FEATURE)
124  _UR_ERRC(UR_RESULT_ERROR_INVALID_ARGUMENT)
125  _UR_ERRC(UR_RESULT_ERROR_INVALID_NULL_HANDLE)
126  _UR_ERRC(UR_RESULT_ERROR_HANDLE_OBJECT_IN_USE)
127  _UR_ERRC(UR_RESULT_ERROR_INVALID_NULL_POINTER)
128  _UR_ERRC(UR_RESULT_ERROR_INVALID_SIZE)
129  _UR_ERRC(UR_RESULT_ERROR_UNSUPPORTED_SIZE)
130  _UR_ERRC(UR_RESULT_ERROR_UNSUPPORTED_ALIGNMENT)
131  _UR_ERRC(UR_RESULT_ERROR_INVALID_SYNCHRONIZATION_OBJECT)
132  _UR_ERRC(UR_RESULT_ERROR_INVALID_ENUMERATION)
133  _UR_ERRC(UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION)
134  _UR_ERRC(UR_RESULT_ERROR_UNSUPPORTED_IMAGE_FORMAT)
135  _UR_ERRC(UR_RESULT_ERROR_INVALID_NATIVE_BINARY)
136  _UR_ERRC(UR_RESULT_ERROR_INVALID_GLOBAL_NAME)
137  _UR_ERRC(UR_RESULT_ERROR_FUNCTION_ADDRESS_NOT_AVAILABLE)
138  _UR_ERRC(UR_RESULT_ERROR_INVALID_GROUP_SIZE_DIMENSION)
139  _UR_ERRC(UR_RESULT_ERROR_INVALID_GLOBAL_WIDTH_DIMENSION)
140  _UR_ERRC(UR_RESULT_ERROR_PROGRAM_UNLINKED)
141  _UR_ERRC(UR_RESULT_ERROR_OVERLAPPING_REGIONS)
142  _UR_ERRC(UR_RESULT_ERROR_INVALID_HOST_PTR)
143  _UR_ERRC(UR_RESULT_ERROR_INVALID_USM_SIZE)
144  _UR_ERRC(UR_RESULT_ERROR_OBJECT_ALLOCATION_FAILURE)
145  _UR_ERRC(UR_RESULT_ERROR_ADAPTER_SPECIFIC)
146  _UR_ERRC(UR_RESULT_ERROR_LAYER_NOT_PRESENT)
147  _UR_ERRC(UR_RESULT_ERROR_IN_EVENT_LIST_EXEC_STATUS)
148  _UR_ERRC(UR_RESULT_ERROR_DEVICE_NOT_AVAILABLE)
149  _UR_ERRC(UR_RESULT_ERROR_INVALID_COMMAND_BUFFER_EXP)
150  _UR_ERRC(UR_RESULT_ERROR_INVALID_COMMAND_BUFFER_SYNC_POINT_EXP)
151  _UR_ERRC(UR_RESULT_ERROR_INVALID_COMMAND_BUFFER_SYNC_POINT_WAIT_LIST_EXP)
152  _UR_ERRC(UR_RESULT_ERROR_INVALID_COMMAND_BUFFER_COMMAND_HANDLE_EXP)
153  _UR_ERRC(UR_RESULT_ERROR_UNKNOWN)
154 #undef _UR_ERRC
155 #undef _UR_ERRC_WITH_MSG
156 
157  default:
158  return "Unknown error code";
159  }
160 }
161 } // namespace detail
162 
163 } // namespace _V1
164 } // namespace sycl
The context class represents a SYCL context on which kernel functions may be executed.
Definition: context.hpp:50
void TraceEventXPTI(const char *Message)
static GlobalHandler & instance()
bool has_context() const noexcept
Definition: exception.cpp:51
context get_context() const
Definition: exception.cpp:53
const char * what() const noexcept final
Definition: exception.cpp:49
const std::error_code & code() const noexcept
Definition: exception.cpp:43
virtual ~exception()
Definition: exception.cpp:41
const std::error_category & category() const noexcept
Definition: exception.cpp:45
exception(std::error_code, const char *Msg)
Definition: exception.cpp:20
#define _UR_ERRC(NAME)
const char * stringifyErrorCode(int32_t error)
Definition: exception.cpp:70
const std::error_category & sycl_category() noexcept
Definition: exception.cpp:60
std::error_code make_error_code(sycl::errc E) noexcept
Constructs an error code using e and sycl_category()
Definition: exception.cpp:65
Definition: access.hpp:18
error_code
Definition: defs.hpp:70
_Abi const simd< _Tp, _Abi > & noexcept
Definition: simd.hpp:1324