Skip to content
This repository has been archived by the owner on Mar 12, 2021. It is now read-only.

Commit

Permalink
Merge pull request #554 from JuliaGPU/tb/showerror
Browse files Browse the repository at this point in the history
Improve error display.
  • Loading branch information
maleadt authored Jan 7, 2020
2 parents 652b464 + 0284c78 commit 72882b2
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 205 deletions.
56 changes: 28 additions & 28 deletions src/blas/error.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,38 @@ export CUBLASError

struct CUBLASError <: Exception
code::cublasStatus_t
msg::AbstractString
end
Base.show(io::IO, err::CUBLASError) = print(io, "CUBLASError(code $(err.code), $(err.msg))")

function CUBLASError(code::cublasStatus_t)
msg = status_message(code)
return CUBLASError(code, msg)
end
Base.convert(::Type{cublasStatus_t}, err::CUBLASError) = err.code

Base.showerror(io::IO, err::CUBLASError) =
print(io, "CUBLASError: ", description(err), " (code $(reinterpret(Int32, err.code)), $(name(err)))")

name(err::CUBLASError) = string(err.code)

function status_message(status)
if status == CUBLAS_STATUS_SUCCESS
return "the operation completed successfully"
elseif status == CUBLAS_STATUS_NOT_INITIALIZED
return "the library was not initialized"
elseif status == CUBLAS_STATUS_ALLOC_FAILED
return "the resource allocation failed"
elseif status == CUBLAS_STATUS_INVALID_VALUE
return "an invalid value was used as an argument"
elseif status == CUBLAS_STATUS_ARCH_MISMATCH
return "an absent device architectural feature is required"
elseif status == CUBLAS_STATUS_MAPPING_ERROR
return "an access to GPU memory space failed"
elseif status == CUBLAS_STATUS_EXECUTION_FAILED
return "the GPU program failed to execute"
elseif status == CUBLAS_STATUS_INTERNAL_ERROR
return "an internal operation failed"
elseif status == CUBLAS_STATUS_NOT_SUPPORTED
return "the requested feature is not supported"
elseif status == CUBLAS_STATUS_LICENSE_ERROR
return "error detected trying to check the license"
function description(err)
if err.code == CUBLAS_STATUS_SUCCESS
"the operation completed successfully"
elseif err.code == CUBLAS_STATUS_NOT_INITIALIZED
"the library was not initialized"
elseif err.code == CUBLAS_STATUS_ALLOC_FAILED
"the resource allocation failed"
elseif err.code == CUBLAS_STATUS_INVALID_VALUE
"an invalid value was used as an argument"
elseif err.code == CUBLAS_STATUS_ARCH_MISMATCH
"an absent device architectural feature is required"
elseif err.code == CUBLAS_STATUS_MAPPING_ERROR
"an access to GPU memory space failed"
elseif err.code == CUBLAS_STATUS_EXECUTION_FAILED
"the GPU program failed to execute"
elseif err.code == CUBLAS_STATUS_INTERNAL_ERROR
"an internal operation failed"
elseif err.code == CUBLAS_STATUS_NOT_SUPPORTED
"the requested feature is not supported"
elseif err.code == CUBLAS_STATUS_LICENSE_ERROR
"error detected trying to check the license"
else
return "unknown status"
"no description for this error"
end
end

Expand Down
12 changes: 6 additions & 6 deletions src/dnn/error.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ export CUDNNError

struct CUDNNError <: Exception
code::cudnnStatus_t
msg::AbstractString
end
Base.show(io::IO, err::CUDNNError) = print(io, "CUDNNError(code $(err.code), $(err.msg))")

function CUDNNError(status::cudnnStatus_t)
msg = unsafe_string(cudnnGetErrorString(status))
return CUDNNError(status, msg)
end
Base.convert(::Type{cudnnStatus_t}, err::CUDNNError) = err.code

Base.showerror(io::IO, err::CUDNNError) =
print(io, "CUDNNError: ", name(err), " (code $(reinterpret(Int32, err.code)))")

name(err::CUDNNError) = unsafe_string(cudnnGetErrorString(err))


