Commit 4ad2b395 authored by rusty1s's avatar rusty1s
Browse files

build separate cpu and cuda images

parent 2ce0f235
...@@ -110,25 +110,26 @@ install: ...@@ -110,25 +110,26 @@ install:
- source activate test - source activate test
- conda install pytorch=${TORCH_VERSION} ${TOOLKIT} -c pytorch --yes - conda install pytorch=${TORCH_VERSION} ${TOOLKIT} -c pytorch --yes
- source script/torch.sh - source script/torch.sh
- pip install flake8 codecov - pip install flake8
- pip install codecov
- pip install scipy==1.4.1 - pip install scipy==1.4.1
- python setup.py install - python setup.py .[test]
script: script:
- flake8 . - flake8 .
- python setup.py test - python setup.py test
after_success: after_success:
- python setup.py bdist_wheel --dist-dir=dist/torch-${TORCH_VERSION} - python setup.py bdist_wheel --dist-dir=dist
- python script/rename_wheel.py ${IDX} - ls -lah dist/
- codecov - codecov
deploy: deploy:
provider: s3 provider: s3
edge: true
region: eu-central-1 region: eu-central-1
edge: true
access_key_id: ${S3_ACCESS_KEY} access_key_id: ${S3_ACCESS_KEY}
secret_access_key: ${S3_SECRET_ACCESS_KEY} secret_access_key: ${S3_SECRET_ACCESS_KEY}
bucket: pytorch-geometric.com bucket: pytorch-geometric.com
local_dir: dist/torch-${TORCH_VERSION} local_dir: dist
upload_dir: whl/torch-${TORCH_VERSION} upload_dir: whl/torch-${TORCH_VERSION}+${IDX}
acl: public_read acl: public_read
on: on:
all_branches: true all_branches: true
......
cmake_minimum_required(VERSION 3.0) cmake_minimum_required(VERSION 3.0)
project(torchcluster) project(torchcluster)
set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD 14)
set(TORCHCLUSTER_VERSION 1.5.8) set(TORCHCLUSTER_VERSION 1.5.9)
option(WITH_CUDA "Enable CUDA support" OFF) option(WITH_CUDA "Enable CUDA support" OFF)
......
...@@ -8,7 +8,11 @@ ...@@ -8,7 +8,11 @@
#endif #endif
#ifdef _WIN32 #ifdef _WIN32
PyMODINIT_FUNC PyInit__fps(void) { return NULL; } #ifdef WITH_CUDA
PyMODINIT_FUNC PyInit__fps_cuda(void) { return NULL; }
#else
PyMODINIT_FUNC PyInit__fps_cpu(void) { return NULL; }
#endif
#endif #endif
torch::Tensor fps(torch::Tensor src, torch::Tensor ptr, torch::Tensor ratio, torch::Tensor fps(torch::Tensor src, torch::Tensor ptr, torch::Tensor ratio,
......
...@@ -8,7 +8,11 @@ ...@@ -8,7 +8,11 @@
#endif #endif
#ifdef _WIN32 #ifdef _WIN32
PyMODINIT_FUNC PyInit__graclus(void) { return NULL; } #ifdef WITH_CUDA
PyMODINIT_FUNC PyInit__graclus_cuda(void) { return NULL; }
#else
PyMODINIT_FUNC PyInit__graclus_cpu(void) { return NULL; }
#endif
#endif #endif
torch::Tensor graclus(torch::Tensor rowptr, torch::Tensor col, torch::Tensor graclus(torch::Tensor rowptr, torch::Tensor col,
......
...@@ -8,7 +8,11 @@ ...@@ -8,7 +8,11 @@
#endif #endif
#ifdef _WIN32 #ifdef _WIN32
PyMODINIT_FUNC PyInit__grid(void) { return NULL; } #ifdef WITH_CUDA
PyMODINIT_FUNC PyInit__grid_cuda(void) { return NULL; }
#else
PyMODINIT_FUNC PyInit__grid_cpu(void) { return NULL; }
#endif
#endif #endif
torch::Tensor grid(torch::Tensor pos, torch::Tensor size, torch::Tensor grid(torch::Tensor pos, torch::Tensor size,
......
...@@ -8,7 +8,11 @@ ...@@ -8,7 +8,11 @@
#endif #endif
#ifdef _WIN32 #ifdef _WIN32
PyMODINIT_FUNC PyInit__knn(void) { return NULL; } #ifdef WITH_CUDA
PyMODINIT_FUNC PyInit__knn_cuda(void) { return NULL; }
#else
PyMODINIT_FUNC PyInit__knn_cpu(void) { return NULL; }
#endif
#endif #endif
torch::Tensor knn(torch::Tensor x, torch::Tensor y, torch::Tensor knn(torch::Tensor x, torch::Tensor y,
......
...@@ -6,7 +6,11 @@ ...@@ -6,7 +6,11 @@
#endif #endif
#ifdef _WIN32 #ifdef _WIN32
PyMODINIT_FUNC PyInit__nearest(void) { return NULL; } #ifdef WITH_CUDA
PyMODINIT_FUNC PyInit__nearest_cuda(void) { return NULL; }
#else
PyMODINIT_FUNC PyInit__nearest_cpu(void) { return NULL; }
#endif
#endif #endif
torch::Tensor nearest(torch::Tensor x, torch::Tensor y, torch::Tensor ptr_x, torch::Tensor nearest(torch::Tensor x, torch::Tensor y, torch::Tensor ptr_x,
......
...@@ -8,7 +8,11 @@ ...@@ -8,7 +8,11 @@
#endif #endif
#ifdef _WIN32 #ifdef _WIN32
PyMODINIT_FUNC PyInit__radius(void) { return NULL; } #ifdef WITH_CUDA
PyMODINIT_FUNC PyInit__radius_cuda(void) { return NULL; }
#else
PyMODINIT_FUNC PyInit__radius_cpu(void) { return NULL; }
#endif
#endif #endif
torch::Tensor radius(torch::Tensor x, torch::Tensor y, torch::Tensor radius(torch::Tensor x, torch::Tensor y,
......
...@@ -8,7 +8,11 @@ ...@@ -8,7 +8,11 @@
#endif #endif
#ifdef _WIN32 #ifdef _WIN32
PyMODINIT_FUNC PyInit__rw(void) { return NULL; } #ifdef WITH_CUDA
PyMODINIT_FUNC PyInit__rw_cuda(void) { return NULL; }
#else
PyMODINIT_FUNC PyInit__rw_cpu(void) { return NULL; }
#endif
#endif #endif
std::tuple<torch::Tensor, torch::Tensor> std::tuple<torch::Tensor, torch::Tensor>
......
...@@ -4,7 +4,11 @@ ...@@ -4,7 +4,11 @@
#include "cpu/sampler_cpu.h" #include "cpu/sampler_cpu.h"
#ifdef _WIN32 #ifdef _WIN32
PyMODINIT_FUNC PyInit__sampler(void) { return NULL; } #ifdef WITH_CUDA
PyMODINIT_FUNC PyInit__sampler_cuda(void) { return NULL; }
#else
PyMODINIT_FUNC PyInit__sampler_cpu(void) { return NULL; }
#endif
#endif #endif
torch::Tensor neighbor_sampler(torch::Tensor start, torch::Tensor rowptr, torch::Tensor neighbor_sampler(torch::Tensor start, torch::Tensor rowptr,
......
...@@ -6,7 +6,11 @@ ...@@ -6,7 +6,11 @@
#endif #endif
#ifdef _WIN32 #ifdef _WIN32
PyMODINIT_FUNC PyInit__version(void) { return NULL; } #ifdef WITH_CUDA
PyMODINIT_FUNC PyInit__version_cuda(void) { return NULL; }
#else
PyMODINIT_FUNC PyInit__version_cpu(void) { return NULL; }
#endif
#endif #endif
int64_t cuda_version() { int64_t cuda_version() {
......
...@@ -69,7 +69,7 @@ if [ "${TRAVIS_OS_NAME}" = "osx" ] && [ "$IDX" = "cpu" ]; then ...@@ -69,7 +69,7 @@ if [ "${TRAVIS_OS_NAME}" = "osx" ] && [ "$IDX" = "cpu" ]; then
fi fi
if [ "${IDX}" = "cpu" ]; then if [ "${IDX}" = "cpu" ]; then
export FORCE_CPU=1 export FORCE_ONLY_CPU=1
else else
export FORCE_CUDA=1 export FORCE_CUDA=1
fi fi
......
import sys
import os
import os.path as osp
import glob
import shutil
idx = sys.argv[1]
assert idx in ['cpu', 'cu92', 'cu101', 'cu102', 'cu110']
dist_dir = osp.join(osp.dirname(osp.abspath(__file__)), '..', 'dist')
wheels = glob.glob(osp.join('dist', '**', '*.whl'), recursive=True)
for wheel in wheels:
if idx in wheel:
continue
paths = wheel.split(osp.sep)
names = paths[-1].split('-')
name = '-'.join(names[:-4] + ['latest+' + idx] + names[-3:])
shutil.copyfile(wheel, osp.join(*paths[:-1], name))
name = '-'.join(names[:-4] + [names[-4] + '+' + idx] + names[-3:])
os.rename(wheel, osp.join(*paths[:-1], name))
...@@ -5,4 +5,4 @@ description-file = README.md ...@@ -5,4 +5,4 @@ description-file = README.md
test = pytest test = pytest
[tool:pytest] [tool:pytest]
addopts = --capture=no --cov addopts = --cov
import os import os
import os.path as osp
import sys import sys
import glob import glob
import os.path as osp
from itertools import product
from setuptools import setup, find_packages from setuptools import setup, find_packages
import torch import torch
...@@ -10,44 +11,46 @@ from torch.utils.cpp_extension import BuildExtension ...@@ -10,44 +11,46 @@ from torch.utils.cpp_extension import BuildExtension
from torch.utils.cpp_extension import CppExtension, CUDAExtension, CUDA_HOME from torch.utils.cpp_extension import CppExtension, CUDAExtension, CUDA_HOME
WITH_CUDA = torch.cuda.is_available() and CUDA_HOME is not None WITH_CUDA = torch.cuda.is_available() and CUDA_HOME is not None
suffices = ['cpu', 'cuda'] if WITH_CUDA else ['cpu']
if os.getenv('FORCE_CUDA', '0') == '1': if os.getenv('FORCE_CUDA', '0') == '1':
WITH_CUDA = True suffices = ['cuda', 'cpu']
if os.getenv('FORCE_CPU', '0') == '1': if os.getenv('FORCE_ONLY_CUDA', '0') == '1':
WITH_CUDA = False suffices = ['cuda']
if os.getenv('FORCE_ONLY_CPU', '0') == '1':
suffices = ['cpu']
BUILD_DOCS = os.getenv('BUILD_DOCS', '0') == '1' BUILD_DOCS = os.getenv('BUILD_DOCS', '0') == '1'
def get_extensions(): def get_extensions():
Extension = CppExtension extensions = []
define_macros = []
extra_compile_args = {'cxx': ['-O2']}
extra_link_args = ['-s']
info = parallel_info()
if 'parallel backend: OpenMP' in info and 'OpenMP not found' not in info:
extra_compile_args['cxx'] += ['-DAT_PARALLEL_OPENMP']
if sys.platform == 'win32':
extra_compile_args['cxx'] += ['/openmp']
else:
extra_compile_args['cxx'] += ['-fopenmp']
else:
print('Compiling without OpenMP...')
if WITH_CUDA:
Extension = CUDAExtension
define_macros += [('WITH_CUDA', None)]
nvcc_flags = os.getenv('NVCC_FLAGS', '')
nvcc_flags = [] if nvcc_flags == '' else nvcc_flags.split(' ')
nvcc_flags += ['-arch=sm_35', '--expt-relaxed-constexpr', '-O2']
extra_compile_args['nvcc'] = nvcc_flags
extensions_dir = osp.join(osp.dirname(osp.abspath(__file__)), 'csrc') extensions_dir = osp.join(osp.dirname(osp.abspath(__file__)), 'csrc')
main_files = glob.glob(osp.join(extensions_dir, '*.cpp')) main_files = glob.glob(osp.join(extensions_dir, '*.cpp'))
extensions = []
for main in main_files:
name = main.split(os.sep)[-1][:-4]
for main, suffix in product(main_files, suffices):
define_macros = []
extra_compile_args = {'cxx': ['-O2']}
extra_link_args = ['-s']
info = parallel_info()
if 'backend: OpenMP' in info and 'OpenMP not found' not in info:
extra_compile_args['cxx'] += ['-DAT_PARALLEL_OPENMP']
if sys.platform == 'win32':
extra_compile_args['cxx'] += ['/openmp']
else:
extra_compile_args['cxx'] += ['-fopenmp']
else:
print('Compiling without OpenMP...')
if suffix == 'cuda':
define_macros += [('WITH_CUDA', None)]
nvcc_flags = os.getenv('NVCC_FLAGS', '')
nvcc_flags = [] if nvcc_flags == '' else nvcc_flags.split(' ')
nvcc_flags += ['-arch=sm_35', '--expt-relaxed-constexpr', '-O2']
extra_compile_args['nvcc'] = nvcc_flags
name = main.split(os.sep)[-1][:-4]
sources = [main] sources = [main]
path = osp.join(extensions_dir, 'cpu', f'{name}_cpu.cpp') path = osp.join(extensions_dir, 'cpu', f'{name}_cpu.cpp')
...@@ -58,8 +61,9 @@ def get_extensions(): ...@@ -58,8 +61,9 @@ def get_extensions():
if WITH_CUDA and osp.exists(path): if WITH_CUDA and osp.exists(path):
sources += [path] sources += [path]
Extension = CppExtension if suffix == 'cpu' else CUDAExtension
extension = Extension( extension = Extension(
'torch_cluster._' + name, f'torch_cluster._{name}_{suffix}',
sources, sources,
include_dirs=[extensions_dir], include_dirs=[extensions_dir],
define_macros=define_macros, define_macros=define_macros,
...@@ -77,7 +81,7 @@ tests_require = ['pytest', 'pytest-cov', 'scipy'] ...@@ -77,7 +81,7 @@ tests_require = ['pytest', 'pytest-cov', 'scipy']
setup( setup(
name='torch_cluster', name='torch_cluster',
version='1.5.8', version='1.5.9',
author='Matthias Fey', author='Matthias Fey',
author_email='matthias.fey@tu-dortmund.de', author_email='matthias.fey@tu-dortmund.de',
url='https://github.com/rusty1s/pytorch_cluster', url='https://github.com/rusty1s/pytorch_cluster',
...@@ -97,8 +101,7 @@ setup( ...@@ -97,8 +101,7 @@ setup(
extras_require={'test': tests_require}, extras_require={'test': tests_require},
ext_modules=get_extensions() if not BUILD_DOCS else [], ext_modules=get_extensions() if not BUILD_DOCS else [],
cmdclass={ cmdclass={
'build_ext': 'build_ext': BuildExtension.with_options(no_python_abi_suffix=True)
BuildExtension.with_options(no_python_abi_suffix=True, use_ninja=False)
}, },
packages=find_packages(), packages=find_packages(),
) )
...@@ -3,16 +3,18 @@ import os.path as osp ...@@ -3,16 +3,18 @@ import os.path as osp
import torch import torch
__version__ = '1.5.8' __version__ = '1.5.9'
suffix = 'cuda' if torch.cuda.is_available() else 'cpu'
for library in [ for library in [
'_version', '_grid', '_graclus', '_fps', '_rw', '_sampler', '_nearest', '_version', '_grid', '_graclus', '_fps', '_rw', '_sampler', '_nearest',
'_knn', '_radius' '_knn', '_radius'
]: ]:
torch.ops.load_library(importlib.machinery.PathFinder().find_spec( torch.ops.load_library(importlib.machinery.PathFinder().find_spec(
library, [osp.dirname(__file__)]).origin) f'{library}_{suffix}', [osp.dirname(__file__)]).origin)
if torch.version.cuda is not None: # pragma: no cover if torch.cuda.is_available(): # pragma: no cover
cuda_version = torch.ops.torch_cluster.cuda_version() cuda_version = torch.ops.torch_cluster.cuda_version()
if cuda_version == -1: if cuda_version == -1:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment