Skip to content

Commit a763309

Browse files
authored
Allow precompiling CUDA code. (#1865)
1 parent 0cca216 commit a763309

File tree

5 files changed

+15
-17
lines changed

5 files changed

+15
-17
lines changed

lib/cudnn/src/cuDNN.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,22 +151,21 @@ end
151151

152152
function __init__()
153153
precompiling = ccall(:jl_generating_output, Cint, ()) != 0
154-
precompiling && return
155154

156155
CUDA.functional() || return
157156

158157
global libcudnn
159158
if CUDA_Runtime == CUDA_Runtime_jll
160159
if !CUDNN_jll.is_available()
161-
@error "cuDNN is not available for your platform ($(Base.BinaryPlatforms.triplet(CUDNN_jll.host_platform)))"
160+
precompiling || @error "cuDNN is not available for your platform ($(Base.BinaryPlatforms.triplet(CUDNN_jll.host_platform)))"
162161
return
163162
end
164163
libcudnn = CUDNN_jll.libcudnn
165164
else
166165
dirs = CUDA_Runtime.find_toolkit()
167166
path = CUDA_Runtime.get_library(dirs, "cudnn"; optional=true)
168167
if path === nothing
169-
@error "cuDNN is not available on your system (looked in $(join(dirs, ", ")))"
168+
precompiling || @error "cuDNN is not available on your system (looked in $(join(dirs, ", ")))"
170169
return
171170
end
172171
libcudnn = path

lib/custatevec/src/cuStateVec.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,22 +103,21 @@ end
103103

104104
function __init__()
105105
precompiling = ccall(:jl_generating_output, Cint, ()) != 0
106-
precompiling && return
107106

108107
CUDA.functional() || return
109108

110109
global libcustatevec
111110
if CUDA_Runtime == CUDA_Runtime_jll
112111
if !cuQuantum_jll.is_available()
113-
@error "cuQuantum is not available for your platform ($(Base.BinaryPlatforms.triplet(cuQuantum_jll.host_platform)))"
112+
precompiling || @error "cuQuantum is not available for your platform ($(Base.BinaryPlatforms.triplet(cuQuantum_jll.host_platform)))"
114113
return
115114
end
116115
libcustatevec = cuQuantum_jll.libcustatevec
117116
else
118117
dirs = CUDA_Runtime.find_toolkit()
119118
path = CUDA_Runtime.get_library(dirs, "custatevec"; optional=true)
120119
if path === nothing
121-
@error "cuQuantum is not available on your system (looked for custatevec in $(join(dirs, ", ")))"
120+
precompiling || @error "cuQuantum is not available on your system (looked for custatevec in $(join(dirs, ", ")))"
122121
return
123122
end
124123
libcustatevec = path

lib/cutensor/src/cuTENSOR.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,22 +87,21 @@ end
8787

8888
function __init__()
8989
precompiling = ccall(:jl_generating_output, Cint, ()) != 0
90-
precompiling && return
9190

9291
CUDA.functional() || return
9392

9493
global libcutensor
9594
if CUDA_Runtime == CUDA_Runtime_jll
9695
if !CUTENSOR_jll.is_available()
97-
@error "cuTENSOR is not available for your platform ($(Base.BinaryPlatforms.triplet(CUTENSOR_jll.host_platform)))"
96+
precompiling || @error "cuTENSOR is not available for your platform ($(Base.BinaryPlatforms.triplet(CUTENSOR_jll.host_platform)))"
9897
return
9998
end
10099
libcutensor = CUTENSOR_jll.libcutensor
101100
else
102101
dirs = CUDA_Runtime.find_toolkit()
103102
path = CUDA_Runtime.get_library(dirs, "cutensor"; optional=true)
104103
if path === nothing
105-
@error "cuTENSOR is not available on your system (looked in $(join(dirs, ", ")))"
104+
precompiling || @error "cuTENSOR is not available on your system (looked in $(join(dirs, ", ")))"
106105
return
107106
end
108107
libcutensor = path

lib/cutensornet/src/cuTensorNet.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,22 +104,21 @@ end
104104

105105
function __init__()
106106
precompiling = ccall(:jl_generating_output, Cint, ()) != 0
107-
precompiling && return
108107

109108
CUDA.functional() || return
110109

111110
global libcutensornet
112111
if CUDA_Runtime == CUDA_Runtime_jll
113112
if !cuQuantum_jll.is_available()
114-
@error "cuQuantum is not available for your platform ($(Base.BinaryPlatforms.triplet(cuQuantum_jll.host_platform)))"
113+
precompiling || @error "cuQuantum is not available for your platform ($(Base.BinaryPlatforms.triplet(cuQuantum_jll.host_platform)))"
115114
return
116115
end
117116
libcutensornet = cuQuantum_jll.libcutensornet
118117
else
119118
dirs = CUDA_Runtime.find_toolkit()
120119
path = CUDA_Runtime.get_library(dirs, "cutensornet"; optional=true)
121120
if path === nothing
122-
@error "cuQuantum is not available on your system (looked for cutensornet in $(join(dirs, ", ")))"
121+
precompiling || @error "cuQuantum is not available on your system (looked for cutensornet in $(join(dirs, ", ")))"
123122
return
124123
end
125124
libcutensornet = path

src/initialization.jl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ end
3030

3131
function __init__()
3232
precompiling = ccall(:jl_generating_output, Cint, ()) != 0
33-
precompiling && return
3433

3534
# TODO: make errors here (and in submodules/subpackages like cuBLAS and cuDNN) fatal,
3635
# and remove functional(), once people sufficiently use weak dependencies.
@@ -124,12 +123,15 @@ function __init__()
124123
end
125124

126125
# register device overrides
127-
eval(Expr(:block, overrides...))
128-
empty!(overrides)
129-
@require SpecialFunctions="276daf66-3868-5448-9aa4-cd146d93841b" begin
130-
include("device/intrinsics/special_math.jl")
126+
if !precompiling
131127
eval(Expr(:block, overrides...))
132128
empty!(overrides)
129+
130+
@require SpecialFunctions="276daf66-3868-5448-9aa4-cd146d93841b" begin
131+
include("device/intrinsics/special_math.jl")
132+
eval(Expr(:block, overrides...))
133+
empty!(overrides)
134+
end
133135
end
134136

135137
# ensure that operations executed by the REPL back-end finish before returning,

0 commit comments

Comments
 (0)