## API call wrapper
Expand Down
84 changes: 42 additions & 42 deletions src/fft/error.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,52 @@ export CUFFTError

struct CUFFTError <: Exception
code::cufftResult
msg::AbstractString
end
Base.show(io::IO, err::CUFFTError) = print(io, "CUFFTError(code $(err.code), $(err.msg))")

function CUFFTError(code::cufftResult)
msg = status_message(code)
return CUFFTError(code, msg)
end
Base.convert(::Type{cufftResult}, err::CUFFTError) = err.code

Base.showerror(io::IO, err::CUFFTError) =
print(io, "CUFFTError: ", description(err), " (code $(reinterpret(Int32, err.code)), $(name(err)))")

name(err::CUFFTError) = string(err.code)

function status_message(status)
if status == CUFFT_SUCCESS
return "the operation completed successfully"
elseif status == CUFFT_INVALID_PLAN
return "cuFFT was passed an invalid plan handle"
elseif status == CUFFT_ALLOC_FAILED
return "cuFFT failed to allocate GPU or CPU memory"
elseif status == CUFFT_INVALID_TYPE
return "cuFFT invalid type " # No longer used
elseif status == CUFFT_INVALID_VALUE
return "User specified an invalid pointer or parameter"
elseif status == CUFFT_INTERNAL_ERROR
return "Driver or internal cuFFT library error"
elseif status == CUFFT_EXEC_FAILED
return "Failed to execute an FFT on the GPU"
elseif status == CUFFT_SETUP_FAILED
return "The cuFFT library failed to initialize"
elseif status == CUFFT_INVALID_SIZE
return "User specified an invalid transform size"
elseif status == CUFFT_UNALIGNED_DATA
return "cuFFT unaligned data" # No longer used
elseif status == CUFFT_INCOMPLETE_PARAMETER_LIST
return "Missing parameters in call"
elseif status == CUFFT_INVALID_DEVICE
return "Execution of a plan was on different GPU than plan creation"
elseif status == CUFFT_PARSE_ERROR
return "Internal plan database error"
elseif status == CUFFT_NO_WORKSPACE
return "No workspace has been provided prior to plan execution"
elseif status == CUFFT_NOT_IMPLEMENTED
return "Function does not implement functionality for parameters given."
elseif status == CUFFT_LICENSE_ERROR
return "cuFFT license error" # Used in previous versions.
elseif status == CUFFT_NOT_SUPPORTED
return "Operation is not supported for parameters given."
function description(err::CUFFTError)
if err.code == CUFFT_SUCCESS
"the operation completed successfully"
elseif err.code == CUFFT_INVALID_PLAN
"cuFFT was passed an invalid plan handle"
elseif err.code == CUFFT_ALLOC_FAILED
"cuFFT failed to allocate GPU or CPU memory"
elseif err.code == CUFFT_INVALID_TYPE
"cuFFT invalid type " # No longer used
elseif err.code == CUFFT_INVALID_VALUE
"user specified an invalid pointer or parameter"
elseif err.code == CUFFT_INTERNAL_ERROR
"driver or internal cuFFT library error"
elseif err.code == CUFFT_EXEC_FAILED
"failed to execute an FFT on the GPU"
elseif err.code == CUFFT_SETUP_FAILED
"the cuFFT library failed to initialize"
elseif err.code == CUFFT_INVALID_SIZE
"user specified an invalid transform size"
elseif err.code == CUFFT_UNALIGNED_DATA
"cuFFT unaligned data" # No longer used
elseif err.code == CUFFT_INCOMPLETE_PARAMETER_LIST
"missing parameters in call"
elseif err.code == CUFFT_INVALID_DEVICE
"execution of a plan was on different GPU than plan creation"
elseif err.code == CUFFT_PARSE_ERROR
"internal plan database error"
elseif err.code == CUFFT_NO_WORKSPACE
"no workspace has been provided prior to plan execution"
elseif err.code == CUFFT_NOT_IMPLEMENTED
"function does not implement functionality for parameters given."
elseif err.code == CUFFT_LICENSE_ERROR
"cuFFT license error" # Used in previous versions.
elseif err.code == CUFFT_NOT_SUPPORTED
"operation is not supported for parameters given."
else
return "unknown status"
"no description for this error"
end
end

