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}
5
+
6
+ ARG CUDA_VERSION=12.6
7
+
8
+ ARG PACKAGE_SPEC=CUDA
9
+
10
+ LABEL org.opencontainers.image.authors=
"Tim Besard <[email protected] >"
11
+ LABEL org.opencontainers.image.description="CUDA.jl container with CUDA ${CUDA_VERSION} installed for Julia ${JULIA_VERSION}"
12
+ LABEL org.opencontainers.image.title="CUDA.jl"
13
+ LABEL org.opencontainers.image.url="https://juliagpu.org/cuda/"
14
+ LABEL org.opencontainers.image.source="https://github.com/JuliaGPU/CUDA.jl"
15
+ LABEL org.opencontainers.image.licenses="MIT"
4
16
5
17
6
18
# system-wide packages
7
19
20
+ # no trailing ':' as to ensure we don't touch anything outside this directory. without it,
21
+ # Julia touches the compilecache timestamps in its shipped depot (for some reason; a bug?)
8
22
ENV JULIA_DEPOT_PATH=/usr/local/share/julia
9
23
10
- RUN julia -e 'using Pkg; Pkg.add("CUDA")'
24
+ # pre-install the CUDA toolkit from an artifact. we do this separately from CUDA.jl so that
25
+ # this layer can be cached independently. it also avoids double precompilation of CUDA.jl in
26
+ # order to call `CUDA.set_runtime_version!`.
27
+ RUN julia -e '#= configure the preference =# \
28
+ env = "/usr/local/share/julia/environments/v$(VERSION.major).$(VERSION.minor)"; \
29
+ mkpath(env); \
30
+ write("$env/LocalPreferences.toml", \
31
+ "[CUDA_Runtime_jll]\n version = \" ' ${CUDA_VERSION}'\" "); \
32
+ \
33
+ #= install the JLL =# \
34
+ using Pkg; \
35
+ Pkg.add("CUDA_Runtime_jll")' && \
36
+ # = demote the JLL to an [extras] dep =# \
37
+ find /usr/local/share/julia/environments -name Project.toml -exec sed -i 's/deps/extras/' {} + && \
38
+ # = remove nondeterminisms =# \
39
+ cd /usr/local/share/julia && \
40
+ rm -rf compiled registries scratchspaces logs && \
41
+ find -exec touch -h -d "@0" {} + && \
42
+ touch -h -d "@0" /usr/local/share
11
43
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
15
-
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()'
44
+ # install CUDA.jl itself
45
+ RUN julia -e 'using Pkg; pkg"add ' ${PACKAGE_SPEC}'"; \
46
+ using CUDA; CUDA.precompile_runtime()' && \
47
+ # = remove useless stuff =# \
48
+ cd /usr/local/share/julia && \
49
+ rm -rf registries scratchspaces logs
19
50
20
51
21
52
# user environment
@@ -25,6 +56,17 @@ RUN julia -e 'using CUDA; CUDA.precompile_runtime()'
25
56
# case there might not be a (writable) home directory.
26
57
27
58
RUN mkdir -m 0777 /depot
28
- ENV JULIA_DEPOT_PATH=/depot:/usr/local/share/julia
59
+
60
+ # we add the user environment from a start-up script
61
+ # so that the user can mount `/depot` for persistency
62
+ ENV JULIA_DEPOT_PATH=/usr/local/share/julia:
63
+ COPY <<EOF /usr/local/share/julia/config/startup.jl
64
+ if !isdir("/depot/environments/v$(VERSION.major).$(VERSION.minor)" )
65
+ mkpath("/depot/environments" )
66
+ cp("/usr/local/share/julia/environments/v$(VERSION.major).$(VERSION.minor)" ,
67
+ "/depot/environments/v$(VERSION.major).$(VERSION.minor)" )
68
+ end
69
+ pushfirst!(DEPOT_PATH, "/depot" )
70
+ EOF
29
71
30
72
WORKDIR "/workspace"
0 commit comments