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

v4-CMake #430

Open
wants to merge 46 commits into
base: v4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
cc19cda
CMakeLists.txt: v4 initial commit
otbrown Jul 2, 2024
4f45f74
CMake: added build options, and checked build of api files with multi…
otbrown Jul 5, 2024
bc3245f
CMake: added remaining new core source files
otbrown Jul 8, 2024
1ccebb9
CMake: Added TESTING option and tests subdirectory
otbrown Jul 8, 2024
6108e77
CMake: Taking hint from test CMake that link to math library not requ…
otbrown Jul 8, 2024
85acc8d
CMake: Made user config compile definitions public so they can be pic…
otbrown Jul 8, 2024
2c941b4
CMake: added example subdirectory
otbrown Jul 8, 2024
b30edbb
examples: added *extremely* simple example using new API, delete this…
otbrown Jul 8, 2024
b87b7f5
CMake: Bump to CMak 3.14, added install target, rationalised includes
otbrown Jul 9, 2024
77247b6
CMake: added install target for hadamard example
otbrown Jul 9, 2024
11a5f2d
CMake: User Source exists again!
otbrown Jul 9, 2024
1b77823
Merge branch 'v4' into v4
otbrown Jul 9, 2024
54bb2a7
Merge remote-tracking branch 'origin/v4' into v4
otbrown Jul 30, 2024
d1771ed
CMake: updated include directories and source files
otbrown Jul 30, 2024
f9638e0
CMake: updated C++ standard to 17
otbrown Jul 30, 2024
a44894f
CMake: Updated compile definitions
otbrown Jul 30, 2024
f075967
CMake: updated install paths
otbrown Jul 30, 2024
c029446
Merge branch 'v4' of github.com:QuEST-Kit/QuEST into v4
otbrown Aug 28, 2024
35e11d3
Merge remote-tracking branch 'upstream/v4' into v4
otbrown Aug 30, 2024
5ea2ed5
CMakeLists.txt: updated properties
otbrown Aug 30, 2024
e164632
CMake: added CUDA support NOTE: cmake version bumped to 3.18
otbrown Aug 30, 2024
b65b481
CMakeLists.txt: added MPI support
otbrown Aug 30, 2024
8424009
CMakeLists.txt: Added library naming, resolves #351
otbrown Aug 30, 2024
e4c2de7
Merge branch 'v4' of github.com:QuEST-Kit/QuEST into v4
otbrown Sep 2, 2024
940b496
Merge branch 'v4' of github.com:QuEST-Kit/QuEST into v4
otbrown Sep 13, 2024
c5fc925
CMake: initial AMD support
otbrown Sep 13, 2024
2657163
CMake: split ENABLE_GPU_ACCELERATION to ENABLE_CUDA and ENABLE_HIP
otbrown Sep 13, 2024
67f7b47
CMakeLists.txt: USE_HIP->COMPILE_HIP
otbrown Sep 13, 2024
7acdf52
Merge branch 'v4' of github.com:QuEST-Kit/QuEST into v4
otbrown Oct 1, 2024
f4600fb
Merge branch 'v4' of github.com:QuEST-Kit/QuEST into v4
otbrown Nov 25, 2024
40e1e8f
CMake: updated source file listings and made sure COMPILE_CUQUANTUM i…
otbrown Nov 25, 2024
320a462
hadamard.cpp: updated to use applyHadamard
otbrown Nov 25, 2024
225b90c
test/main.cpp: updated to new API
otbrown Nov 25, 2024
62407ab
utilities.hpp/cpp: WIP commit. Converted to v4 API up to QVector toQV…
otbrown Nov 25, 2024
51a0731
misc bug fixes
TysonRayJones Nov 25, 2024
feb127f
dumped v3 unit tests draft
TysonRayJones Nov 25, 2024
994f13c
correcting some v3 tests
TysonRayJones Dec 25, 2024
90d6d69
Merge branch 'scratch-v3-tests' of github.com:QuEST-Kit/QuEST into v4
otbrown Dec 30, 2024
5726beb
DEAULT_VALIDATION_PRECISION -> DEFAULT_VALIDATION_PRECISION
otbrown Dec 30, 2024
8990a63
tests: updated CMake
otbrown Dec 30, 2024
c08dd22
CMake: protected maths find
otbrown Dec 30, 2024
310cfca
examples: removed hadamard
otbrown Dec 30, 2024
01f6d4e
examples: added all new examples
otbrown Dec 30, 2024
7f74aed
CMake: added BUILD_EXAMPLES and ENABLE_DEPRECATED options for complet…
otbrown Dec 30, 2024
8c43af5
cmake.md: initial commit, documenting new CMake options
otbrown Dec 31, 2024
2b1aa8f
cmake.md: added USER_SOURCE and OUTPUT_EXE
otbrown Dec 31, 2024
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
330 changes: 330 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,330 @@
# author : Ania Brown
# author : Jacob Wilkins
# author : Balint Koczor (Windows compatibility)
# author : Tyson Jones (testing)
# author : Oliver Thomson Brown (v4)

