1 | /* Copyright 2015-2017 Philippe Tillet |
2 | * |
3 | * Permission is hereby granted, free of charge, to any person obtaining |
4 | * a copy of this software and associated documentation files |
5 | * (the "Software"), to deal in the Software without restriction, |
6 | * including without limitation the rights to use, copy, modify, merge, |
7 | * publish, distribute, sublicense, and/or sell copies of the Software, |
8 | * and to permit persons to whom the Software is furnished to do so, |
9 | * subject to the following conditions: |
10 | * |
11 | * The above copyright notice and this permission notice shall be |
12 | * included in all copies or substantial portions of the Software. |
13 | * |
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
21 | */ |
22 | |
23 | #include "triton/driver/error.h" |
24 | |
25 | namespace triton |
26 | { |
27 | namespace driver |
28 | { |
29 | |
30 | void check(CUresult err) |
31 | { |
32 | using namespace exception::cuda; |
33 | switch(err) |
34 | { |
35 | case CUDA_SUCCESS : break; |
36 | case CUDA_ERROR_INVALID_VALUE : throw invalid_value(); |
37 | case CUDA_ERROR_OUT_OF_MEMORY : throw out_of_memory(); |
38 | case CUDA_ERROR_NOT_INITIALIZED : throw not_initialized(); |
39 | case CUDA_ERROR_DEINITIALIZED : throw deinitialized(); |
40 | case CUDA_ERROR_PROFILER_DISABLED : throw profiler_disabled(); |
41 | case CUDA_ERROR_PROFILER_NOT_INITIALIZED : throw profiler_not_initialized(); |
42 | case CUDA_ERROR_PROFILER_ALREADY_STARTED : throw profiler_already_started(); |
43 | case CUDA_ERROR_PROFILER_ALREADY_STOPPED : throw profiler_already_stopped(); |
44 | case CUDA_ERROR_NO_DEVICE : throw no_device(); |
45 | case CUDA_ERROR_INVALID_DEVICE : throw invalid_device(); |
46 | case CUDA_ERROR_INVALID_IMAGE : throw invalid_image(); |
47 | case CUDA_ERROR_INVALID_CONTEXT : throw invalid_context(); |
48 | case CUDA_ERROR_CONTEXT_ALREADY_CURRENT : throw context_already_current(); |
49 | case CUDA_ERROR_MAP_FAILED : throw map_failed(); |
50 | case CUDA_ERROR_UNMAP_FAILED : throw unmap_failed(); |
51 | case CUDA_ERROR_ARRAY_IS_MAPPED : throw array_is_mapped(); |
52 | case CUDA_ERROR_ALREADY_MAPPED : throw already_mapped(); |
53 | case CUDA_ERROR_NO_BINARY_FOR_GPU : throw no_binary_for_gpu(); |
54 | case CUDA_ERROR_ALREADY_ACQUIRED : throw already_acquired(); |
55 | case CUDA_ERROR_NOT_MAPPED : throw not_mapped(); |
56 | case CUDA_ERROR_NOT_MAPPED_AS_ARRAY : throw not_mapped_as_array(); |
57 | case CUDA_ERROR_NOT_MAPPED_AS_POINTER : throw not_mapped_as_pointer(); |
58 | case CUDA_ERROR_ECC_UNCORRECTABLE : throw ecc_uncorrectable(); |
59 | case CUDA_ERROR_UNSUPPORTED_LIMIT : throw unsupported_limit(); |
60 | case CUDA_ERROR_CONTEXT_ALREADY_IN_USE : throw context_already_in_use(); |
61 | case CUDA_ERROR_PEER_ACCESS_UNSUPPORTED : throw peer_access_unsupported(); |
62 | case CUDA_ERROR_INVALID_PTX : throw invalid_ptx(); |
63 | case CUDA_ERROR_INVALID_GRAPHICS_CONTEXT : throw invalid_graphics_context(); |
64 | case CUDA_ERROR_INVALID_SOURCE : throw invalid_source(); |
65 | case CUDA_ERROR_FILE_NOT_FOUND : throw file_not_found(); |
66 | case CUDA_ERROR_SHARED_OBJECT_SYMBOL_NOT_FOUND : throw shared_object_symbol_not_found(); |
67 | case CUDA_ERROR_SHARED_OBJECT_INIT_FAILED : throw shared_object_init_failed(); |
68 | case CUDA_ERROR_OPERATING_SYSTEM : throw operating_system(); |
69 | case CUDA_ERROR_INVALID_HANDLE : throw invalid_handle(); |
70 | case CUDA_ERROR_NOT_FOUND : throw not_found(); |
71 | case CUDA_ERROR_NOT_READY : throw not_ready(); |
72 | case CUDA_ERROR_ILLEGAL_ADDRESS : throw illegal_address(); |
73 | case CUDA_ERROR_LAUNCH_OUT_OF_RESOURCES : throw launch_out_of_resources(); |
74 | case CUDA_ERROR_LAUNCH_TIMEOUT : throw launch_timeout(); |
75 | case CUDA_ERROR_LAUNCH_INCOMPATIBLE_TEXTURING : throw launch_incompatible_texturing(); |
76 | case CUDA_ERROR_PEER_ACCESS_ALREADY_ENABLED : throw peer_access_already_enabled(); |
77 | case CUDA_ERROR_PEER_ACCESS_NOT_ENABLED : throw peer_access_not_enabled(); |
78 | case CUDA_ERROR_PRIMARY_CONTEXT_ACTIVE : throw primary_context_active(); |
79 | case CUDA_ERROR_CONTEXT_IS_DESTROYED : throw context_is_destroyed(); |
80 | case CUDA_ERROR_ASSERT : throw assert_error(); |
81 | case CUDA_ERROR_TOO_MANY_PEERS : throw too_many_peers(); |
82 | case CUDA_ERROR_HOST_MEMORY_ALREADY_REGISTERED : throw host_memory_already_registered(); |
83 | case CUDA_ERROR_HOST_MEMORY_NOT_REGISTERED : throw host_memory_not_registered(); |
84 | case CUDA_ERROR_HARDWARE_STACK_ERROR : throw hardware_stack_error(); |
85 | case CUDA_ERROR_ILLEGAL_INSTRUCTION : throw illegal_instruction(); |
86 | case CUDA_ERROR_MISALIGNED_ADDRESS : throw misaligned_address(); |
87 | case CUDA_ERROR_INVALID_ADDRESS_SPACE : throw invalid_address_space(); |
88 | case CUDA_ERROR_INVALID_PC : throw invalid_pc(); |
89 | case CUDA_ERROR_LAUNCH_FAILED : throw launch_failed(); |
90 | case CUDA_ERROR_NOT_PERMITTED : throw not_permitted(); |
91 | case CUDA_ERROR_NOT_SUPPORTED : throw not_supported(); |
92 | case CUDA_ERROR_UNKNOWN : throw unknown(); |
93 | default : throw std::runtime_error("unimplemented code: " + std::to_string(err)); |
94 | } |
95 | } |
96 | |
97 | void check(hipError_t error) { |
98 | using namespace exception::hip; |
99 | switch(error) |
100 | { |
101 | case hipSuccess : break; |
102 | case hipErrorInvalidValue : throw invalid_value(); |
103 | case hipErrorMemoryAllocation : throw out_of_memory(); |
104 | case hipErrorNotInitialized : throw not_initialized(); |
105 | case hipErrorDeinitialized : throw deinitialized(); |
106 | case hipErrorProfilerDisabled : throw profiler_disabled(); |
107 | case hipErrorProfilerNotInitialized : throw profiler_not_initialized(); |
108 | case hipErrorProfilerAlreadyStarted : throw profiler_already_started(); |
109 | case hipErrorProfilerAlreadyStopped : throw profiler_already_stopped(); |
110 | case hipErrorNoDevice : throw no_device(); |
111 | case hipErrorInvalidSymbol : throw invalid_symbol(); |
112 | case hipErrorInvalidDevice : throw invalid_device(); |
113 | case hipErrorInvalidImage : throw invalid_image(); |
114 | case hipErrorInvalidContext : throw invalid_context(); |
115 | case hipErrorContextAlreadyCurrent : throw context_already_current(); |
116 | case hipErrorMapFailed : throw map_failed(); |
117 | case hipErrorUnmapFailed : throw unmap_failed(); |
118 | case hipErrorArrayIsMapped : throw array_is_mapped(); |
119 | case hipErrorAlreadyMapped : throw already_mapped(); |
120 | case hipErrorNoBinaryForGpu : throw no_binary_for_gpu(); |
121 | case hipErrorAlreadyAcquired : throw already_acquired(); |
122 | case hipErrorNotMapped : throw not_mapped(); |
123 | case hipErrorNotMappedAsArray : throw not_mapped_as_array(); |
124 | case hipErrorNotMappedAsPointer : throw not_mapped_as_pointer(); |
125 | case hipErrorECCNotCorrectable : throw ecc_uncorrectable(); |
126 | case hipErrorUnsupportedLimit : throw unsupported_limit(); |
127 | case hipErrorContextAlreadyInUse : throw context_already_in_use(); |
128 | case hipErrorPeerAccessUnsupported : throw peer_access_unsupported(); |
129 | case hipErrorInvalidKernelFile : throw invalid_ptx(); |
130 | case hipErrorInvalidGraphicsContext : throw invalid_graphics_context(); |
131 | case hipErrorInvalidSource : throw invalid_source(); |
132 | case hipErrorFileNotFound : throw file_not_found(); |
133 | case hipErrorSharedObjectSymbolNotFound : throw shared_object_symbol_not_found(); |
134 | case hipErrorSharedObjectInitFailed : throw shared_object_init_failed(); |
135 | case hipErrorOperatingSystem : throw operating_system(); |
136 | case hipErrorInvalidResourceHandle : throw invalid_handle(); |
137 | case hipErrorNotFound : throw not_found(); |
138 | case hipErrorNotReady : throw not_ready(); |
139 | case hipErrorIllegalAddress : throw illegal_address(); |
140 | case hipErrorLaunchOutOfResources : throw launch_out_of_resources(); |
141 | case hipErrorLaunchTimeOut : throw launch_timeout(); |
142 | // case hipErrorLaunchIncompatibleTexturing : throw launch_incompatible_texturing(); |
143 | case hipErrorPeerAccessAlreadyEnabled : throw peer_access_already_enabled(); |
144 | case hipErrorPeerAccessNotEnabled : throw peer_access_not_enabled(); |
145 | // case hipErrorPrimaryContextActive : throw primary_context_active(); |
146 | // case hipErrorContextIsDestroyed : throw context_is_destroyed(); |
147 | case hipErrorAssert : throw assert_error(); |
148 | // case hipErrorTooManyPeers : throw too_many_peers(); |
149 | case hipErrorHostMemoryAlreadyRegistered : throw host_memory_already_registered(); |
150 | case hipErrorHostMemoryNotRegistered : throw host_memory_not_registered(); |
151 | // case hipErrorHardwareStackError : throw hardware_stack_error(); |
152 | // case hipErrorIllegalInstruction : throw illegal_instruction(); |
153 | // case hipErrorMisalignedAddress : throw misaligned_address(); |
154 | // case hipErrorInvalidAddressSpace : throw invalid_address_space(); |
155 | // case hipErrorInvalidPc : throw invalid_pc(); |
156 | case hipErrorLaunchFailure : throw launch_failed(); |
157 | // case hipErrorNotPermitted : throw not_permitted(); |
158 | case hipErrorNotSupported : throw not_supported(); |
159 | case hipErrorUnknown : throw unknown(); |
160 | default : throw unknown(); |
161 | } |
162 | } |
163 | |
164 | } |
165 | } |
166 | |
167 | |