Skip to content

Commit

Permalink
Add build-time flag to enable OpenMP in Lightning gate kernels (#510)
Browse files Browse the repository at this point in the history
* Add OMP to CNOT and CZ AVX kernels

* Add OMP to CNOT and CZ to LM kernels

* Add pragma-controlled parallelism to gate kernels for LQ

* Add pragma-controlled parallelism to gate kernels for LQ +1

* Add compile-time generation for gate kernel OMP threading in LQ

* Rename OMP macros and add SIMD annotations to short loops

* Update macros & uses

* Remove simd macro from constexpr/consteval

* Remove simd from additional constexpr/consteval operations

* Update changelog

* Auto update version

* Fix LM kernels to support changes; remove PI OMP

* Fix format and CI test builds

* Auto update version

* Auto update version

* Update pennylane_lightning/core/src/simulators/lightning_qubit/gates/cpu_kernels/GatePragmas.hpp

Co-authored-by: Ali Asadi <[email protected]>

* Auto update version

* Trigger CI

* Improve kernel testing with OpenMP

* Add missing directory return in CI

* Auto update version

* Trigger CI

* Add my name to the changelog and remove redundant comment

* Update pennylane_lightning/core/src/simulators/lightning_qubit/gates/cpu_kernels/GatePragmas.hpp

Co-authored-by: Amintor Dusko <[email protected]>

---------

Co-authored-by: Dev version update bot <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Ali Asadi <[email protected]>
Co-authored-by: Amintor Dusko <[email protected]>
  • Loading branch information
4 people authored Jan 12, 2024
1 parent f591388 commit ac8795d
Show file tree
Hide file tree
Showing 39 changed files with 264 additions and 152 deletions.
6 changes: 5 additions & 1 deletion .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

### Improvements

* OpenMP acceleration can now be enabled at compile time for all `lightning.qubit` gate kernels using the "-DLQ_ENABLE_KERNEL_OMP=1" CMake argument.
[(#510)](https://github.com/PennyLaneAI/pennylane-lightning/pull/510)

### Documentation

### Bug fixes
Expand All @@ -17,6 +20,7 @@

This release contains contributions from (in alphabetical order):

Lee J. O'Riordan,
Shuli Shu

---
Expand Down Expand Up @@ -58,7 +62,7 @@ Shuli Shu
[(#540)] (https://github.com/PennyLaneAI/pennylane-lightning/pull/540)

### Improvements

* Ensure aligned memory used for numpy arrays with state-vector without reallocations.
[(#572)](https://github.com/PennyLaneAI/pennylane-lightning/pull/572)

Expand Down
38 changes: 29 additions & 9 deletions .github/workflows/tests_linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,27 +59,46 @@ jobs:
-DPL_BACKEND=${{ matrix.pl_backend }} \
-DCMAKE_CXX_COMPILER=$(which g++-$GCC_VERSION) \
-DENABLE_COVERAGE=ON
cmake . -BBuildKernelOMP -G Ninja \
-DCMAKE_BUILD_TYPE=Debug \
-DBUILD_TESTS=ON \
-DENABLE_PYTHON=OFF \
-DPL_BACKEND=${{ matrix.pl_backend }} \
-DCMAKE_CXX_COMPILER=$(which g++-$GCC_VERSION) \
-DENABLE_COVERAGE=ON \
-DLQ_ENABLE_KERNEL_OMP=ON
cmake --build ./Build
cd ./Build
mkdir -p ./tests/results
for file in *runner ; do ./$file --order lex --reporter junit --out ./tests/results/report_$file.xml; done;
lcov --directory . -b ../pennylane_lightning/core/src --capture --output-file coverage.info
lcov --remove coverage.info '/usr/*' --output-file coverage.info
cmake --build ./BuildKernelOMP
for d in Build BuildKernelOMP; do
cd ./$d
mkdir -p ./tests/results
for file in *runner ; do ./$file --order lex --reporter junit --out ./tests/results/report_$file.xml; done;
lcov --directory . -b ../pennylane_lightning/core/src --capture --output-file coverage.info
lcov --remove coverage.info '/usr/*' --output-file coverage.info
cd ..
done
lcov --add-tracefile ./Build/coverage.info -a ./BuildKernelOMP/coverage.info -o coverage.info
mv coverage.info coverage-${{ github.job }}-${{ matrix.pl_backend }}.info
- name: Upload test results
uses: actions/upload-artifact@v3
if: always()
with:
name: ubuntu-tests-reports-${{ github.job }}-${{ matrix.pl_backend }}
path: ./Build/tests/results/
path: |
./Build/tests/results/
./BuildKernelOMP/tests/results/
if-no-files-found: error

- name: Upload code coverage results
uses: actions/upload-artifact@v3
with:
name: ubuntu-codecov-results-cpp
path: ./Build/coverage-${{ github.job }}-${{ matrix.pl_backend }}.info
path: ./coverage-${{ github.job }}-${{ matrix.pl_backend }}.info
if-no-files-found: error

pythontests:
Expand Down Expand Up @@ -158,7 +177,7 @@ jobs:
- name: Install backend device
run: |
cd main
CMAKE_ARGS="-DPL_BACKEND=${{ matrix.pl_backend }} -DENABLE_PYTHON=ON -DCMAKE_CXX_COMPILER=$(which g++-$GCC_VERSION)" \
CMAKE_ARGS="-DPL_BACKEND=${{ matrix.pl_backend }} -DLQ_ENABLE_KERNEL_OMP=ON -DENABLE_PYTHON=ON -DCMAKE_CXX_COMPILER=$(which g++-$GCC_VERSION)" \
python -m pip install -e . -vv
- name: Run PennyLane-Lightning unit tests
Expand Down Expand Up @@ -265,7 +284,8 @@ jobs:
-DBUILD_TESTS=ON \
-DENABLE_LAPACK=OFF \
-DCMAKE_CXX_COMPILER=$(which g++-$GCC_VERSION) \
-DENABLE_COVERAGE=ON
-DENABLE_COVERAGE=ON \
-DLQ_ENABLE_KERNEL_OMP=ON
cmake --build ./Build
cd ./Build
mkdir -p ./tests/results
Expand Down
2 changes: 1 addition & 1 deletion pennylane_lightning/core/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
Version number (major.minor.patch[-label])
"""

__version__ = "0.35.0-dev0"
__version__ = "0.35.0-dev1"
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ add_library(lightning_qubit STATIC ${LQUBIT_FILES})

option(ENABLE_BLAS "Enable BLAS" OFF)
option(ENABLE_GATE_DISPATCHER "Enable gate kernel dispatching on AVX/AVX2/AVX512" ON)
option(LQ_ENABLE_KERNEL_OMP "Enable OpenMP pragmas for gate kernels" OFF)

# Inform the compiler that this device is enabled.
target_compile_options(lightning_compile_options INTERFACE "-D_ENABLE_PLQUBIT=1")
Expand All @@ -46,6 +47,10 @@ else()
message(STATUS "ENABLE_BLAS is OFF.")
endif()

if(LQ_ENABLE_KERNEL_OMP)
add_definitions("-DPL_LQ_KERNEL_OMP")
endif()

target_link_libraries(lightning_qubit PUBLIC lightning_compile_options
lightning_external_libs
lightning_base
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "Error.hpp"
#include "GateImplementationsLM.hpp"
#include "GateOperation.hpp"
#include "GatePragmas.hpp"
#include "Gates.hpp"
#include "KernelType.hpp"
#include "LinearAlgebra.hpp"
Expand Down
Loading

0 comments on commit ac8795d

Please sign in to comment.