예제 #1
0
 public static void ThrowIfFailed(CudaError cudaStatus)
 {
     if (cudaStatus != CudaError.CUDA_SUCCESS)
     {
         throw new CudaException(cudaStatus);
     }
 }
예제 #2
0
 internal static void VerifyDisposed(bool disposing, CudaError cudaStatus)
 {
     if (disposing)
     {
         ThrowIfFailed(cudaStatus);
     }
 }
예제 #3
0
 /// <summary>
 /// Resolves the error string for the given error status.
 /// </summary>
 /// <param name="error">The error to resolve.</param>
 /// <returns>The resolved error string.</returns>
 public string GetErrorString(CudaError error)
 {
     if (GetErrorString(error, out IntPtr ptr) != CudaError.CUDA_SUCCESS)
     {
         return(RuntimeErrorMessages.CannotResolveErrorString);
     }
     return(Marshal.PtrToStringAnsi(ptr));
 }
예제 #4
0
        public CudaError EnsureCapacity(SizeT lastSizeInBytes, SizeT newSizeInBytes)
        {
            if (newSizeInBytes <= lastSizeInBytes && Handle != IntPtr.Zero)
            {
                return(CudaError.Success);
            }

            if (Handle != IntPtr.Zero)
            {
                CudaError error = Deallocate(this);
                if (error != CudaError.Success)
                {
                    return(error);
                }
            }
            return(Allocate(newSizeInBytes, ref this));
        }
예제 #5
0
 /// <summary>
 /// Constructs a new Cuda exception.
 /// </summary>
 /// <param name="error">The Cuda runtime error.</param>
 public CudaException(CudaError error)
     : base(CurrentAPI.GetErrorString(error))
 {
     Error = error.ToString();
 }
예제 #6
0
 /// <summary>
 /// Constructs a new Cuda exception.
 /// </summary>
 /// <param name="error">The Cuda runtime error.</param>
 private CudaException(CudaError error)
     : base(CudaAPI.Current.GetErrorString(error))
 {
     Error = error.ToString();
 }
예제 #7
0
 public CudaException(CudaError error, Exception innerException)
     : this(error, null, innerException)
 {
 }
예제 #8
0
 public CudaException(CudaError error, String message, Exception innerException)
     : base(innerException)
 {
     Error = error.AssertThat(ec => ec != CudaError.Success);
     _message = message;
 }
예제 #9
0
 public CudaException(CudaError error, Exception innerException)
     : this(error, null, innerException)
 {
 }
예제 #10
0
 /// <summary cref="CudaAPI.GetErrorString(CudaError, out IntPtr)"/>
 internal override CudaError GetErrorString(CudaError error, out IntPtr pStr)
 {
     return(cuGetErrorString(error, out pStr));
 }
예제 #11
0
 private static extern CudaError cuGetErrorString(
     [In] CudaError error,
     [Out] out IntPtr pStr);
예제 #12
0
 /// <summary cref="CudaAPI.GetErrorString(CudaError, out IntPtr)"/>
 internal override CudaError GetErrorString(CudaError error, out IntPtr pStr) =>
 cuGetErrorString(error, out pStr);
예제 #13
0
 public CudaException(CudaError error, String message, Exception innerException)
     : base(innerException)
 {
     Error    = error.AssertThat(ec => ec != CudaError.Success);
     _message = message;
 }
예제 #14
0
 public CudaException(CudaError error, String message)
     : this(error, message, null)
 {
 }
예제 #15
0
 public CudaResult(CudaError error, T result)
 {
     Error  = error;
     Result = result;
 }
예제 #16
0
 public CudaException(CudaError error)
     : this(error, null, null)
 {
 }
예제 #17
0
 /// <summary>
 /// Resolves the error string for the given error status.
 /// </summary>
 /// <param name="error">The error to resolve.</param>
 /// <param name="pStr">The resolved error string.</param>
 /// <returns>The error status.</returns>
 internal abstract CudaError GetErrorString(
     CudaError error,
     out IntPtr pStr);
예제 #18
0
 public CudaException(CudaError error, String message)
     : this(error, message, null)
 {
 }
예제 #19
0
 /// <summary cref="CudaAPI.GetErrorString(CudaError, out IntPtr)"/>
 internal override CudaError GetErrorString(CudaError error, out IntPtr pStr)
 {
     pStr = IntPtr.Zero;
     return(CudaError.CUDA_ERROR_NOT_INITIALIZED);
 }
예제 #20
0
 /// <summary>
 /// Resolves the error string for the given error status.
 /// </summary>
 /// <param name="error">The error to resolve.</param>
 /// <returns>The resolved error string.</returns>
 public string GetErrorString(CudaError error) =>
 cuGetErrorString(error, out IntPtr ptr) != CudaError.CUDA_SUCCESS
     ? RuntimeErrorMessages.CannotResolveErrorString
     : Marshal.PtrToStringAnsi(ptr);
예제 #21
0
 public CudaException(CudaError error)
     : this(error, null, null)
 {
 }