1 /**/
2 
3 module dcompute.driver.error;
4 
5 // Helpfully OpenCL errors are negative and CUDAs are positive
6 enum Status : int {
7     Success = 0,
8     // CUDA Errors.
9     invalidValue                = 1,
10     outOfMemory                 = 2,
11     notInitialized              = 3,
12     deinitialized               = 4,
13     profilerDisabled            = 5,
14     profilerNotInitialized      = 6,
15     profilerAlreadyStarted      = 7,
16     profilerAlradyStopped       = 8,
17     noDevice                    = 100,
18     invalidDevice               = 101,
19     invalidImage                = 200,
20     invalidContext              = 201,
21     contextAlreadyCurrent       = 202,
22     mapFailed                   = 205,
23     unmapFailed                 = 206,
24     arrayIsMapped               = 207,
25     alreadyMapped               = 208,
26     noBinaryForGPU              = 209,
27     alreadyAcquired             = 210,
28     notMapped                   = 211,
29     notMappedAsArray            = 212,
30     notMappedAsPointer          = 213,
31     eccUncorrectable            = 214,
32     unsupportedLimit            = 215,
33     contextAlredyInUse          = 216,
34     peerAccessUnsupported       = 217,
35     invalidPtx                  = 218,
36     invalidGraphicsContext      = 219,
37     nvlinkUncorrectable         = 220,
38     jitCompilerNotFound         = 221,
39     invalidSource               = 300,
40     fileNotFound                = 301,
41     sharedObjectSymbolNotFound  = 302,
42     sharedObjectInitFailed      = 303,
43     operatingSystem             = 304,
44     invalidHandle               = 400,
45     illegalState                = 401,
46     notFound                    = 500,
47     notReady                    = 600,
48     illegalAddress              = 700,
49     launchOutOfResources        = 701,
50     launchTimeout               = 702,
51     launchIncompatibleTexturing = 703,
52     peerAccessAlreadyEnabled    = 704,
53     peerAccessNotEnabled        = 705,
54     primaryContextActive        = 708,
55     contextIsDestroyed          = 709,
56     assertError                 = 710,
57     tooManyPeers                = 711,
58     hostMemoryAlreadyRegistered = 712,
59     hostMemoryNotRegistered     = 713,
60     hardwareStackError          = 714,
61     illegalInstruction          = 715,
62     misalignedAddress           = 716,
63     invalidAddressSpace         = 717,
64     invalidPC                   = 718,
65     launchFailed                = 719,
66     cooperativeLaunchTooLarge   = 720,
67     notPermitted                = 800,
68     notSupported                = 801,
69     systemNotReady              = 802,
70     systemDriverMismatch        = 803,
71     compatNotSupportedOnDevice  = 804,
72     streamCaptureUnsupported    = 900,
73     streamCaptureInvalidated    = 901,
74     streamCaptureMerge          = 902,
75     streamCaptureUnmatched      = 903,
76     streamCaptureUnjoined       = 904,
77     streamCaptureIsolation      = 905,
78     streamCaptureImplicit       = 906,
79     capturedEvent               = 907,
80     streamCaptureWrongThread    = 908,
81     unknown                     = 999,
82 
83     // OpenCL Errors.
84     deviceNotFound                 = -1,
85     deviceNotAvailable             = -2,
86     compilerNotAvailable           = -3,
87     memoryObjectAloocationFailure  = -4,
88     outOfResources                 = -5,
89     outOfHostMemory                = -6,
90     profilingInfomationAvailable   = -7,
91     memoryCopyOverlap              = -8,
92     imageFormatMismatch            = -9,
93     imageFormatNotSupported        = -10,
94     buildProgramFailed             = -11,
95     mapFailure                     = -12,
96     misalignedSubBufferOffset      = -13,
97     errorsInWaitList               = -14,
98     compileProgramFailure          = -15,
99     linkerNotAvailable             = -16,
100     linkerFailure                  = -17,
101     devicePartitionFailure         = -18,
102     kernelArgInfoNotAvailable      = -19,
103     
104     invalidValueCL                 = -30,
105     invalidDeviceType              = -31,
106     invalidPlatform                = -32,
107     invalidDeviceCL                = -33,
108     invalidContextCL               = -34,
109     invalidQueueProperties         = -35,
110     invalidQueue                   = -36,
111     invalidHostPointerCL           = -37,
112     invalidMemoryObject            = -38,
113     invalidImageFormatDesctiptor   = -39,
114     invalidImageSize               = -40,
115     invalidSampler                 = -41,
116     invalidBinary                  = -42,
117     invalidBuildOptions            = -43,
118     invalidProgram                 = -44,
119     invalidExecutable              = -45,
120     invalidKernelName              = -46,
121     invalidKernelDefinition        = -47,
122     invalidKernel                  = -48,
123     invalidArgumentIndex           = -49,
124     invalidArgumentValue           = -50,
125     invalidArgumentSize            = -51,
126     invalidKernelArguments         = -52,
127     invalidWorkDimensions          = -53,
128     invaildWorkGroupSize           = -54,
129     invaildWorkItemSize            = -55,
130     invalidGlobalOffest            = -56,
131     invalidEventWaitList           = -57,
132     invalidEvent                   = -58,
133     invalidOperation               = -59,
134     invalidGLObject                = -60,
135     invalidBufferSize              = -61,
136     invalidMipLevel                = -62,
137     invalidGlobalWorkSize          = -63,
138     invalidProperty                = -64,
139     invalidImageDescriptor         = -65,
140     invalidCompilerOptions         = -66,
141     invalidLinkerOptions           = -67,
142     invalidDevicePartitionCount    = -68,
143     
144     invalidGLSharegroupReference   = -1000,
145     platformNotFound               = -1001,
146     invalidD3D10Device             = -1002,
147     invalidD3D10Resource           = -1003,
148     D3D10ResouceAlreadyAcquired    = -1004,
149     D3D10ResourceNotAcquires       = -1005,
150     invalidD3D11Device             = -1006,
151     invalidD3D11Resource           = -1007,
152     D3D11ResourceAlredyAcquired    = -1008,
153     D3D11ResourceNotAcquired       = -1009,
154     invalidDX9MediaAdapter         = -1010,
155     invalidDX9MediaSurface         = -1011,
156     DX9MediaSurfaceAlreadyAcquired = -1012,
157     DX9MediaSurfaceNotAcquired     = -1013,
158     
159     devicePartitionFailed          = -1057,
160     invalidPartitionCount          = -1058,
161     invalidPartitionName           = -1059,
162     
163     invalidEGLObject               = -1093,
164     EGLResourceNotAcquired         = -1092,
165 }
166 
167 version (D_BetterC)
168 {
169     void delegate (Status) nothrow @nogc onDriverError = (Status _status) 
170     { 
171         defaultOnDriverError(_status);
172     };
173     
174     immutable void delegate (Status) nothrow @nogc defaultOnDriverError = 
175     (Status _status)
176     {
177         import core.stdc.stdio : fprintf, stderr;
178         import std.conv : to;
179         fprintf(stderr,"*** DCompute driver error:%s\n",
180                _status.to!(string).toStringz);
181     };
182 }
183 else
184 {
185     class DComputeDriverException : Exception
186     {
187         this(string msg, string file = __FILE__,
188              size_t line = __LINE__, Throwable next = null)
189         {
190             super(msg, file, line, next);
191         }
192         
193         this(Status err, string file = __FILE__, 
194              size_t line = __LINE__, Throwable next = null)
195         {
196             import std.conv : to;
197             super(err.to!string, file, line, next);
198         }
199     }
200     void delegate(Status) onDriverError = (Status _status) 
201     {
202         defaultOnDriverError(_status);
203     };
204     immutable void delegate(Status) defaultOnDriverError =
205     (Status _status)
206     {
207         throw new DComputeDriverException(_status);
208     };
209 }
210 
211 // Thread local status
212 Status status;
213 
214 version(DComputeIgnoreDriverErrors)
215 {
216     void checkErrors() {}
217 }
218 else
219 {
220     void checkErrors()
221     {
222         if (status) onDriverError(status);
223     }
224 
225 }