cmake_minimum_required(VERSION 3.21)

project(QuEST
VERSION 4.0.0
DESCRIPTION "Quantum Exact Simulation Toolkit"
LANGUAGES CXX C
)

## Dependencies

# GNUInstallDirs to provide sensible default install directory names
include(GNUInstallDirs)

# Maths
if (NOT MSVC)
find_library(MATH_LIBRARY m REQUIRED)
endif()

## Configuration options

# Build type
# Default to "Release"
# Using recipe from Kitware Blog post
# https://www.kitware.com/cmake-and-the-default-build-type/
set(default_build_type "Release")
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to '${default_build_type}' as none was specified.")
set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE
STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
"Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()

# Library type
# Shared library by default
option(BUILD_SHARED_LIBS "Build shared library. Turned ON by default." ON)
message(STATUS "Shared library is turned ${BUILD_SHARED_LIBS}. Set BUILD_SHARED_LIBS to modify.")

# Library naming
set(LIB_NAME QuEST
CACHE
STRING
"Change library name. LIB_NAME is QuEST by default."
)
message(STATUS "Library will be named lib${LIB_NAME}. Set LIB_NAME to modify.")

option(VERBOSE_LIB_NAME "Modify library name based on compilation configuration. Turned OFF by default." OFF)
message(STATUS "Verbose library naming is turned ${VERBOSE_LIB_NAME}. Set VERBOSE_LIB_NAME to modify.")

# Precision
set(FLOAT_PRECISION 2
CACHE
STRING
"Whether to use single, double, or quad floating point precision in the state vector. {1,2,4}"
)
set_property(CACHE FLOAT_PRECISION PROPERTY STRINGS
1
2
4
)
message(STATUS "Precision set to ${FLOAT_PRECISION}. Set FLOAT_PRECISION to modify.")

if (VERBOSE_LIB_NAME)
string(CONCAT LIB_NAME ${LIB_NAME} "-fp${FLOAT_PRECISION}")
endif()

# Examples
option(
BUILD_EXAMPLES
"Whether the example programs will be built alongside the QuEST library. Turned ON by default."
ON
)
message(STATUS "Examples are turned ${BUILD_EXAMPLES}. Set BUILD_EXAMPLES to modify.")

# Testing
option(
ENABLE_TESTING
"Whether the test suite will be built alongside the QuEST library. Turned ON by default."
ON
)
message(STATUS "Testing is turned ${ENABLE_TESTING}. Set ENABLE_TESTING to modify.")

# Multithreading
option(
ENABLE_MULTITHREADING
"Whether QuEST will be built with shared-memory parallelism support using OpenMP. Turned ON by default."
ON
)
message(STATUS "Multithreading is turned ${ENABLE_MULTITHREADING}. Set ENABLE_MULTITHREADING to modify.")

# Distribution
option(
ENABLE_DISTRIBUTION
"Whether QuEST will be built with distributed parallelism support using MPI. Turned OFF by default."
OFF
)
message(STATUS "Distribution is turned ${ENABLE_DISTRIBUTION}. Set ENABLE_DISTRIBUTION to modify.")

