-
Notifications
You must be signed in to change notification settings - Fork 178
Make qsimcirq Apple Silicon (M1, M2, ARM64) compatible and improve build scripts #643
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
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
b4bc7bf
Compile for M1
basnijholt 7e2a8f9
Make qsimcirq Apple Silicon (M1, M2, ARM64) compatible
basnijholt 6694970
make work
basnijholt 44ed305
Support Apple x86 and ARM in setup.py with homebrew and current PATH
basnijholt 31536d8
Style
basnijholt a10c693
remove debug messages in cmake
basnijholt 0fbbc89
Generalize pybind11 finding
basnijholt 08ad3d7
Set project first
basnijholt e8b6ed6
Simplify
basnijholt 423b8ed
Simplify logic in CMakeLists.txt
basnijholt e333c2e
Simplify CMakeLists.txt even more
basnijholt fff819e
Implement suggestion by @sergeisakov
basnijholt 1ca5477
Set flags for OpenMP_CXX
basnijholt 6f074e9
Link libomp with homebrew
basnijholt b605cad
Remove setting of CXX flags and lib
basnijholt bb92b2e
Rely on 'find_package(OpenMP REQUIRED)' to set -fopenmp
basnijholt 6727376
Build wheels for Apple Silicon
basnijholt 0d324c0
Add --overwrite
basnijholt e7649ff
Add macos-13-large to testing wheels too
basnijholt b06b395
overwrite Python
basnijholt 34ca2a5
Call target_link_libraries for OpenMP
basnijholt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,10 +12,14 @@ jobs: | |
fail-fast: false | ||
matrix: | ||
include: | ||
- os: macos-12 | ||
- os: macos-12 # x86_64 | ||
name: mac | ||
cibw: | ||
build: "cp37* cp38* cp39* cp310* cp311*" | ||
- os: macos-13-large # Apple Silicon | ||
name: mac_arm64 | ||
cibw: | ||
build: "cp37* cp38* cp39* cp310* cp311*" | ||
- os: ubuntu-20.04 | ||
name: manylinux2014 | ||
cibw: | ||
|
@@ -32,7 +36,7 @@ jobs: | |
CIBW_SKIP: "*musllinux*" | ||
CIBW_ARCHS: "${{ matrix.cibw.arch || 'auto' }}" | ||
CIBW_MANYLINUX_X86_64_IMAGE: "${{ matrix.cibw.manylinux_image }}" | ||
CIBW_BEFORE_BUILD_MACOS: "brew install libomp llvm" | ||
CIBW_BEFORE_BUILD_MACOS: "brew install libomp llvm && brew link --overwrite [email protected] && brew link --force libomp" | ||
CIBW_REPAIR_WHEEL_COMMAND_MACOS: "delocate-listdeps {wheel} && delocate-wheel --verbose --require-archs {delocate_archs} -w {dest_dir} {wheel}" | ||
# to install latest delocate package | ||
CIBW_DEPENDENCY_VERSIONS: "latest" | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,10 +17,14 @@ jobs: | |
fail-fast: false | ||
matrix: | ||
include: | ||
- os: macos-12 | ||
- os: macos-12 # x86_64 | ||
name: mac | ||
cibw: | ||
build: "cp37* cp38* cp39* cp310* cp311*" | ||
- os: macos-13-large # Apple Silicon | ||
name: mac_arm64 | ||
cibw: | ||
build: "cp37* cp38* cp39* cp310* cp311*" | ||
- os: ubuntu-20.04 | ||
name: manylinux2014 | ||
cibw: | ||
|
@@ -37,7 +41,7 @@ jobs: | |
CIBW_SKIP: "*musllinux*" | ||
CIBW_ARCHS: "${{ matrix.cibw.arch || 'auto' }}" | ||
CIBW_MANYLINUX_X86_64_IMAGE: "${{ matrix.cibw.manylinux_image }}" | ||
CIBW_BEFORE_BUILD_MACOS: "brew install libomp llvm" | ||
CIBW_BEFORE_BUILD_MACOS: "brew install libomp llvm && brew link --overwrite [email protected] && brew link --force libomp" | ||
CIBW_REPAIR_WHEEL_COMMAND_MACOS: "delocate-listdeps {wheel} && delocate-wheel --verbose --require-archs {delocate_archs} -w {dest_dir} {wheel}" | ||
# to install latest delocate package | ||
CIBW_DEPENDENCY_VERSIONS: "latest" | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,51 @@ | ||
set(CMAKE_CXX_STANDARD 11) | ||
cmake_minimum_required(VERSION 3.11) | ||
|
||
execute_process(COMMAND which nvcc OUTPUT_VARIABLE has_nvcc) | ||
if(has_nvcc STREQUAL "") | ||
execute_process(COMMAND which hipcc OUTPUT_VARIABLE has_hipcc) | ||
if(has_hipcc STREQUAL "") | ||
project(qsim) | ||
else() | ||
project(qsim LANGUAGES CXX HIP) | ||
ADD_SUBDIRECTORY(pybind_interface/hip) | ||
# Set APPLE_ARM to TRUE if running on Apple Silicon | ||
if(APPLE) | ||
execute_process(COMMAND uname -m OUTPUT_VARIABLE OSX_ARCH OUTPUT_STRIP_TRAILING_WHITESPACE) | ||
if (OSX_ARCH STREQUAL "arm64") | ||
set(APPLE_ARM TRUE) | ||
else() # x86_64 | ||
set(APPLE_ARM FALSE) | ||
endif() | ||
else() | ||
project(qsim LANGUAGES CXX CUDA) | ||
ADD_SUBDIRECTORY(pybind_interface/cuda) | ||
if(DEFINED ENV{CUQUANTUM_ROOT}) | ||
ADD_SUBDIRECTORY(pybind_interface/custatevec) | ||
set(APPLE_ARM FALSE) | ||
endif(APPLE) | ||
|
||
# Set the project name and language | ||
if(APPLE) | ||
project(qsim LANGUAGES CXX) | ||
else() | ||
execute_process(COMMAND which nvcc OUTPUT_VARIABLE has_nvcc OUTPUT_STRIP_TRAILING_WHITESPACE) | ||
if(has_nvcc) | ||
project(qsim LANGUAGES CXX CUDA) | ||
else() | ||
execute_process(COMMAND which hipcc OUTPUT_VARIABLE has_hipcc OUTPUT_STRIP_TRAILING_WHITESPACE) | ||
if(has_hipcc) | ||
project(qsim LANGUAGES CXX HIP) | ||
else() | ||
project(qsim LANGUAGES CXX) | ||
endif() | ||
endif() | ||
endif() | ||
|
||
ADD_SUBDIRECTORY(pybind_interface/sse) | ||
ADD_SUBDIRECTORY(pybind_interface/avx512) | ||
ADD_SUBDIRECTORY(pybind_interface/avx2) | ||
find_package(OpenMP REQUIRED) | ||
|
||
# Add subdirectories based on the architecture or available compilers | ||
ADD_SUBDIRECTORY(pybind_interface/basic) | ||
ADD_SUBDIRECTORY(pybind_interface/decide) | ||
if(NOT APPLE_ARM) | ||
if(has_nvcc) | ||
ADD_SUBDIRECTORY(pybind_interface/cuda) | ||
if(DEFINED ENV{CUQUANTUM_ROOT}) | ||
ADD_SUBDIRECTORY(pybind_interface/custatevec) | ||
endif() | ||
elseif(has_hipcc) | ||
ADD_SUBDIRECTORY(pybind_interface/hip) | ||
endif() | ||
|
||
ADD_SUBDIRECTORY(pybind_interface/sse) | ||
ADD_SUBDIRECTORY(pybind_interface/avx512) | ||
ADD_SUBDIRECTORY(pybind_interface/avx2) | ||
endif() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,48 @@ | ||
cmake_minimum_required(VERSION 3.11) | ||
|
||
execute_process(COMMAND which nvcc OUTPUT_VARIABLE has_nvcc) | ||
if(has_nvcc STREQUAL "") | ||
execute_process(COMMAND which hipcc OUTPUT_VARIABLE has_hipcc) | ||
if(has_hipcc STREQUAL "") | ||
project(qsim) | ||
else() | ||
project(qsim LANGUAGES CXX HIP) | ||
endif() | ||
if(WIN32) | ||
set(CMAKE_CXX_FLAGS "/O2 /openmp") | ||
else() | ||
project(qsim LANGUAGES CXX CUDA) | ||
set(CMAKE_CXX_FLAGS "-O3") | ||
endif() | ||
|
||
IF (WIN32) | ||
set(CMAKE_CXX_FLAGS "/O2 /openmp") | ||
ELSE() | ||
set(CMAKE_CXX_FLAGS "-O3 -fopenmp") | ||
ENDIF() | ||
|
||
if(APPLE) | ||
if(APPLE AND NOT APPLE_ARM) | ||
set(CMAKE_CXX_STANDARD 14) | ||
include_directories("/usr/local/include" "/usr/local/opt/llvm/include") | ||
link_directories("/usr/local/lib" "/usr/local/opt/llvm/lib") | ||
endif() | ||
|
||
INCLUDE(../GetPybind11.cmake) | ||
|
||
if(has_nvcc STREQUAL "") | ||
if(has_hipcc STREQUAL "") | ||
pybind11_add_module(qsim_decide decide.cpp) | ||
else() | ||
include(../GetPybind11.cmake) | ||
|
||
# Configure based on the detected platform | ||
if(has_nvcc) | ||
find_package(CUDA REQUIRED) | ||
cuda_add_library(qsim_decide MODULE decide.cpp) | ||
if(DEFINED ENV{CUQUANTUM_ROOT}) | ||
target_compile_options(qsim_decide PRIVATE | ||
$<$<COMPILE_LANGUAGE:CUDA>:-D__CUSTATEVEC__> | ||
) | ||
endif() | ||
find_package(Python3 3.7 REQUIRED COMPONENTS Interpreter Development) | ||
include_directories(${PYTHON_INCLUDE_DIRS} ${pybind11_SOURCE_DIR}/include) | ||
set_target_properties(qsim_decide PROPERTIES | ||
PREFIX "${PYTHON_MODULE_PREFIX}" | ||
SUFFIX "${PYTHON_MODULE_EXTENSION}" | ||
) | ||
set_source_files_properties(decide.cpp PROPERTIES LANGUAGE CUDA) | ||
elseif(has_hipcc) | ||
list(APPEND CMAKE_MODULE_PATH "/opt/rocm/lib/cmake/hip") | ||
find_package(HIP REQUIRED) | ||
find_package(PythonLibs 3.7 REQUIRED) | ||
|
||
include_directories(${PYTHON_INCLUDE_DIRS} ${pybind11_SOURCE_DIR}/include) | ||
|
||
hip_add_library(qsim_decide MODULE decide.cpp) | ||
|
||
set_source_files_properties(decide.cpp PROPERTIES LANGUAGE HIP) | ||
find_package(Python3 3.7 REQUIRED COMPONENTS Interpreter Development) | ||
include_directories(${PYTHON_INCLUDE_DIRS} ${pybind11_SOURCE_DIR}/include) | ||
set_target_properties(qsim_decide PROPERTIES | ||
PREFIX "${PYTHON_MODULE_PREFIX}" | ||
SUFFIX "${PYTHON_MODULE_EXTENSION}" | ||
PREFIX "${PYTHON_MODULE_PREFIX}" | ||
SUFFIX "${PYTHON_MODULE_EXTENSION}" | ||
) | ||
set_source_files_properties(decide.cpp PROPERTIES LANGUAGE HIP) | ||
endif() | ||
else() | ||
find_package(PythonLibs 3.7 REQUIRED) | ||
find_package(CUDA REQUIRED) | ||
|
||
include_directories(${PYTHON_INCLUDE_DIRS} ${pybind11_SOURCE_DIR}/include) | ||
|
||
cuda_add_library(qsim_decide MODULE decide.cpp) | ||
|
||
if(DEFINED ENV{CUQUANTUM_ROOT}) | ||
target_compile_options(qsim_decide PRIVATE | ||
$<$<COMPILE_LANGUAGE:CUDA>:-D__CUSTATEVEC__> | ||
) | ||
endif() | ||
|
||
set_target_properties(qsim_decide PROPERTIES | ||
PREFIX "${PYTHON_MODULE_PREFIX}" | ||
SUFFIX "${PYTHON_MODULE_EXTENSION}" | ||
) | ||
set_source_files_properties(decide.cpp PROPERTIES LANGUAGE CUDA) | ||
pybind11_add_module(qsim_decide decide.cpp) | ||
endif() | ||
|
||
target_link_libraries(qsim_decide PUBLIC OpenMP::OpenMP_CXX) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.