From 0c1475ff2b9292f19ada4b1c020d417d414ebad2 Mon Sep 17 00:00:00 2001 From: AmintorDusko Date: Fri, 23 Sep 2022 08:33:43 -0400 Subject: [PATCH 01/11] update dev version --- pennylane_lightning/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pennylane_lightning/_version.py b/pennylane_lightning/_version.py index b837caeb38..5363ca8fe8 100644 --- a/pennylane_lightning/_version.py +++ b/pennylane_lightning/_version.py @@ -16,4 +16,4 @@ Version number (major.minor.patch[-label]) """ -__version__ = "0.27.0-dev5" +__version__ = "0.27.0-dev6" From fdc304d4ecdddb5b9b41ef16b8349356004a74a2 Mon Sep 17 00:00:00 2001 From: AmintorDusko Date: Fri, 23 Sep 2022 08:35:46 -0400 Subject: [PATCH 02/11] update Kokkos and Kokkos Kernels --- .github/workflows/build_and_cache_Kokkos_linux.yml | 2 +- .github/workflows/set_wheel_build_matrix.yml | 2 +- .github/workflows/tests_windows.yml | 2 +- cmake/process_options.cmake | 14 +++++++------- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/build_and_cache_Kokkos_linux.yml b/.github/workflows/build_and_cache_Kokkos_linux.yml index 119e54d9c9..33aa3560ae 100644 --- a/.github/workflows/build_and_cache_Kokkos_linux.yml +++ b/.github/workflows/build_and_cache_Kokkos_linux.yml @@ -34,7 +34,7 @@ jobs: - name: Kokkos version id: kokkos_version - run: echo "::set-output name=kokkos_version::[\"3.6.00\"]" + run: echo "::set-output name=kokkos_version::[\"3.7.00\"]" outputs: exec_model: ${{ steps.exec_model.outputs.exec_model }} diff --git a/.github/workflows/set_wheel_build_matrix.yml b/.github/workflows/set_wheel_build_matrix.yml index 74761df1ba..de8191123f 100644 --- a/.github/workflows/set_wheel_build_matrix.yml +++ b/.github/workflows/set_wheel_build_matrix.yml @@ -54,7 +54,7 @@ jobs: - name: Kokkos version id: kokkos_version - run: echo "::set-output name=kokkos_version::[\"3.6.00\"]" + run: echo "::set-output name=kokkos_version::[\"3.7.00\"]" outputs: python_version: ${{ steps.pyver.outputs.python_version }} diff --git a/.github/workflows/tests_windows.yml b/.github/workflows/tests_windows.yml index a18c48788e..4cbb422bc7 100644 --- a/.github/workflows/tests_windows.yml +++ b/.github/workflows/tests_windows.yml @@ -72,7 +72,7 @@ jobs: - name: Kokkos version id: kokkos_version - run: echo "::set-output name=kokkos_version::[\"3.6.00\"]" + run: echo "::set-output name=kokkos_version::[\"3.7.00\"]" outputs: exec_model: ${{ steps.exec_model.outputs.exec_model }} diff --git a/cmake/process_options.cmake b/cmake/process_options.cmake index 495baa0289..b249383b1f 100644 --- a/cmake/process_options.cmake +++ b/cmake/process_options.cmake @@ -1,6 +1,6 @@ ############################################################################## -# This file processes ENABLE_WARNINGS, ENABLE_NATIVE, ENABLE_OPENMP, -# ENABLE_KOKKOS, and ENABLE_BLAS +# This file processes ENABLE_WARNINGS, ENABLE_NATIVE, ENABLE_OPENMP, +# ENABLE_KOKKOS, and ENABLE_BLAS # options and produces interface libraries # lightning_compile_options and lightning_external_libs. ############################################################################## @@ -151,10 +151,10 @@ if(ENABLE_KOKKOS) FetchContent_Declare(kokkos GIT_REPOSITORY https://github.com/kokkos/kokkos.git - GIT_TAG 3.6.00 + GIT_TAG 3.7.00 GIT_SUBMODULES "" # Avoid recursively cloning all submodules ) - + FetchContent_MakeAvailable(kokkos) get_target_property(kokkos_INC_DIR kokkos INTERFACE_INCLUDE_DIRECTORIES) @@ -162,12 +162,12 @@ if(ENABLE_KOKKOS) FetchContent_Declare(kokkoskernels GIT_REPOSITORY https://github.com/kokkos/kokkos-kernels.git - GIT_TAG 3.6.00 + GIT_TAG 3.7.00 GIT_SUBMODULES "" # Avoid recursively cloning all submodules ) - + FetchContent_MakeAvailable(kokkoskernels) - + get_target_property(kokkoskernels_INC_DIR kokkoskernels INTERFACE_INCLUDE_DIRECTORIES) set_target_properties(kokkoskernels PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${kokkoskernels_INC_DIR}") From 18dec74b1f661b791e409813c597295e019ba7c5 Mon Sep 17 00:00:00 2001 From: AmintorDusko Date: Mon, 26 Sep 2022 08:57:39 -0400 Subject: [PATCH 03/11] change result view to unmanaged --- Makefile | 2 +- pennylane_lightning/src/util/Kokkos_Sparse.hpp | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 983a03a897..305b59e8a8 100644 --- a/Makefile +++ b/Makefile @@ -111,7 +111,7 @@ test-cpp-kokkos: gbenchmark: rm -rf ./BuildGBench cmake $(LIGHTNING_CPP_DIR) -BBuildGBench -DBUILD_BENCHMARKS=ON -DENABLE_OPENMP=ON -DENABLE_BLAS=ON -DCMAKE_BUILD_TYPE=Release -DBLA_VENDOR=OpenBLAS - cmake --build ./BuildGBench + cmake --build ./BuildGBench .PHONY: format format-cpp format-python format: format-cpp format-python diff --git a/pennylane_lightning/src/util/Kokkos_Sparse.hpp b/pennylane_lightning/src/util/Kokkos_Sparse.hpp index becde8618f..fdc1fade56 100644 --- a/pennylane_lightning/src/util/Kokkos_Sparse.hpp +++ b/pennylane_lightning/src/util/Kokkos_Sparse.hpp @@ -21,6 +21,8 @@ #include "Error.hpp" +// #define _ENABLE_KOKKOS + #ifdef _ENABLE_KOKKOS #include "KokkosKernels_default_types.hpp" @@ -131,15 +133,17 @@ void apply_Sparse_Matrix_Kokkos( const_data_view_type vector_view( reinterpret_cast *>(vector_ptr), vector_size); - Kokkos::View *> result_view("rhs", vector_size); + std::vector> result_view_vector(vector_size); + data_view_type result_view(result_view_vector.data(), + vector_size); - const_crs_matrix_type myMatrix = + const_crs_matrix_type Sparse_matrix = create_Kokkos_Sparse_Matrix(row_map_ptr, row_map_size - 1, entries_ptr, values_ptr, numNNZ); const data_type alpha(1.0); const data_type beta; - KokkosSparse::spmv("N", alpha, myMatrix, vector_view, beta, + KokkosSparse::spmv("N", alpha, Sparse_matrix, vector_view, beta, result_view); result = std::move(std::vector>( From c8760a7416eb5301ae77ff7bfa52f0ab73ab4d6f Mon Sep 17 00:00:00 2001 From: AmintorDusko Date: Mon, 26 Sep 2022 09:03:09 -0400 Subject: [PATCH 04/11] Format --- pennylane_lightning/src/util/Kokkos_Sparse.hpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pennylane_lightning/src/util/Kokkos_Sparse.hpp b/pennylane_lightning/src/util/Kokkos_Sparse.hpp index fdc1fade56..9714db2b58 100644 --- a/pennylane_lightning/src/util/Kokkos_Sparse.hpp +++ b/pennylane_lightning/src/util/Kokkos_Sparse.hpp @@ -133,9 +133,10 @@ void apply_Sparse_Matrix_Kokkos( const_data_view_type vector_view( reinterpret_cast *>(vector_ptr), vector_size); - std::vector> result_view_vector(vector_size); - data_view_type result_view(result_view_vector.data(), + std::vector> result_view_vector( vector_size); + data_view_type result_view(result_view_vector.data(), + vector_size); const_crs_matrix_type Sparse_matrix = create_Kokkos_Sparse_Matrix(row_map_ptr, row_map_size - 1, From 2af0edbfd9e13bbaa00b1d97d7e262798d0ee1d7 Mon Sep 17 00:00:00 2001 From: AmintorDusko Date: Mon, 26 Sep 2022 09:06:16 -0400 Subject: [PATCH 05/11] rename --- pennylane_lightning/src/util/Kokkos_Sparse.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pennylane_lightning/src/util/Kokkos_Sparse.hpp b/pennylane_lightning/src/util/Kokkos_Sparse.hpp index 9714db2b58..0988d12f1c 100644 --- a/pennylane_lightning/src/util/Kokkos_Sparse.hpp +++ b/pennylane_lightning/src/util/Kokkos_Sparse.hpp @@ -138,13 +138,13 @@ void apply_Sparse_Matrix_Kokkos( data_view_type result_view(result_view_vector.data(), vector_size); - const_crs_matrix_type Sparse_matrix = + const_crs_matrix_type sparse_matrix = create_Kokkos_Sparse_Matrix(row_map_ptr, row_map_size - 1, entries_ptr, values_ptr, numNNZ); const data_type alpha(1.0); const data_type beta; - KokkosSparse::spmv("N", alpha, Sparse_matrix, vector_view, beta, + KokkosSparse::spmv("N", alpha, sparse_matrix, vector_view, beta, result_view); result = std::move(std::vector>( From 5a61e0c97425c860883e4a62fdf845412164f738 Mon Sep 17 00:00:00 2001 From: AmintorDusko Date: Mon, 26 Sep 2022 09:39:40 -0400 Subject: [PATCH 06/11] update changelog --- .github/CHANGELOG.md | 3 +++ pennylane_lightning/src/util/Kokkos_Sparse.hpp | 2 -- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/CHANGELOG.md b/.github/CHANGELOG.md index 3fcb623cbf..c64fdcac06 100644 --- a/.github/CHANGELOG.md +++ b/.github/CHANGELOG.md @@ -12,6 +12,9 @@ * Improve tests and checks CI/CD pipelines. [(#353)](https://github.com/PennyLaneAI/pennylane-lightning/pull/353) +* Upgrade Kokkos and Kokkos Kernels to 3.7.00. +[(#361)](https://github.com/PennyLaneAI/pennylane-lightning/pull/361) + ### Documentation ### Bug fixes diff --git a/pennylane_lightning/src/util/Kokkos_Sparse.hpp b/pennylane_lightning/src/util/Kokkos_Sparse.hpp index 0988d12f1c..299d50ea2d 100644 --- a/pennylane_lightning/src/util/Kokkos_Sparse.hpp +++ b/pennylane_lightning/src/util/Kokkos_Sparse.hpp @@ -21,8 +21,6 @@ #include "Error.hpp" -// #define _ENABLE_KOKKOS - #ifdef _ENABLE_KOKKOS #include "KokkosKernels_default_types.hpp" From 2c11d680bcf4ef154529c6e4f3e2ad8cba5cc4de Mon Sep 17 00:00:00 2001 From: Dev version update bot Date: Mon, 3 Oct 2022 12:18:43 +0000 Subject: [PATCH 07/11] Auto update version --- pennylane_lightning/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pennylane_lightning/_version.py b/pennylane_lightning/_version.py index 5363ca8fe8..1fbf3fb921 100644 --- a/pennylane_lightning/_version.py +++ b/pennylane_lightning/_version.py @@ -16,4 +16,4 @@ Version number (major.minor.patch[-label]) """ -__version__ = "0.27.0-dev6" +__version__ = "0.27.0-dev7" From 8a93140393d46390bb6229c7e0907c09f1d7e22e Mon Sep 17 00:00:00 2001 From: Dev version update bot Date: Tue, 4 Oct 2022 12:48:36 +0000 Subject: [PATCH 08/11] Auto update version --- pennylane_lightning/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pennylane_lightning/_version.py b/pennylane_lightning/_version.py index 1fbf3fb921..68243943e6 100644 --- a/pennylane_lightning/_version.py +++ b/pennylane_lightning/_version.py @@ -16,4 +16,4 @@ Version number (major.minor.patch[-label]) """ -__version__ = "0.27.0-dev7" +__version__ = "0.27.0-dev8" From 4ea86a8e28ca3fb25670cf2427c98e32a91401e2 Mon Sep 17 00:00:00 2001 From: AmintorDusko Date: Tue, 4 Oct 2022 09:54:20 -0400 Subject: [PATCH 09/11] improve Kokkos implementation --- .../src/util/Kokkos_Sparse.hpp | 21 +++++-------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/pennylane_lightning/src/util/Kokkos_Sparse.hpp b/pennylane_lightning/src/util/Kokkos_Sparse.hpp index 299d50ea2d..35f300085b 100644 --- a/pennylane_lightning/src/util/Kokkos_Sparse.hpp +++ b/pennylane_lightning/src/util/Kokkos_Sparse.hpp @@ -47,7 +47,7 @@ using const_index_view_type = typename Kokkos::View>; -template using data_type = Kokkos::complex; +template using data_type = std::complex; template using crs_matrix_type = @@ -94,9 +94,7 @@ const_crs_matrix_type create_Kokkos_Sparse_Matrix( const index_type numNNZ) { const_index_view_type row_map(row_map_ptr, numRows + 1); const_index_view_type entries(entries_ptr, numNNZ); - const_data_view_type values( - reinterpret_cast *>(values_ptr), - numNNZ); + const_data_view_type values(values_ptr, numNNZ); const_graph_type myGraph(entries, row_map); const_crs_matrix_type SparseMatrix("matrix", numRows, values, @@ -128,13 +126,9 @@ void apply_Sparse_Matrix_Kokkos( Kokkos::initialize(); { - const_data_view_type vector_view( - reinterpret_cast *>(vector_ptr), - vector_size); - std::vector> result_view_vector( - vector_size); - data_view_type result_view(result_view_vector.data(), - vector_size); + const_data_view_type vector_view(vector_ptr, vector_size); + result.resize(vector_size); + data_view_type result_view(result.data(), vector_size); const_crs_matrix_type sparse_matrix = create_Kokkos_Sparse_Matrix(row_map_ptr, row_map_size - 1, @@ -144,11 +138,6 @@ void apply_Sparse_Matrix_Kokkos( const data_type beta; KokkosSparse::spmv("N", alpha, sparse_matrix, vector_view, beta, result_view); - - result = std::move(std::vector>( - reinterpret_cast *>(result_view.data()), - reinterpret_cast *>(result_view.data()) + - result_view.size())); } Kokkos::finalize(); }; From ecc53fb985de8a99b84506ec849b3ca36ba874d3 Mon Sep 17 00:00:00 2001 From: AmintorDusko Date: Tue, 4 Oct 2022 12:52:53 -0400 Subject: [PATCH 10/11] expand gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 2880d1a5ee..b998491e7e 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,5 @@ cpptests /.vs /pennylane_lightning/.vs /pennylane_lightning/*.pyd +/pennylane_lightning/src/Kokkos/ +/pennylane_lightning/src/GBenchmarks/ From c2fc536941176e28163996ef85162405e5f95819 Mon Sep 17 00:00:00 2001 From: AmintorDusko Date: Tue, 4 Oct 2022 13:13:55 -0400 Subject: [PATCH 11/11] update changelog --- .github/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CHANGELOG.md b/.github/CHANGELOG.md index 18c227dfa9..f97df5d2d3 100644 --- a/.github/CHANGELOG.md +++ b/.github/CHANGELOG.md @@ -15,7 +15,7 @@ * Implement 3 Qubits gates (CSWAP & Toffoli) & 4 Qubits gates (DoubleExcitation, DoubleExcitationMinus, DoubleExcitationPlus) in LM manner. [(#362)](https://github.com/PennyLaneAI/pennylane-lightning/pull/362) -* Upgrade Kokkos and Kokkos Kernels to 3.7.00. +* Upgrade Kokkos and Kokkos Kernels to 3.7.00, and improve sparse matrix-vector multiplication performance and memory usage. [(#361)](https://github.com/PennyLaneAI/pennylane-lightning/pull/361) ### Documentation