Skip to content

Commit ad371a0

Browse files
committed
feat: add LLVM setup script for modular installation
Add scripts/devinstall_llvm.sh to support LLVM installation and configuration within containers. This script: - Downloads LLVM source from GitHub when not mounted as a volume - Installs build dependencies for LLVM compilation - Provides a clean interface for LLVM integration The script supports the INSTALL_LLVM environment variable with 'source' or 'skip' options, enabling flexible LLVM setup for different container configurations. This is part of the modular script architecture introduced in PR #115. Signed-off-by: Craig Magina <cmagina@redhat.com>
1 parent d43501e commit ad371a0

File tree

11 files changed

+138
-16
lines changed

11 files changed

+138
-16
lines changed

.github/workflows/amd-image.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ on: # yamllint disable-line rule:truthy
1010
- scripts/entrypoint.sh
1111
- scripts/devinstall_software.sh
1212
- scripts/ldpretend.sh
13+
- scripts/devinstall_llvm.sh
1314
- scripts/devinstall_triton.sh
1415
- scripts/devcreate_user.sh
1516
- scripts/devsetup.sh
@@ -20,6 +21,7 @@ on: # yamllint disable-line rule:truthy
2021
- scripts/entrypoint.sh
2122
- scripts/devinstall_software.sh
2223
- scripts/ldpretend.sh
24+
- scripts/devinstall_llvm.sh
2325
- scripts/devinstall_triton.sh
2426
- scripts/devcreate_user.sh
2527
- scripts/devsetup.sh

.github/workflows/cpu-image.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ on: # yamllint disable-line rule:truthy
1010
- scripts/entrypoint.sh
1111
- scripts/devinstall_software.sh
1212
- scripts/ldpretend.sh
13+
- scripts/devinstall_llvm.sh
1314
- scripts/devinstall_triton.sh
1415
- scripts/devcreate_user.sh
1516
- scripts/devsetup.sh
@@ -20,6 +21,7 @@ on: # yamllint disable-line rule:truthy
2021
- scripts/entrypoint.sh
2122
- scripts/devinstall_software.sh
2223
- scripts/ldpretend.sh
24+
- scripts/devinstall_llvm.sh
2325
- scripts/devinstall_triton.sh
2426
- scripts/devcreate_user.sh
2527
- scripts/devsetup.sh

.github/workflows/llvm-image.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ on: # yamllint disable-line rule:truthy
66
- main
77
paths:
88
- .github/workflows/llvm-image.yml
9+
- scripts/devinstall_llvm.sh
910
- dockerfiles/Dockerfile.llvm
1011
pull_request:
1112
paths:
1213
- .github/workflows/llvm-image.yml
14+
- scripts/devinstall_llvm.sh
1315
- dockerfiles/Dockerfile.llvm
1416
schedule:
1517
- cron: '0 0 * * 0' # Runs every Sunday at midnight UTC

.github/workflows/nvidia-image.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ on: # yamllint disable-line rule:truthy
1010
- scripts/entrypoint.sh
1111
- scripts/devinstall_software.sh
1212
- scripts/ldpretend.sh
13+
- scripts/devinstall_llvm.sh
1314
- scripts/devinstall_triton.sh
1415
- scripts/devcreate_user.sh
1516
- scripts/devsetup.sh
@@ -20,6 +21,7 @@ on: # yamllint disable-line rule:truthy
2021
- scripts/entrypoint.sh
2122
- scripts/devinstall_software.sh
2223
- scripts/ldpretend.sh
24+
- scripts/devinstall_llvm.sh
2325
- scripts/devinstall_triton.sh
2426
- scripts/devcreate_user.sh
2527
- scripts/devsetup.sh

