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

[WIP] Include GPU in wheels #479

Draft
wants to merge 43 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
4bf007a
GPU in wheels, attempt 1
95-martin-orion Nov 16, 2021
2b230f7
Checking for nvcc binary
95-martin-orion Nov 16, 2021
0c57285
PATH testing
95-martin-orion Nov 16, 2021
9d6eac3
Appease YAML
95-martin-orion Nov 16, 2021
d2c2c00
CIBW PATH
95-martin-orion Nov 16, 2021
bbb7a50
jumping YAML hoops
95-martin-orion Nov 16, 2021
85220a7
CIBW which nvcc
95-martin-orion Nov 16, 2021
033d67f
hardcoded PATH
95-martin-orion Nov 19, 2021
178f51b
yaml fixup
95-martin-orion Nov 19, 2021
2a5ff71
pwd and ls
95-martin-orion Dec 1, 2021
bf2061d
rm CIBW_TEST_COMMAND_LINUX
95-martin-orion Dec 1, 2021
74942aa
the mystery deepens
95-martin-orion Dec 3, 2021
dc6a9e8
env-pass
95-martin-orion Dec 3, 2021
43db2ca
script-based CUDA install
95-martin-orion Dec 3, 2021
159aec6
bash the .sh
95-martin-orion Dec 3, 2021
c53ce63
don't sudo what's already sudone
95-martin-orion Dec 3, 2021
925cc0b
preload deps to prevent reboot
95-martin-orion Dec 3, 2021
4c85cd3
double install, yay
95-martin-orion Dec 3, 2021
1142a18
ooc install, ic no pre-install
95-martin-orion Dec 3, 2021
bf7d029
move script into qsim
95-martin-orion Dec 10, 2021
95e2d73
export directly
95-martin-orion Dec 10, 2021
3a6b86f
need more data
95-martin-orion Dec 10, 2021
6033c9f
sourcery
95-martin-orion Dec 10, 2021
578264f
version and which-nvcc check
95-martin-orion Dec 10, 2021
247bdda
passthrough PATH
95-martin-orion Dec 10, 2021
47361d1
move the env
95-martin-orion Dec 10, 2021
aed7e6a
less PATH is more PATH
95-martin-orion Dec 13, 2021
164974c
and without changing the PATH...
95-martin-orion Dec 13, 2021
9671f4a
remove which nvcc also
95-martin-orion Dec 13, 2021
a09c4ad
pass unmodified PATH
95-martin-orion Dec 13, 2021
ba997ef
path after PATH
95-martin-orion Dec 21, 2021
29d4993
LD_LIBRARY_PATH passthrough
95-martin-orion Dec 21, 2021
1026221
find Python (not libs)
95-martin-orion Dec 21, 2021
9989069
find all components
95-martin-orion Dec 21, 2021
2dc97e0
install python-devel
95-martin-orion Dec 21, 2021
08080f8
prioritize CUDA in PATH
95-martin-orion Dec 21, 2021
3095486
try version pin
95-martin-orion Dec 23, 2021
f2e0707
Merge branch 'master' into qsim-gha-gpu
95-martin-orion Jan 5, 2022
f9e88d3
Skip GPU tests on GPU-less machines
95-martin-orion Jan 5, 2022
168c9ee
Fix Windows test; potential Ubuntu flake
95-martin-orion Jan 6, 2022
c0a864b
Split out qsimcirq-gpu
95-martin-orion Jan 26, 2022
921d08f
Merge branch 'qsim-split' into qsim-gha-gpu
95-martin-orion Jan 26, 2022
e798db0
format
95-martin-orion Jan 26, 2022
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
23 changes: 19 additions & 4 deletions .github/workflows/testing_wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,47 @@ jobs:
arch: x86_64
build: "cp36* cp37* cp38* cp39*"
manylinux_image: manylinux2014
- os: ubuntu-20.04
name: manylinux2014-gpu
cibw:
arch: x86_64
build: "cp36*"
manylinux_image: manylinux2014
- os: windows-2019
name: win_amd64
architecture: x64
cibw:
build: "cp36-win_amd64 cp37-win_amd64 cp38-win_amd64 cp39-win_amd64"
env:
QSIMCIRQ_PROJECT: "${{ matrix.name == 'manylinux2014-gpu' && 'qsimcirq-gpu' || 'qsimcirq'}}"
CIBW_BUILD: "${{ matrix.cibw.build || '*' }}"
CIBW_ARCHS: "${{ matrix.cibw.arch || 'auto' }}"
CIBW_MANYLINUX_X86_64_IMAGE: "${{ matrix.cibw.manylinux_image }}"
CIBW_BEFORE_ALL_LINUX: "bash build_tools/cuda_install.sh && echo $PATH"
CIBW_ENVIRONMENT_LINUX: PATH=/usr/local/cuda-11/bin:$PATH LD_LIBRARY_PATH=/usr/local/cuda-11/lib64:$LD_LIBRARY_PATH
CIBW_ENVIRONMENT_PASS_LINUX: PATH LD_LIBRARY_PATH
CIBW_BEFORE_BUILD_MACOS: "brew install libomp"
CIBW_REPAIR_WHEEL_COMMAND_MACOS: ""
# due to package and module name conflict have to temporarily move it away to run tests
CIBW_BEFORE_TEST: "mv {package}/qsimcirq /tmp"
CIBW_TEST_COMMAND: "pytest {package}/qsimcirq_tests/qsimcirq_test.py && mv /tmp/qsimcirq {package}"
# prevent GPU tests (no GPU on GHA runners)
CIBW_TEST_COMMAND: "pytest {package}/qsimcirq_tests/qsimcirq_test.py -k \"not gpu\" && mv /tmp/qsimcirq {package}"
steps:
- uses: actions/checkout@v2