# GPU Acceleration
option(
ENABLE_CUDA
"Whether QuEST will be built with support for NVIDIA GPU acceleration. Turned OFF by default."
OFF
)
message(STATUS "NVIDIA GPU acceleration is turned ${ENABLE_CUDA}. Set ENABLE_CUDA to modify.")

if (ENABLE_CUDA)
option(
ENABLE_CUQUANTUM
"Whether QuEST will be built with support for NVIDIA CuQuantum. Turned OFF by default."
OFF
)
message(STATUS "CuQuantum support is turned ${ENABLE_CUQUANTUM}. Set ENABLE_CUQUANTUM to modify.")
endif()

option(
ENABLE_HIP
"Whether QuEST will be built with support for AMD GPU acceleration. Turned OFF by default."
)
message(STATUS "AMD GPU acceleration is turned ${ENABLE_HIP}. Set ENABLE_HIP to modify.")

# Throw on disallowed combinations
if (ENABLE_CUDA AND ENABLE_HIP)
message(FATAL_ERROR "QuEST cannot support CUDA and HIP simultaneously.")
endif()

if ((ENABLE_CUDA OR ENABLE_HIP) AND FLOAT_PRECISION STREQUAL 4)
message(FATAL_ERROR "Quad precision is not supported on GPU. Please disable GPU acceleration or lower precision.")
endif()

# Deprecated API
option(
ENABLE_DEPRECATED
"Whether QuEST will be built with deprecated API support. Turned OFF by default."
OFF
)
message(STATUS "Deprecated API support is turned ${ENABLE_DEPRECATED}. Set ENABLE_DEPRECATED to modify.")

## Library

add_library(QuEST)

# Add namespaced alias to support inclusion of QuEST as a subproject
add_library(QuEST::QuEST ALIAS QuEST)

# Set include directories
target_include_directories(QuEST
PUBLIC
$<BUILD_INTERFACE:
${CMAKE_CURRENT_SOURCE_DIR};
${CMAKE_CURRENT_SOURCE_DIR}/quest/include
>
$<INSTALL_INTERFACE:quest/include>
)

# Add required C and C++ standards
target_compile_features(QuEST
PUBLIC
c_std_11
cxx_std_17
)

# Turn on all compiler warnings
if (MSVC)
target_compile_options(QuEST PRIVATE /W4)
else()
target_compile_options(QuEST PRIVATE -Wall)
endif()

# Set user options
target_compile_definitions(QuEST PUBLIC FLOAT_PRECISION=${FLOAT_PRECISION})

if (ENABLE_MULTITHREADING)
find_package(OpenMP REQUIRED)
target_compile_definitions(QuEST PUBLIC COMPILE_OPENMP=1)
target_link_libraries(QuEST
PUBLIC
OpenMP::OpenMP_CXX
OpenMP::OpenMP_C
)
if (VERBOSE_LIB_NAME)
string(CONCAT LIB_NAME ${LIB_NAME} "+mt")
endif()
else()
target_compile_definitions(QuEST PUBLIC COMPILE_OPENMP=0)
endif()

if (ENABLE_DISTRIBUTION)
find_package(MPI REQUIRED
COMPONENTS CXX
)
target_compile_definitions(QuEST PUBLIC COMPILE_MPI=1)
target_link_libraries(QuEST
PUBLIC
MPI::MPI_CXX
)
if (VERBOSE_LIB_NAME)
string(CONCAT LIB_NAME ${LIB_NAME} "+mpi")
endif()
else()
target_compile_definitions(QuEST PUBLIC COMPILE_MPI=0)
endif()

if (ENABLE_CUDA)
enable_language(CUDA)
set(CMAKE_CUDA_STANDARD_REQUIRED ON)
set_property(TARGET QuEST PROPERTY CUDA_STANDARD 17)

target_compile_definitions(QuEST PUBLIC COMPILE_CUDA=1)

if (VERBOSE_LIB_NAME)
string(CONCAT LIB_NAME ${LIB_NAME} "+cuda")
endif()
else()
target_compile_definitions(QuEST PUBLIC COMPILE_CUDA=0)
endif()

