Skip to content

Commit 4529ef0

Browse files
authored
Build fixes (both bazel and cmake) (#28)
* fix local Enzyme-JAX for debugging * working enzyme-clang build using bazel * update BUILD * reuse upstream PreserveNVVM * remove attributeKnownFunctions * pull in EnzymePreserveNVVM * Remove enzyme-opt * Enable Enzyme-JAX and libRaise Builds * Add script to run lbm tests * update build + test script * fix output resource dir for clang * updated run script * add workflow file for custom clang * add workflow file for plugin clang * rename * update workflow * make plugin name same as cmake * also build llvm * update deps * update test runner * rename plugin name * add script for running LBM in test * rename CMake targets, add upstream enzyme as dependency * update workflows, enzyme-cmake * update embedded clang workflow * update workflow * rename workflow * update * A bunch of stuff -only brings in PreserveNVVM from Enzyme -Fixes workspace -Updates Enzyme-JAX * update enzyme-jax * use lld in workflow * update Enzyme-JAX * testing stuff * add upterm * fix typo * install tmux * start upterm just before lbm * just stick to 1 * Fix Bazel clang-linker-wrapper handling in CI * Bump upstream Enzyme FetchContent SHA * Fix plugin workflow clang binary path * CI: stop at LBM compile on runners without GPUs * time to debug plugin * disabe bazel plugin for now, use cmake instead * remove clang-linker-wrapper * explicitly build clang-linker-wrapper
1 parent 803c188 commit 4529ef0

21 files changed

+709
-3358
lines changed
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
name: Reactant Bazel (Custom Clang)
2+
3+
on:
4+
schedule:
5+
- cron: 0 0 * * *
6+
push:
7+
branches:
8+
- main
9+
paths:
10+
- '.github/workflows/enzyme-bazel-only.yml'
11+
- 'enzyme/Enzyme/**'
12+
- 'enzyme/include/**'
13+
- 'enzyme/test/**'
14+
- 'enzyme/tools/**'
15+
- 'enzyme/BUILD'
16+
- 'enzyme/WORKSPACE'
17+
- 'enzyme/clang_resource_dir.bzl'
18+
pull_request:
19+
branches:
20+
- main
21+
paths:
22+
- '.github/workflows/enzyme-bazel-only.yml'
23+
- 'enzyme/Enzyme/**'
24+
- 'enzyme/include/**'
25+
- 'enzyme/test/**'
26+
- 'enzyme/tools/**'
27+
- 'enzyme/BUILD'
28+
- 'enzyme/WORKSPACE'
29+
- 'enzyme/clang_resource_dir.bzl'
30+
- 'enzyme/run_lbm_bazel.py'
31+
merge_group:
32+
33+
concurrency:
34+
# Skip intermediate builds: always.
35+
# Cancel intermediate builds: only if it is a pull request build.
36+
group: ${{ github.workflow }}-${{ github.ref }}
37+
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
38+
39+
jobs:
40+
build:
41+
name: Reactant Build - ${{ matrix.os }}
42+
runs-on: ${{ matrix.os }}
43+
44+
strategy:
45+
fail-fast: false
46+
matrix:
47+
build: ["Release"] # "RelWithDebInfo"
48+
llbuild: ["Release"]
49+
os: [linux-x86-n2-32]
50+
51+
timeout-minutes: 500
52+
53+
container:
54+
image: ${{ (contains(matrix.os, 'linux') && 'ghcr.io/enzymead/reactant-docker-images@sha256:d1ef9dda4ae609152f96ff0bf1e3ddec62c2969a020fed96f72daf1908bc5f34' ) || '' }}
55+
56+
steps:
57+
- name: Install dependencies
58+
run: |
59+
apt-get update
60+
apt-get install -y binutils ninja-build cmake gcc g++ python3 python3-dev gnupg ca-certificates opencl-headers ocl-icd-opencl-dev tmux
61+
curl -fsSL https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2404/x86_64/3bf863cc.pub | gpg --dearmor -o /usr/share/keyrings/cuda-archive-keyring.gpg
62+
echo "deb [signed-by=/usr/share/keyrings/cuda-archive-keyring.gpg] https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2404/x86_64 /" > /etc/apt/sources.list.d/cuda.list
63+
apt-get update
64+
apt-get install -y cuda-toolkit-12-9
65+
ln -sf /usr/local/cuda-12.9 /usr/local/cuda
66+
67+
- name: Check out Reactant
68+
uses: actions/checkout@v6
69+
with:
70+
path: 'Reactant'
71+
72+
- name: Check out Enzyme GPU Tests
73+
uses: actions/checkout@v6
74+
with:
75+
repository: 'wsmoses/Enzyme-GPU-Tests'
76+
path: 'Enzyme-GPU-Tests'
77+
ref: 'mlir'
78+
79+
80+
- name: Set BASE_DIR
81+
# We have to use `${GITHUB_WORKSPACE}` instead of `github.workspace` because GitHub
82+
# is terrible and the two don't match inside containers:
83+
# https://github.com/actions/runner/issues/2058
84+
run: |
85+
BASE_DIR=${GITHUB_WORKSPACE}
86+
# Make sure this directory exists, for good measure
87+
ls -lhrt "${BASE_DIR}"/Reactant
88+
ls -lhrt "${BASE_DIR}"/Enzyme-GPU-Tests
89+
echo "BASE_DIR=${BASE_DIR}" >> ${GITHUB_ENV}
90+
91+
- uses: bazel-contrib/setup-bazel@0.15.0
92+
name: Set up Bazel
93+
with:
94+
# Avoid downloading Bazel every time.
95+
bazelisk-cache: true
96+
# Store build cache per workflow.
97+
disk-cache: ${{ github.workflow }}-${{ matrix.os }}
98+
# Share repository cache between workflows.
99+
repository-cache: true
100+
bazelisk-version: 1.x
101+
102+
- name: Set BAZEL_FLAGS
103+
shell: bash
104+
run: |
105+
BAZEL_FLAGS=(
106+
--linkopt=-fuse-ld=lld
107+
--test_env=TPU_TOPOLOGY
108+
--test_env=TPU_WORKER_ID
109+
--test_env=TPU_SKIP_MDS_QUERY=true
110+
--test_env=TPU_TOPOLOGY_WRAP
111+
--test_env=TPU_CHIPS_PER_HOST_BOUNDS
112+
--test_env=TPU_ACCELERATOR_TYPE
113+
--test_env=TPU_RUNTIME_METRICS_PORTS
114+
--test_env=TPU_TOPOLOGY_ALT
115+
--test_env=TPU_HOST_BOUNDS
116+
--test_env=TPU_WORKER_HOSTNAMES
117+
--test_env=CHIPS_PER_HOST_BOUNDS
118+
--test_env=HOST_BOUNDS
119+
--test_env=ALT=false
120+
--test_env=WRAP
121+
--test_env=VBAR_CONTROL_SERVICE_URL
122+
--repo_env=CC=$(which clang)
123+
--define=using_clang=true
124+
--config=public_cache_push
125+
)
126+
echo "BAZEL_FLAGS=${BAZEL_FLAGS[@]}" >> "${GITHUB_ENV}"
127+
128+
- name: Reactant C++ build
129+
working-directory: ${{ env.BASE_DIR }}/Reactant/enzyme
130+
run: |
131+
bazel build $BAZEL_FLAGS --color=yes -c opt @llvm-project//clang:clang-linker-wrapper //:ClangReactantPlugin //:reactant-clang //:reactant-clang-resource @enzyme_ad//:libRaise.so --test_output=errors
132+
133+
- name: LBM build
134+
working-directory: ${{ env.BASE_DIR }}/Enzyme-GPU-Tests
135+
env:
136+
ENZYME_PATH: ${{ env.BASE_DIR }}/Reactant/enzyme/bazel-bin/libClangReactant-23.so
137+
CLANG_PATH: ${{ env.BASE_DIR }}/Reactant/enzyme/bazel-bin/reactant-clang -resource-dir=${{ env.BASE_DIR }}/Reactant/enzyme/bazel-bin/reactant-clang-resource
138+
LIB_RAISE_PATH: ${{ env.BASE_DIR }}/Reactant/enzyme/bazel-bin/external/enzyme_ad/libRaise.so
139+
CUDA_PATH: /usr/local/cuda
140+
run: |
141+
export PATH="${{ env.BASE_DIR }}/Reactant/enzyme/bazel-bin/external/llvm-project/clang:$PATH"
142+
cd LBM
143+
make EMBEDDED_CLANG=yes -j
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
name: Reactant Bazel (Plugin Clang)
2+
3+
on:
4+
schedule:
5+
- cron: 0 0 * * *
6+
push:
7+
branches:
8+
- main
9+
paths:
10+
- '.github/workflows/enzyme-bazel-only.yml'
11+
- 'enzyme/Enzyme/**'
12+
- 'enzyme/include/**'
13+
- 'enzyme/test/**'
14+
- 'enzyme/tools/**'
15+
- 'enzyme/BUILD'
16+
- 'enzyme/WORKSPACE'
17+
- 'enzyme/clang_resource_dir.bzl'
18+
pull_request:
19+
branches:
20+
- main
21+
paths:
22+
- '.github/workflows/enzyme-bazel-only.yml'
23+
- 'enzyme/Enzyme/**'
24+
- 'enzyme/include/**'
25+
- 'enzyme/test/**'
26+
- 'enzyme/tools/**'
27+
- 'enzyme/BUILD'
28+
- 'enzyme/WORKSPACE'
29+
- 'enzyme/clang_resource_dir.bzl'
30+
- 'enzyme/run_lbm_bazel.py'
31+
merge_group:
32+
33+
concurrency:
34+
# Skip intermediate builds: always.
35+
# Cancel intermediate builds: only if it is a pull request build.
36+
group: ${{ github.workflow }}-${{ github.ref }}
37+
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
38+
39+
jobs:
40+
build:
41+
if: ${{ false }}
42+
name: Reactant Build - ${{ matrix.os }}
43+
runs-on: ${{ matrix.os }}
44+
45+
strategy:
46+
fail-fast: false
47+
matrix:
48+
build: ["Release"] # "RelWithDebInfo"
49+
llbuild: ["Release"]
50+
os: [linux-x86-n2-32]
51+
52+
timeout-minutes: 500
53+
54+
container:
55+
image: ${{ (contains(matrix.os, 'linux') && 'ghcr.io/enzymead/reactant-docker-images@sha256:d1ef9dda4ae609152f96ff0bf1e3ddec62c2969a020fed96f72daf1908bc5f34' ) || '' }}
56+
57+
steps:
58+
- name: Install dependencies
59+
run: |
60+
apt-get update
61+
apt-get install -y binutils ninja-build cmake gcc g++ python3 python3-dev gnupg ca-certificates opencl-headers ocl-icd-opencl-dev tmux
62+
curl -fsSL https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2404/x86_64/3bf863cc.pub | gpg --dearmor -o /usr/share/keyrings/cuda-archive-keyring.gpg
63+
echo "deb [signed-by=/usr/share/keyrings/cuda-archive-keyring.gpg] https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2404/x86_64 /" > /etc/apt/sources.list.d/cuda.list
64+
apt-get update
65+
apt-get install -y cuda-toolkit-12-9
66+
ln -sf /usr/local/cuda-12.9 /usr/local/cuda
67+
68+
- name: Check out Reactant
69+
uses: actions/checkout@v6
70+
with:
71+
path: 'Reactant'
72+
73+
- name: Check out Enzyme GPU Tests
74+
uses: actions/checkout@v6
75+
with:
76+
repository: 'wsmoses/Enzyme-GPU-Tests'
77+
path: 'Enzyme-GPU-Tests'
78+
ref: 'mlir'
79+
80+
81+
- name: Set BASE_DIR
82+
# We have to use `${GITHUB_WORKSPACE}` instead of `github.workspace` because GitHub
83+
# is terrible and the two don't match inside containers:
84+
# https://github.com/actions/runner/issues/2058
85+
run: |
86+
BASE_DIR=${GITHUB_WORKSPACE}
87+
# Make sure this directory exists, for good measure
88+
ls -lhrt "${BASE_DIR}"/Reactant
89+
ls -lhrt "${BASE_DIR}"/Enzyme-GPU-Tests
90+
echo "BASE_DIR=${BASE_DIR}" >> ${GITHUB_ENV}
91+
92+
- uses: bazel-contrib/setup-bazel@0.15.0
93+
name: Set up Bazel
94+
with:
95+
# Avoid downloading Bazel every time.
96+
bazelisk-cache: true
97+
# Store build cache per workflow.
98+
disk-cache: ${{ github.workflow }}-${{ matrix.os }}
99+
# Share repository cache between workflows.
100+
repository-cache: true
101+
bazelisk-version: 1.x
102+
103+
- name: Set BAZEL_FLAGS
104+
shell: bash
105+
run: |
106+
BAZEL_FLAGS=(
107+
--linkopt=-fuse-ld=lld
108+
--test_env=TPU_TOPOLOGY
109+
--test_env=TPU_WORKER_ID
110+
--test_env=TPU_SKIP_MDS_QUERY=true
111+
--test_env=TPU_TOPOLOGY_WRAP
112+
--test_env=TPU_CHIPS_PER_HOST_BOUNDS
113+
--test_env=TPU_ACCELERATOR_TYPE
114+
--test_env=TPU_RUNTIME_METRICS_PORTS
115+
--test_env=TPU_TOPOLOGY_ALT
116+
--test_env=TPU_HOST_BOUNDS
117+
--test_env=TPU_WORKER_HOSTNAMES
118+
--test_env=CHIPS_PER_HOST_BOUNDS
119+
--test_env=HOST_BOUNDS
120+
--test_env=ALT=false
121+
--test_env=WRAP
122+
--test_env=VBAR_CONTROL_SERVICE_URL
123+
--repo_env=CC=$(which clang)
124+
--define=using_clang=true
125+
--config=public_cache_push
126+
)
127+
echo "BAZEL_FLAGS=${BAZEL_FLAGS[@]}" >> "${GITHUB_ENV}"
128+
129+
- name: Reactant C++ build
130+
working-directory: ${{ env.BASE_DIR }}/Reactant/enzyme
131+
run: |
132+
bazel build $BAZEL_FLAGS --color=yes -c opt //:ClangReactantPlugin @llvm-project//clang:clang //:reactant-clang-resource @enzyme_ad//:libRaise.so --test_output=errors
133+
134+
- name: Setup upterm session
135+
uses: owenthereal/action-upterm@v1
136+
137+
- name: LBM build
138+
working-directory: ${{ env.BASE_DIR }}/Enzyme-GPU-Tests
139+
env:
140+
ENZYME_PATH: ${{ env.BASE_DIR }}/Reactant/enzyme/bazel-bin/libClangReactant-23.so
141+
CLANG_PATH: ${{ env.BASE_DIR }}/Reactant/enzyme/bazel-bin/external/llvm-project/clang/clang -resource-dir=${{ env.BASE_DIR }}/Reactant/enzyme/bazel-bin/reactant-clang-resource
142+
LIB_RAISE_PATH: ${{ env.BASE_DIR }}/Reactant/enzyme/bazel-bin/external/enzyme_ad/libRaise.so
143+
CUDA_PATH: /usr/local/cuda
144+
run: |
145+
export PATH="${{ env.BASE_DIR }}/Reactant/enzyme/bazel-bin/external/llvm-project/clang:$PATH"
146+
cd LBM
147+
make EMBEDDED_CLANG=no -j

.github/workflows/enzyme-bazel.yml renamed to .github/workflows/reactant-cmake-plugin.yml

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Bazel
1+
name: Reactant CMake (Plugin Clang)
22

33
on:
44
schedule:
@@ -12,8 +12,8 @@ on:
1212
- 'enzyme/include/**'
1313
- 'enzyme/test/**'
1414
- 'enzyme/tools/**'
15-
- 'enzyme/BUILD'
16-
- 'enzyme/WORKSPACE'
15+
- 'enzyme/CMakeLists.txt'
16+
- 'enzyme/CMakePresets.json'
1717
pull_request:
1818
branches:
1919
- main
@@ -23,8 +23,8 @@ on:
2323
- 'enzyme/include/**'
2424
- 'enzyme/test/**'
2525
- 'enzyme/tools/**'
26-
- 'enzyme/BUILD'
27-
- 'enzyme/WORKSPACE'
26+
- 'enzyme/CMakeLists.txt'
27+
- 'enzyme/CMakePresets.json'
2828
merge_group:
2929

3030
concurrency:
@@ -54,13 +54,14 @@ jobs:
5454
- name: Install dependencies
5555
run: |
5656
apt-get update
57-
apt-get install -y binutils ninja-build cmake gcc g++ python3 python3-dev gnupg ca-certificates opencl-headers ocl-icd-opencl-dev
57+
apt-get install -y binutils ninja-build cmake gcc g++ python3 python3-dev gnupg ca-certificates opencl-headers ocl-icd-opencl-dev tmux
5858
curl -fsSL https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2404/x86_64/3bf863cc.pub | gpg --dearmor -o /usr/share/keyrings/cuda-archive-keyring.gpg
5959
echo "deb [signed-by=/usr/share/keyrings/cuda-archive-keyring.gpg] https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2404/x86_64 /" > /etc/apt/sources.list.d/cuda.list
6060
apt-get update
6161
apt-get install -y cuda-toolkit-12-9
6262
ln -sf /usr/local/cuda-12.9 /usr/local/cuda
63-
63+
64+
6465
- name: Check out Reactant
6566
uses: actions/checkout@v6
6667
with:
@@ -70,7 +71,7 @@ jobs:
7071
uses: actions/checkout@v6
7172
with:
7273
repository: 'llvm/llvm-project'
73-
ref: '4749bf56a65e38ee7b05ac7f9fe261aab6cb5bc6'
74+
ref: 'c6bb1afbc5086c3f483921c575262bd95c346e5b'
7475
path: 'llvm-project'
7576

7677
- name: Check out Enzyme-JAX
@@ -116,15 +117,15 @@ jobs:
116117
run: |
117118
mkdir mlir-build && cd mlir-build && cmake ../llvm -GNinja -DLLVM_ENABLE_PROJECTS="llvm;clang;mlir" -DLLVM_ENABLE_RUNTIMES=openmp -DCMAKE_BUILD_TYPE=${{ matrix.llbuild }} \
118119
-DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_TARGETS_TO_BUILD="X86;NVPTX" \
119-
-DLLVM_USE_LINKER=gold -DLLVM_PARALLEL_LINK_JOBS=2 \
120+
-DLLVM_USE_LINKER=lld -DLLVM_PARALLEL_LINK_JOBS=2 \
120121
-DCLANG_ENABLE_STATIC_ANALYZER=OFF -DCLANG_ENABLE_ARCMT=OFF \
121122
-DLLVM_OPTIMIZED_TABLEGEN=ON && ninja || echo "already built"
122123
123-
- name: Reactant build
124+
- name: Build Reactant plugin
124125
working-directory: ${{ env.BASE_DIR }}/'Reactant'
125126
run: |
126127
mkdir reactant-build && cd reactant-build
127-
cmake ../enzyme -GNinja -DCMAKE_BUILD_TYPE=${{ matrix.build }} -DLLVM_DIR=${{ env.BASE_DIR }}/llvm-project/mlir-build -DENZYME_CLANG_PLUGIN=ON
128+
cmake ../enzyme -GNinja -DCMAKE_BUILD_TYPE=${{ matrix.build }} -DLLVM_DIR=${{ env.BASE_DIR }}/llvm-project/mlir-build -DREACTANT_CLANG=ON
128129
ninja
129130
130131
- uses: bazel-contrib/setup-bazel@0.15.0
@@ -169,20 +170,13 @@ jobs:
169170
run: |
170171
bazel build $BAZEL_FLAGS --color=yes -c opt //:libRaise.so --test_output=errors
171172
172-
- name: Build Enzyme plugin
173-
working-directory: ${{ env.BASE_DIR }}/'Reactant'
174-
run: |
175-
cd reactant-build
176-
ninja ClangEnzyme-22
177-
178173
- name: LBM build
179174
working-directory: ${{ env.BASE_DIR }}/'Enzyme-GPU-Tests'
180175
env:
181-
ENZYME_PATH: ${{ env.BASE_DIR }}/Reactant/reactant-build/Enzyme/ClangEnzyme-22.so
176+
ENZYME_PATH: ${{ env.BASE_DIR }}/Reactant/reactant-build/Enzyme/libClangReactant-23.so
182177
CLANG_PATH: ${{ env.BASE_DIR }}/llvm-project/mlir-build/bin/clang++
183178
LIB_RAISE_PATH: ${{ env.BASE_DIR }}/Enzyme-JaX/bazel-bin/libRaise.so
184179
CUDA_PATH: /usr/local/cuda
185180
run: |
186181
cd LBM
187182
make -j
188-
make run

enzyme/.bazelrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ common:public_cache --remote_cache="https://storage.googleapis.com/enzyme-presub
55
common:public_cache_push --config=public_cache --remote_upload_local_results=true --google_default_credentials
66

77
common --noenable_bzlmod
8+
common --repo_env=USE_PYWRAP_RULES=True
89

910
build --announce_rc
1011

@@ -23,4 +24,3 @@ build --define=use_fast_cpp_protos=true
2324
build --define=allow_oversize_protos=true
2425

2526
build -c opt
26-

0 commit comments

Comments
 (0)