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

MacOS Support #174

Merged
merged 34 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
59acbd7
add macos ci
KowerKoint Sep 17, 2024
7903a1f
add macos ci
KowerKoint Sep 17, 2024
49e46e6
fix literal
KowerKoint Sep 17, 2024
9216b63
fix literal
KowerKoint Sep 17, 2024
a099156
rename format CI
KowerKoint Sep 17, 2024
1487db0
fix runs-on variable
KowerKoint Sep 20, 2024
541ffc9
fix ninja installation
KowerKoint Sep 20, 2024
51a83e9
fix ccache specification
KowerKoint Sep 20, 2024
f1e8a31
fix CMAKE_CXX_COMPILER
KowerKoint Sep 20, 2024
64335d4
add C, not only CXX
KowerKoint Sep 20, 2024
1649f43
add CMAKE_ prefix on C*_COMPILER
KowerKoint Sep 20, 2024
10aa422
PROCS for macos
KowerKoint Sep 20, 2024
72cb44c
nprocs -> nproc
KowerKoint Sep 20, 2024
81933e0
no asan on macos
KowerKoint Sep 20, 2024
78eb233
comma
KowerKoint Sep 20, 2024
8e461ac
remove format check
KowerKoint Sep 20, 2024
87ef406
add CMAKE_* property to pyproject.toml
KowerKoint Sep 20, 2024
585251b
use nvcc when cuda
KowerKoint Sep 20, 2024
0f72a69
NPROC on macos
KowerKoint Sep 20, 2024
74fe505
correct integer type
KowerKoint Sep 20, 2024
16c7810
do not use ccache when cuda is used
KowerKoint Sep 24, 2024
e603b99
correct C/CXX
KowerKoint Sep 24, 2024
b5e7824
reverse generate expression
KowerKoint Sep 24, 2024
68aa5dd
do not use compiler launcher
KowerKoint Sep 24, 2024
09a51e7
distinct os ccache
KowerKoint Sep 24, 2024
1a51d3b
add $
KowerKoint Sep 24, 2024
7c0b4ae
Yes/No -> ON/OFF
KowerKoint Sep 24, 2024
01dbb5d
Release type on CUDA
KowerKoint Sep 24, 2024
51f0f9d
remove useless property from pyproject.toml
KowerKoint Sep 24, 2024
d1b72e8
FetchContent_Populate -> FetchContent_MakeAvailable
KowerKoint Sep 24, 2024
2ee81b8
do not check stub if cuda
KowerKoint Sep 24, 2024
cdda846
specify compiler
KowerKoint Sep 24, 2024
453bdc7
correct env
KowerKoint Sep 24, 2024
fc09b84
MACOSX_DEPLOYMENT_TARGET=13.0
KowerKoint Sep 24, 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
129 changes: 0 additions & 129 deletions .github/workflows/ci_ubuntu.yml

This file was deleted.

40 changes: 40 additions & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Format

on:
push:
paths-ignore:
- ".devcontainer/**"
- ".vscode/**"
- "doc/**"
- "*.md"
pull_request:
paths-ignore:
- ".devcontainer/**"
- ".vscode/**"
- "doc/**"
- "*.md"

jobs:
check-format:
name: Check Format
runs-on: "ubuntu-22.04"
steps:
- uses: actions/checkout@v4

- name: Setup cmake
uses: lukka/get-cmake@latest

- name: Install Ninja
run: sudo apt install ninja-build

- name: Configure
run: |
mkdir -p ./build
cmake -B build -G Ninja

- name: Check format
run: |
ninja -C build format
diff=$(git diff)
echo -n "$diff"
test $(echo -n "$diff" | wc -l) -eq 0
97 changes: 97 additions & 0 deletions .github/workflows/test.yml
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CPU版とGPU版を1種類のjobにしてmatrixで分けた

Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: Build and Test

on:
push:
paths-ignore:
- ".devcontainer/**"
- ".vscode/**"
- "doc/**"
- "*.md"
pull_request:
paths-ignore:
- ".devcontainer/**"
- ".vscode/**"
- "doc/**"
- "*.md"