# Used to host cibuildwheel
- uses: actions/setup-python@v2

# Install NVCC on Ubuntu to include GPU in the wheel.
- name: cuda-toolkit
if: ${{ matrix.os == 'ubuntu-20.04' }}
uses: Jimver/[email protected]
with:
cuda: "11.5.1"

- name: Install cibuildwheel and twine
run: python -m pip install cibuildwheel==1.11.0

- name: Run C++ tests
run: bash build_tools/test_libs.sh

- name: Build wheels
run: python -m cibuildwheel --output-dir wheelhouse

Expand Down
7 changes: 3 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
cmake_minimum_required(VERSION 3.11)

execute_process(COMMAND which nvcc OUTPUT_VARIABLE has_nvcc)
if(has_nvcc STREQUAL "")
project(qsim)
else()
if(ENV{QSIMCIRQ_PROJECT} STREQUAL "qsimcirq-gpu")
project(qsim LANGUAGES CXX CUDA)
ADD_SUBDIRECTORY(pybind_interface/cuda)
if(DEFINED ENV{CUQUANTUM_DIR})
ADD_SUBDIRECTORY(pybind_interface/custatevec)
endif()
else()
project(qsim)
endif()

ADD_SUBDIRECTORY(pybind_interface/sse)
Expand Down
31 changes: 31 additions & 0 deletions build_tools/cuda_install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash
set -x

# install dependencies
kernel_version=$(uname -r)
yum clean all
yum install -y kernel
yum install -y kernel-devel-${kernel_version} kernel-headers-${kernel_version} pciutils

# install python and CUDA toolkit
# TODO: need to pin version

yum install -y yum-utils epel-release
yum install -y python3-devel.x86_64
yum-config-manager --add-repo https://developer.download.nvidia.com/compute/cuda/repos/rhel7/x86_64/cuda-rhel7.repo
yum clean all
yum -y install nvidia-driver-latest-dkms cuda
yum -y install cuda-drivers

# post-install actions

# commented to allow outer PATH-setting
# export PATH=/usr/local/cuda-11/bin:$PATH
# export LD_LIBRARY_PATH=/usr/local/cuda-11/lib64:$LD_LIBRARY_PATH

