forked from JuliaGPU/CUDA.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.jl
59 lines (48 loc) · 1.67 KB
/
error.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
export CUSOLVERError
struct CUSOLVERError <: Exception
code::cusolverStatus_t
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)
## COV_EXCL_START
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
"no description for this error"
end
end
## COV_EXCL_STOP
## API call wrapper
# outlined functionality to avoid GC frame allocation
@noinline function throw_api_error(res)
throw(CUSOLVERError(res))
end
function initialize_api()
CUDA.prepare_cuda_call()
end
macro check(ex)
quote
res = @retry_reclaim isequal(CUSOLVER_STATUS_ALLOC_FAILED) $(esc(ex))
if res != CUSOLVER_STATUS_SUCCESS
throw_api_error(res)
end
return
end
end