jobs:
test:
name: Build and Test
strategy:
matrix:
os: ["linux", "macos"]
architecture: ["x86_64"]
device: ["cpu", "cuda"]
python-version: ["3.10"]
exclude:
- os: "macos"
device: "cuda"
include:
- os: "linux"
architecture: "x86_64"
runs-on: "ubuntu-22.04"
- os: "macos"
architecture: "x86_64"
runs-on: "macos-13"
runs-on: ${{ matrix.runs-on }}
env:
CMAKE_C_COMPILER: ${{ matrix.os == 'macos' && '/usr/local/opt/ccache/libexec/gcc-14' || '/usr/lib/ccache/gcc' }}
CMAKE_CXX_COMPILER: ${{ matrix.os == 'macos' && '/usr/local/opt/ccache/libexec/g++-14' || '/usr/lib/ccache/g++' }}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Macではg++の中身はclang++になっているので…

CMAKE_BUILD_TYPE: ${{ matrix.device == 'cuda' && 'Release' || 'Debug' }}
SCALUQ_USE_TEST: "ON"
SCALUQ_USE_CUDA: ${{ matrix.device == 'cuda' && 'ON' || 'OFF' }}
SCALUQ_CUDA_ARCH: "PASCAL61"
steps:
- uses: actions/checkout@v4

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

公式runnerに入っているもののパッケージを見て、GCCやCMakeのインストールは不要なことがわかったので消しました

- name: Install Ninja
if: ${{ matrix.os == 'linux' }}
run: sudo apt update && sudo apt install ninja-build

- name: Install Ninja
if: ${{ matrix.os == 'macos' }}
run: brew install ninja

- name: Setup ccache
uses: hendrikmuhs/ccache-action@v1.2
with:
key: "${{ github.job }}-${{ matrix.os }}-${{ matrix.device }}"
verbose: 2

- name: Install CUDA toolkit
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

このstepが圧倒的に重いのでなんとかしたい………
CUDA版のCI用のイメージをghcr.ioに作っておいておくとか

if: ${{ matrix.device == 'cuda' }}
uses: Jimver/cuda-toolkit@v0.2.11
with:
cuda: "12.2.0"
method: "network"

- name: Show installed Compiler version
run: |
[ $SCALUQ_USE_CUDA = 'ON' ] && nvcc --version
ccache --version
$CMAKE_C_COMPILER --version
$CMAKE_CXX_COMPILER --version
cmake --version
ninja --version

- name: Install scaluq for Ubuntu
run: ./script/build_gcc.sh

- name: Install scaluq Python module
run: pip install .[ci]

- name: Test in Ubuntu
if: ${{ matrix.device == 'cpu' }} # currently GPU runner is not supported
run: |
if [ "$(uname)" == 'Darwin' ]; then
NPROC=$(sysctl -n hw.logicalcpu)
else
NPROC=$(nproc)
fi
OMP_PROC_BIND=false ninja test -C build -j ${NPROC}

- name: Test if stub exists
if: ${{ matrix.device == 'cpu' }} # currently GPU runner is not supported
run: |
echo -e "from scaluq import StateVector\nfrom scaluq.gate import I" > /tmp/stub_sample.py
mypy /tmp/stub_sample.py
22 changes: 16 additions & 6 deletions .github/workflows/wheel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,18 @@ jobs:
strategy:
fail-fast: false
matrix:
os-arch: ["manylinux_x86_64"]
os: ["linux", "macos"]
arch: ["x86_64"]
cibw-python: ["cp38", "cp39", "cp310", "cp311", "cp312"]
include:
- os-arch: "manylinux_x86_64"
os: "ubuntu-22.04"
- os: "linux"
arch: "x86_64"
runs-on: "ubuntu-22.04"
cibw-os-arch: "manylinux_x86_64"
- os: "macos"
arch: "x86_64"
runs-on: "macos-13"
cibw-os-arch: "macosx_x86_64"
- cibw-python: "cp38"
python-version: "3.8"
- cibw-python: "cp39"
Expand All @@ -33,10 +40,13 @@ jobs:
python-version: "3.11"
- cibw-python: "cp312"
python-version: "3.12"
runs-on: ${{ matrix.os }}
runs-on: ${{ matrix.runs-on }}
env:
CIBW_BUILD: ${{ matrix.cibw-python }}-${{ matrix.os-arch }}
CMAKE_C_COMPILER: ${{ matrix.os == 'macos' && 'gcc-14' || 'gcc' }}
CMAKE_CXX_COMPILER: ${{ matrix.os == 'macos' && 'g++-14' || 'g++' }}
CIBW_BUILD: ${{ matrix.cibw-python }}-${{ matrix.cibw-os-arch }}
PYTHON: ${{ matrix.python-version }}
MACOSX_DEPLOYMENT_TARGET: "13.0"
steps:
- uses: actions/checkout@v4

