forked from tsai/mathnet-numerics
committed by
Christoph Ruegg
10 changed files with 488 additions and 142 deletions
@ -0,0 +1,110 @@ |
|||
// <copyright file="CuSolverException.cs" company="Math.NET">
|
|||
// Math.NET Numerics, part of the Math.NET Project
|
|||
// http://numerics.mathdotnet.com
|
|||
// http://github.com/mathnet/mathnet-numerics
|
|||
// http://mathnetnumerics.codeplex.com
|
|||
//
|
|||
// Copyright (c) 2009-2013 Math.NET
|
|||
//
|
|||
// Permission is hereby granted, free of charge, to any person
|
|||
// obtaining a copy of this software and associated documentation
|
|||
// files (the "Software"), to deal in the Software without
|
|||
// restriction, including without limitation the rights to use,
|
|||
// copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|||
// copies of the Software, and to permit persons to whom the
|
|||
// Software is furnished to do so, subject to the following
|
|||
// conditions:
|
|||
//
|
|||
// The above copyright notice and this permission notice shall be
|
|||
// included in all copies or substantial portions of the Software.
|
|||
//
|
|||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|||
// OTHER DEALINGS IN THE SOFTWARE.
|
|||
// </copyright>
|
|||
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
|
|||
namespace MathNet.Numerics.Providers.LinearAlgebra.Cuda |
|||
{ |
|||
/// <summary>
|
|||
/// Exceptions thrown by the cuSolverDn API.
|
|||
/// </summary>
|
|||
public class CuSolverException : Exception |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="CuSolverException"/> class.
|
|||
/// </summary>
|
|||
/// <param name="statusCode">The status code returned from the API</param>
|
|||
public CuSolverException(int statusCode) |
|||
: base(CuSolverException.GetErrorMessage(statusCode)) |
|||
{ |
|||
this.StatusCode = statusCode; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Gets the status code returned by the cuSolverDn API
|
|||
/// </summary>
|
|||
public int StatusCode { get; private set; } |
|||
|
|||
/// <summary>
|
|||
/// Returns the appropriate error message for each status code.
|
|||
/// </summary>
|
|||
/// <param name="code">The status code returned from the API</param>
|
|||
/// <returns>The corresponding error message</returns>
|
|||
private static string GetErrorMessage(int statusCode) |
|||
{ |
|||
switch (statusCode) |
|||
{ |
|||
case 0: // CUSOLVER_STATUS_SUCCESS
|
|||
return "The operation completed successfully."; |
|||
|
|||
case 1: // CUSOLVER_STATUS_NOT_INITIALIZED
|
|||
return "The cuSolver library was not initialized. This is usually caused by the lack of a prior call, an error in the CUDA Runtime API called by the cuSolver routine, or an error in the hardware setup."; |
|||
|
|||
case 2: // CUSOLVER_STATUS_ALLOC_FAILED
|
|||
return "Resource allocation failed inside the cuSolver library. This is usually caused by a cudaMalloc() failure."; |
|||
|
|||
case 3: // CUSOLVER_STATUS_INVALID_VALUE
|
|||
return "An unsupported value or parameter was passed to the function (a negative vector size, for example)."; |
|||
|
|||
case 4: // CUSOLVER_STATUS_ARCH_MISMATCH
|
|||
return "The function requires a feature absent from the device architecture; usually caused by the lack of support for atomic operations or double precision."; |
|||
|
|||
case 5: // CUSOLVER_STATUS_MAPPING_ERROR
|
|||
return "Mapping Error"; |
|||
|
|||
case 6: // CUSOLVER_STATUS_EXECUTION_FAILED
|
|||
return "The GPU program failed to execute. This is often caused by a launch failure of the kernel on the GPU, which can be caused by multiple reasons."; |
|||
|
|||
case 7: //CUSOLVER_STATUS_INTERNAL_ERROR
|
|||
return "An internal cuSolver operation failed. This error is usually caused by a cudaMemcpyAsync() failure."; |
|||
|
|||
case 8: // CUSOLVER_STATUS_MATRIX_TYPE_NOT_SUPPORTED
|
|||
return "The matrix type is not supported by this function. This is usually caused by passing an invalid matrix descriptor to the function."; |
|||
|
|||
case 9: // CUSOLVER_STATUS_NOT_SUPPORTED
|
|||
return "The functionality requested is not supported"; |
|||
|
|||
case 10: // CUSOLVER_STATUS_ZERO_PIVOT
|
|||
return "Zero Pivot"; |
|||
|
|||
case 11: //CUSOLVER_STATUS_INVALID_LICENSE
|
|||
return "The functionality requested requires some license and an error was detected when trying to check the current licensing. This error can happen if the license is not present or is expired or if the environment variable NVIDIA_LICENSE_FILE is not set properly."; |
|||
|
|||
default: |
|||
throw new Exception("Unrecognized cuSolverDn status code"); |
|||
|
|||
|
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,102 @@ |
|||
// <copyright file="CuBLASException.cs" company="Math.NET">
|
|||
// Math.NET Numerics, part of the Math.NET Project
|
|||
// http://numerics.mathdotnet.com
|
|||
// http://github.com/mathnet/mathnet-numerics
|
|||
// http://mathnetnumerics.codeplex.com
|
|||
//
|
|||
// Copyright (c) 2009-2013 Math.NET
|
|||
//
|
|||
// Permission is hereby granted, free of charge, to any person
|
|||
// obtaining a copy of this software and associated documentation
|
|||
// files (the "Software"), to deal in the Software without
|
|||
// restriction, including without limitation the rights to use,
|
|||
// copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|||
// copies of the Software, and to permit persons to whom the
|
|||
// Software is furnished to do so, subject to the following
|
|||
// conditions:
|
|||
//
|
|||
// The above copyright notice and this permission notice shall be
|
|||
// included in all copies or substantial portions of the Software.
|
|||
//
|
|||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|||
// OTHER DEALINGS IN THE SOFTWARE.
|
|||
// </copyright>
|
|||
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
|
|||
namespace MathNet.Numerics.Providers.LinearAlgebra.Cuda |
|||
{ |
|||
/// <summary>
|
|||
/// Exceptions thrown by the cuBLAS api.
|
|||
/// </summary>
|
|||
public class CuBLASException : Exception |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="CuBLASException"/> class.
|
|||
/// </summary>
|
|||
/// <param name="statusCode">The status code returned from the API</param>
|
|||
public CuBLASException(int statusCode) |
|||
: base(CuBLASException.GetErrorMessage(statusCode)) |
|||
{ |
|||
this.StatusCode = statusCode; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Gets the status code returned by the cuBLAS API.
|
|||
/// </summary>
|
|||
public int StatusCode { get; private set; } |
|||
|
|||
/// <summary>
|
|||
/// Returns the appropriate error message for each status code.
|
|||
/// </summary>
|
|||
/// <param name="code">The status code returned from the API</param>
|
|||
/// <returns>The corresponding error message</returns>
|
|||
private static string GetErrorMessage(int statusCode) |
|||
{ |
|||
switch (statusCode) |
|||
{ |
|||
case 0: // CUBLAS_STATUS_SUCCESS
|
|||
return "The operation completed successfully."; |
|||
|
|||
case 1: // CUBLAS_STATUS_NOT_INITIALIZED
|
|||
return "The cuBLAS library was not initialized. This is usually caused by the lack of a prior cublasCreate() call, an error in the CUDA Runtime API called by the cuBLAS routine, or an error in the hardware setup."; |
|||
|
|||
case 2: // CUSOLVER_STATUS_ALLOC_FAILED
|
|||
return "Resource allocation failed inside the cuBLAS library. This is usually caused by a cudaMalloc() failure."; |
|||
|
|||
case 7: // CUBLAS_STATUS_INVALID_VALUE
|
|||
return "An unsupported value or parameter was passed to the function (a negative vector size, for example)."; |
|||
|
|||
case 8: // CUBLAS_STATUS_ARCH_MISMATCH
|
|||
return "The function requires a feature absent from the device architecture; usually caused by the lack of support for double precision."; |
|||
|
|||
case 11: // CUBLAS_STATUS_MAPPING_ERROR
|
|||
return "An access to GPU memory space failed, which is usually caused by a failure to bind a texture."; |
|||
|
|||
case 13: // CUBLAS_STATUS_EXECUTION_FAILED
|
|||
return "The GPU program failed to execute. This is often caused by a launch failure of the kernel on the GPU, which can be caused by multiple reasons."; |
|||
|
|||
case 14: // CUBLAS_STATUS_INTERNAL_ERROR
|
|||
return "An internal cuBLAS operation failed. This error is usually caused by a cudaMemcpyAsync() failure."; |
|||
|
|||
case 15: // CUBLAS_STATUS_NOT_SUPPORTED
|
|||
return "The functionality requested is not supported"; |
|||
|
|||
case 16: // CUBLAS_STATUS_LICENSE_ERROR
|
|||
return "The functionality requested requires some license and an error was detected when trying to check the current licensing. This error can happen if the license is not present or is expired or if the environment variable NVIDIA_LICENSE_FILE is not set properly."; |
|||
|
|||
default: |
|||
return "Unrecognized cuBLAS status code"; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,90 @@ |
|||
// <copyright file="CudaException.cs" company="Math.NET">
|
|||
// Math.NET Numerics, part of the Math.NET Project
|
|||
// http://numerics.mathdotnet.com
|
|||
// http://github.com/mathnet/mathnet-numerics
|
|||
// http://mathnetnumerics.codeplex.com
|
|||
//
|
|||
// Copyright (c) 2009-2013 Math.NET
|
|||
//
|
|||
// Permission is hereby granted, free of charge, to any person
|
|||
// obtaining a copy of this software and associated documentation
|
|||
// files (the "Software"), to deal in the Software without
|
|||
// restriction, including without limitation the rights to use,
|
|||
// copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|||
// copies of the Software, and to permit persons to whom the
|
|||
// Software is furnished to do so, subject to the following
|
|||
// conditions:
|
|||
//
|
|||
// The above copyright notice and this permission notice shall be
|
|||
// included in all copies or substantial portions of the Software.
|
|||
//
|
|||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|||
// OTHER DEALINGS IN THE SOFTWARE.
|
|||
// </copyright>
|
|||
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
|
|||
namespace MathNet.Numerics.Providers.LinearAlgebra.Cuda |
|||
{ |
|||
/// <summary>
|
|||
/// Exception thrown by the Cuda Runtime API
|
|||
/// </summary>
|
|||
public class CudaException : Exception |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="CudaException"/> class.
|
|||
/// </summary>
|
|||
/// <param name="errorCode">The error code returned by the API</param>
|
|||
public CudaException(int errorCode) |
|||
: base(CudaException.GetErrorMessage(errorCode)) |
|||
{ |
|||
this.ErrorCode = errorCode; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Gets the error code returned by the Cuda Runtime API.
|
|||
/// </summary>
|
|||
public int ErrorCode { get; private set; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the error message for a particular error code.
|
|||
/// </summary>
|
|||
/// <param name="errorCode">The error code returned by the API</param>
|
|||
/// <returns>The corresponding error message</returns>
|
|||
private static string GetErrorMessage(int errorCode) |
|||
{ |
|||
switch (errorCode) |
|||
{ |
|||
case 0: // cudaSuccess
|
|||
return "The API call returned with no errors."; |
|||
|
|||
case 2: // cudaErrorMemoryAllocation
|
|||
return "The API call failed because it was unable to allocate enough memory to perform the requested operation."; |
|||
|
|||
case 3: // cudaErrorInitializationError
|
|||
return "The API call failed because the CUDA driver and runtime could not be initialized."; |
|||
|
|||
case 11: // cudaErrorInvalidValue
|
|||
return "This indicates that one or more of the parameters passed to the API call is not within an acceptable range of values."; |
|||
|
|||
case 17: // cudaErrorInvalidDevicePointer
|
|||
return "This indicates that at least one device pointer passed to the API call is not a valid device pointer. "; |
|||
|
|||
case 21: // cudaErrorInvalidMemcpyDirection
|
|||
return "This indicates that the direction of the memcpy passed to the API call is not one of the types specified by cudaMemcpyKind. "; |
|||
|
|||
default: |
|||
return "Unknown Cuda Runtime error code"; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,58 @@ |
|||
// <copyright file="CudaResults.cs" company="Math.NET">
|
|||
// Math.NET Numerics, part of the Math.NET Project
|
|||
// http://numerics.mathdotnet.com
|
|||
// http://github.com/mathnet/mathnet-numerics
|
|||
// http://mathnetnumerics.codeplex.com
|
|||
//
|
|||
// Copyright (c) 2009-2013 Math.NET
|
|||
//
|
|||
// Permission is hereby granted, free of charge, to any person
|
|||
// obtaining a copy of this software and associated documentation
|
|||
// files (the "Software"), to deal in the Software without
|
|||
// restriction, including without limitation the rights to use,
|
|||
// copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|||
// copies of the Software, and to permit persons to whom the
|
|||
// Software is furnished to do so, subject to the following
|
|||
// conditions:
|
|||
//
|
|||
// The above copyright notice and this permission notice shall be
|
|||
// included in all copies or substantial portions of the Software.
|
|||
//
|
|||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|||
// OTHER DEALINGS IN THE SOFTWARE.
|
|||
// </copyright>
|
|||
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
|
|||
namespace MathNet.Numerics.Providers.LinearAlgebra.Cuda |
|||
{ |
|||
/// <summary>
|
|||
/// Struct containing the various results from different CUDA API calls.
|
|||
/// </summary>
|
|||
private struct CudaResults |
|||
{ |
|||
/// <summary>
|
|||
/// Maps to cudaError_t
|
|||
/// </summary>
|
|||
public int Error; |
|||
|
|||
/// <summary>
|
|||
/// Maps to cublasStatus_t
|
|||
/// </summary>
|
|||
public int BlasStatus; |
|||
|
|||
/// <summary>
|
|||
/// Maps to cusolverStatus_t
|
|||
/// </summary>
|
|||
public int SolverStatus; |
|||
} |
|||
} |
|||
Loading…
Reference in new issue