forked from JuliaGPU/CUDA.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.jl
82 lines (71 loc) · 2.59 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
export CUFFTError
struct CUFFTError <: Exception
code::cufftResult
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)
## COV_EXCL_START
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
"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)
if res == CUFFT_ALLOC_FAILED
throw(OutOfGPUMemoryError())
else
throw(CUFFTError(res))
end
end
macro check(ex, errs...)
check = :(isequal(err, CUFFT_ALLOC_FAILED))
for err in errs
check = :($check || isequal(err, $(esc(err))))
end
quote
res = @retry_reclaim err->$check $(esc(ex))
if res != CUFFT_SUCCESS
throw_api_error(res)
end
nothing
end
end