Skip to content

Commit

Permalink
Merge pull request #30 from Qulacs-Osaka/24-GPUenv
Browse files Browse the repository at this point in the history
setup of build environment for GPU
  • Loading branch information
KowerKoint authored Jan 9, 2024
2 parents a862a33 + cea4b57 commit 29231bd
Show file tree
Hide file tree
Showing 27 changed files with 887 additions and 228 deletions.
43 changes: 32 additions & 11 deletions .devcontainer/cpu/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/blob/main/containers/python-3/.devcontainer/base.Dockerfile

# Pick a Python version: 3, 3.10, 3.9, 3.8, 3.7, 3.6
# Append -bullseye or -buster to pin to an OS version.
# Use -bullseye variants on local on arm64/Apple Silicon.
FROM mcr.microsoft.com/vscode/devcontainers/python:0-3.9-bullseye
FROM ubuntu:22.04

ENV DEBIAN_FRONTEND=noninteractive

Expand All @@ -15,22 +10,37 @@ ENV PYTHONPATH="${PROJECT_DIR}/build:${PYTHONPATH}"

RUN apt-get update && \
apt-get install -y software-properties-common && \
apt-get update && \
apt-get install -y gcc-10 g++-10 && \
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 100 && \
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-10 100 \
apt-get install -y gcc-11 g++-11 && \
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 100 && \
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 100 \
# Remove imagemagick due to https://security-tracker.debian.org/tracker/CVE-2019-10131, which is done in Microsoft's devcontainer image.
&& apt-get purge -y imagemagick imagemagick-6-common \
&& apt-get install -y --no-install-recommends \
build-essential \
ca-certificates \
clang-format \
curl \
git \
gdb \
cmake \
libboost-dev \
libpython3-dev \
ninja-build \
python3 \
python3-distutils \
python3-pip \
wget \
&& apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/*

RUN pip install -U pip \
&& pip install black flake8 openfermion mypy pybind11-stubgen

RUN wget https://github.com/Kitware/CMake/releases/download/v3.28.0/cmake-3.28.0-Linux-x86_64.sh -q -O /tmp/cmake-install.sh && \
chmod u+x /tmp/cmake-install.sh && \
mkdir /opt/cmake-3.28.0 && \
/tmp/cmake-install.sh --skip-license --prefix=/opt/cmake-3.28.0 && \
rm /tmp/cmake-install.sh && \
ln -s /opt/cmake-3.28.0/bin/* /usr/local/bin

RUN git clone --recursive https://github.com/kokkos/kokkos.git /tmp/kokkos --depth 1 && \
mkdir /tmp/kokkos/build && \
cd /tmp/kokkos/build && \
Expand All @@ -39,4 +49,15 @@ RUN git clone --recursive https://github.com/kokkos/kokkos.git /tmp/kokkos --dep
cp -r /tmp/kokkos-build/include /usr/local/include/kokkos && \
rm -rf /tmp/kokkos /tmp/kokkos-build

ARG USERNAME=vscode
ARG GROUPNAME=vscode
ARG USER_UID=1000
ARG USER_GID=$USER_UID
RUN groupadd --gid $USER_GID $GROUPNAME \
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \
&& apt-get update \
&& apt-get install -y sudo \
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME\
&& chmod 0440 /etc/sudoers.d/$USERNAME

USER vscode
20 changes: 11 additions & 9 deletions .devcontainer/gpu/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM nvidia/cuda:12.2.0-devel-ubuntu20.04
FROM nvidia/cuda:12.2.0-devel-ubuntu22.04

ENV DEBIAN_FRONTEND=noninteractive

Expand All @@ -10,24 +10,19 @@ ENV PYTHONPATH="${PROJECT_DIR}/build:${PYTHONPATH}"

RUN apt-get update && \
apt-get install -y software-properties-common && \
apt-get update && \
apt-get install -y gcc-10 g++-10 && \
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 100 && \
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-10 100 \
apt-get install -y gcc-11 g++-11 && \
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 100 && \
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 100 \
# Remove imagemagick due to https://security-tracker.debian.org/tracker/CVE-2019-10131, which is done in Microsoft's devcontainer image.
&& apt-get purge -y imagemagick imagemagick-6-common \
&& apt-get install -y --no-install-recommends \
ca-certificates \
clang-format \
g++-10 \
cmake \
curl \
git \
gdb \
libboost-dev \
libpython3-dev \
manpages \
man-db \
ninja-build \
python3 \
python3-distutils \
Expand All @@ -38,6 +33,13 @@ RUN apt-get update && \
RUN pip install -U pip \
&& pip install black flake8 openfermion mypy pybind11-stubgen

RUN wget https://github.com/Kitware/CMake/releases/download/v3.28.0/cmake-3.28.0-Linux-x86_64.sh -q -O /tmp/cmake-install.sh && \
chmod u+x /tmp/cmake-install.sh && \
mkdir /opt/cmake-3.28.0 && \
/tmp/cmake-install.sh --skip-license --prefix=/opt/cmake-3.28.0 && \
rm /tmp/cmake-install.sh && \
ln -s /opt/cmake-3.28.0/bin/* /usr/local/bin

RUN git clone --recursive https://github.com/kokkos/kokkos.git /tmp/kokkos --depth 1 && \
mkdir /tmp/kokkos/build && \
cd /tmp/kokkos/build && \
Expand Down
83 changes: 67 additions & 16 deletions .github/workflows/ci_ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,27 @@ on:
- "*.md"

jobs:
gcc10-build:
name: GCC10 build
gcc11-build:
name: GCC11 build
strategy:
matrix:
python-version: ["3.10"]
runs-on: "ubuntu-20.04"
runs-on: "ubuntu-22.04"
env:
CXX_COMPILER: "/usr/lib/ccache/g++"
C_COMPILER: "/usr/lib/ccache/gcc"
QULACS_OPT_FLAGS: "-mtune=haswell -march=haswell -mfpmath=both"
COVERAGE: "Yes"
USE_TEST: "Yes"
QULACS_USE_TEST: "Yes"
steps:
- uses: actions/checkout@v3

- name: Install gcc-10/g++-10
uses: sudo apt-get update && \
apt-get install -y software-properties-common && \
add-apt-repository ppa:ubuntu-toolchain-r/test && \
apt-get update && \
apt-get install -y gcc-10 g++-10 && \
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 100 && \
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-10 100 \
- name: Install gcc-11/g++-11
run: |
sudo apt update && \
sudo apt install -y software-properties-common && \
sudo apt update && \
sudo apt install -y gcc-11 g++-11 && \
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 100 && \
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 100
- name: Setup cmake
uses: lukka/get-cmake@latest
Expand All @@ -48,12 +46,65 @@ jobs:
- name: Setup ccache
uses: hendrikmuhs/[email protected]
with:
key: "${{ github.job }}-ubuntu-20.04"
key: "${{ github.job }}-ubuntu-22.04"
verbose: 2

- name: Install qulacs for Ubuntu
run: ./script/build_gcc.sh
run: CMAKE_BUILD_TYPE=Debug ./script/build_gcc.sh

- name: Test in Ubuntu
run: |
ninja test -C build -j $(nproc)
nvcc-build:
name: NVCC build
strategy:
matrix:
python-version: ["3.10"]
runs-on: "ubuntu-22.04"
env:
CXX_COMPILER: "/usr/lib/ccache/g++"
C_COMPILER: "/usr/lib/ccache/gcc"
QULACS_USE_TEST: "Yes"
QULACS_USE_CUDA: "Yes"
steps:
- uses: actions/checkout@v3

- name: Install gcc-11/g++-11
run: |
sudo apt update && \
sudo apt install -y software-properties-common && \
sudo apt update && \
sudo apt install -y gcc-11 g++-11 && \
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 100 && \
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 100
- name: Setup cmake
uses: lukka/get-cmake@latest

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

- name: Setup ccache
uses: hendrikmuhs/[email protected]
with:
key: "${{ github.job }}-ubuntu-22.04"
verbose: 2

- name: Install CUDA toolkit
uses: Jimver/[email protected]
with:
cuda: "12.2.0"
method: "network"

- name: Show installed Compiler version
run: |
nvcc --version
gcc --version
g++ --version
cmake --version
- name: Install qulacs for Ubuntu
run: ./script/build_gcc.sh

# GitHub Actions cannot run CUDA program
82 changes: 44 additions & 38 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,32 +1,52 @@
cmake_minimum_required(VERSION 3.11)
cmake_minimum_required(VERSION 3.21)

project(qulacs)

include(FetchContent)

### Define variables ###
if(NOT DEFINED QULACS_USE_OMP)
set(QULACS_USE_OMP Yes)
set(QULACS_USE_OMP ON)
endif(NOT DEFINED QULACS_USE_OMP)
if(NOT DEFINED QULACS_USE_CUDA)
set(QULACS_USE_CUDA No)
set(QULACS_USE_CUDA OFF)
endif(NOT DEFINED QULACS_USE_CUDA)
if(NOT DEFINED QULACS_USE_PYTHON)
set(QULACS_USE_PYTHON No)
set(QULACS_USE_PYTHON OFF)
endif(NOT DEFINED QULACS_USE_PYTHON)
if(NOT DEFINED QULACS_USE_TEST)
set(QULACS_USE_TEST Yes)
set(QULACS_USE_TEST ON)
endif(NOT DEFINED QULACS_USE_TEST)
if(NOT DEFINED QULACS_USE_EXE)
set(QULACS_USE_EXE ON)
endif(NOT DEFINED QULACS_USE_EXE)

message(STATUS "QULACS_USE_PYTHON = ${QULACS_USE_PYTHON}")
message(STATUS "QULACS_USE_TEST = ${QULACS_USE_TEST}")

### Kokkos options ###
set(Kokkos_ENABLE_SERIAL ON CACHE BOOL "Enable Kokkos Serial backend")
if(QULACS_USE_OMP)
set(Kokkos_ENABLE_OPENMP ON CACHE BOOL "Enable Kokkos OpenMP backend")
endif(QULACS_USE_OMP)
if(QULACS_USE_CUDA)
set(Kokkos_ENABLE_CUDA ON CACHE BOOL "Enable Kokkos CUDA backend")
set(Kokkos_ARCH_PASCAL61 ON CACHE BOOL "Enable Kokkos CUDA Pascal61 architecture")
find_program(CUDA_NVCC_EXECUTABLE nvcc)
if(CUDA_NVCC_EXECUTABLE)
set(CMAKE_CUDA_COMPILER_WRAPPER ${CUDA_NVCC_EXECUTABLE})
message(STATUS "Using nvcc_wrapper for CUDA compilation")
else()
message(SEND_ERROR "nvcc not found")
endif()
endif(QULACS_USE_CUDA)

### Fetch dependencies ###
# Kokkos
FetchContent_Declare(
kokkos_fetch
GIT_REPOSITORY https://github.com/kokkos/kokkos
GIT_TAG 4.1.00
GIT_TAG 4.2.00
)
FetchContent_GetProperties(kokkos_fetch)
if(NOT kokkos_fetch_POPULATED)
Expand Down Expand Up @@ -80,47 +100,30 @@ else()
message(STATUS "Skip downloding googletest")
endif(QULACS_USE_TEST)

### Kokkos options ###
set(Kokkos_ENABLE_SERIAL Yes)
if(QULACS_USE_OMP)
set(Kokkos_ENABLE_OPENMP Yes)
endif(QULACS_USE_OMP)
if(QULACS_USE_CUDA)
set(Kokkos_ENABLE_CUDA Yes)
endif(QULACS_USE_CUDA)

### Compile Warnings ###
if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
set(WARNING_CPP "-Wall -Wdate-time -Wendif-labels -Werror=format=2 \
-Werror=missing-declarations -Werror=return-type -Wextra \
-Wfloat-equal -Wimplicit-fallthrough=5 -Wlogical-op \
-Wmissing-include-dirs -Wpointer-arith -Wredundant-decls \
-Wshadow -Wstrict-aliasing=2 -Wsuggest-attribute=noreturn -Wwrite-strings \
-fdiagnostics-color=auto -fstrict-aliasing")
# -Werror=undef is eliminated due to conflict with boost
elseif ((${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang") OR (${CMAKE_CXX_COMPILER_ID} STREQUAL "AppleClang"))
set(WARNING_CPP "-Wall -Wdate-time -Wendif-labels -Werror=format=2 \
-Werror=missing-declarations -Werror=return-type -Wextra \
-Wfloat-equal -Wimplicit-fallthrough \
-Wmissing-include-dirs -Wpointer-arith -Wredundant-decls \
-Wshadow -Wstrict-aliasing=2 -Wwrite-strings \
-fdiagnostics-color=auto -fstrict-aliasing")
endif()
add_library(qulacs)

### Compiler options ###
if ((${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU") OR (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang") OR (${CMAKE_CXX_COMPILER_ID} STREQUAL "AppleClang"))
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# Standard
target_compile_features(qulacs PUBLIC cxx_std_20)

# Warning
target_compile_options(qulacs PUBLIC
-Wall -Wextra -Wunused-parameter -Wshadow -pedantic
-Wsign-compare -Wtype-limits -Wuninitialized)

# Enable pthread
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
target_compile_options(qulacs PUBLIC -pthread)

# Enable openmp
if(QULACS_USE_OMP)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
add_compile_definitions(OPENMP)
target_compile_options(qulacs PUBLIC -fopenmp)
target_compile_definitions(qulacs PUBLIC OPENMP)
endif()

# Debug options
target_compile_options(qulacs PUBLIC $<$<CONFIG:Debug>:-O0 -g -fsanitize=address,undefined>)
target_link_options(qulacs PUBLIC $<$<CONFIG:Debug>:-fsanitize=address,undefined>)
endif()

### Add subdirectories ###
Expand All @@ -131,6 +134,9 @@ endif(QULACS_USE_PYTHON)
if(QULACS_USE_TEST)
add_subdirectory(tests)
endif(QULACS_USE_TEST)
if(QULACS_USE_EXE)
add_subdirectory(exe)
endif(QULACS_USE_EXE)

### Custom target ###
# test
Expand Down
37 changes: 36 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,36 @@
# qulacs2023
# qulacs2023

## 依存ライブラリ
- GCC 11 以上
- CMake 3.21 以上
- CUDA 12.2 以上(GPU利用時のみ)

## ビルド・実行方法

### ビルド (CPU)
```
script/build_gcc.sh
```

### ビルド(GPU)
```
QULACS_USE_CUDA script/build_gcc.sh
```

※キャッシュ変数がセットされるため、ターゲットを変えてビルドする際は `build/CMakeCache.txt` を削除する

### テスト
```
ninja -C build test
```

### qulacs2023 を用いての C++ 単一ファイルの手元実行
`exe` の中に cpp ファイルを作成し、`exe/CMakeLists.txt` に追記してビルド

### フォーマット
```
ninja -C build format
```

### Python へのインストール
要確認
Loading

0 comments on commit 29231bd

Please sign in to comment.