Makefile

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ gitconfig_path ?="$(HOME)/.gitconfig"
4242
USERNAME ?=triton
4343
# NOTE: Requires host build system to have a valid Red Hat Subscription if true
4444
INSTALL_NSIGHT ?=false
45+
llvm_path ?=
4546
user_path ?=
47+
INSTALL_LLVM ?= skip # Options: source, skip
4648
INSTALL_TRITON ?= source # Options: release, source, skip
4749
INSTALL_JUPYTER ?= true
4850
USE_CCACHE ?= 0
@@ -113,6 +115,9 @@ define run_container
113115
else \
114116
volume_arg=""; \
115117
fi; \
118+
if [ -n "$(llvm_path)" ]; then \
119+
volume_arg+=" -v $(llvm_path):/workspace/llvm-project$(SELINUXFLAG)"; \
120+
fi; \
116121
if [ -n "$(user_path)" ]; then \
117122
volume_arg+=" -v $(user_path):/workspace/user$(SELINUXFLAG)"; \
118123
fi; \
@@ -151,12 +156,15 @@ define run_container
151156
else \
152157
port_arg=""; \
153158
fi; \
159+
if [ "$(CUSTOM_LLVM)" = "false" ]; then \
160+
install_llvm="-e INSTALL_LLVM=$(INSTALL_LLVM)"; \
161+
fi; \
154162
env_vars="-e USERNAME=$(USER) -e USER_UID=`id -u $(USER)` -e USER_GID=`id -g $(USER)` -e TORCH_VERSION=$(torch_version) -e CUSTOM_LLVM=$(CUSTOM_LLVM) -e INSTALL_TOOLS=$(DEMO_TOOLS) -e INSTALL_JUPYTER=$(INSTALL_JUPYTER) -e NOTEBOOK_PORT=$(NOTEBOOK_PORT) -e INSTALL_TRITON=$(INSTALL_TRITON) -e USE_CCACHE=$(USE_CCACHE) -e MAX_JOBS=$(MAX_JOBS)"; \
155163
if [ "$(STRIPPED_CMD)" = "docker" ]; then \
156-
$(CTR_CMD) run $$env_vars $$gpu_args $$profiling_args $$port_arg \
164+
$(CTR_CMD) run $$env_vars $$gpu_args $$profiling_args $$install_llvm $$port_arg \
157165
-ti $$volume_arg $$gitconfig_arg $(IMAGE_REPO)/$(strip $(1)):$(TRITON_TAG) bash; \
158166
elif [ "$(STRIPPED_CMD)" = "podman" ]; then \
159-
$(CTR_CMD) run $$env_vars $$keep_ns_arg $$gpu_args $$profiling_args $$port_arg \
167+
$(CTR_CMD) run $$env_vars $$keep_ns_arg $$gpu_args $$profiling_args $$install_llvm $$port_arg \
160168
-ti $$volume_arg $$gitconfig_arg $(IMAGE_REPO)/$(strip $(1)):$(TRITON_TAG) bash; \
161169
fi
162170
endef

dockerfiles/Dockerfile.llvm

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,18 @@ ARG TRITON_CPU_BACKEND=0
88
ARG LLVM_TAG
99
USER 0
1010

11+
COPY scripts/devinstall_llvm.sh devinstall_llvm
12+
1113
# Conditionally execute the build based on CUSTOM_LLVM
1214
RUN if [ "$CUSTOM_LLVM" = "true" ]; then \
1315
dnf update -y && \
1416
dnf -y install clang rpm-build git ninja-build cmake lld && \
1517
dnf clean all && rm -rf /var/cache/dnf && \
16-
python3 -m pip install --upgrade pip && \
17-
python3 -m pip install --upgrade cmake ninja sccache pybind11 && \
18-
if [ ! -d "/llvm-project" ]; then \
19-
git clone https://github.com/llvm/llvm-project /llvm-project; \
20-
else \
21-
cd /llvm-project && git fetch origin; \
22-
fi && \
23-
cd /llvm-project && \
24-
python3 -m pip install -r mlir/python/requirements.txt && \
18+
python3 -m pip install --upgrade uv && \
19+
uv pip install --system --upgrade cmake ninja sccache pybind11 && \
20+
export WORKSPACE=/usr/src && \
21+
./devinstall_llvm source && \
22+
cd "/usr/src/llvm-project" && \
2523
REPO="triton"; \
2624
PROJECTS="mlir;llvm;lld"; \
2725
if [ "$TRITON_CPU_BACKEND" = "1" ]; then REPO="triton-cpu"; fi; \
@@ -63,8 +61,6 @@ RUN if [ "$CUSTOM_LLVM" = "true" ]; then \
6361
-DLLVM_INCLUDE_BENCHMARKS=OFF \
6462
-DMLIR_ENABLE_EXECUTION_ENGINE:bool=OFF && \
6563
ninja install; \
66-
else \
67-
echo "LLVM is already up-to-date. Skipping rebuild."; \
6864
fi \
6965
else \
7066
echo "Skipping LLVM build because CUSTOM_LLVM is not true"; \

dockerfiles/Dockerfile.triton

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ RUN dnf -y update && \
3232

3333
# Stage for llvm-local-true
3434
FROM base AS llvm-local-true
35-
COPY --from=quay.io/triton-dev-containers/llvm:latest /install /llvm-project/install
35+
COPY --from=quay.io/triton-dev-containers/llvm:latest /install /llvm-install
3636

3737
# Stage for llvm-local-false
3838
FROM base AS llvm-local-false
@@ -66,6 +66,7 @@ ENV BASH_ENV=/workspace/bin/activate \
6666

6767
COPY --from=quay.io/triton-dev-containers/gosu /usr/local/bin/gosu /usr/local/bin/gosu
6868

69+
COPY scripts/devinstall_llvm.sh /workspace/bin/devinstall_llvm
6970
COPY scripts/devinstall_triton.sh /workspace/bin/devinstall_triton
7071
COPY scripts/devcreate_user.sh /workspace/bin/devcreate_user
7172
COPY scripts/devsetup.sh /workspace/bin/devsetup

dockerfiles/Dockerfile.triton-amd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ ENV LC_ALL=C.UTF-8 \
4949

5050
# LLVM Integration Stages
5151
FROM base AS llvm-local-true
52-
COPY --from=quay.io/triton-dev-containers/llvm:latest /install /llvm-project/install
52+
COPY --from=quay.io/triton-dev-containers/llvm:latest /install /llvm-install
5353