# works here, does not escape to build process
nvcc --version
which nvcc
nvidia-smi

set +x
2 changes: 1 addition & 1 deletion pybind_interface/cuda/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ if(NOT pybind11_POPULATED)
add_subdirectory(${pybind11_SOURCE_DIR} ${pybind11_BINARY_DIR})
endif()

find_package(PythonLibs 3.6 REQUIRED)
find_package(Python 3.6 REQUIRED COMPONENTS Interpreter Development)
find_package(CUDA REQUIRED)

include_directories(${PYTHON_INCLUDE_DIRS} ${pybind11_SOURCE_DIR}/include)
Expand Down
13 changes: 6 additions & 7 deletions pybind_interface/decide/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
cmake_minimum_required(VERSION 3.11)

execute_process(COMMAND which nvcc OUTPUT_VARIABLE has_nvcc)
if(has_nvcc STREQUAL "")
project(qsim)
else()
if(ENV{QSIMCIRQ_PROJECT} STREQUAL "qsimcirq-gpu")
project(qsim LANGUAGES CXX CUDA)
else()
project(qsim)
endif()

IF (WIN32)
Expand Down Expand Up @@ -32,9 +31,7 @@ if(NOT pybind11_POPULATED)
add_subdirectory(${pybind11_SOURCE_DIR} ${pybind11_BINARY_DIR})
endif()

if(has_nvcc STREQUAL "")
pybind11_add_module(qsim_decide decide.cpp)
else()
if(ENV{QSIMCIRQ_PROJECT} STREQUAL "qsimcirq-gpu")
find_package(PythonLibs 3.6 REQUIRED)
find_package(CUDA REQUIRED)

Expand All @@ -53,4 +50,6 @@ else()
SUFFIX "${PYTHON_MODULE_EXTENSION}"
)
set_source_files_properties(decide.cpp PROPERTIES LANGUAGE CUDA)
else()
pybind11_add_module(qsim_decide decide.cpp)
endif()
34 changes: 21 additions & 13 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
from distutils.version import LooseVersion


project_name = os.environ.get("QSIMCIRQ_PROJECT", "qsimcirq")


class CMakeExtension(Extension):
def __init__(self, name, sourcedir=""):
Extension.__init__(self, name, sources=[])
Expand Down Expand Up @@ -87,27 +90,32 @@ def build_extension(self, ext):
__version__ = ""
exec(open("qsimcirq/_version.py").read())

cmake_exts = [
CMakeExtension("qsimcirq/qsim_avx512"),
CMakeExtension("qsimcirq/qsim_avx2"),
CMakeExtension("qsimcirq/qsim_sse"),
CMakeExtension("qsimcirq/qsim_basic"),
CMakeExtension("qsimcirq/qsim_decide"),
]
if "gpu" in project_name:
cmake_exts += [
CMakeExtension("qsimcirq/qsim_cuda"),
CMakeExtension("qsimcirq/qsim_custatevec"),
]

setup(
name="qsimcirq",
name=project_name,
version=__version__,
url="https://github.com/quantumlib/qsim",
author="Vamsi Krishna Devabathini",
author_email="devabathini92@gmail.com",
python_requires=">=3.3.0",
author="The qsim Developers",
author_email="qsim-qsimh-dev@googlegroups.com",
python_requires=">=3.6.0",
install_requires=requirements,
license="Apache 2",
description=description,
long_description=long_description,
long_description_content_type="text/markdown",
ext_modules=[
CMakeExtension("qsimcirq/qsim_avx512"),
CMakeExtension("qsimcirq/qsim_avx2"),
CMakeExtension("qsimcirq/qsim_sse"),
CMakeExtension("qsimcirq/qsim_basic"),
CMakeExtension("qsimcirq/qsim_cuda"),
CMakeExtension("qsimcirq/qsim_custatevec"),
CMakeExtension("qsimcirq/qsim_decide"),
],
ext_modules=cmake_exts,
cmdclass=dict(build_ext=CMakeBuild),
zip_safe=False,
packages=["qsimcirq"],
Expand Down