if (ENABLE_CUQUANTUM)
target_compile_definitions(QuEST PUBLIC COMPILE_CUQUANTUM=1)
if (VERBOSE_LIB_NAME)
string(CONCAT LIB_NAME ${LIB_NAME} "+cuquantum")
endif()
else()
target_compile_definitions(QuEST PUBLIC COMPILE_CUQUANTUM=0)
endif()

if (ENABLE_HIP)
enable_language(HIP)
set(CMAKE_HIP_STANDARD_REQUIRED ON)
set_property(TARGET QuEST PROPERTY HIP_STANDARD 17)

target_compile_definitions(QuEST
PUBLIC COMPILE_CUDA=1
PUBLIC COMPILE_CUQUANTUM=0
PUBLIC COMPILE_HIP=1
PUBLIC __HIP_PLATFORM_AMD__
)

if (VERBOSE_LIB_NAME)
string(CONCAT LIB_NAME ${LIB_NAME} "+hip")
endif()
endif()

if (ENABLE_DEPRECATED)
target_compile_definitions(QuEST PUBLIC INCLUDE_DEPRECATED_FUNCTIONS=1)

if (VERBOSE_LIB_NAME)
string(CONCAT LIB_NAME ${LIB_NAME} "+depr")
endif()
endif()

# add math library
if (NOT MSVC)
target_link_libraries(QuEST PUBLIC ${MATH_LIBRARY})
endif()

# Set output name
set_target_properties(QuEST PROPERTIES OUTPUT_NAME ${LIB_NAME})

# Add source files
add_subdirectory(quest)

## Examples

if (BUILD_EXAMPLES)
add_subdirectory(examples)
endif()

## User Source

if (USER_SOURCE AND NOT OUTPUT_EXE)
message(SEND_ERROR "USER_SOURCE specified, but not OUTPUT_EXE.")
endif()
if (OUTPUT_EXE AND NOT USER_SOURCE)
message(SEND_ERROR "OUTPUT_EXE specified, but not USER_SOURCE.")
endif()
if (USER_SOURCE AND OUTPUT_EXE)
message(STATUS "Compiling ${USER_SOURCE} to executable ${OUTPUT_EXE}.")

