1
1
# example of a Docker container for CUDA.jl with a specific toolkit embedded at run time.
2
2
3
- FROM julia:1.8-bullseye
3
+ ARG JULIA_VERSION=1
4
+ FROM julia:${JULIA_VERSION}
4
5
6
+ ARG CUDA_VERSION=12.6
5
7
6
- # system-wide packages
8
+ ARG PACKAGE_SPEC=CUDA
9
+
10
+ LABEL maintainer=
"Tim Besard <[email protected] >"
11
+ LABEL description="CUDA.jl container with CUDA ${CUDA_VERSION} installed for Julia ${JULIA_VERSION}"
12
+ LABEL version="1.0"
7
13
8
- ENV JULIA_DEPOT_PATH=/usr/local/share/julia
9
14
10
- RUN julia -e 'using Pkg; Pkg.add("CUDA")'
15
+ # system-wide packages
11
16
12
- # hard-code a CUDA toolkit version
13
- RUN julia -e 'using CUDA; CUDA.set_runtime_version!(v"12.2")'
14
- # re-importing CUDA.jl below will trigger a download of the relevant artifacts
17
+ # no trailing ':' as to ensure we don't touch anything outside this directory. without it,
18
+ # Julia touches the compilecache timestamps in its shipped depot (for some reason; a bug?)
19
+ ENV JULIA_DEPOT_PATH=/usr/local/share/julia
15
20
16
- # generate the device runtime library for all known and supported devices.
17
- # this is to avoid having to do this over and over at run time.
18
- RUN julia -e 'using CUDA; CUDA.precompile_runtime()'
21
+ # pre-install the CUDA toolkit from an artifact. we do this separately from CUDA.jl so that
22
+ # this layer can be cached independently. it also avoids double precompilation of CUDA.jl in
23
+ # order to call `CUDA.set_runtime_version!`.
24
+ RUN julia -e '#= configure the preference =# \
25
+ env = "/usr/local/share/julia/environments/v$(VERSION.major).$(VERSION.minor)"; \
26
+ mkpath(env); \
27
+ write("$env/LocalPreferences.toml", \
28
+ "[CUDA_Runtime_jll]\n version = \" ' ${CUDA_VERSION}'\" "); \
29
+ \
30
+ #= install the JLL =# \
31
+ using Pkg; \
32
+ Pkg.add("CUDA_Runtime_jll")' && \
33
+ # = remove nondeterminisms =# \
34
+ cd /usr/local/share/julia && \
35
+ rm -rf compiled registries scratchspaces logs && \
36
+ find -exec touch -h -d "@0" {} + && \
37
+ touch -h -d "@0" /usr/local/share
38
+
39
+ # install CUDA.jl itself
40
+ RUN julia -e 'using Pkg; pkg"add ' ${PACKAGE_SPEC}'"; \
41
+ using CUDA; CUDA.precompile_runtime()' && \
42
+ # = remove useless stuff =# \
43
+ cd /usr/local/share/julia && \
44
+ rm -rf registries scratchspaces logs
19
45
20
46
21
47
# user environment
@@ -25,6 +51,11 @@ RUN julia -e 'using CUDA; CUDA.precompile_runtime()'
25
51
# case there might not be a (writable) home directory.
26
52
27
53
RUN mkdir -m 0777 /depot
28
- ENV JULIA_DEPOT_PATH=/depot:/usr/local/share/julia
54
+ ENV JULIA_DEPOT_PATH=/depot:/usr/local/share/julia:
55
+
56
+ # make sure the user depot is the one used by default (which requires a valid Project.toml)
57
+ # TODO: do this with a startup script so that you can mount `/depot` as a volume
58
+ # TODO: demote CUDA_Runtime_jll as an [extra] dep so that it doesn't show in the status
59
+ RUN cp -ar /usr/local/share/julia/environments /depot
29
60
30
61
WORKDIR "/workspace"
0 commit comments