Expand Down
68 changes: 34 additions & 34 deletions src/rand/error.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,44 @@ export CURANDError

struct CURANDError <: Exception
code::curandStatus_t
msg::AbstractString
end
Base.show(io::IO, err::CURANDError) = print(io, "CURANDError(code $(err.code), $(err.msg))")

function CURANDError(code::curandStatus_t)
msg = status_message(code)
return CURANDError(code, msg)
end
Base.convert(::Type{curandStatus_t}, err::CURANDError) = err.code

Base.showerror(io::IO, err::CURANDError) =
print(io, "CURANDError: ", description(err), " (code $(reinterpret(Int32, err.code)), $(name(err)))")

name(err::CURANDError) = string(err.code)

function status_message(status)
if status == CURAND_STATUS_SUCCESS
return "generator was created successfully"
elseif status == CURAND_STATUS_VERSION_MISMATCH
return "Header file and linked library version do not match"
elseif status == CURAND_STATUS_NOT_INITIALIZED
return "Generator not initialized"
elseif status == CURAND_STATUS_ALLOCATION_FAILED
return "Memory allocation failed"
elseif status == CURAND_STATUS_TYPE_ERROR
return "Generator is wrong type"
elseif status == CURAND_STATUS_OUT_OF_RANGE
return "Argument out of range"
elseif status == CURAND_STATUS_LENGTH_NOT_MULTIPLE
return "Length requested is not a multple of dimension"
elseif status == CURAND_STATUS_DOUBLE_PRECISION_REQUIRED
return "GPU does not have double precision required by MRG32k3a"
elseif status == CURAND_STATUS_LAUNCH_FAILURE
return "Kernel launch failure"
elseif status == CURAND_STATUS_PREEXISTING_FAILURE
return "Preexisting failure on library entry"
elseif status == CURAND_STATUS_INITIALIZATION_FAILED
return "Initialization of CUDA failed"
elseif status == CURAND_STATUS_ARCH_MISMATCH
return "Architecture mismatch, GPU does not support requested feature"
elseif status == CURAND_STATUS_INTERNAL_ERROR
return "Internal library error"
function description(err)
if err.code == CURAND_STATUS_SUCCESS
"generator was created successfully"
elseif err.code == CURAND_STATUS_VERSION_MISMATCH
"header file and linked library version do not match"
elseif err.code == CURAND_STATUS_NOT_INITIALIZED
"generator not initialized"
elseif err.code == CURAND_STATUS_ALLOCATION_FAILED
"memory allocation failed"
elseif err.code == CURAND_STATUS_TYPE_ERROR
"generator is wrong type"
elseif err.code == CURAND_STATUS_OUT_OF_RANGE
"argument out of range"
elseif err.code == CURAND_STATUS_LENGTH_NOT_MULTIPLE
"length requested is not a multple of dimension"
elseif err.code == CURAND_STATUS_DOUBLE_PRECISION_REQUIRED
"GPU does not have double precision required by MRG32k3a"
elseif err.code == CURAND_STATUS_LAUNCH_FAILURE
"kernel launch failure"
elseif err.code == CURAND_STATUS_PREEXISTING_FAILURE
"preexisting failure on library entry"
elseif err.code == CURAND_STATUS_INITIALIZATION_FAILED
"initialization of CUDA failed"
elseif err.code == CURAND_STATUS_ARCH_MISMATCH
"architecture mismatch, GPU does not support requested feature"
elseif err.code == CURAND_STATUS_INTERNAL_ERROR
"internal library error"
else
return "unknown status"
"no description for this error"
end
end

Expand Down
48 changes: 24 additions & 24 deletions src/solver/error.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,34 @@ export CUSOLVERError

struct CUSOLVERError <: Exception
code::cusolverStatus_t
msg::AbstractString
end
Base.show(io::IO, err::CUSOLVERError) = print(io, "CUSOLVERError(code $(err.code), $(err.msg))")