5454
FROM base AS llvm-local-false
5555
ENV TRITON_OFFLINE_BUILD=NO
@@ -84,6 +84,7 @@ WORKDIR /workspace
8484

8585
COPY --from=quay.io/triton-dev-containers/gosu /usr/local/bin/gosu /usr/local/bin/gosu
8686

87+
COPY scripts/devinstall_llvm.sh /workspace/bin/devinstall_llvm
8788
COPY scripts/devinstall_triton.sh /workspace/bin/devinstall_triton
8889
COPY scripts/devcreate_user.sh /workspace/bin/devcreate_user
8990
COPY scripts/devsetup.sh /workspace/bin/devsetup

dockerfiles/Dockerfile.triton-cpu

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ RUN dnf update -y && \
2828

2929
# Stage for llvm-local-true
3030
FROM base AS llvm-local-true
31-
COPY --from=quay.io/triton-dev-containers/llvm:cpu-latest /install /llvm-project/install
31+
COPY --from=quay.io/triton-dev-containers/llvm:cpu-latest /install /llvm-install
3232

3333
# Stage for llvm-local-false
3434
FROM base AS llvm-local-false
@@ -63,6 +63,7 @@ WORKDIR /workspace
6363

6464
COPY --from=quay.io/triton-dev-containers/gosu /usr/local/bin/gosu /usr/local/bin/gosu
6565

66+
COPY scripts/devinstall_llvm.sh /workspace/bin/devinstall_llvm
6667
COPY scripts/devinstall_triton.sh /workspace/bin/devinstall_triton
6768
COPY scripts/devcreate_user.sh /workspace/bin/devcreate_user
6869
COPY scripts/devsetup.sh /workspace/bin/devsetup

scripts/devinstall_llvm.sh

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#! /bin/bash -e
2+
3+
trap "echo -e '\nScript interrupted. Exiting gracefully.'; exit 1" SIGINT
4+
5+
# Copyright (C) 2024-2025 Red Hat, Inc.
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#
19+
# SPDX-License-Identifier: Apache-2.0
20+
set -euo pipefail
21+
22+
WORKSPACE=${WORKSPACE:-${HOME}}
23+
24+
LLVM_DIR=${WORKSPACE}/llvm-project
25+
LLVM_REPO=https://github.com/llvm/llvm-project.git
26+
LLVM_BUILD_PATH=$LLVM_DIR/build
27+
28+
pip_install() {
29+
if command -v uv &>/dev/null; then
30+
uv pip install "$@"
31+
else
32+
pip install "$@"
33+
fi
34+
}
35+
36+
setup_src() {
37+
echo "Downloading LLVM source code and setting up the environment for building from source..."
38+
39+
if [ ! -d "$LLVM_DIR" ]; then
40+
echo "Cloning the LLVM Project repo $LLVM_REPO to $LLVM_DIR ..."
41+
git clone "$LLVM_REPO" "$LLVM_DIR"
42+
if [ ! -d "$LLVM_DIR" ]; then
43+
echo "$LLVM_DIR not found. ERROR Cloning repository..."
44+
exit 1
45+
else
46+
pushd "$LLVM_DIR" 1>/dev/null || exit 1
47+
git fetch origin
48+
49+
# shellcheck source=/dev/null
50+
[ -f "${HOME}"/.bashrc ] && source "${HOME}"/.bashrc
51+
52+
if [ -n "${LLVM_GITREF:-}" ]; then
53+
git checkout "$LLVM_GITREF"
54+
fi
55+
popd 1>/dev/null
56+
fi
57+
else
58+
echo "LLVM repo already present, not cloning ..."
59+
fi
60+
61+
echo "Adding LLVM_BUILD_PATH to ${HOME}/.bashrc ..."
62+
echo "export LLVM_BUILD_PATH=$LLVM_BUILD_PATH" >>"${HOME}/.bashrc"
63+
echo "Run 'source ${HOME}/.bashrc' to update the current shell"
64+
}
65+
66+
install_build_deps() {
67+
pushd "$LLVM_DIR" 1>/dev/null || exit 1
68+
if [ -f mlir/python/requirements.txt ]; then
69+
echo "Installing LLVM build dependencies ..."
70+
pip_install -r mlir/python/requirements.txt
71+
fi
72+
popd 1>/dev/null
73+
}
74+
75+
usage() {
76+
cat >&2 <<EOF
77+
Usage: $(basename "$0") [COMMAND]
78+
source Download LLVM's source (if needed) and install the build deps
79+
EOF
80+
}
81+
82+
##
83+
## Main
84+
##
85+
86+
if [ $# -ne 1 ]; then
87+
usage
88+
exit 1
89+
fi
90+
91+
COMMAND=${1,,}
92+
93+
case $COMMAND in
94+
source)
95+
setup_src
96+
install_build_deps
97+
;;
98+
*)
99+
usage
100+
exit 1
101+
;;
102+
esac

0 commit comments

Comments
 (0)