Skip to content
This repository has been archived by the owner on Oct 27, 2023. It is now read-only.

Add tests for Windows #2

Draft
wants to merge 38 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
9dab64b
Update _version.py
mlxd Sep 16, 2022
8fd1500
Add windows tests
mlxd Sep 16, 2022
98c6043
Add SYCL and multi-OS support
mlxd Sep 16, 2022
673934b
Update win
mlxd Sep 16, 2022
212d70b
Ensure clang compiler used
mlxd Sep 16, 2022
71104c7
Ensure c++17 used
mlxd Sep 16, 2022
3ca1585
Remove 3rd party compile env
mlxd Sep 16, 2022
2ee6dfb
Remove santizer
mlxd Sep 16, 2022
b639061
Add math defines for windows
mlxd Sep 16, 2022
3c6a2a3
Add math defines for windows again
mlxd Sep 16, 2022
cfc921e
Add math defines for windows again x2
mlxd Sep 16, 2022
48be477
FF
mlxd Sep 16, 2022
1a723a6
math defines x3
mlxd Sep 16, 2022
0ee17f1
Verbosity
mlxd Sep 16, 2022
fedc7d4
Update cmath pre-include
mlxd Sep 16, 2022
dd866a6
Update cmath stuff one last time
mlxd Sep 16, 2022
43b0232
Update cmath stuff one last time
mlxd Sep 16, 2022
35383e6
Define the missing values
mlxd Sep 16, 2022
cc03c6a
Define the missing values again
mlxd Sep 16, 2022
8636526
Define the missing values againx1q23451253
mlxd Sep 16, 2022
4901e1c
Define the missing values againnnnnn
mlxd Sep 16, 2022
f5f723c
Define the missing values againx23
mlxd Sep 16, 2022
8eab496
Modifying compiler
mlxd Sep 16, 2022
057c1e2
Update windows tests
mlxd Sep 19, 2022
584135f
Update windows tests
mlxd Sep 19, 2022
9a8b921
Allow cahcing of Kokkos in Win build
mlxd Sep 19, 2022
cfa166f
Remove kokkos kernels
mlxd Sep 19, 2022
eace9ac
Remove CIBUILDWHEEL
mlxd Sep 19, 2022
cec7906
Remove ML interfaces
mlxd Sep 19, 2022
be8ff4c
Remove main
mlxd Sep 19, 2022
3e7dc3f
Remove Ninja from windows build
mlxd Sep 19, 2022
114d48c
disable ninja for windows explicitly
mlxd Sep 19, 2022
3383906
Ensure C lang set for MSVC errors
mlxd Sep 19, 2022
65aaf8d
Aim to froce clang-cl to work
mlxd Sep 19, 2022
993734b
Add build verbosity
mlxd Sep 19, 2022
1970a59
Update WIndows builder version
mlxd Sep 19, 2022
d0afc79
Merge branch 'main' into win_tests
mlxd Sep 21, 2022
7d72dcd
Merge branch 'main' into win_tests
mlxd Dec 9, 2022
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
161 changes: 161 additions & 0 deletions .github/workflows/tests_windows.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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/[email protected]
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/[email protected]
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
63 changes: 55 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

##########################
Expand Down Expand Up @@ -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()


############################
Expand Down Expand Up @@ -159,13 +195,24 @@ 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)
target_compile_options(pennylane_lightning_kokkos INTERFACE -march=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()
Expand Down
2 changes: 1 addition & 1 deletion pennylane_lightning_kokkos/_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.27.0"
__version__ = "0.28.0-dev2"
3 changes: 3 additions & 0 deletions pennylane_lightning_kokkos/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 6 additions & 2 deletions pennylane_lightning_kokkos/src/simulator/ExpValFunctors.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
#pragma once

#include <Kokkos_Core.hpp>
#ifndef _USE_MATH_DEFINES
#define _USE_MATH_DEFINES // for C++
#endif
#include <cmath>

#include "Util.hpp"
#include <Kokkos_Core.hpp>

namespace {
using namespace Pennylane::Util;
}
} // namespace

namespace Pennylane {
namespace Functors {
Expand Down
5 changes: 5 additions & 0 deletions pennylane_lightning_kokkos/src/simulator/GateFunctors.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#pragma once

#ifndef _USE_MATH_DEFINES
#define _USE_MATH_DEFINES // for C++
#endif
#include <cmath>

#include <Kokkos_Core.hpp>
#include <Kokkos_StdAlgorithms.hpp>

Expand Down
2 changes: 1 addition & 1 deletion pennylane_lightning_kokkos/src/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions pennylane_lightning_kokkos/src/util/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/DS>
)
)
9 changes: 5 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -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")
Expand All @@ -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:
Expand Down