function CUSOLVERError(code::cusolverStatus_t)
msg = status_message(code)
return CUSOLVERError(code, msg)
end
Base.convert(::Type{cusolverStatus_t}, err::CUSOLVERError) = err.code

Base.showerror(io::IO, err::CUSOLVERError) =
print(io, "CUSOLVERError: ", description(err), " (code $(reinterpret(Int32, err.code)), $(name(err)))")

name(err::CUSOLVERError) = string(err.code)

function status_message(status)
if status == CUSOLVER_STATUS_SUCCESS
return "the operation completed successfully"
elseif status == CUSOLVER_STATUS_NOT_INITIALIZED
return "the library was not initialized"
elseif status == CUSOLVER_STATUS_ALLOC_FAILED
return "the resource allocation failed"
elseif status == CUSOLVER_STATUS_INVALID_VALUE
return "an invalid value was used as an argument"
elseif status == CUSOLVER_STATUS_ARCH_MISMATCH
return "an absent device architectural feature is required"
elseif status == CUSOLVER_STATUS_EXECUTION_FAILED
return "the GPU program failed to execute"
elseif status == CUSOLVER_STATUS_INTERNAL_ERROR
return "an internal operation failed"
elseif status == CUSOLVER_STATUS_MATRIX_TYPE_NOT_SUPPORTED
return "the matrix type is not supported."
function description(err)
if err.code == CUSOLVER_STATUS_SUCCESS
"the operation completed successfully"
elseif err.code == CUSOLVER_STATUS_NOT_INITIALIZED
"the library was not initialized"
elseif err.code == CUSOLVER_STATUS_ALLOC_FAILED
"the resource allocation failed"
elseif err.code == CUSOLVER_STATUS_INVALID_VALUE
"an invalid value was used as an argument"
elseif err.code == CUSOLVER_STATUS_ARCH_MISMATCH
"an absent device architectural feature is required"
elseif err.code == CUSOLVER_STATUS_EXECUTION_FAILED
"the GPU program failed to execute"
elseif err.code == CUSOLVER_STATUS_INTERNAL_ERROR
"an internal operation failed"
elseif err.code == CUSOLVER_STATUS_MATRIX_TYPE_NOT_SUPPORTED
"the matrix type is not supported."
else
return "unknown status"
"no description for this error"
end
end

Expand Down
42 changes: 7 additions & 35 deletions src/sparse/error.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,16 @@ export CUSPARSEError

struct CUSPARSEError <: Exception
code::cusparseStatus_t
msg::AbstractString
end
Base.show(io::IO, err::CUSPARSEError) = print(io, "CUSPARSEError(code $(err.code), $(err.msg))")

function CUSPARSEError(code::cusparseStatus_t)
msg = status_message(code)
return CUSPARSEError(code, msg)
end
Base.convert(::Type{cusparseStatus_t}, err::CUSPARSEError) = err.code

function status_message( status )
if status == CUSPARSE_STATUS_SUCCESS
return "success"
end
if status == CUSPARSE_STATUS_NOT_INITIALIZED
return "not initialized"
end
if status == CUSPARSE_STATUS_ALLOC_FAILED
return "allocation failed"
end
if status == CUSPARSE_STATUS_INVALID_VALUE
return "invalid value"
end
if status == CUSPARSE_STATUS_ARCH_MISMATCH
return "architecture mismatch"
end
if status == CUSPARSE_STATUS_MAPPING_ERROR
return "mapping error"
end
if status == CUSPARSE_STATUS_EXECUTION_FAILED
return "execution failed"
end
if status == CUSPARSE_STATUS_INTERNAL_ERROR
return "internal error"
end
if status == CUSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED
return "matrix type not supported"
end
end
Base.showerror(io::IO, err::CUSPARSEError) =
print(io, "CUSPARSEError: ", description(err), " (code $(reinterpret(Int32, err.code)), $(name(err)))")

name(err::CUSPARSEError) = unsafe_string(cusparseGetErrorName(err))

description(err::CUSPARSEError) = unsafe_string(cusparseGetErrorString(err))


## API call wrapper
Expand Down
Loading

0 comments on commit 72882b2

Please sign in to comment.