forked from KanuaK/triton-ascend
-
Notifications
You must be signed in to change notification settings - Fork 0
254 lines (224 loc) · 9.13 KB
/
Copy pathllvm-build.yml
File metadata and controls
254 lines (224 loc) · 9.13 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
name: LLVM Build
on:
push:
paths:
- cmake/llvm-hash.txt
- third_party/ascend/patch/llvm_patch_*.patch
- .github/workflows/llvm-build.yml
- .github/workflows/build/almalinux.Dockerfile
pull_request:
paths:
- cmake/llvm-hash.txt
- third_party/ascend/patch/llvm_patch_*.patch
- .github/workflows/llvm-build.yml
- .github/workflows/build/almalinux.Dockerfile
workflow_dispatch:
concurrency:
group: llvm-build-${{ github.ref }}
cancel-in-progress: true
env:
SCCACHE_DIR: ${{ github.workspace }}/sccache
permissions:
contents: read
id-token: write
jobs:
build:
name: Build on ${{ matrix.config.runner }}
runs-on: ${{ matrix.config.runs_on }}
# Cann container provides buildx remote builder config for AlmaLinux.
# Ubuntu native builds also work inside this container.
container:
image: swr.cn-southwest-2.myhuaweicloud.com/base_image/ascend-ci/cann:9.0.0-a3-ubuntu22.04-py3.12
timeout-minutes: 240
env:
PIP_INDEX_URL: http://cache-service.nginx-pypi-cache.svc.cluster.local/pypi/simple
PIP_TRUSTED_HOST: cache-service.nginx-pypi-cache.svc.cluster.local
strategy:
fail-fast: false
matrix:
config:
- {runner: 'Ubuntu 22.04', runs_on: 'linux-amd64-cpu-4', target-os: 'ubuntu', arch: 'x64'}
- {runner: 'Ubuntu 22.04 ARM64', runs_on: 'linux-aarch64-cpu-4', target-os: 'ubuntu', arch: 'arm64'}
- {runner: 'AlmaLinux 8', runs_on: 'linux-amd64-cpu-4', target-os: 'almalinux', arch: 'x64'}
- {runner: 'AlmaLinux 8 ARM64', runs_on: 'linux-aarch64-cpu-4', target-os: 'almalinux', arch: 'arm64'}
steps:
- name: Checkout Repo
uses: actions/checkout@v5
- name: Config mirrors & install build tools
if: matrix.config.target-os == 'ubuntu'
shell: bash
run: |
sed -i 's|http://archive.ubuntu.com|http://cache-service.nginx-pypi-cache.svc.cluster.local:8081|g' /etc/apt/sources.list 2>/dev/null || true
sed -i 's|http://ports.ubuntu.com|http://cache-service.nginx-pypi-cache.svc.cluster.local:8081|g' /etc/apt/sources.list 2>/dev/null || true
sed -i 's|http://security.ubuntu.com|http://cache-service.nginx-pypi-cache.svc.cluster.local:8081|g' /etc/apt/sources.list 2>/dev/null || true
apt-get update
apt-get install -y --no-install-recommends clang lld
- name: Fetch LLVM Commit Hash
shell: bash
run: |
LLVM_COMMIT_HASH="$(cat cmake/llvm-hash.txt)"
echo "Found LLVM commit hash: ${LLVM_COMMIT_HASH}"
echo "llvm_commit_hash=${LLVM_COMMIT_HASH}" >> ${GITHUB_ENV}
SHORT_LLVM_COMMIT_HASH="${LLVM_COMMIT_HASH:0:8}"
echo "Short LLVM commit hash: ${SHORT_LLVM_COMMIT_HASH}"
echo "short_llvm_commit_hash=${SHORT_LLVM_COMMIT_HASH}" >> ${GITHUB_ENV}
- name: Compute Patch Hash
shell: bash
run: |
PATCH_DIR="third_party/ascend/patch"
if [ -d "${PATCH_DIR}" ] && find "${PATCH_DIR}" -maxdepth 1 -type f -name 'llvm_patch_*.patch' -print -quit | grep -q .; then
PATCH_HASH=$(
LC_ALL=C find "${PATCH_DIR}" -maxdepth 1 -type f -name 'llvm_patch_*.patch' -print0 \
| sort -z \
| xargs -0 cat \
| sha256sum \
| cut -d' ' -f1 \
| cut -c1-8
)
else
PATCH_HASH="00000000"
fi
echo "Patch hash: ${PATCH_HASH}"
echo "patch_hash=${PATCH_HASH}" >> ${GITHUB_ENV}
INSTALL_DIR="llvm-${{ env.short_llvm_commit_hash }}-${PATCH_HASH}-${{ matrix.config.target-os }}-${{ matrix.config.arch }}"
echo "LLVM installation directory name: ${INSTALL_DIR}"
echo "llvm_install_dir=${INSTALL_DIR}" >> ${GITHUB_ENV}
- name: Checkout LLVM
uses: actions/checkout@v5
with:
repository: llvm/llvm-project
path: llvm-project
ref: ${{ env.llvm_commit_hash }}
- name: Apply LLVM patches
shell: bash
run: |
LLVM_SHORT="${{ env.short_llvm_commit_hash }}"
PATCH_DIR="third_party/ascend/patch"
if [ -d "${PATCH_DIR}" ]; then
cd llvm-project
for patchfile in ${GITHUB_WORKSPACE}/${PATCH_DIR}/llvm_patch_*.patch; do
if [ -f "$patchfile" ]; then
echo "Applying $patchfile..."
git apply "$patchfile"
fi
done
cd ..
fi
- name: Set up Python
shell: bash
run: |
if command -v python3 2>/dev/null; then
python3 --version
elif command -v apt-get 2>/dev/null; then
apt-get update && apt-get install -y python3 python3-pip
python3 --version
else
echo "ERROR: cannot find or install python3"
exit 1
fi
- name: Install Prerequisites
shell: bash
run: |
python3 -m pip install cmake ninja sccache
mkdir -p ${{ env.SCCACHE_DIR }}
rm -rf ${{ env.SCCACHE_DIR }}/*
- name: Install lld (Ubuntu)
# Linking mlir-opt with GNU ld needs 6-10GB and gets OOM-killed on the
# 4-CPU pods. lld uses far less memory and is required by
# -DCMAKE_LINKER=lld in the configure step below.
if: matrix.config.target-os == 'ubuntu'
shell: bash
run: |
apt-get install -y lld-15
update-alternatives --install /usr/bin/lld lld /usr/bin/lld-15 100
- name: Enable Cache
uses: actions/cache@v4
with:
path: ${{ env.SCCACHE_DIR }}
key: ${{ matrix.config.target-os }}-${{ matrix.config.arch }}-${{ env.short_llvm_commit_hash }}-${{ env.patch_hash }}
restore-keys: ${{ matrix.config.target-os }}-${{ matrix.config.arch }}-
- name: Configure, Build, and Install LLVM (Ubuntu)
if: matrix.config.target-os == 'ubuntu'
shell: bash
env:
LLVM_INSTALL_DIR: ${{ env.llvm_install_dir }}
run: >
python3 -m pip install -r llvm-project/mlir/python/requirements.txt
cmake -GNinja -Bllvm-project/build
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++
-DCMAKE_C_COMPILER_LAUNCHER=sccache -DCMAKE_CXX_COMPILER_LAUNCHER=sccache
-DCMAKE_INSTALL_PREFIX="${LLVM_INSTALL_DIR}"
-DCMAKE_LINKER=lld
-DLLVM_BUILD_UTILS=ON
-DLLVM_BUILD_TOOLS=ON
-DLLVM_ENABLE_ASSERTIONS=ON
-DMLIR_ENABLE_BINDINGS_PYTHON=OFF
-DLLVM_ENABLE_PROJECTS="mlir;lld"
-DLLVM_INSTALL_UTILS=ON
-DLLVM_TARGETS_TO_BUILD="host;NVPTX;AMDGPU"
-DLLVM_ENABLE_TERMINFO=OFF
-DLLVM_ENABLE_ZSTD=OFF
-DLLVM_PARALLEL_LINK_JOBS=1
llvm-project/llvm
ninja -C llvm-project/build install
tar czf "${LLVM_INSTALL_DIR}.tar.gz" "${LLVM_INSTALL_DIR}"
- name: Ensure sccache dir exists
if: matrix.config.target-os == 'almalinux'
env:
SCCACHE_DIR_PATH: ${{ env.SCCACHE_DIR }}
run: |
mkdir -p "${SCCACHE_DIR_PATH}"
touch "${SCCACHE_DIR_PATH}/.gitkeep"
- name: Build LLVM Image (AlmaLinux)
if: matrix.config.target-os == 'almalinux'
uses: docker/build-push-action@v7
with:
context: .
file: .github/workflows/build/almalinux.Dockerfile
build-args: |
BASE_IMAGE=swr.cn-southwest-2.myhuaweicloud.com/modelfoundry/almalinux:8.10-20250411
llvm_dir=llvm-project
target: output
outputs: type=local,dest=.
- name: Extract LLVM Artifacts (AlmaLinux)
if: matrix.config.target-os == 'almalinux'
shell: bash
env:
SCCACHE_DIR_PATH: ${{ env.SCCACHE_DIR }}
LLVM_INSTALL_DIR: ${{ env.llvm_install_dir }}
run: |
rm -rf "${SCCACHE_DIR_PATH}" "${LLVM_INSTALL_DIR}"
tar xzf llvm.tar.gz
mv install "${LLVM_INSTALL_DIR}"
tar czf "${LLVM_INSTALL_DIR}.tar.gz" "${LLVM_INSTALL_DIR}"
tar xzf sccache.tar.gz
rm -f llvm.tar.gz sccache.tar.gz
- name: Upload Build Artifacts
uses: actions/upload-artifact@v4
with:
name: llvm-${{ matrix.config.target-os }}-${{ matrix.config.arch }}
path: |
${{ github.workspace }}/llvm-*-${{ matrix.config.target-os }}-${{ matrix.config.arch }}.tar.gz
- name: Setup obsutil and upload to OBS
if: github.event_name == 'push' && github.repository == 'triton-lang/triton-ascend'
shell: bash
env:
AK: ${{ secrets.OBS_AK }}
SK: ${{ secrets.OBS_SK }}
ARCH: ${{ matrix.config.arch == 'x64' && 'amd64' || 'arm64' }}
run: |
set -eu
if [ -z "${AK}" ] || [ -z "${SK}" ]; then
echo "OBS credentials are empty."
exit 1
fi
curl -fL "https://obs-community.obs.cn-north-1.myhuaweicloud.com/obsutil/current/obsutil_linux_${ARCH}.tar.gz" -o obsutil.tar.gz
gzip -t obsutil.tar.gz || { echo "obsutil.tar.gz is not a valid gzip"; exit 1; }
tar xzf obsutil.tar.gz
rm -f obsutil.tar.gz
mv obsutil_linux_* obsutil
obsutil/obsutil config -i="${AK}" -k="${SK}" -e=https://obs.cn-southwest-2.myhuaweicloud.com
obsutil/obsutil cp -u "${{ env.llvm_install_dir }}.tar.gz" obs://triton-ascend-artifacts/llvm-builds/
- name: Dump Sccache Statistics
run: sccache --show-stats