forked from JuliaGPU/CUDA.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.jl
74 lines (63 loc) · 2.29 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
export CURANDError
struct CURANDError <: Exception
code::curandStatus_t
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)
## COV_EXCL_START
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
"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 == CURAND_STATUS_ALLOCATION_FAILED
throw(OutOfGPUMemoryError())
else
throw(CURANDError(res))
end
end
macro check(ex, errs...)
check = :(isequal(err, CURAND_STATUS_ALLOCATION_FAILED))
for err in errs
check = :($check || isequal(err, $(esc(err))))
end
quote
res = @retry_reclaim err->$check $(esc(ex))
if res != CURAND_STATUS_SUCCESS
throw_api_error(res)
end
nothing
end
end