Expand All @@ -53,7 +63,7 @@ jobs:
- name: Upload wheel to GitHub
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.cibw-python }}-${{ matrix.os-arch }}
name: ${{ matrix.cibw-python }}-${{ matrix.cibw-os-arch }}
path: ./wheels/*.whl

- name: Upload wheel data if the Git tag is set
Expand Down
37 changes: 13 additions & 24 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,30 +43,20 @@ endif(SCALUQ_USE_CUDA)
### Fetch dependencies ###
# Kokkos
FetchContent_Declare(
kokkos_fetch
kokkos
GIT_REPOSITORY https://github.com/kokkos/kokkos
GIT_TAG 4.2.00
)
FetchContent_GetProperties(kokkos_fetch)
if(NOT kokkos_fetch_POPULATED)
message(STATUS "Fetch Kokkos for parallel execution")
FetchContent_Populate(kokkos_fetch)
add_subdirectory(${kokkos_fetch_SOURCE_DIR})
set_property(TARGET kokkoscore PROPERTY POSITION_INDEPENDENT_CODE ON)
endif(NOT kokkos_fetch_POPULATED)
FetchContent_MakeAvailable(kokkos)
set_property(TARGET kokkoscore PROPERTY POSITION_INDEPENDENT_CODE ON)

# Eigen
FetchContent_Declare(
eigen_fetch
eigen
GIT_REPOSITORY https://gitlab.com/libeigen/eigen
GIT_TAG 3.4.0
)
FetchContent_GetProperties(eigen_fetch)
if(NOT eigen_fetch_POPULATED)
message(STATUS "Fetch Eigen for matrix operation")
FetchContent_Populate(eigen_fetch)
add_subdirectory(${eigen_fetch_SOURCE_DIR})
endif(NOT eigen_fetch_POPULATED)
FetchContent_MakeAvailable(eigen)

# nanobind
if(SKBUILD)
Expand All @@ -88,16 +78,11 @@ endif(SKBUILD)
# Google test
if(SCALUQ_USE_TEST)
FetchContent_Declare(
googletest_fetch
googletest
GIT_REPOSITORY https://github.com/google/googletest
GIT_TAG release-1.12.1
)
FetchContent_GetProperties(googletest_fetch)
if(NOT googletest_fetch_POPULATED)
message(STATUS "Fetch googletest for C++ testing")
FetchContent_Populate(googletest_fetch)
add_subdirectory(${googletest_fetch_SOURCE_DIR})
endif()
FetchContent_MakeAvailable(googletest)
else()
message(STATUS "Skip downloding googletest")
endif(SCALUQ_USE_TEST)
Expand Down Expand Up @@ -140,8 +125,12 @@ if ((${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU") OR (${CMAKE_CXX_COMPILER_ID} STREQ
endif()

# Debug options
target_compile_options(scaluq PUBLIC $<IF:$<CONFIG:Debug>,-O0 -g -fsanitize=address$<COMMA>undefined,-O3>)
target_link_options(scaluq PUBLIC $<$<CONFIG:Debug>:-fsanitize=address$<COMMA>undefined>)
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
target_compile_options(scaluq PUBLIC $<IF:$<CONFIG:Debug>,-O0 -g,-O3>)
else()
target_compile_options(scaluq PUBLIC $<IF:$<CONFIG:Debug>,-O0 -g -fsanitize=address$<COMMA>undefined,-O3>)
target_link_options(scaluq PUBLIC $<$<CONFIG:Debug>:-fsanitize=address$<COMMA>undefined>)
endif()
endif()

### Add subdirectories ###
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ metadata.version.provider = "scikit_build_core.metadata.setuptools_scm"
sdist.include = ["python/scaluq/_version.py"]

[tool.scikit-build.cmake.define]
CMAKE_C_COMPILER = {env="CMAKE_C_COMPILER", default="gcc"}
CMAKE_CXX_COMPILER = {env="CMAKE_CXX_COMPILER", default="g++"}
SCALUQ_USE_OMP = {env="SCALUQ_USE_OMP", default="Yes"}
SCALUQ_USE_CUDA = {env="SCALUQ_USE_CUDA", default="No"}
SCALUQ_CUDA_ARCH = {env="SCALUQ_CUDA_ARCH"}
Expand Down
Loading
Loading