Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MLIR/Frontend] C++ compiler driver improvements, ability to compile textual IR #216

Merged
merged 198 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
198 commits
Select commit Hold shift + click to select a range
e91aefa
[MLIR/LLVM] Canonicalization and C++ Compiler Driver Base (#172)
pengmai Jul 17, 2023
ed0af43
Merge branch 'main' of github.com:PennyLaneAI/catalyst into staging/c…
pengmai Jul 17, 2023
9b469a8
Saving WIP compilation from IR
pengmai Jul 12, 2023
f4b368b
Add compilation of LLVM IR module to object file
pengmai Jun 23, 2023
0ef21fe
Remove llvm module dump, set PIC as relocation model
pengmai Jun 23, 2023
6b572ac
Add support for compiling from textual IR (MLIR/LLVM IR)
pengmai Jul 13, 2023
110dc0c
Break out compiler driver into separate pybind 11 module with C++ lin…
pengmai Jul 13, 2023
77298fc
Removed unused 'source' compile option from Python
pengmai Jul 13, 2023
5d1558a
Implement printing intermediate IR to workspace
pengmai Jul 14, 2023
48fcb55
Add dumping of LLVM IR, use std::optional instead of raw pointer
pengmai Jul 17, 2023
a484bee
Always dump the LLVM IR module, tweaks to the printing intermediate p…
pengmai Jul 17, 2023
3b4964e
break out registerAllCatalystPasses to reduce redundancy
pengmai Jul 20, 2023
71e5cc2
Bugfixes with pass pipeline and running compiler pipeline
pengmai Jul 20, 2023
8f29239
Add workaround for test_tensor_ops tests
pengmai Jul 20, 2023
74a5808
Remove unused include
pengmai Jul 20, 2023
45c25bc
Support 'verbose' Python-side argument
Jul 24, 2023
60d1648
Adjust the comments and apply formatters
Jul 24, 2023
241d66f
Print messages using py::print
Jul 25, 2023
da99eaa
[WIP] Add Python-side pipeline configuration parameter
Jul 26, 2023
b3be13e
Implementing the pipeline configuration and result retrieval API
Jul 27, 2023
d2dbfe1
Rename CompilerDriver -> CppCompiler
Jul 28, 2023
a43e415
Re-organise compiler wrappers, adjust tests
Jul 28, 2023
f0d8c1d
Merge Pipelines into CompileDriver file
Jul 28, 2023
1b380a5
Merge CompileSpec into CompileOptions, update tests
Jul 28, 2023
3ff1d3c
Rename compile_asm -> run_compiler_driver
Jul 28, 2023
3ad3387
Apply formatting
Jul 28, 2023
0e22fee
Fix lit tests imported names
Jul 28, 2023
86d8a0e
Update docstrings
Jul 28, 2023
55b01f7
Update the changelog
Jul 28, 2023
0a42ee8
Update doc/changelog.md
Jul 31, 2023
b4af530
Update mlir/python/PyCompilerDriver.cpp
Jul 31, 2023
f7674db
Adjust default verbosity level; Fix stderr printing
Jul 31, 2023
dab17c8
Address C++ formatting issues
Jul 31, 2023
dff0b7f
Remove meaningless pipeline assignments in test
Jul 31, 2023
f21a864
Fix changed CompilerOutput function names
Jul 31, 2023
55cec96
Remame CppCompiler -> LinkerDriver
Jul 31, 2023
5745a7a
Remove the unused Enzyme driver code
Jul 31, 2023
b20a702
Update frontend/catalyst/compiler.py
Aug 2, 2023
015655f
Update frontend/catalyst/compiler.py
Aug 2, 2023
3a03ca4
Update mlir/python/PyCompilerDriver.cpp
Aug 2, 2023
bc433be
Review suggestions: rename MHLOPass -> HLOLoweringPass
Aug 2, 2023
1d21127
Fix the inconsistency within the macro definition
Aug 2, 2023
f1845a0
Review suggestions: re-organize includes
Aug 2, 2023
c180f9d
Addres codecov issues: add LinkerDriver test
Aug 2, 2023
827ca3e
Add test for textual IR compilation
Aug 2, 2023
72176c2
Address formatting issues
Aug 2, 2023
67fdbb1
Address CodeFactor issues
Aug 2, 2023
b778df3
Address CodeFactor issues
Aug 2, 2023
ae00d3c
Address CodeFactor issues
Aug 2, 2023
a5d68f8
Merge branch 'main' into jmp/c++-compile-from-ir
erick-xanadu Aug 2, 2023
8875517
?
erick-xanadu Aug 2, 2023
d8d9719
Fix CI/CD.
erick-xanadu Aug 2, 2023
37868ea
Test.
erick-xanadu Aug 2, 2023
f535d82
Review suggestions: encode pass key as Pass pointer
Aug 3, 2023
86ca25b
Review suggestions: fix issues regarding driver arguments
Aug 3, 2023
24f2473
Merge branch 'eochoa/2023-08-02/compile-from-or-merge-with-main' into…
erick-xanadu Aug 3, 2023
972fa60
Reduce line length.
erick-xanadu Aug 3, 2023
24c9658
Remove unused variable.
erick-xanadu Aug 3, 2023
d217e1c
Disable warning for protected access to _compiler.
erick-xanadu Aug 3, 2023
e19c23a
clang format.
erick-xanadu Aug 3, 2023
c3ccb40
linter.
erick-xanadu Aug 3, 2023
1eb7beb
Disable warning.
erick-xanadu Aug 3, 2023
a1289e2
llc -O0
erick-xanadu Aug 3, 2023
3cfa57a
Add -scalarize to HLO lowering pass.
erick-xanadu Aug 3, 2023
418ee39
Update documentation
Aug 4, 2023
792e59d
Merge branch 'main' into jmp/c++-compile-from-ir
erick-xanadu Aug 4, 2023
93c7716
Re-enable buffer deallocation, part of merging with main.
erick-xanadu Aug 4, 2023
f351801
Adds LLVM pipelines.
erick-xanadu Aug 4, 2023
dca51aa
Add dummy runLLVMPasses method.
erick-xanadu Aug 4, 2023
34b0fb4
Fix merge.
erick-xanadu Aug 4, 2023
2e1b38e
Add -O2 for Pre-Enzyme.
erick-xanadu Aug 4, 2023
363160c
Update mlir/include/Catalyst/Driver/CompilerDriver.h
Aug 9, 2023
2dbc68a
Review suggestions: rename attemtLLVMLowering -> lowerToLLVM
Aug 9, 2023
1abfbc6
Review suggestions: C-style enum -> C++-style enum
Aug 9, 2023
9536d05
Merge branch 'main' into jmp/c++-compile-from-ir
erick-xanadu Aug 10, 2023
c6ee78b
Building statically.
erick-xanadu Aug 11, 2023
b356ed9
Enzyme integration into the compiler driver.
erick-xanadu Aug 11, 2023
af545e9
Works but only when Enzyme is a static library.
erick-xanadu Aug 11, 2023
7df9e0c
Update Enzyme version.
erick-xanadu Aug 15, 2023
581c2cf
Build the static library for Enzyme.
erick-xanadu Aug 15, 2023
4678c59
Merge branch 'main' into jmp/c++-compile-from-ir
erick-xanadu Aug 15, 2023
65d4e84
Merge branch 'main' into jmp/c++-compile-from-ir
erick-xanadu Aug 15, 2023
1029277
Add branch to submodule.
erick-xanadu Aug 15, 2023
33ea751
Remove Enzyme submodule.
erick-xanadu Aug 15, 2023
1f05091
Delete and re-add.
erick-xanadu Aug 15, 2023
7b5ee34
Fixes github workflow.
erick-xanadu Aug 15, 2023
3170930
Do not add suffix for cache as this is checkout.
erick-xanadu Aug 15, 2023
eda56d2
Add ENZYME_SRC_DIR flag.
erick-xanadu Aug 15, 2023
fa1f620
Fix build scripts.
erick-xanadu Aug 15, 2023
5aa9749
Make enzyme dependency to dialects.
erick-xanadu Aug 15, 2023
e43da38
Get Enzyme source during compilation.
erick-xanadu Aug 15, 2023
e57d626
Merge branch 'main' into jmp/c++-compile-from-ir
erick-xanadu Aug 15, 2023
9d0b6e4
Remove enzyme as a dependency.
erick-xanadu Aug 15, 2023
0399404
Remove Enzyme from CI/CD.
erick-xanadu Aug 15, 2023
45fec19
Change name of function.
erick-xanadu Aug 16, 2023
92bd7d8
Apply code review suggestion.
erick-xanadu Aug 16, 2023
ff3b2ee
Shape unneeded.
erick-xanadu Aug 18, 2023
6766b5a
Merge branch 'main' into jmp/c++-compile-from-ir
erick-xanadu Aug 18, 2023
e5b8f39
Fix Enzyme version.
erick-xanadu Aug 18, 2023
cf63856
Revert "[MLIR] Eliminate the need for build patches (#245)"
erick-xanadu Aug 25, 2023
b215a89
Move convert array to after bufferization.
erick-xanadu Aug 25, 2023
fe3bf7a
Merge branch 'main' into jmp/c++-compile-from-ir
erick-xanadu Aug 25, 2023
895c335
Revert "Revert "[MLIR] Eliminate the need for build patches (#245)""
erick-xanadu Aug 25, 2023
19cd99b
wip
erick-xanadu Aug 25, 2023
1c909be
Merge branch 'main' into jmp/c++-compile-from-ir
erick-xanadu Aug 25, 2023
077c7f0
Style.
erick-xanadu Aug 28, 2023
29d6a72
Test compiler.
erick-xanadu Aug 28, 2023
5db08cb
Fix merge.
erick-xanadu Aug 28, 2023
42bf402
Remove unused imports.
erick-xanadu Aug 28, 2023
67b584a
Imports.
erick-xanadu Aug 28, 2023
7291769
Imports
erick-xanadu Aug 28, 2023
123deeb
Imports.
erick-xanadu Aug 28, 2023
d67227c
Remove unused function.
erick-xanadu Aug 28, 2023
2134ea4
Close the library.
erick-xanadu Aug 28, 2023
d82e859
Revert "Remove unused function."
erick-xanadu Aug 28, 2023
42f1b60
Revert "Close the library."
erick-xanadu Aug 28, 2023
576c706
Remove unused code.
erick-xanadu Aug 28, 2023
fcf505f
Close the library.
erick-xanadu Aug 28, 2023
e7d64d9
Mock mlir_quantum
erick-xanadu Aug 28, 2023
0be2d6f
Mock compiler_driver module.
erick-xanadu Aug 28, 2023
630fc8b
Merge branch 'main' into jmp/c++-compile-from-ir
erick-xanadu Aug 28, 2023
f1a7057
catalyst.entry_point for compile from ir.
erick-xanadu Aug 28, 2023
d4a4bf3
Change module name.
erick-xanadu Aug 28, 2023
f8e9b35
wip
erick-xanadu Aug 29, 2023
4abbc0f
Fix changelog.
erick-xanadu Aug 31, 2023
953741c
Revert "wip"
erick-xanadu Aug 31, 2023
fdfae1c
Merge branch 'main' into jmp/c++-compile-from-ir
erick-xanadu Aug 31, 2023
0462d1b
Fix merge.
erick-xanadu Sep 1, 2023
3703f27
Fix Enzyme version.
erick-xanadu Sep 1, 2023
ee8ae8e
Lit tests.
erick-xanadu Sep 1, 2023
6bec190
wip
erick-xanadu Aug 29, 2023
1771ad4
wip
erick-xanadu Aug 31, 2023
3991786
wip
erick-xanadu Sep 1, 2023
8d6c0bd
Static...
erick-xanadu Sep 5, 2023
124f047
Register all passes.
erick-xanadu Sep 5, 2023
2f64dea
Do not move python bindings files.
erick-xanadu Sep 6, 2023
654c878
Style.
erick-xanadu Sep 6, 2023
782ce22
Mock mlir_quantum.compiler_driver
erick-xanadu Sep 6, 2023
5f72854
Add libCatalystPythonDriver to list of mocked modules.
erick-xanadu Sep 6, 2023
923a53d
Cleanup.
erick-xanadu Sep 6, 2023
d5f913e
Remove dead code.
erick-xanadu Sep 6, 2023
3bb53c4
Style.
erick-xanadu Sep 6, 2023
a1c65c0
Update docstring.
erick-xanadu Sep 6, 2023
abdae33
Remove unused import.
erick-xanadu Sep 6, 2023
f629e6b
Disable line too long.
erick-xanadu Sep 6, 2023
899a16c
Codecov.
erick-xanadu Sep 6, 2023
5fd82b4
Whitelines.
erick-xanadu Sep 6, 2023
83e5722
Submodules
erick-xanadu Sep 6, 2023
b4dac90
style.
erick-xanadu Sep 6, 2023
12a3d67
Prints PreEnzymeOpt and Enzyme passes.
erick-xanadu Sep 6, 2023
20e3d16
Change name from libCatalystPythonDriver to compiler_driver.
erick-xanadu Sep 6, 2023
48528d1
Remove inplace option.
erick-xanadu Sep 6, 2023
94fb6f3
Apply suggestions from code review
erick-xanadu Sep 8, 2023
b4c7069
Merge branch 'main' into eochoa/2023-09-07/c++-compile-from-ir
erick-xanadu Sep 8, 2023
0573612
Style.
erick-xanadu Sep 8, 2023
db04308
Style.
erick-xanadu Sep 8, 2023
44d6bde
Remove unused field from CompilerOptions and return unique_ptr.
erick-xanadu Sep 8, 2023
edc2fe0
Fix comment.
erick-xanadu Sep 8, 2023
dd8d5b5
Document inferResultType.
erick-xanadu Sep 8, 2023
ccdcc2c
Move Driver out of Catalyst folder.
erick-xanadu Sep 11, 2023
9a7bea6
Update doc/changelog.md
erick-xanadu Sep 8, 2023
9ebaa44
Namespace driver.
erick-xanadu Sep 11, 2023
4eca881
Apply suggestions from code review
erick-xanadu Sep 18, 2023
77c57b1
Document
erick-xanadu Sep 18, 2023
7b13f4e
Rename function.
erick-xanadu Sep 18, 2023
e26c55f
Improve comments.
erick-xanadu Sep 18, 2023
99c3420
Disable pylint line-to-long for whole file.
erick-xanadu Sep 18, 2023
a00c5f6
Remove UnraisableExceptionWarning.
erick-xanadu Sep 18, 2023
8f7851a
Remove duplicate file.
erick-xanadu Sep 18, 2023
3bcf081
Wrap driver around catalyst namespace.
erick-xanadu Sep 18, 2023
41ddb67
Namespace.
erick-xanadu Sep 18, 2023
3820e36
Namespace.
erick-xanadu Sep 18, 2023
5df39b4
Remove Vectorize from LLVM_LINK_COMPONENTS.
erick-xanadu Sep 18, 2023
3197d62
Remove TransformUtils from LLVM_LINK_COMPONENTS.
erick-xanadu Sep 18, 2023
5fc7c3d
Remove TargetParser to LLVM_LINK_COMPONENTS.
erick-xanadu Sep 18, 2023
5fa77e4
Remove Target from LLVM_LINK_COMPONENTS.
erick-xanadu Sep 18, 2023
de1c680
Remove Support from LLVM_LINK_COMPONENTS.
erick-xanadu Sep 18, 2023
5c9bdf7
Remove SelectionDAG.
erick-xanadu Sep 18, 2023
d4bc092
Remove ScalarOpts.
erick-xanadu Sep 18, 2023
5c49e3a
Remove a bunch.
erick-xanadu Sep 18, 2023
2a7652f
More.
erick-xanadu Sep 18, 2023
96af1ff
More.
erick-xanadu Sep 18, 2023
d630c7f
More.
erick-xanadu Sep 18, 2023
24f233c
Comment.
erick-xanadu Sep 18, 2023
3b74d0b
Only dependency on z.
erick-xanadu Sep 18, 2023
1dcb84b
Merge branch 'main' into eochoa/2023-09-07/c++-compile-from-ir
erick-xanadu Sep 18, 2023
8ac3e33
Apply suggestions from code review
erick-xanadu Sep 18, 2023
135be31
Apply suggestions from code review
erick-xanadu Sep 18, 2023
ffe25de
Add documentation for pipelines.
erick-xanadu Sep 19, 2023
e9107e2
Style.
erick-xanadu Sep 19, 2023
de35930
Typo.
erick-xanadu Sep 19, 2023
45f3359
Target the compiler_driver.
erick-xanadu Sep 19, 2023
0f95b85
Update Makefile echo.
erick-xanadu Sep 19, 2023
16025d5
Adds comments.
erick-xanadu Sep 19, 2023
f99ece8
Comment.
erick-xanadu Sep 19, 2023
69ed526
Move linking to core catalyst driver.
erick-xanadu Sep 19, 2023
f0dfdbb
Re-add test.
erick-xanadu Sep 19, 2023
a352ba8
Only print intermediates when keep_intermediate=True.
erick-xanadu Sep 19, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .dep-versions
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
jax=0.4.14
mhlo=00be4a6ce2c4d464e07d10eae51918a86f8df7b4
llvm=4706251a3186c34da0ee8fd894f7e6b095da8fdc
enzyme=86197cb2d776d72e2063695be21b729f6cffeb9b
enzyme=8d22ed1b8c424a061ed9d6d0baf0cc0d2d6842e2
erick-xanadu marked this conversation as resolved.
Show resolved Hide resolved
49 changes: 40 additions & 9 deletions .github/workflows/check-catalyst.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,17 @@ jobs:
key: ${{ runner.os }}-llvm-${{ needs.constants.outputs.llvm_version }}-default-build-opt
fail-on-cache-miss: True

- name: Cache MHLO Source
id: cache-mhlo-source
uses: actions/cache@v3
with:
path: mlir/mlir-hlo
key: ${{ runner.os }}-mhlo-${{ needs.constants.outputs.mhlo_version }}-default-source
enableCrossOsArchive: True

- name: Clone MHLO Submodule
if: |
steps.cache-mhlo.outputs.cache-hit != 'true' &&
steps.cache-mhlo.outputs.cache-hit != 'true' ||
steps.cache-mhlo-source.outputs.cache-hit != 'true'
uses: actions/checkout@v3
with:
Expand Down Expand Up @@ -213,7 +221,7 @@ jobs:

quantum:
name: Quantum Dialects Build
needs: [constants, llvm]
needs: [constants, mhlo, llvm]
runs-on: ubuntu-latest

steps:
Expand All @@ -234,6 +242,15 @@ jobs:
enableCrossOsArchive: True
fail-on-cache-miss: True

- name: Get Cached MHLO Source
id: cache-mhlo-source
erick-xanadu marked this conversation as resolved.
Show resolved Hide resolved
uses: actions/cache@v3
with:
path: mlir/mlir-hlo
key: ${{ runner.os }}-mhlo-${{ needs.constants.outputs.mhlo_version }}-default-source
enableCrossOsArchive: True
maliasadi marked this conversation as resolved.
Show resolved Hide resolved
fail-on-cache-miss: True

erick-xanadu marked this conversation as resolved.
Show resolved Hide resolved
- name: Get Cached LLVM Build
id: cache-llvm-build
uses: actions/cache@v3
Expand All @@ -242,6 +259,14 @@ jobs:
key: ${{ runner.os }}-llvm-${{ needs.constants.outputs.llvm_version }}-default-build-opt
fail-on-cache-miss: True

- name: Get Cached MHLO Build
id: cache-mhlo-build
uses: actions/cache@v3
with:
path: mhlo-build
key: ${{ runner.os }}-mhlo-${{ needs.constants.outputs.mhlo_version }}-default-build
fail-on-cache-miss: True

- name: Cache CCache
id: cache-ccache
uses: actions/cache@v3
Expand All @@ -253,11 +278,21 @@ jobs:
key: ${{ runner.os }}-ccache-${{ github.run_id }}
restore-keys: ${{ runner.os }}-ccache-

- name: Clone Enzyme Submodule
if: |
steps.cache-enzyme.outputs.cache-hit != 'true'
uses: actions/checkout@v3
with:
repository: EnzymeAD/Enzyme
ref: ${{ needs.constants.outputs.enzyme_version }}
path: mlir/Enzyme

- name: Build MLIR Dialects
run: |
CCACHE_DIR="$(pwd)/.ccache" \
LLVM_BUILD_DIR="$(pwd)/llvm-build" \
MHLO_BUILD_DIR="$(pwd)/mhlo-build" \
ENZYME_SRC_DIR="$(pwd)/Enzyme" \
DIALECTS_BUILD_DIR="$(pwd)/quantum-build" \
make dialects

Expand All @@ -273,7 +308,7 @@ jobs:

frontend-tests:
name: Frontend Tests
needs: [constants, runtime, mhlo, quantum, enzyme]
needs: [constants, runtime, mhlo, quantum]
runs-on: ubuntu-latest

steps:
Expand Down Expand Up @@ -331,7 +366,6 @@ jobs:
echo "PYTHONPATH=$PYTHONPATH:$(pwd)/quantum-build/python_packages/quantum" >> $GITHUB_ENV
echo "RUNTIME_LIB_DIR=$(pwd)/runtime-build/lib" >> $GITHUB_ENV
echo "MLIR_LIB_DIR=$(pwd)/llvm-build/lib" >> $GITHUB_ENV
echo "ENZYME_LIB_DIR=$(pwd)/enzyme-build/Enzyme" >> $GITHUB_ENV
chmod +x quantum-build/bin/quantum-opt # artifact upload does not preserve permissions

- name: Run Python Lit Tests
Expand All @@ -358,7 +392,7 @@ jobs:

frontend-tests-lightning-kokkos:
name: Frontend Tests (backend="lightning.kokkos")
needs: [constants, runtime, mhlo, quantum, enzyme]
needs: [constants, runtime, mhlo, quantum]
runs-on: ubuntu-latest

steps:
Expand Down Expand Up @@ -410,14 +444,12 @@ jobs:

- name: Add Frontend Dependencies to PATH
run: |
echo "$(pwd)/enzyme-build/Enzyme" >> $GITHUB_PATH
echo "$(pwd)/llvm-build/bin" >> $GITHUB_PATH
echo "$(pwd)/mhlo-build/bin" >> $GITHUB_PATH
echo "$(pwd)/quantum-build/bin" >> $GITHUB_PATH
echo "PYTHONPATH=$PYTHONPATH:$(pwd)/quantum-build/python_packages/quantum" >> $GITHUB_ENV
echo "RUNTIME_LIB_DIR=$(pwd)/runtime-build/lib" >> $GITHUB_ENV
echo "MLIR_LIB_DIR=$(pwd)/llvm-build/lib" >> $GITHUB_ENV
echo "ENZYME_LIB_DIR=$(pwd)/enzyme-build/Enzyme" >> $GITHUB_ENV
chmod +x quantum-build/bin/quantum-opt # artifact upload does not preserve permissions

- name: Install lightning.kokkos used in Python tests
Expand All @@ -430,7 +462,7 @@ jobs:

frontend-tests-openqasm-device:
name: Frontend Tests (backend="openqasm3")
needs: [constants, mhlo, quantum, enzyme, llvm]
needs: [constants, mhlo, quantum, llvm]
runs-on: ubuntu-latest

steps:
Expand Down Expand Up @@ -494,7 +526,6 @@ jobs:
echo "PYTHONPATH=$PYTHONPATH:$(pwd)/quantum-build/python_packages/quantum" >> $GITHUB_ENV
echo "RUNTIME_LIB_DIR=$(pwd)/runtime-build/lib" >> $GITHUB_ENV
echo "MLIR_LIB_DIR=$(pwd)/llvm-build/lib" >> $GITHUB_ENV
echo "ENZYME_LIB_DIR=$(pwd)/enzyme-build/Enzyme" >> $GITHUB_ENV
chmod +x quantum-build/bin/quantum-opt # artifact upload does not preserve permissions

- name: Run Python Pytest Tests
Expand Down
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
url = https://github.com/llvm/llvm-project.git
shallow = true
ignore = dirty
[submodule "enzyme"]
[submodule "Enzyme"]
path = mlir/Enzyme
url = https://github.com/EnzymeAD/Enzyme.git
dime10 marked this conversation as resolved.
Show resolved Hide resolved
shallow = true
Expand Down
15 changes: 14 additions & 1 deletion doc/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@
* Update the Lightning backend device to work with the PL-Lightning monorepo.
[(#259)](https://github.com/PennyLaneAI/catalyst/pull/259)

* Move to an alternate compiler driver in C++. This improves compile-time performance by
avoiding *round-tripping*, which is when the entire program being compiled is dumped to
a textual form and re-parsed by another tool.

This is also a requirement for providing custom metadata at the LLVM level, which is
necessary for better integration with tools like Enzyme. Finally, this makes it more natural
to improve error messages originating from C++ when compared to the prior subprocess-based
approach.
[(#216)](https://github.com/PennyLaneAI/catalyst/pull/216)

* Build both `"lightning.qubit"` and `"lightning.kokkos"` against the PL-Lightning monorepo.
[(#277)](https://github.com/PennyLaneAI/catalyst/pull/277)

Expand All @@ -18,7 +28,10 @@

This release contains contributions from (in alphabetical order):

Ali Asadi
Ali Asadi,
Erick Ochoa Lopez,
Jacob Mai Peng,
Sergei Mironov.

# Release 0.3.0

Expand Down
2 changes: 2 additions & 0 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,15 @@ def __getattr__(cls, name):


MOCK_MODULES = [
"mlir_quantum",
"mlir_quantum.runtime",
"mlir_quantum.dialects",
"mlir_quantum.dialects.arith",
"mlir_quantum.dialects.tensor",
"mlir_quantum.dialects.scf",
"mlir_quantum.dialects.quantum",
"mlir_quantum.dialects.gradient",
"mlir_quantum.compiler_driver",
"pybind11",
]

Expand Down
139 changes: 63 additions & 76 deletions doc/dev/debugging.rst
Original file line number Diff line number Diff line change
Expand Up @@ -118,98 +118,79 @@ Will print out something close to the following:
Pass Pipelines
==============

The compilation steps which take MLIR as an input and lower it to binary are broken into pass pipelines.
A ``PassPipeline`` is a class that specifies which binary and which flags are used for compilation.
Users can implement their own ``PassPipeline`` by inheriting from this class and implementing the relevant methods/attributes.
Catalyst's compilation strategy can then be adjusted by overriding the default pass pipeline.
For example, let's imagine that a user is interested in testing different optimization levels when compiling LLVM IR to binary using ``llc``.
The user would then create a ``PassPipeline`` that replaces the ``LLVMIRToObjectFile`` class.
First let's take a look at the ``LLVMIRToObjectFile``.
The compilation steps which take MLIR as an input and lower it to binary are broken into MLIR pass
pipelines. The ``pipelines`` argument of the ``qjit`` function may be used to alter the steps used
for compilation. The default set of pipelines is defined via the ``catalyst.compiler.DEFAULT_PIPELINES``
list. Its structure is shown below.

.. code-block:: python

class LLVMIRToObjectFile(PassPipeline):
"""LLVMIR To Object File."""

_executable = get_executable_path("llvm", "llc")
_default_flags = [
"--filetype=obj",
"--relocation-model=pic",
DEFAULT_PIPELINES = [
(
"HLOLoweringPass",
[
"canonicalize",
"func.func(chlo-legalize-to-hlo)",
erick-xanadu marked this conversation as resolved.
Show resolved Hide resolved
"stablehlo-legalize-to-hlo",
"func.func(mhlo-legalize-control-flow)",
...
],
),
(
"QuantumCompilationPass",
[
"lower-gradients",
"adjoint-lowering",
"convert-arraylist-to-memref",
],
),
...
]

@staticmethod
def get_output_filename(infile):
path = pathlib.Path(infile)
if not path.exists():
raise FileNotFoundError("Cannot find {infile}.")
return str(path.with_suffix(".o"))


The ``LLVMDialectTOLLVMIR`` and all classes derived from ``PassPipeline`` must define an ``_executable`` and ``_default_flags`` fields.
The ``_executable`` field is string that corresponds to the command that will be used to execute in a subprocess.
The ``_default_flags`` are the flags that will be used when running the executable.
The method ``get_output_filename`` computes the name of the output file given an input file.
It is expected that the output of a ``PassPipeline`` will be fed as an input to the following ``PassPipeline``.

From here, we can see that in order for the user to test different optimization levels, all that is needed is create a class that extends either ``PassPipeline`` or ``LLVMDialectToLLVMIR`` and appends the ``-O3`` flag to the ``_default_flags`` field. For example, either of the following classes would work:

One could customize what compilation passes are executed. A good use case of this would be if you
are debugging Catalyst itself or you want to enable or disable passes within a specific pipeline.
It is recommended to copy the default pipelines and edit them to suit your goals and afterwards
passing them to the ``@qjit`` decorator. E.g. if you want to disable inlining

.. code-block:: python

class MyLLCOpt(PassPipeline):
"""LLVMIR To Object File."""

_executable = get_executable_path("llvm", "llc")
_default_flags = [
"--filetype=obj",
"--relocation-model=pic",
"-O3",
]

@staticmethod
def get_output_filename(infile):
path = pathlib.Path(infile)
if not path.exists():
raise FileNotFoundError("Cannot find {infile}.")
return str(path.with_suffix(".o"))

or

.. code-block:: python

class MyLLCOpt(LLVMIRToObjectFile):
"""LLVMIR To Object File."""

_default_flags = [
"--filetype=obj",
"--relocation-model=pic",
"-O3",
my_pipelines = [
...
(
"MyBufferizationPass",
[
"one-shot-bufferize{dialect-filter=memref}",
# "inline",
"gradient-bufferize",
...
],
),
...
]

In order to actually use this ``PassPipeline``, the user must override the default ``PassPipeline``.
To do so, use the ``pipelines`` keyword parameter in ``@qjit`` decorator.
The value assigned to ``pipelines`` must be a list of ``PassPipeline`` that will lower MLIR to binary.
In this particular case, we are substituting the ``LLVMIRToObjectFile`` pass pipeline with ``MyLLCOpt`` in the default pass pipeline.
The following will work:

@qjit(pipelines=my_pipelines)
@qml.qnode(dev)
def circuit():
...

.. code-block:: python

custom_pipeline = [MHLOPass, QuantumCompilationPass, BufferizationPass, MLIRToLLVMDialect, LLVMDialectToLLVMIR, MyLLCOpt, CompilerDriver]

@qjit(pipelines=custom_pipeline)
def foo():
"""A method to be JIT compiled using a custom pipeline"""
...
Here, each item represents a pipeline. Each pipeline has a name and a list of MLIR passes
to perform. Most of the standard passes are described in the
`MLIR passes documentation <https://mlir.llvm.org/docs/Passes/>`_. Quantum MLIR passes are
implemented in Catalyst and can be found in the sources.
erick-xanadu marked this conversation as resolved.
Show resolved Hide resolved

Users that are interested in ``PassPipeline`` classes are encouraged to look at the ``compiler.py`` file to look at different ``PassPipeline`` child classes.
All pipelines are executed in sequence, the output MLIR of each pipeline is stored in
memory and becomes available via the ``get_output_of`` method of the ``QJIT`` object.

Printing the IR generated by Pass Pipelines
==========================================
===========================================

We won't get into too much detail here, but sometimes it is useful to look at the output of a specific ``PassPipeline``.
We won't get into too much detail here, but sometimes it is useful to look at the output of a
specific pass pipeline.
To do so, simply use the ``get_output_of`` method available in ``QJIT``.
erick-xanadu marked this conversation as resolved.
Show resolved Hide resolved
For example, if one wishes to inspect the output of the ``BufferizationPass``, simply run the following command.
For example, if one wishes to inspect the output of the ``BufferizationPass`` pipeline, simply run
the following command.

.. code-block:: python

Expand Down Expand Up @@ -278,15 +259,21 @@ compiler used by TensorFlow.

.. code-block:: python

print(circuit.mlir)
print(circuit.mlir)

Lowering out of the MHLO dialect leaves us with the classical computation represented by generic
dialects such as ``arith``, ``math``, or ``linalg``. This allows us to later generate machine code
via standard LLVM-MLIR tooling.

.. code-block:: python

circuit.get_output_of("MHLOPass")
circuit.get_output_of("HLOLoweringPass")

The quantum compilation pipeline expands high-level quantum instructions like adjoint, and applies quantum differentiation methods and optimization techniques.

.. code-block:: python

circuit.get_output_of("QuantumCompilationPass")

An important step in getting to machine code from a high-level representation is allocating memory
for all the tensor/array objects in the program.
Expand Down
Loading
Loading