Skip to content

Commit 7ceba90

Browse files
committed
Allow quantum registers returned from functions during buffer deallocation (#1408)
**Context:** This patch fixes a bug in upstream MLIR that prevents buffer deallocation from working in certain cases. The patch was also submitted upstream: llvm/llvm-project#121582 **Description of the Change:** This PR adds a patch to the llvm-project source, and updates the relevant build recipes. The llvm step during wheel builds is now also handled through Make instead of replicating the CMake configuration in each wheel script. **Benefits:** Unblocks our friends over at Qrisp. **Possible Drawbacks:** Patching dependencies is not great, but hopefully temporary. **Related GitHub Issues:** [sc-81444]
1 parent 07ffe5b commit 7ceba90

11 files changed

+234
-491
lines changed

.github/workflows/build-enzyme-v0.0.130.yaml

Lines changed: 0 additions & 155 deletions
This file was deleted.

.github/workflows/build-wheel-linux-arm64.yaml

Lines changed: 20 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -62,23 +62,23 @@ jobs:
6262
id: cache-llvm-source
6363
uses: actions/cache@v4
6464
with:
65-
path: mlir/llvm-project
65+
path: ${{ github.workspace }}/mlir/llvm-project
6666
key: llvm-${{ needs.constants.outputs.llvm_version }}-default-source
6767
enableCrossOsArchive: True
6868

6969
- name: Cache MHLO Source
7070
id: cache-mhlo-source
7171
uses: actions/cache@v4
7272
with:
73-
path: mlir/mlir-hlo
73+
path: ${{ github.workspace }}/mlir/mlir-hlo
7474
key: mhlo-${{ needs.constants.outputs.mhlo_version }}-default-source
7575
enableCrossOsArchive: True
7676

7777
- name: Cache Enzyme Source
7878
id: cache-enzyme-source
7979
uses: actions/cache@v4
8080
with:
81-
path: mlir/Enzyme
81+
path: ${{ github.workspace }}/mlir/Enzyme
8282
key: enzyme-${{ needs.constants.outputs.enzyme_version }}-default-source
8383
enableCrossOsArchive: True
8484

@@ -88,60 +88,48 @@ jobs:
8888
with:
8989
repository: llvm/llvm-project
9090
ref: ${{ needs.constants.outputs.llvm_version }}
91-
path: mlir/llvm-project
91+
path: ${{ github.workspace }}/mlir/llvm-project
9292

9393
- name: Clone MHLO Submodule
9494
if: steps.cache-mhlo-source.outputs.cache-hit != 'true'
9595
uses: actions/checkout@v4
9696
with:
9797
repository: tensorflow/mlir-hlo
9898
ref: ${{ needs.constants.outputs.mhlo_version }}
99-
path: mlir/mlir-hlo
99+
path: ${{ github.workspace }}/mlir/mlir-hlo
100100

101101
- name: Clone Enzyme Submodule
102102
if: steps.cache-enzyme-source.outputs.cache-hit != 'true'
103103
uses: actions/checkout@v4
104104
with:
105105
repository: EnzymeAD/Enzyme
106106
ref: ${{ needs.constants.outputs.enzyme_version }}
107-
path: mlir/Enzyme
107+
path: ${{ github.workspace }}/mlir/Enzyme
108108

109109
# Cache external project builds
110110
- name: Restore LLVM Build
111111
id: cache-llvm-build
112112
uses: actions/cache/restore@v4
113113
with:
114-
path: llvm-build
114+
path: ${{ github.workspace }}/llvm-build
115115
key: ${{ matrix.container_name }}-llvm-${{ needs.constants.outputs.llvm_version }}-wheel-build
116116

117117
- name: Restore MHLO Build
118118
id: cache-mhlo-build
119119
uses: actions/cache/restore@v4
120120
with:
121-
path: mhlo-build
121+
path: ${{ github.workspace }}/mhlo-build
122122
key: ${{ matrix.container_name }}-mhlo-${{ needs.constants.outputs.mhlo_version }}-wheel-build
123123
lookup-only: True
124124

125125
- name: Restore Enzyme Build
126126
id: cache-enzyme-build
127127
uses: actions/cache/restore@v4
128128
with:
129-
path: enzyme-build
129+
path: ${{ github.workspace }}/enzyme-build
130130
key: ${{ matrix.container_name }}-enzyme-${{ needs.constants.outputs.llvm_version }}-${{ needs.constants.outputs.enzyme_version }}-wheel-build
131131
lookup-only: True
132132

133-
- name: Build LLD
134-
if: steps.cache-llvm-build.outputs.cache-hit != 'true'
135-
run: |
136-
set -x
137-
# With GCC 13, LLVM fails some tests, then we use GCC 12 instead (Copied from below)
138-
export GCC_VERSION=12
139-
docker run --rm --platform linux/aarch64 \
140-
-v /var/run/docker.sock:/var/run/docker.sock \
141-
-v `pwd`:/catalyst \
142-
-i ${{ matrix.container_img }} \
143-
bash /catalyst/.github/workflows/scripts/linux_arm64/rh8/build_lld.sh $GCC_VERSION ${{ matrix.python_version.major_minor }} ${{ matrix.python_version.patch }} ${{ matrix.python_version.package }}
144-
145133
- name: Build LLVM / MLIR
146134
if: steps.cache-llvm-build.outputs.cache-hit != 'true'
147135
run: |
@@ -159,7 +147,7 @@ jobs:
159147
if: steps.cache-llvm-build.outputs.cache-hit != 'true'
160148
uses: actions/cache/save@v4
161149
with:
162-
path: llvm-build
150+
path: ${{ github.workspace }}/llvm-build
163151
key: ${{ matrix.container_name }}-llvm-${{ needs.constants.outputs.llvm_version }}-wheel-build
164152

165153
- name: Build MHLO Dialect
@@ -178,7 +166,7 @@ jobs:
178166
if: steps.cache-mhlo-build.outputs.cache-hit != 'true'
179167
uses: actions/cache/save@v4
180168
with:
181-
path: mhlo-build
169+
path: ${{ github.workspace }}/mhlo-build
182170
key: ${{ matrix.container_name }}-mhlo-${{ needs.constants.outputs.mhlo_version }}-wheel-build
183171

184172
- name: Build Enzyme
@@ -197,7 +185,7 @@ jobs:
197185
if: steps.cache-enzyme-build.outputs.cache-hit != 'true'
198186
uses: actions/cache/save@v4
199187
with:
200-
path: enzyme-build
188+
path: ${{ github.workspace }}/enzyme-build
201189
key: ${{ matrix.container_name }}-enzyme-${{ needs.constants.outputs.llvm_version }}-${{ needs.constants.outputs.enzyme_version }}-wheel-build
202190

203191
catalyst-linux-wheels-arm64:
@@ -230,7 +218,7 @@ jobs:
230218
id: cache-llvm-source
231219
uses: actions/cache/restore@v4
232220
with:
233-
path: mlir/llvm-project
221+
path: ${{ github.workspace }}/mlir/llvm-project
234222
key: llvm-${{ needs.constants.outputs.llvm_version }}-default-source
235223
enableCrossOsArchive: True
236224
fail-on-cache-miss: True
@@ -239,15 +227,15 @@ jobs:
239227
id: cache-llvm-build
240228
uses: actions/cache/restore@v4
241229
with:
242-
path: llvm-build
230+
path: ${{ github.workspace }}/llvm-build
243231
key: ${{ matrix.container_name }}-llvm-${{ needs.constants.outputs.llvm_version }}-wheel-build
244232
fail-on-cache-miss: True
245233

246234
- name: Get Cached MHLO Source
247235
id: cache-mhlo-source
248236
uses: actions/cache/restore@v4
249237
with:
250-
path: mlir/mlir-hlo
238+
path: ${{ github.workspace }}/mlir/mlir-hlo
251239
key: mhlo-${{ needs.constants.outputs.mhlo_version }}-default-source
252240
enableCrossOsArchive: True
253241
fail-on-cache-miss: True
@@ -256,15 +244,15 @@ jobs:
256244
id: cache-mhlo-build
257245
uses: actions/cache/restore@v4
258246
with:
259-
path: mhlo-build
247+
path: ${{ github.workspace }}/mhlo-build
260248
key: ${{ matrix.container_name }}-mhlo-${{ needs.constants.outputs.mhlo_version }}-wheel-build
261249
fail-on-cache-miss: True
262250

263251
- name: Get Cached Enzyme Source
264252
id: cache-enzyme-source
265253
uses: actions/cache/restore@v4
266254
with:
267-
path: mlir/Enzyme
255+
path: ${{ github.workspace }}/mlir/Enzyme
268256
key: enzyme-${{ needs.constants.outputs.enzyme_version }}-default-source
269257
enableCrossOsArchive: True
270258
fail-on-cache-miss: True
@@ -273,7 +261,7 @@ jobs:
273261
id: cache-enzyme-build
274262
uses: actions/cache/restore@v4
275263
with:
276-
path: enzyme-build
264+
path: ${{ github.workspace }}/enzyme-build
277265
key: ${{ matrix.container_name }}-enzyme-${{ needs.constants.outputs.llvm_version }}-${{ needs.constants.outputs.enzyme_version }}-wheel-build
278266
fail-on-cache-miss: True
279267

@@ -292,7 +280,7 @@ jobs:
292280
uses: actions/upload-artifact@v4
293281
with:
294282
name: catalyst-linux_arm64-wheel-py-${{ matrix.python_version.major_minor}}.zip
295-
path: wheel/
283+
path: ${{ github.workspace }}/wheel/
296284
retention-days: 14
297285

298286
test-wheels:
@@ -326,16 +314,7 @@ jobs:
326314
uses: actions/download-artifact@v4
327315
with:
328316
name: catalyst-linux_arm64-wheel-py-${{ matrix.python_version.major_minor }}.zip
329-
path: dist
330-
331-
# Needed for accessing llvm-symbolizer
332-
- name: Get Cached LLVM Build
333-
id: cache-llvm-build
334-
uses: actions/cache@v4
335-
with:
336-
path: llvm-build
337-
key: ${{ matrix.container_name }}-llvm-${{ needs.constants.outputs.llvm_version }}-wheel-build
338-
fail-on-cache-miss: True
317+
path: ${{ github.workspace }}/dist
339318

340319
- name: Run Python Pytest Tests
341320
run: |

0 commit comments

Comments
 (0)