-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #643 from basnijholt/apple-silicon
Make qsimcirq Apple Silicon (M1, M2, ARM64) compatible and improve build scripts
- Loading branch information
Showing
14 changed files
with
157 additions
and
97 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 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 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.