| 1 | #!/usr/bin/env bash |
| 2 | # SPDX-License-Identifier: Apache-2.0 |
| 3 | # SPDX-FileCopyrightText: Copyright contributors to the vLLM project |
| 4 | |
| 5 | set -euxo pipefail |
| 6 | |
| 7 | # Surface the isolated snapshot-runtime install cost in the CI build log. The |
| 8 | # trap captures the status first: the date substitution below would reset it. |
| 9 | _snapshot_install_started=$(date +%s) |
| 10 | code=0 |
| 11 | trap 'code=$?; echo "[TIMING] snapshot runtime install: $(( $(date +%s) - _snapshot_install_started )) s (exit $code)"' EXIT |
| 12 | |
| 13 | readonly CRIU_VERSION="4.2.1" |
| 14 | readonly CRIU_SOURCE_SHA256="feffdf4638125ebb12d2434754f80a1d7bbba85a3e6bee98c216f88fb99a5d96" |
| 15 | readonly DYNAMO_CHECKPOINT_HELPER_COMMIT="fdf25efad60f696a73393caf341c527a93d84190" |
| 16 | readonly DYNAMO_CHECKPOINT_HELPER_SHA256="7b8ea21baecb1da729202c32e0fecbbbafb789d65e5c1c0649ea253ad09b8f82" |
| 17 | readonly DYNAMO_LICENSE_SHA256="aeeca3d74a13b91d17ab9211c407b8d94a77bf8d9e5750c467818d3066b8adcf" |
| 18 | |
| 19 | # Keep the compiler and NL headers required by runtime JIT and RDMA. |
| 20 | snapshot_shared_build_deps=( |
| 21 | build-essential |
| 22 | libnl-3-dev |
| 23 | libnl-route-3-dev |
| 24 | ) |
| 25 | snapshot_build_deps=( |
| 26 | pkg-config |
| 27 | libbsd-dev |
| 28 | libcap-dev |
| 29 | libnet1-dev |
| 30 | libprotobuf-dev |
| 31 | libprotobuf-c-dev |
| 32 | protobuf-c-compiler |
| 33 | protobuf-compiler |
| 34 | python3-protobuf |
| 35 | libgnutls28-dev |
| 36 | libnftables-dev |
| 37 | uuid-dev |
| 38 | ) |
| 39 | snapshot_runtime_deps=( |
| 40 | libbsd0 |
| 41 | libcap2 |
| 42 | libnet1 |
| 43 | libnl-3-200 |
| 44 | libnl-route-3-200 |
| 45 | libprotobuf-c1 |
| 46 | libgnutls30t64 |
| 47 | libnftables1 |
| 48 | iproute2 |
| 49 | iptables |
| 50 | procps |
| 51 | uuid-runtime |
| 52 | util-linux |
| 53 | ) |
| 54 | |
| 55 | apt-get update -y |
| 56 | apt-get install -y --no-install-recommends \ |
| 57 | "${snapshot_shared_build_deps[@]}" \ |
| 58 | "${snapshot_build_deps[@]}" \ |
| 59 | "${snapshot_runtime_deps[@]}" |
| 60 | |
| 61 | snapshot_build_dir="$(mktemp -d)" |
| 62 | curl -fsSL \ |
| 63 | "https://github.com/checkpoint-restore/criu/archive/refs/tags/v${CRIU_VERSION}.tar.gz" \ |
| 64 | -o "${snapshot_build_dir}/criu.tar.gz" |
| 65 | echo "${CRIU_SOURCE_SHA256} ${snapshot_build_dir}/criu.tar.gz" | sha256sum -c - |
| 66 | mkdir "${snapshot_build_dir}/criu" |
| 67 | tar -xzf "${snapshot_build_dir}/criu.tar.gz" \ |
| 68 | --strip-components=1 -C "${snapshot_build_dir}/criu" |
| 69 | make -C "${snapshot_build_dir}/criu" -j"${MAX_JOBS:-$(nproc)}" criu cuda_plugin |
| 70 | install -D -m 0755 "${snapshot_build_dir}/criu/criu/criu" \ |
| 71 | /usr/local/sbin/criu |
| 72 | install -D -m 0755 \ |
| 73 | "${snapshot_build_dir}/criu/plugins/cuda/cuda_plugin.so" \ |
| 74 | /usr/local/lib/criu/cuda_plugin.so |
| 75 | |
| 76 | helper_url="https://raw.githubusercontent.com/ai-dynamo/dynamo/${DYNAMO_CHECKPOINT_HELPER_COMMIT}/deploy/snapshot/cmd/cuda-checkpoint-helper/main.c" |
| 77 | curl -fsSL "${helper_url}" -o "${snapshot_build_dir}/cuda-checkpoint.c" |
| 78 | echo "${DYNAMO_CHECKPOINT_HELPER_SHA256} ${snapshot_build_dir}/cuda-checkpoint.c" \ |
| 79 | | sha256sum -c - |
| 80 | gcc -O2 -Wall -Wextra \ |
| 81 | -I/usr/local/cuda/include \ |
| 82 | -L/usr/local/cuda/lib64/stubs \ |
| 83 | "${snapshot_build_dir}/cuda-checkpoint.c" -lcuda \ |
| 84 | -o /usr/local/sbin/cuda-checkpoint |
| 85 | |
| 86 | license_url="https://raw.githubusercontent.com/ai-dynamo/dynamo/${DYNAMO_CHECKPOINT_HELPER_COMMIT}/LICENSE" |
| 87 | curl -fsSL "${license_url}" -o "${snapshot_build_dir}/DYNAMO-LICENSE" |
| 88 | echo "${DYNAMO_LICENSE_SHA256} ${snapshot_build_dir}/DYNAMO-LICENSE" \ |
| 89 | | sha256sum -c - |
| 90 | |
| 91 | install -D -m 0644 "${snapshot_build_dir}/criu.tar.gz" \ |
| 92 | /usr/share/doc/criu/source/criu.tar.gz |
| 93 | install -D -m 0644 "${snapshot_build_dir}/criu/COPYING" \ |
| 94 | /usr/share/doc/criu/COPYING |
| 95 | install -D -m 0644 "${snapshot_build_dir}/cuda-checkpoint.c" \ |
| 96 | /usr/share/doc/cuda-checkpoint-helper/main.c |
| 97 | install -D -m 0644 "${snapshot_build_dir}/DYNAMO-LICENSE" \ |
| 98 | /usr/share/doc/cuda-checkpoint-helper/LICENSE |
| 99 | |
| 100 | criu --version |
| 101 | ln -s /usr/local/cuda/lib64/stubs/libcuda.so \ |
| 102 | "${snapshot_build_dir}/libcuda.so.1" |
| 103 | LD_LIBRARY_PATH="${snapshot_build_dir}" \ |
| 104 | cuda-checkpoint --help | grep -q -- "--action" |
| 105 | test -x /usr/local/lib/criu/cuda_plugin.so |
| 106 | |
| 107 | apt-get purge -y --auto-remove "${snapshot_build_deps[@]}" |
| 108 | rm -rf "${snapshot_build_dir}" |
| 109 | rm -rf /var/lib/apt/lists/* |