Example #1
0
 public static void ThrowIfFailed(CudaError cudaStatus)
 {
     if (cudaStatus != CudaError.CUDA_SUCCESS)
     {
         throw new CudaException(cudaStatus);
     }
 }
Example #2
0
 internal static void VerifyDisposed(bool disposing, CudaError cudaStatus)
 {
     if (disposing)
     {
         ThrowIfFailed(cudaStatus);
     }
 }
Example #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));
 }
Example #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));
        }
Example #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();
 }
Example #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();
 }
Example #7
0
 public CudaException(CudaError error, Exception innerException)
     : this(error, null, innerException)
 {
 }
Example #8
0
 public CudaException(CudaError error, String message, Exception innerException)
     : base(innerException)
 {
     Error = error.AssertThat(ec => ec != CudaError.Success);
     _message = message;
 }
Example #9
0
 public CudaException(CudaError error, Exception innerException)
     : this(error, null, innerException)
 {
 }
Example #10
0
 /// <summary cref="CudaAPI.GetErrorString(CudaError, out IntPtr)"/>
 internal override CudaError GetErrorString(CudaError error, out IntPtr pStr)
 {
     return(cuGetErrorString(error, out pStr));
 }
Example #11
0
 private static extern CudaError cuGetErrorString(
     [In] CudaError error,
     [Out] out IntPtr pStr);
Example #12
0
 /// <summary cref="CudaAPI.GetErrorString(CudaError, out IntPtr)"/>
 internal override CudaError GetErrorString(CudaError error, out IntPtr pStr) =>
 cuGetErrorString(error, out pStr);
Example #13
0
 public CudaException(CudaError error, String message, Exception innerException)
     : base(innerException)
 {
     Error    = error.AssertThat(ec => ec != CudaError.Success);
     _message = message;
 }
Example #14
0
 public CudaException(CudaError error, String message)
     : this(error, message, null)
 {
 }
Example #15
0
 public CudaResult(CudaError error, T result)
 {
     Error  = error;
     Result = result;
 }
Example #16
0
 public CudaException(CudaError error)
     : this(error, null, null)
 {
 }
Example #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);
Example #18
0
 public CudaException(CudaError error, String message)
     : this(error, message, null)
 {
 }
Example #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);
 }
Example #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);
Example #21
0
 public CudaException(CudaError error)
     : this(error, null, null)
 {
 }