Example #1
0
        internal static void ThrowCudaException(NativeMethods.ErrorType error)
        {
            if (error == NativeMethods.ErrorType.OK)
            {
                return;
            }

            var tmp = (int)error;
            var max = (int)NativeMethods.ErrorType.CudaError;                // 0x77000000
            var min = (int)NativeMethods.ErrorType.CudaErrorApiFailureBase;  // -(CudaError | 10000)

            if (!(min <= tmp && tmp < -max))
            {
                return;
            }

            tmp = -(tmp + (int)NativeMethods.ErrorType.CudaError);

            NativeMethods.dnn_cuda_cudaDriverGetVersion(out var driverVersion);
            NativeMethods.dnn_cuda_cudaRuntimeGetVersion(out var runtimeVersion);
            var namePtr = NativeMethods.dnn_cuda_cudaGetErrorName(tmp);
            var name    = namePtr != IntPtr.Zero ? Marshal.PtrToStringAnsi(namePtr) : null;
            var strPtr  = NativeMethods.dnn_cuda_cudaGetErrorString(tmp);
            var message = strPtr != IntPtr.Zero ? Marshal.PtrToStringAnsi(strPtr) : null;

            throw new CudaException(tmp, NativeMethods.NativeDnnLibrary, driverVersion, runtimeVersion, name, message);
        }
Example #2
0
        private static void AssertNativeError(bool success, IntPtr error)
        {
            if (success)
            {
                return;
            }

            if (error == IntPtr.Zero)
            {
                throw new ArgumentNullException("error");
            }

#if !UNITY_EDITOR || UNITY_EDITOR_OSX || UNITY_EDITOR_OVERRIDE
            try {
                NativeMethods.ErrorType code = (NativeMethods.ErrorType)NativeMethods.NSError.code(error);
                if (code == NativeMethods.ErrorType.None)
                {
                    return;
                }

                string localizedDescription = NativeMethods.NSError.localizedDescription(error);
                switch (code)
                {
                case NativeMethods.ErrorType.None:
                    break;

                case NativeMethods.ErrorType.Fatal:
                    throw new ApplicationException(localizedDescription);

                case NativeMethods.ErrorType.NotSupported:
                    throw new NotSupportedException(localizedDescription);

                case NativeMethods.ErrorType.SessionActive:
                    throw new InvalidOperationException(
                              "Local multiplayer session must be non-active for this operation. " +
                              "Check the value of Session.IsSessionActive"
                              );

                case NativeMethods.ErrorType.SessionNotActive:
                    throw new InvalidOperationException(
                              "Local multiplayer session must be active for this operation. " +
                              "Check the value of Session.IsSessionActive"
                              );

                case NativeMethods.ErrorType.InvalidState:
                    throw new InvalidOperationException(localizedDescription);

                case NativeMethods.ErrorType.InvalidInput:
                    throw new ArgumentException(localizedDescription);

                default:
                    throw new ArgumentOutOfRangeException(
                              String.Format("Unknown native error: (code {0}) {1} ", code, localizedDescription));
                }
            } finally {
                NativeMethods.NSObject.release(error);
            }
#endif
        }
Example #3
0
        internal static void ThrowCudaException(NativeMethods.ErrorType error)
        {
            if (error == NativeMethods.ErrorType.OK)
            {
                return;
            }

            var tmp = -(int)error;

            if ((tmp & (int)NativeMethods.ErrorType.CudaError) != (int)NativeMethods.ErrorType.CudaError)
            {
                return;
            }

            tmp -= (int)NativeMethods.ErrorType.CudaError;

            NativeMethods.dnn_cuda_cudaDriverGetVersion(out var driverVersion);
            NativeMethods.dnn_cuda_cudaRuntimeGetVersion(out var runtimeVersion);
            throw new CudaException(tmp, NativeMethods.NativeDnnLibrary, driverVersion, runtimeVersion);
        }