add_executable(${OUTPUT_EXE} ${USER_SOURCE})
target_link_libraries(${OUTPUT_EXE} PUBLIC QuEST)
install(TARGETS ${OUTPUT_EXE} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
set_target_properties(${OUTPUT_EXE} PROPERTIES INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/quest/${CMAKE_INSTALL_LIBDIR}")
endif()

## Tests

if (ENABLE_TESTING)
add_subdirectory(tests)
endif()

## Install

install(TARGETS QuEST
EXPORT QuESTTargets
LIBRARY DESTINATION quest/${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION quest/${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION quest/${CMAKE_INSTALL_BINDIR}
)

install(EXPORT QuESTTargets
FILE QuESTTargets.cmake
NAMESPACE QuEST::
DESTINATION "cmake/QuEST"
)

## Export

# Write CMake version file for QuEST
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
QuESTConfigVersion.cmake
VERSION ${PACKAGE_VERSION}
COMPATIBILITY AnyNewerVersion
)

export(TARGETS QuEST
NAMESPACE QuEST::
FILE QuESTTargets.cmake
)

set(CMAKE_EXPORT_PACKAGE_REGISTRY ON)
export(PACKAGE QuEST)
36 changes: 36 additions & 0 deletions docs/cmake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# CMake Configuration Options in QuEST

Version 4 of QuEST includes reworked CMake to support library builds, CMake export, and installation. Here we detail useful variables to configure the compilation of QuEST. Any of these variables can be set using the `-D` flag when invoking CMake, for example:

```
cmake -Bbuild -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/opt/QuEST -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DENABLE_MULTITHREADING=ON -DENABLE_DISTRIBUTION=OFF ./
```

## QuEST CMake variables

| Variable | (Default) Values | Notes |
| -------- | ---------------- | ----- |
| `LIB_NAME` | (`QuEST`), String | The QuEST library will be named `lib${LIB_NAME}.so`. Can be used to differentiate multiple versions of QuEST which have been compiled. |
| `VERBOSE_LIB_NAME` | (`OFF`), `ON` | When turned on `LIB_NAME` will be modified according to the other configuration options chosen. For example compiling QuEST with multithreading, distribution, and double precision with `VERBOSE_LIB_NAME` turned on creates `libQuEST-fp2+mt+mpi.so`. |
| `FLOAT_PRECISION` | (`2`), `1`, `4` | Determines which floating-point precision QuEST will use: double, single, or quad. *Note: Quad precision is not supported when also compiling for GPU.* |
| `BUILD_EXAMPLES` | (`ON`), `OFF` | Determines whether the example programs will be built alongside QuEST. |
| `ENABLE_TESTING` | (`ON`), `OFF` | Determines whether Catch2 tests will be built alongisde QuEST. If built, tests can be run from the build directory with `make test`. |
| `ENABLE_MULTITHREADING` | (`ON`), OFF | Determines whether QuEST will be built with support for parallelisation with OpenMP. |
| `ENABLE_DISTRIBUTION` | (`OFF`), ON | Determines whether QuEST will be built with support for parallelisation with MPI. |
| `ENABLE_CUDA` | (`OFF`), `ON` | Determines whether QuEST will be built with support for NVIDIA GPU acceleration. If turned on, `CMAKE_CUDA_ARCHITECTURES` should probably also be set. |
| `ENABLE_CUQUANTUM` | (`OFF`), `ON` | Determines whether QuEST will make use of the NVIDIA CuQuantum library. Cannot be turned on if `ENABLE_CUDA` is off. |
| `ENABLE_HIP` | (`OFF`), `ON` | Determines whether QuEST will be built with support for AMD GPU acceleration. If turned on, `CMAKE_HIP_ARCHITECTURES` should probably also be set. |
| `ENABLE_DEPRECATION` | (`OFF`), `ON` | Determines whether QuEST will be built with support for the deprecated (v3) API. *Note: will generate compiler warnings, and not supported by GCC.` |
| `USER_SOURCE` | (Undefined), String | The source file for a user program which will be compiled alongside QuEST. `OUTPUT_EXE` *must* also be defined. |
| `OUTPUT_EXE` | (Undefined), String | The name of the executable which will be created from the provided `USER_SOURCE`. `USER_SOURCE` *must* also be defined. |

## Standard CMake variables

| Variable | Description | CMake Doc Page |
| -------- | ----------- | ----- |
| `CMAKE_BUILD_TYPE` | Whether QuEST will be built with or without optimisations and debugging info. QuEST defaults to a `Release` build which is with optimisation and without debugging info. | [CMAKE_BUILD_TYPE](https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html) |
| `CMAKE_CXX_COMPILER` | The C++ compiler that will be used to compile QuEST. | [CMAKE_\<LANG\>_COMPILER](https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_COMPILER.html) |
| `CMAKE_C_COMPILER` | The C compiler that will be used to compile QuEST. | [CMAKE_\<LANG\>_COMPILER](https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_COMPILER.html) |
| `CMAKE_INSTALL_PREFIX` | The directory to which QuEST will be installed when `make install` is invoked. A standard GNU directory structure (lib, bin, include) will be used inside the prefix directory. | [CMAKE_INSTALL_PREFIX](https://cmake.org/cmake/help/latest/variable/CMAKE_INSTALL_PREFIX.html) <br> [GNUInstallDirs](https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html) |
| `CMAKE_CUDA_ARCHITECTURES` | Used to set the value of `arch` when compiling for NVIDIA GPU. | [CMAKE_CUDA_ARCHITECTURES](https://cmake.org/cmake/help/latest/variable/CMAKE_CUDA_ARCHITECTURES.html) |
| `CMAKE_HIP_ARCHITECTURES` | Used to set the HIP platform which QuEST is compiled for when compiling for AMD GPU. | [CMAKE_HIP_ARCHITECTURES](https://cmake.org/cmake/help/latest/variable/CMAKE_HIP_ARCHITECTURES.html) |
6 changes: 6 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
add_subdirectory(krausmaps)
add_subdirectory(matrices)
add_subdirectory(numbers)
add_subdirectory(paulis)
add_subdirectory(reporters)
add_subdirectory(superoperators)
Loading