diff --git a/.github/workflows/tests_windows.yml b/.github/workflows/tests_windows.yml new file mode 100644 index 00000000..71e48cd4 --- /dev/null +++ b/.github/workflows/tests_windows.yml @@ -0,0 +1,161 @@ +name: Testing (Windows) +on: + pull_request: + push: + branches: + - master + release: + types: [published] + +env: + DISTUTILS_USE_SDK: 1 + MSSdk: 1 + +jobs: + win-set-matrix-x86: + name: Set builder matrix + runs-on: ubuntu-latest + + steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.10.0 + with: + access_token: ${{ github.token }} + + - uses: actions/checkout@v2 + + - name: Kokkos execution strategy + id: exec_model + run: echo "::set-output name=exec_model::[\"SERIAL\"]" # We may also adopt [OPENMP, THREADS] in later iterations + + - name: Kokkos version + id: kokkos_version + run: echo "::set-output name=kokkos_version::[\"3.6.00\"]" + + outputs: + exec_model: ${{ steps.exec_model.outputs.exec_model }} + kokkos_version: ${{ steps.kokkos_version.outputs.kokkos_version }} + + build_dependencies: + needs: [win-set-matrix-x86] + strategy: + fail-fast: false + matrix: + os: [windows-latest] + exec_model: ${{ fromJson(needs.win-set-matrix-x86.outputs.exec_model) }} + kokkos_version: ${{ fromJson(needs.win-set-matrix-x86.outputs.kokkos_version) }} + + name: Kokkos core (${{ matrix.exec_model }}) + runs-on: ${{ matrix.os }} + + steps: + - name: Cancel previous runs + uses: styfle/cancel-workflow-action@0.10.0 + with: + access_token: ${{ github.token }} + + - name: Configure MSVC for amd64 # Use cl.exe as a default compiler + uses: ilammy/msvc-dev-cmd@v1 + with: + arch: amd64 + + - name: Cache installation directories + id: kokkos-cache + uses: actions/cache@v3 + with: + path: D:\a\install_dir\${{ matrix.exec_model }} + key: ${{ matrix.os }}-kokkos${{ matrix.kokkos_version }}-${{ matrix.exec_model }} + + - name: Clone Kokkos libs + if: steps.kokkos-cache.outputs.cache-hit != 'true' + run: | + cd D:\a + git clone https://github.com/kokkos/kokkos.git + cd D:\a\kokkos + git checkout ${{ matrix.kokkos_version }} + cd D:\a + + - name: Create installation directory + if: steps.kokkos-cache.outputs.cache-hit != 'true' + run: mkdir -p D:\a\install_dir\${{ matrix.exec_model }} + + - name: Install dependencies + if: steps.kokkos-cache.outputs.cache-hit != 'true' + run: | + python -m pip install cmake build + + - name: Build Kokkos core library + if: steps.kokkos-cache.outputs.cache-hit != 'true' + run: | + cd D:\a\kokkos + cmake -BBuild . -DCMAKE_INSTALL_PREFIX=D:\a\install_dir\${{ matrix.exec_model }} ` + -DKokkos_ENABLE_COMPLEX_ALIGN=OFF ` + -DKokkos_ENABLE_${{ matrix.exec_model }}=ON ` + -DKokkos_ENABLE_DEPRECATION_WARNINGS=OFF ` + -DCMAKE_CXX_STANDARD=17 ` + -DCMAKE_POSITION_INDEPENDENT_CODE=ON ` + -DCMAKE_BUILD_TYPE=RelWithDebInfo ` + -T clangcl + cmake --build ./Build --config RelWithDebInfo --verbose + cmake --install ./Build --config RelWithDebInfo --verbose + + pythontests_serial: + needs: [win-set-matrix-x86, build_dependencies] + strategy: + fail-fast: false + matrix: + os: [windows-latest] + arch: [AMD64] + exec_model: ${{ fromJson(needs.win-set-matrix-x86.outputs.exec_model) }} + kokkos_version: ${{ fromJson(needs.win-set-matrix-x86.outputs.kokkos_version) }} + name: Python tests (SERIAL) + runs-on: ${{ matrix.os }} + + steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.10.0 + with: + access_token: ${{ github.token }} + + - name: Configure MSVC for amd64 # Use cl.exe as a default compiler + uses: ilammy/msvc-dev-cmd@v1 + with: + arch: amd64 + + - name: Restoring cached dependencies + id: kokkos-cache + uses: actions/cache@v3 + with: + path: D:\a\install_dir\${{ matrix.exec_model }} + key: ${{ matrix.os }}-kokkos${{ matrix.kokkos_version }}-${{ matrix.exec_model }} + + - uses: actions/checkout@v3 + + - name: Copy cached libraries + if: steps.kokkos-cache.outputs.cache-hit == 'true' + run: | + Copy-Item -Path "D:\a\install_dir\${{ matrix.exec_model }}\" ` + -Destination "D:\a\pennylane-lightning-kokkos\pennylane-lightning-kokkos\Kokkos" -Recurse -Force + + - uses: actions/setup-python@v3 + name: Install Python + with: + python-version: '3.10' + + - name: Get required Python packages + run: | + python -m pip install --upgrade pip + python -m pip install pytest pytest-mock flaky + pip uninstall pennylane -y + pip install git+https://github.com/PennyLaneAI/pennylane.git + + - name: Install lightning.kokkos device + run: | + Set-Variable -Name BACKEND -Value "SERIAL" + python setup.py build_ext + python -m pip install -e . + + - name: Run unit tests + run: | + pytest tests/ + pl-device-test --device lightning.kokkos diff --git a/CMakeLists.txt b/CMakeLists.txt index 382de20a..58b8a86e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,7 @@ set(CMAKE_OSX_DEPLOYMENT_TARGET "10.15" CACHE STRING "Minimum OS X deployment ve project(pennylane_lightning_kokkos DESCRIPTION "Lightning-Kokkos bindings for PennyLane. Backed by the Kokkos library." - LANGUAGES CXX C + LANGUAGES C CXX ) ########################## @@ -101,14 +101,50 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON) option(Kokkos_ENABLE_DEPRECATION_WARNINGS "Enable Kokkos deprecation warnings" OFF) -include(FetchContent) -FetchContent_Declare(kokkos - GIT_REPOSITORY https://github.com/kokkos/kokkos.git - GIT_TAG 3.6.00 +find_package(Kokkos +HINTS ${CMAKE_SOURCE_DIR}/Kokkos + /usr + /usr/local + /opt ) -FetchContent_MakeAvailable(kokkos) -get_target_property(PLKOKKOS_KOKKOS_INC_DIR kokkos INTERFACE_INCLUDE_DIRECTORIES) -set_target_properties(kokkos PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${PLKOKKOS_KOKKOS_INC_DIR}") +if(Kokkos_FOUND) + message(STATUS "Found existing Kokkos library") +endif() + +find_package(KokkosKernels +HINTS ${CMAKE_SOURCE_DIR}/Kokkos + ${CMAKE_SOURCE_DIR}/KokkosKernels + /usr + /usr/local + /opt +) +if(KokkosKernels_FOUND) + message(STATUS "Found existing Kokkos Kernels library") +endif() + + +if (NOT (Kokkos_FOUND AND KokkosKernels_FOUND)) + # Setting the Serial device. + option(Kokkos_ENABLE_SERIAL "Enable Kokkos SERIAL device" ON) + message(STATUS "KOKKOS SERIAL DEVICE ENABLED.") + + option(Kokkos_ENABLE_COMPLEX_ALIGN "Enable complex alignment in memory" OFF) + + set(CMAKE_POSITION_INDEPENDENT_CODE ON) + include(FetchContent) + + FetchContent_Declare(kokkos + GIT_REPOSITORY https://github.com/kokkos/kokkos.git + GIT_TAG 3.6.00 + GIT_SUBMODULES "" # Avoid recursively cloning all submodules + ) + + FetchContent_MakeAvailable(kokkos) + + get_target_property(PLKOKKOS_KOKKOS_INC_DIR kokkos INTERFACE_INCLUDE_DIRECTORIES) + set_target_properties(kokkos PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${PLKOKKOS_KOKKOS_INC_DIR}") + +endif() ############################ @@ -159,6 +195,12 @@ if(PLKOKKOS_ENABLE_WARNINGS) # Explicitly disable warnings for Kokkos-specific library issues. endif() +if(WIN32) # For M_PI +target_compile_options(kokkos INTERFACE "/D_USE_MATH_DEFINES=ON") +target_compile_options(lightning_kokkos_qubit_ops PUBLIC "/D_USE_MATH_DEFINES=ON") +target_compile_options(pennylane_lightning_kokkos INTERFACE "/D_USE_MATH_DEFINES=ON") +endif() + if(PLKOKKOS_ENABLE_NATIVE) message(STATUS "ENABLE_NATIVE is ON. Using -march=native") add_compile_options(-march=native) @@ -166,6 +208,11 @@ if(PLKOKKOS_ENABLE_NATIVE) target_compile_options(lightning_kokkos_qubit_ops PRIVATE -march=native) endif() + +IF(MSVC) + SET(CMAKE_CXX_FLAGS "/EHsc") +ENDIF(MSVC) + if (PLKOKKOS_BUILD_TESTS) enable_testing() endif() diff --git a/pennylane_lightning_kokkos/_version.py b/pennylane_lightning_kokkos/_version.py index 96a3bd19..828d3a41 100644 --- a/pennylane_lightning_kokkos/_version.py +++ b/pennylane_lightning_kokkos/_version.py @@ -16,4 +16,4 @@ Version number (major.minor.patch[-label]) """ -__version__ = "0.27.0" +__version__ = "0.28.0-dev2" diff --git a/pennylane_lightning_kokkos/src/CMakeLists.txt b/pennylane_lightning_kokkos/src/CMakeLists.txt index 55163805..bf803d2b 100644 --- a/pennylane_lightning_kokkos/src/CMakeLists.txt +++ b/pennylane_lightning_kokkos/src/CMakeLists.txt @@ -1,4 +1,7 @@ project(lightning_kokkos_components LANGUAGES CXX) +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_EXTENSIONS OFF) +set(CMAKE_CXX_STANDARD_REQUIRED ON) ############################################################################### # Include all nested sources directories diff --git a/pennylane_lightning_kokkos/src/simulator/ExpValFunctors.hpp b/pennylane_lightning_kokkos/src/simulator/ExpValFunctors.hpp index 7304565f..2905a6ee 100644 --- a/pennylane_lightning_kokkos/src/simulator/ExpValFunctors.hpp +++ b/pennylane_lightning_kokkos/src/simulator/ExpValFunctors.hpp @@ -1,12 +1,16 @@ #pragma once -#include +#ifndef _USE_MATH_DEFINES +#define _USE_MATH_DEFINES // for C++ +#endif +#include #include "Util.hpp" +#include namespace { using namespace Pennylane::Util; -} +} // namespace namespace Pennylane { namespace Functors { diff --git a/pennylane_lightning_kokkos/src/simulator/GateFunctors.hpp b/pennylane_lightning_kokkos/src/simulator/GateFunctors.hpp index 904c0fe2..bbfc6c90 100644 --- a/pennylane_lightning_kokkos/src/simulator/GateFunctors.hpp +++ b/pennylane_lightning_kokkos/src/simulator/GateFunctors.hpp @@ -1,5 +1,10 @@ #pragma once +#ifndef _USE_MATH_DEFINES +#define _USE_MATH_DEFINES // for C++ +#endif +#include + #include #include diff --git a/pennylane_lightning_kokkos/src/tests/CMakeLists.txt b/pennylane_lightning_kokkos/src/tests/CMakeLists.txt index 4dba552a..b8d7c62c 100644 --- a/pennylane_lightning_kokkos/src/tests/CMakeLists.txt +++ b/pennylane_lightning_kokkos/src/tests/CMakeLists.txt @@ -6,7 +6,7 @@ set(CMAKE_CXX_STANDARD 17) # Default build type for test code is Debug if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE Debug) + set(CMAKE_BUILD_TYPE RelWithDebInfo) endif() option(PLKOKKOS_ENABLE_NATIVE "Enable native CPU build tuning" OFF) diff --git a/pennylane_lightning_kokkos/src/util/CMakeLists.txt b/pennylane_lightning_kokkos/src/util/CMakeLists.txt index 9d202c1c..a3275e46 100644 --- a/pennylane_lightning_kokkos/src/util/CMakeLists.txt +++ b/pennylane_lightning_kokkos/src/util/CMakeLists.txt @@ -1,7 +1,9 @@ project(lightning_kokkos_utils LANGUAGES CXX) set(CMAKE_CXX_STANDARD 17) -add_library(lightning_kokkos_utils INTERFACE) +set(UTIL_FILES Error.hpp Util.hpp CACHE INTERNAL "" FORCE) + +add_library(lightning_kokkos_utils INTERFACE ${UTIL_FILES}) target_include_directories(lightning_kokkos_utils INTERFACE $ $ -) +) \ No newline at end of file diff --git a/setup.py b/setup.py index 3270d996..0074bca7 100644 --- a/setup.py +++ b/setup.py @@ -42,7 +42,7 @@ class CMakeBuild(build_ext): ("arch=", "A", "Define backend targetted architecture"), ] - backends = {"CUDA", "HIP", "OPENMP", "THREADS", "SERIAL"} + backends = {"CUDA", "HIP", "OPENMP", "THREADS", "SERIAL", "SYCL"} def initialize_options(self): super().initialize_options() @@ -68,7 +68,8 @@ def build_extension(self, ext: CMakeExtension): # Set Python_EXECUTABLE instead if you use PYBIND11_FINDPYTHON configure_args = [ - f"-DCMAKE_CXX_FLAGS=-fno-lto", + f"-DCMAKE_CXX_STANDARD=17", + f"-DCMAKE_CXX_FLAGS=-fno-lto", f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={extdir}", f"-DPYTHON_EXECUTABLE={sys.executable}", f"-DCMAKE_BUILD_TYPE={cfg}", # not used on MSVC, but no harm @@ -118,7 +119,7 @@ def build_extension(self, ext: CMakeExtension): else: configure_args += ["-DKokkos_ENABLE_OPENMP=OFF"] elif platform.system() == "Windows": - configure_args += ["-DKokkos_ENABLE_OPENMP=OFF"] # only build with Clang under Windows + configure_args += ["-DKokkos_ENABLE_OPENMP=OFF"] else: if platform.system() != "Linux": raise RuntimeError(f"Unsupported '{platform.system()}' platform") @@ -129,7 +130,7 @@ def build_extension(self, ext: CMakeExtension): subprocess.check_call( ["cmake", str(ext.sourcedir)] + configure_args, cwd=self.build_temp ) - subprocess.check_call(["cmake", "--build", "."] + build_args, cwd=self.build_temp) + subprocess.check_call(["cmake", "--build", ".", "--verbose"] + build_args, cwd=self.build_temp) with open("pennylane_lightning_kokkos/_version.py") as f: