-
Notifications
You must be signed in to change notification settings - Fork 239
Expand file tree
/
Copy pathdocker-recipe.py
More file actions
151 lines (115 loc) · 6.25 KB
/
docker-recipe.py
File metadata and controls
151 lines (115 loc) · 6.25 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
"""
HPCCM development container for the stdpar C++ and Fortran tutorials
https://github.com/NVIDIA/hpc-container-maker/
"""
import platform
from hpccm.primitives import raw
tutorial = 'stdpar'
ubuntu_ver = '22.04'
nvhpc_ver = '24.3'
cuda_ver = '12.3'
gcc_ver = '13'
llvm_ver = '18'
cmake_ver = '3.27.2'
boost_ver = '1.75.0'
arch = platform.machine()
Stage0 += baseimage(image=f'nvcr.io/nvidia/nvhpc:{nvhpc_ver}-devel-cuda{cuda_ver}-ubuntu{ubuntu_ver}')
Stage0 += environment(variables={
'ACH_STDPAR_NVHPC_VERSION': nvhpc_ver,
'ACH_STDPAR_CUDA_VERSION': cuda_ver,
'ACH_STDPAR_ARCH': arch,
'ACPP_APPDB_DIR': '/accelerated-computing-hub/',
'ACH_NSYS_PATH': f'/opt/nvidia/hpc_sdk/Linux_{arch}/{nvhpc_ver}/compilers/bin/nsys',
'ACH_NCU_PATH': f'/opt/nvidia/hpc_sdk/Linux_{arch}/{nvhpc_ver}/compilers/bin/ncu',
'PATH': '/accelerated-computing-hub/brev/wrappers:$PATH:/opt/adaptivecpp/bin',
'LD_LIBRARY_PATH': f'/usr/lib/llvm-{llvm_ver}/lib:$LD_LIBRARY_PATH',
'LIBRARY_PATH': f'/usr/lib/llvm-{llvm_ver}/lib:$LIBRARY_PATH',
# Silence pip warnings about running as root
'PIP_ROOT_USER_ACTION': 'ignore',
# Simplify running HPC-X on systems without InfiniBand
'OMPI_MCA_coll_hcoll_enable': '0',
# We do not need VFS for the exercises, and using it from a container in a 'generic' way is not trivial:
'UCX_VFS_ENABLE': 'n',
# Suppress warnings about UCX `cuda_copy` failures.
'UCX_LOG_LEVEL': 'warn',
# Allow HPC-X to oversubscribe the CPU with more ranks than cores without using mpirun --oversubscribe
'OMPI_MCA_rmaps_base_oversubscribe' : 'true',
# Select matplotdir config directory to silence warning
'MPLCONFIGDIR': '/tmp/matplotlib',
# Allow OpenMPI to run as root:
'OMPI_ALLOW_RUN_AS_ROOT': '1',
'OMPI_ALLOW_RUN_AS_ROOT_CONFIRM': '1',
# Workaround hwloc binding:
'OMPI_MCA_hwloc_base_binding_policy': 'none',
# Workaround nvfortran limit of 64k thread blocks
'NVCOMPILER_ACC_GANGLIMIT': '67108864', # (1 << 26)
})
Stage0 += packages(ospackages=[
'libtbb-dev', # Required for GCC C++ parallel algorithms
'python3', 'python3-pip', 'python-is-python3', 'python3-setuptools', 'python3-dev',
'make', 'build-essential', 'git', 'git-lfs',
'curl', 'wget', 'zip', 'bc',
'nginx', 'openssh-client',
'libnuma1', 'numactl',
'gosu', 'sudo',
])
Stage0 += boost(version=boost_ver) # Required for AdaptiveCpp
# Install GNU and LLVM toolchains
Stage0 += gnu(version=gcc_ver, extra_repository=True)
Stage0 += llvm(version=llvm_ver, upstream=True, extra_tools=True, toolset=True, _trunk_version='19')
# Patch libstdc++ to use our modified cartesian_product view that doesn't require HMM/ATS and copies
# the underlying range iterators instead of accessing them through host memory. This must be done
# after GCC is installed.
Stage0 += copy(src='tutorials/stdpar/include/ach/cartesian_product.hpp', dest='/usr/include/ach/cartesian_product.hpp')
Stage0 += copy(src='tutorials/stdpar/include/ranges', dest=f'/usr/include/c++/{gcc_ver}/ranges')
# Install CMake
Stage0 += cmake(eula=True, version=cmake_ver)
# Copy only requirements.txt first for better Docker layer caching.
Stage0 += copy(src=f'tutorials/{tutorial}/brev/requirements.txt', dest='/opt/requirements.txt')
Stage0 += shell(commands=[
'set -ex', # Exit on first error and debug output
# Configure the HPC SDK toolchain to pick the latest GCC
f'cd /opt/nvidia/hpc_sdk/Linux_{arch}/{nvhpc_ver}/compilers/bin/',
'makelocalrc -d . -x .',
'cd -',
# Install Python packages
'pip install --no-cache-dir --upgrade pip',
'pip install --no-cache-dir --root-user-action=ignore -r /opt/requirements.txt',
'rm -f /opt/requirements.txt',
# Build and install AdaptiveCpp
'git clone --depth=1 --shallow-submodules --recurse-submodules -b develop https://github.com/AdaptiveCpp/AdaptiveCpp',
'cd AdaptiveCpp',
'git submodule update --recursive',
f'cmake -Bbuild -H. -DCMAKE_C_COMPILER="$(which clang-{llvm_ver})" -DCMAKE_CXX_COMPILER="$(which clang++-{llvm_ver})" -DCMAKE_INSTALL_PREFIX=/opt/adaptivecpp -DWITH_CUDA_BACKEND=ON -DWITH_CPU_BACKEND=ON',
'cmake --build build --target install -j $(nproc)',
'cd -',
'rm -rf AdaptiveCpp',
# Install latest versions of range-v3 and NVIDIA's std::execution implementation
'git clone --depth=1 https://github.com/ericniebler/range-v3.git',
'cp -r range-v3/include/* /usr/include/',
'rm -rf range-v3',
'git clone --depth=1 https://github.com/nvidia/stdexec.git',
'cp -r stdexec/include/* /usr/include/',
'rm -rf stdexec',
# libc++abi: make sure clang with -stdlib=libc++ can find it
f'ln -sf /usr/lib/llvm-{llvm_ver}/lib/libc++abi.so.1 /usr/lib/llvm-{llvm_ver}/lib/libc++abi.so',
# Make mdspan use the paren operator for C++20 compatibility and put it in the std namespace
f'echo "#define MDSPAN_USE_PAREN_OPERATOR 1"|cat - /opt/nvidia/hpc_sdk/Linux_{arch}/{nvhpc_ver}/compilers/include/experimental/mdspan > /tmp/out && mv /tmp/out /opt/nvidia/hpc_sdk/Linux_{arch}/{nvhpc_ver}/compilers/include/experimental/mdspan',
f'echo "namespace std {{ using namespace ::std::experimental; }}" >> /opt/nvidia/hpc_sdk/Linux_{arch}/{nvhpc_ver}/compilers/include/experimental/mdspan',
# Install the NVIDIA HPC SDK mdspan systemwide:
f'ln -sf /opt/nvidia/hpc_sdk/Linux_{arch}/{nvhpc_ver}/compilers/include/experimental/mdspan /usr/include/mdspan',
f'ln -sf /opt/nvidia/hpc_sdk/Linux_{arch}/{nvhpc_ver}/compilers/include/experimental/__p0009_bits /usr/include/__p0009_bits',
# Put the include directory in the systemwide path:
f'ln -sf /accelerated-computing-hub/tutorials/stdpar/include/ach /usr/include/ach',
# Disable unnecessary default Jupyter extensions.
'python -m jupyter labextension disable "@jupyterlab/apputils-extension:announcements"',
'python -m jupyter labextension disable "@jupyterlab/console-extension:tracker"',
])
# Enable passwordless sudo for all users and pass through environment and path
Stage0 += shell(commands=[
"echo 'ALL ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers",
"sed -i -e 's/^Defaults\\s*env_reset/#&/' -e 's/^Defaults\\s*secure_path=/#&/' /etc/sudoers",
])
Stage0 += raw(docker='COPY --chmod=0777 . /accelerated-computing-hub')
Stage0 += workdir(directory=f'/accelerated-computing-hub/tutorials/{tutorial}/notebooks')
Stage0 += raw(docker='ENTRYPOINT ["/accelerated-computing-hub/brev/entrypoint.bash", "jupyter"]')