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

First pass of support for C++ operators #2511

Open
wants to merge 339 commits into
base: experimental/operators
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
339 commits
Select commit Hold shift + click to select a range
45f6926
constrain the templates
bettinaheim Jan 14, 2025
d663b02
making the left hand arithmetics friends
bettinaheim Jan 14, 2025
3dc2d50
cleaned up assignments
bettinaheim Jan 15, 2025
3d52d47
fixing a some types
bettinaheim Jan 16, 2025
6c04650
this builds, but needs to be cleaned up
bettinaheim Jan 16, 2025
0cb84a8
scalar ops tests
bettinaheim Jan 17, 2025
a5399d3
to be deleted again - just some notes
bettinaheim Jan 23, 2025
a637313
more memory experiments
bettinaheim Jan 24, 2025
0aa6e85
revised the data structures - all tests now pass again
bettinaheim Jan 24, 2025
8cb682e
store one coefficient per product only
bettinaheim Jan 27, 2025
ac469ff
getting rid of all elementary operator overloads
bettinaheim Jan 27, 2025
26e356c
clean up for scalars
bettinaheim Jan 28, 2025
357a136
some clean up of op sum
bettinaheim Jan 28, 2025
79a51b3
some clean up for products
bettinaheim Jan 28, 2025
39fd8c2
no type constraints for HandlerTy
bettinaheim Jan 29, 2025
e5ffd5c
left hand arithmetics cleanup
bettinaheim Jan 29, 2025
e4a07e2
more clean up
bettinaheim Jan 29, 2025
9d48f3b
more clean up
bettinaheim Jan 29, 2025
2a7fd34
more clean up
bettinaheim Jan 29, 2025
bf691ca
finished cleanup of arithmetics
bettinaheim Jan 29, 2025
91d0e44
picking up Anthony's changes
bettinaheim Jan 30, 2025
619b266
just a quick renaming
bettinaheim Jan 30, 2025
d12f9cb
minor thing
bettinaheim Jan 30, 2025
5ce0c07
minor thing
bettinaheim Jan 30, 2025
0454209
minor things
bettinaheim Jan 31, 2025
93525b3
enabling a whole bunch of additional tests
bettinaheim Jan 31, 2025
15634ff
some more product op fixes
bettinaheim Feb 3, 2025
1336ada
just some test fixes
bettinaheim Feb 3, 2025
f4ea5b5
fixing matrix reordering issues
bettinaheim Feb 3, 2025
1cd4ffd
enabling the rest of the tests
bettinaheim Feb 3, 2025
f7a9d1b
Adding template parameter HandlerTy for operator_sum and formatting
sacpis Feb 4, 2025
c0ffcc7
Fixing Rydberg with template HandlerTy
sacpis Feb 4, 2025
8d67f30
Fixing with template typename
sacpis Feb 4, 2025
83f7137
Fixing HandlerTy tenplate by setting it to a value
sacpis Feb 4, 2025
193d636
Fixing unittests
sacpis Feb 4, 2025
e4e4699
Adding missing functions in helpers and updating initialize_operator_…
sacpis Feb 4, 2025
cc62bac
fixing helpers.h path
sacpis Feb 5, 2025
1e46c24
Adding equality comparision operation for matrix_2
sacpis Feb 5, 2025
ef3530a
Fixing the helpers.h path
sacpis Feb 5, 2025
b75d4a0
Adding HandlerTy
sacpis Feb 5, 2025
5dc3c9e
Disabling unneeded (for now) variables
sacpis Feb 5, 2025
68188c7
Adding cudaq::matrix_operator as a handler
sacpis Feb 6, 2025
71b87c2
Disabling template method
sacpis Feb 6, 2025
eb7fdc5
Fixing template definition in the header and instatiating it in teh c…
sacpis Feb 6, 2025
37a0ee3
Enabling tests
sacpis Feb 6, 2025
02d4362
Fixing Rydberg and renaming fixture in test_cudm_helpers
sacpis Feb 6, 2025
34b40be
* Enabling dynamic_cast for scalar operator
sacpis Feb 6, 2025
bbd7434
Minor cmake restructure
1tnguyen Feb 6, 2025
bd67453
Adding cudm_op_conversion interface
sacpis Feb 6, 2025
a086a33
Fixing the return type of _wrap_callback_tensor
sacpis Feb 6, 2025
8883ea7
Updating cudm_op_conversion interface to accommodate wrap callback an…
sacpis Feb 6, 2025
4b20e97
Adding cudm_op_conversion implementation, exposing get_generator for …
sacpis Feb 7, 2025
5e9c058
Fix segfault and add an end-to-end stepper check
1tnguyen Feb 7, 2025
bc43e40
Fix RK 1st order and add a test
1tnguyen Feb 7, 2025
3d8b598
Adding unittests for cudm_op_conversion
sacpis Feb 7, 2025
3602887
[core] enable the new QIR codegen for python (#2588)
schweitzpgi Feb 7, 2025
90972a6
Adding operator* method
sacpis Feb 7, 2025
04b85b0
Removing norm method from state
sacpis Feb 7, 2025
18f6072
Fixing midpoint integration
sacpis Feb 7, 2025
3c22ad5
Setting the accumulation for 4 states
sacpis Feb 7, 2025
20e5869
[braket] support reservation ARN (#2553)
yitchen-tim Feb 8, 2025
d279c07
Disabling RK4 for now
sacpis Feb 8, 2025
d5eb3fb
* Adding mode_action_duality
sacpis Feb 8, 2025
29ab744
Fixing AddComplexScalars unittest
sacpis Feb 9, 2025
0c83b33
Fixing AddScalarAndOperator unittest
sacpis Feb 9, 2025
635cd0e
* Changing return type from double to std::complex<double>
sacpis Feb 9, 2025
1e94961
Fixing RK4
sacpis Feb 9, 2025
23bfb2b
Add expectation
1tnguyen Feb 10, 2025
526e4b2
Using cudensitymatStateComputeScaling for multiplication of state wit…
sacpis Feb 10, 2025
2cb8adb
Merge branch 'dynamics_cpp_operators' of https://github.com/sacpis/cu…
sacpis Feb 10, 2025
962f130
Merge in dynamics work and squash commit history (#12)
anthony-santana Jan 9, 2025
1821361
Cleaning up docs preview for PR #12.
cuda-quantum-bot Jan 9, 2025
3ecd247
fixing spellings
sacpis Jan 9, 2025
33925b7
Adding base_integrator and base_time_stepper
sacpis Jan 9, 2025
8aab215
adding base_operators interface
sacpis Jan 13, 2025
39cf6ab
keeping degrees to match the current implementation
sacpis Jan 13, 2025
599fb57
adding base integrator and time stepper
sacpis Jan 13, 2025
c89e9d9
* Adding base test cases for Runge-Kutta stepper and integrator
sacpis Jan 14, 2025
48d4b75
* Adding helpers functionlity
sacpis Jan 14, 2025
4e95258
Formatting
sacpis Jan 14, 2025
fb1ad13
Adding evolution API header
sacpis Jan 15, 2025
f07c55b
Formatting
sacpis Jan 15, 2025
9434238
Replacing Eigen::MatrixXcd with matrix_2
sacpis Jan 15, 2025
824b876
* Adding Rydberg hamiltonian operator
sacpis Jan 16, 2025
94f910e
Adding interface for cudm_helpers
sacpis Jan 16, 2025
d8a9903
Changing matrix to operator_sum
sacpis Jan 16, 2025
8170e32
cudm_helpers implementation
sacpis Jan 21, 2025
5aeb4d7
Formatting
sacpis Jan 21, 2025
664515d
* Adding macro for handling error
sacpis Jan 21, 2025
8058b27
Adding MACRO for error handling
sacpis Jan 22, 2025
e865f76
Fixing convert_to_cudensitymat_operator as per the cudensitymat APIs
sacpis Jan 22, 2025
5668907
Updating CMakeLists and unittests
sacpis Jan 22, 2025
5608fdd
* Adding vector of cudensitymatElementaryOperator_t to store and destroy
sacpis Jan 23, 2025
271558f
Refactoring the code
sacpis Jan 23, 2025
a4c104a
Fixing the matrix in the unittest and other code in compute_lindblad …
sacpis Jan 23, 2025
11c7b65
Adding cudm_state with unittests
sacpis Jan 25, 2025
40e52d9
Addign few more unit tests for cudm_state
sacpis Jan 25, 2025
4ea6415
Adding an enum with initial quantum state and initilize_state based o…
sacpis Jan 25, 2025
31709a4
Fixing spelling
sacpis Jan 26, 2025
dafc31a
* Renaming cudm_mat_state -> cudm_state
sacpis Jan 28, 2025
e51696a
Exposing state's rawData to be used in the stepper
sacpis Jan 28, 2025
8a0bd3a
Adding cudm_time_stepper with unittests
sacpis Jan 28, 2025
d2e0441
Refactoring time_stepper compute method to align with cuquantum workflow
sacpis Jan 30, 2025
67d658b
Exposing handle and adding operator overloading for + and *
sacpis Jan 31, 2025
5d74f17
Removing redundant constructor and updating tests for cudm_state
sacpis Jan 31, 2025
ef1d09d
Implementing compute function in cudm_time_stepper
sacpis Jan 31, 2025
6544bee
Adding test_mocks for unittests
sacpis Jan 31, 2025
847c383
Adding check for step_size=0 condition and few more unittests
sacpis Jan 31, 2025
a51a70c
Adding #pragma once so that header files are included only once durin…
sacpis Jan 31, 2025
ef24742
* Adding partial implementation of runge-kutta integrator
sacpis Jan 31, 2025
04b9d77
* Implementing move constructor and move assignment
sacpis Feb 1, 2025
6cb5db2
temp
sacpis Feb 2, 2025
aea580f
Using cudensitymatStateComputeAccumulation and cudensitymatStateCompu…
sacpis Feb 3, 2025
6cbdd28
Allocating k1, k2, k3, k4 inside the scope blocks
sacpis Feb 3, 2025
c35225b
Adding operator+= to do an accumulation instead of moving the state
sacpis Feb 3, 2025
24ea1a0
just some test renaming to make it easier to find
bettinaheim Jan 13, 2025
0d69aab
a bunch of templates to draft how dragging type information through t…
bettinaheim Jan 13, 2025
265e3b3
wip to use elementary_operator as matrix handler
bettinaheim Jan 14, 2025
46fe387
wip to use elementary_operator as matrix handler
bettinaheim Jan 14, 2025
9912357
kinded of more cleaned up but left-hand arithmethics need more thought
bettinaheim Jan 14, 2025
02fc125
constrain the templates
bettinaheim Jan 14, 2025
071b115
making the left hand arithmetics friends
bettinaheim Jan 14, 2025
c12d4c9
cleaned up assignments
bettinaheim Jan 15, 2025
6d3e4bf
fixing a some types
bettinaheim Jan 16, 2025
ccc5cc2
this builds, but needs to be cleaned up
bettinaheim Jan 16, 2025
1a909db
scalar ops tests
bettinaheim Jan 17, 2025
314d61f
to be deleted again - just some notes
bettinaheim Jan 23, 2025
b3e2edd
more memory experiments
bettinaheim Jan 24, 2025
86e1337
revised the data structures - all tests now pass again
bettinaheim Jan 24, 2025
6908d91
store one coefficient per product only
bettinaheim Jan 27, 2025
69a3412
getting rid of all elementary operator overloads
bettinaheim Jan 27, 2025
ced3e6a
clean up for scalars
bettinaheim Jan 28, 2025
b50ae07
some clean up of op sum
bettinaheim Jan 28, 2025
d8c1689
some clean up for products
bettinaheim Jan 28, 2025
5c932b1
no type constraints for HandlerTy
bettinaheim Jan 29, 2025
9f102e9
left hand arithmetics cleanup
bettinaheim Jan 29, 2025
326b607
more clean up
bettinaheim Jan 29, 2025
42908b0
more clean up
bettinaheim Jan 29, 2025
666734d
more clean up
bettinaheim Jan 29, 2025
53eed45
finished cleanup of arithmetics
bettinaheim Jan 29, 2025
97198fc
picking up Anthony's changes
bettinaheim Jan 30, 2025
759ac0b
just a quick renaming
bettinaheim Jan 30, 2025
d0b0d26
minor thing
bettinaheim Jan 30, 2025
144ed26
minor thing
bettinaheim Jan 30, 2025
aa98969
minor things
bettinaheim Jan 31, 2025
9591195
enabling a whole bunch of additional tests
bettinaheim Jan 31, 2025
28b748f
some more product op fixes
bettinaheim Feb 3, 2025
b118f81
just some test fixes
bettinaheim Feb 3, 2025
b350295
fixing matrix reordering issues
bettinaheim Feb 3, 2025
8d844c1
enabling the rest of the tests
bettinaheim Feb 3, 2025
a4504ad
Adding template parameter HandlerTy for operator_sum and formatting
sacpis Feb 4, 2025
299cb28
Fixing Rydberg with template HandlerTy
sacpis Feb 4, 2025
4edcc73
Fixing with template typename
sacpis Feb 4, 2025
d3decea
Fixing HandlerTy tenplate by setting it to a value
sacpis Feb 4, 2025
cf37744
Fixing unittests
sacpis Feb 4, 2025
7d3a8ff
Adding missing functions in helpers and updating initialize_operator_…
sacpis Feb 4, 2025
a95d141
fixing helpers.h path
sacpis Feb 5, 2025
a4f94fb
Adding equality comparision operation for matrix_2
sacpis Feb 5, 2025
27dd340
Fixing the helpers.h path
sacpis Feb 5, 2025
4eca1b0
Adding HandlerTy
sacpis Feb 5, 2025
e0709e2
Disabling unneeded (for now) variables
sacpis Feb 5, 2025
2150ed2
Adding cudaq::matrix_operator as a handler
sacpis Feb 6, 2025
d6ef90b
Disabling template method
sacpis Feb 6, 2025
f244d9d
Fixing template definition in the header and instatiating it in teh c…
sacpis Feb 6, 2025
6c09737
Enabling tests
sacpis Feb 6, 2025
1881519
Fixing Rydberg and renaming fixture in test_cudm_helpers
sacpis Feb 6, 2025
d42e173
* Enabling dynamic_cast for scalar operator
sacpis Feb 6, 2025
7da22de
Minor cmake restructure
1tnguyen Feb 6, 2025
0a0b435
Adding cudm_op_conversion interface
sacpis Feb 6, 2025
281079c
Fixing the return type of _wrap_callback_tensor
sacpis Feb 6, 2025
700fc35
Updating cudm_op_conversion interface to accommodate wrap callback an…
sacpis Feb 6, 2025
fc7d038
Adding cudm_op_conversion implementation, exposing get_generator for …
sacpis Feb 7, 2025
86292c7
Fix segfault and add an end-to-end stepper check
1tnguyen Feb 7, 2025
2833124
Fix RK 1st order and add a test
1tnguyen Feb 7, 2025
4f33f64
Adding unittests for cudm_op_conversion
sacpis Feb 7, 2025
ea79f4c
Adding operator* method
sacpis Feb 7, 2025
dfbf83f
Removing norm method from state
sacpis Feb 7, 2025
f2ec850
Fixing midpoint integration
sacpis Feb 7, 2025
bb0baff
Setting the accumulation for 4 states
sacpis Feb 7, 2025
1c798e1
Disabling RK4 for now
sacpis Feb 8, 2025
9911353
* Adding mode_action_duality
sacpis Feb 8, 2025
eb48e97
Fixing AddComplexScalars unittest
sacpis Feb 9, 2025
4a70b23
Fixing AddScalarAndOperator unittest
sacpis Feb 9, 2025
0c2a4b5
* Changing return type from double to std::complex<double>
sacpis Feb 9, 2025
a67cec9
Fixing RK4
sacpis Feb 9, 2025
c67d19c
Using cudensitymatStateComputeScaling for multiplication of state wit…
sacpis Feb 10, 2025
573952b
Add expectation
1tnguyen Feb 10, 2025
b857150
Merge branch 'dynamics_cpp_operators' of https://github.com/sacpis/cu…
sacpis Feb 11, 2025
7c64f06
Moving wrapper callbacks into cudm_helpers.cpp and disabling cudm_op_…
sacpis Feb 11, 2025
c503e7f
Adding tests for callback functions
sacpis Feb 11, 2025
0c8607b
[WIP] evolve single impl
1tnguyen Feb 11, 2025
16b69c1
* WIP fix for compute lindblad
sacpis Feb 11, 2025
f3bbf4b
Fix issue with append_elementary_operator_to_term
1tnguyen Feb 11, 2025
4839077
* Moving the tensor callbck wrapper in create_elementary_operator
sacpis Feb 11, 2025
7a2c7e7
replacing tensor callback parameter
sacpis Feb 11, 2025
2c74fa2
End-end evolve test
1tnguyen Feb 12, 2025
3e81144
Fixing lindblad operator
sacpis Feb 12, 2025
47bfb80
reverting accidental change to the logic handling already existing ma…
sacpis Feb 12, 2025
1e1b44e
Add composite system test and fix an issue with create a product term…
1tnguyen Feb 12, 2025
c134c57
Updating compute_lindblad_op with the updated append_elementary_opera…
sacpis Feb 12, 2025
1e693dc
Code restructure: separate cudm-dependency into nvqir target; no oper…
1tnguyen Feb 13, 2025
3b46cc8
Fix RK unit test
1tnguyen Feb 13, 2025
9cf261b
Adding TimeSteppingWithLindblad unitest to test compute_lindblad_oper…
sacpis Feb 13, 2025
9538ec2
Merge branch 'dynamics_cpp_operators' of https://github.com/sacpis/cu…
sacpis Feb 13, 2025
ed5da79
completing tests, including for custom matrices
bettinaheim Feb 4, 2025
f145e3c
minor clean up
bettinaheim Feb 4, 2025
d308886
general clean up
bettinaheim Feb 4, 2025
138b2e9
clean up (moving some files)
bettinaheim Feb 5, 2025
2669d95
prep for adding different handlers
bettinaheim Feb 5, 2025
5a85e9f
trivial spin ops to set up tests before digging into perf optimizations
bettinaheim Feb 5, 2025
59386f3
some more tests, and making dimensions not required for evaluation if…
bettinaheim Feb 5, 2025
7a1aefe
more spin ops tests
bettinaheim Feb 6, 2025
c277d11
commit before removing inheritance
bettinaheim Feb 7, 2025
aa86a87
removing the inheritance from operator sum
bettinaheim Feb 7, 2025
8767426
some more clean up
bettinaheim Feb 7, 2025
3aa6283
implementing remaining conversions
bettinaheim Feb 10, 2025
1377a2f
finished conversion tests
bettinaheim Feb 10, 2025
261f744
gathering some perf numbers before optimization
bettinaheim Feb 10, 2025
705a650
always link the operator lib
bettinaheim Feb 10, 2025
b422030
undoing accidentally committed change
bettinaheim Feb 10, 2025
e411cb7
product optimizations
bettinaheim Feb 10, 2025
de49502
first version with perf improvements
bettinaheim Feb 13, 2025
a70b22c
perf version 2 with map
bettinaheim Feb 13, 2025
fcdb4c8
Fix linblad test and fix leak
1tnguyen Feb 14, 2025
44341e0
Merge branch 'dynamics_cpp_operators' of https://github.com/sacpis/cu…
sacpis Feb 14, 2025
5d6e73e
Add full density matrix evolve and reduce test time
1tnguyen Feb 14, 2025
6769eb6
Merge branch 'dynamics_cpp_operators' of https://github.com/sacpis/cu…
sacpis Feb 14, 2025
0d31c8b
Support static collapse op and add a test
1tnguyen Feb 14, 2025
2178b0e
Merge branch 'dynamics_cpp_operators' of https://github.com/sacpis/cu…
sacpis Feb 14, 2025
eb5688b
* Adding conversion mechanism (to operator_sum<product_operator>) after
sacpis Feb 14, 2025
f2ba966
changes to the test script
bettinaheim Feb 13, 2025
b5ada26
checking in v2 perf numbers for comparison
bettinaheim Feb 14, 2025
79a9b15
Bringing in more commits from Bettina's branch
bettinaheim Feb 14, 2025
ae4ae7c
Hook public API
1tnguyen Feb 15, 2025
4bd04be
Port cudm_state under cudaq::SimulationState type
1tnguyen Feb 17, 2025
69118b5
More cleanup: only use cudaq::state at the API surface
1tnguyen Feb 17, 2025
9fdf186
More cleanup: remove the type alias
1tnguyen Feb 17, 2025
6f03515
Add handle to sim class
1tnguyen Feb 17, 2025
d1ddf76
Some fixes for _wrap_callback and add TODO
1tnguyen Feb 17, 2025
737c667
commit before switching branches
bettinaheim Feb 14, 2025
b682430
third and final version with a decent performance across the board
bettinaheim Feb 17, 2025
a3ad658
adding missing rvalue overloads
bettinaheim Feb 17, 2025
8ee54f2
Fixing Scalar callback using Python callback from cudensitymat and fo…
sacpis Feb 18, 2025
aa8d3f0
Removing mutex
sacpis Feb 18, 2025
272f436
Passing param names to scalar callback
1tnguyen Feb 19, 2025
0521183
integrator + schedule in the loop to resolve parameter values
1tnguyen Feb 19, 2025
1a652bf
Adding tensor callback with the unittest
sacpis Feb 19, 2025
0784b45
Support state vec -> density matrix conversion if collapse ops are pr…
1tnguyen Feb 19, 2025
1b2eecc
Removing batch_size from tensor_callback and formatting
sacpis Feb 19, 2025
d684a15
Fixing unittest and string formatting
sacpis Feb 19, 2025
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
Apply LLVM customizations for Python wheel build (#2504)
This PR fixes an LLVM discrepancy in our Docker images vs our Python wheels. This should fix #1421 and #1799 for our Python wheels. (The Docker images were already correct.)
bmhowe23 authored Jan 13, 2025
commit e2465210cda71cb0b370566b0c6cd305a5e538be
2 changes: 2 additions & 0 deletions docker/build/devdeps.manylinux.Dockerfile
Original file line number Diff line number Diff line change
@@ -85,8 +85,10 @@ RUN curl -L https://github.com/Kitware/CMake/releases/download/v3.26.4/cmake-3.2
# Build the the LLVM libraries and compiler toolchain needed to build CUDA-Q.
ADD ./scripts/build_llvm.sh /scripts/build_llvm.sh
ADD ./cmake/caches/LLVM.cmake /cmake/caches/LLVM.cmake
ADD ./tpls/customizations/llvm/ /tpls/customizations/llvm/
RUN LLVM_PROJECTS='clang;mlir' LLVM_SOURCE=/llvm-project \
LLVM_CMAKE_CACHE=/cmake/caches/LLVM.cmake \
LLVM_CMAKE_PATCHES=/tpls/customizations/llvm \
bash /scripts/build_llvm.sh -c Release -v
# No clean up of the build or source directory,
# since we need to re-build llvm for each python version to get the bindings.
41 changes: 24 additions & 17 deletions scripts/build_llvm.sh
Original file line number Diff line number Diff line change
@@ -93,26 +93,33 @@ if [ ! -d "$LLVM_SOURCE" ] || [ -z "$(ls -A "$LLVM_SOURCE"/* 2> /dev/null)" ]; t
llvm_repo="$(git config --file=.gitmodules submodule.tpls/llvm.url)"
llvm_commit="$(git submodule | grep tpls/llvm | cut -c2- | cut -d ' ' -f1)"
git clone --filter=tree:0 "$llvm_repo" "$LLVM_SOURCE"
cd "$LLVM_SOURCE" && git checkout $llvm_commit
fi

LLVM_CMAKE_PATCHES=${LLVM_CMAKE_PATCHES:-"$this_file_dir/../tpls/customizations/llvm"}
if [ -d "$LLVM_CMAKE_PATCHES" ]; then
echo "Applying LLVM patches in $LLVM_CMAKE_PATCHES..."
for patch in `find "$LLVM_CMAKE_PATCHES"/* -maxdepth 0 -type f -name '*.diff'`; do
# Check if patch is already applied.
git apply "$patch" --ignore-whitespace --reverse --check 2>/dev/null
# Always apply LLVM patches if patch directory exists; patches will be skipped
# if they were already applied previously.
LLVM_CMAKE_PATCHES=${LLVM_CMAKE_PATCHES:-"$this_file_dir/../tpls/customizations/llvm"}
if [ -d "$LLVM_CMAKE_PATCHES" ]; then
cd "$LLVM_SOURCE" && git checkout $llvm_commit
echo "Applying LLVM patches in $LLVM_CMAKE_PATCHES..."
for patch in `find "$LLVM_CMAKE_PATCHES"/* -maxdepth 0 -type f -name '*.diff'`; do
# Check if patch is already applied.
git apply "$patch" --ignore-whitespace --reverse --check 2>/dev/null
if [ ! 0 -eq $? ]; then
# If the patch is not yet applied, apply the patch.
git apply "$patch" --ignore-whitespace
if [ ! 0 -eq $? ]; then
# If the patch is not yet applied, apply the patch.
git apply "$patch" --ignore-whitespace
if [ ! 0 -eq $? ]; then
echo "Applying patch $patch failed. Please update patch."
(return 0 2>/dev/null) && return 1 || exit 1
else
echo "Applied patch $patch."
fi
echo "Applying patch $patch failed. Please update patch."
(return 0 2>/dev/null) && return 1 || exit 1
else
echo "Applied patch $patch."
fi
done
fi
else
echo "Skipping $patch because it has already been applied."
fi
done
else
echo "LLVM patch directory not found. You must apply LLVM patches via the LLVM_CMAKE_PATCHES environment variable."
(return 0 2>/dev/null) && return 1 || exit 1
fi

llvm_build_dir="$LLVM_SOURCE/${LLVM_BUILD_FOLDER:-build}"