setup.py 2.73 KB
Newer Older
Benjamin Thomas Graham's avatar
Benjamin Thomas Graham committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# Copyright 2016-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.

import os
import torch
from torch.utils.ffi import create_extension
this_dir = os.path.dirname(os.path.realpath(__file__))
torch_dir = os.path.dirname(torch.__file__)

print('Building SCN module')
if torch.cuda.is_available():
Benjamin Thomas Graham's avatar
tidy  
Benjamin Thomas Graham committed
15
16
    s=('cd sparseconvnet/SCN; nvcc init.cu -c -o init.cu.o -ccbin /usr/bin/cc'
        + ' -m64 --std c++11 -Xcompiler \"-fopenmp -fPIC -O3\" '
Benjamin Thomas Graham's avatar
Benjamin Thomas Graham committed
17
18
19
20
21
22
23
24
        + '-gencode arch=compute_62,code=sm_62 '
        + '-gencode arch=compute_61,code=sm_61 '
        + '-gencode arch=compute_60,code=sm_60 '
        + '-gencode arch=compute_52,code=sm_52 '
        + '-gencode arch=compute_50,code=sm_50 '
        + '-gencode arch=compute_30,code=sm_30 '
        + '-DNVCC '
        + '-I/usr/local/cuda/include '
Benjamin Thomas Graham's avatar
Benjamin Thomas Graham committed
25
        + '-I' + '/'.join(torch_dir.split('/')[:-4]) + '/include '
Benjamin Thomas Graham's avatar
Benjamin Thomas Graham committed
26
27
28
29
        + '-I' + torch_dir + '/lib/include '
        + '-I' + torch_dir + '/lib/include/TH '
        + '-I' + torch_dir + '/lib/include/THC '
        + '-I.')
Benjamin Thomas Graham's avatar
tidy  
Benjamin Thomas Graham committed
30
    r = os.system(s)
Benjamin Thomas Graham's avatar
Benjamin Thomas Graham committed
31
32
33
34
35
36
37
    assert r == 0
    ffi = create_extension(
        'sparseconvnet.SCN',
        headers=[
            'sparseconvnet/SCN/header_cpu.h',
            'sparseconvnet/SCN/header_gpu.h'],
        sources=[],
38
        include_dirs=[os.path.expandvars('$CUDA_HOME') + '/include'],
Benjamin Thomas Graham's avatar
Benjamin Thomas Graham committed
39
40
41
42
        extra_objects=[
            this_dir +
            '/sparseconvnet/SCN/init.cu.o'],
        relative_to=__file__,
43
        extra_compile_args=["-std=c99"],
Benjamin Thomas Graham's avatar
Benjamin Thomas Graham committed
44
45
46
        with_cuda=True)
else:
    r = os.system(
Benjamin Thomas Graham's avatar
Benjamin Thomas Graham committed
47
48
49
50
51
        'cd sparseconvnet/SCN; g++ -fopenmp -std=c++11 -O3 -fPIC -c init.cpp -o init.cpp.o '
        + '-I' + '/'.join(torch_dir.split('/')[:-4]) + '/include '
        + '-I' + torch_dir + '/lib/include '
        + '-I' + torch_dir + '/lib/include/TH '
        + '-I.')
Benjamin Thomas Graham's avatar
Benjamin Thomas Graham committed
52
53
54
55
56
57
58
59
60
    assert r == 0
    ffi = create_extension(
        'sparseconvnet.SCN',
        headers=['sparseconvnet/SCN/header_cpu.h'],
        sources=[],
        extra_objects=[
            this_dir +
            '/sparseconvnet/SCN/init.cpp.o'],
        relative_to=__file__,
61
        extra_compile_args=["-std=c99"],
Benjamin Thomas Graham's avatar
Benjamin Thomas Graham committed
62
63
64
65
66
67
68
        with_cuda=False)

ffi.build()

from setuptools import setup, find_packages
setup(
    name='sparseconvnet',
Ed Ng's avatar
Ed Ng committed
69
    version='0.1.1',
Benjamin Thomas Graham's avatar
Benjamin Thomas Graham committed
70
71
72
73
    description='Submanifold (Spatially) Sparse Convolutional Networks https://arxiv.org/abs/1706.01307',
    author='Facebook AI Research',
    author_email='benjamingraham@fb.com',
    url='https://github.com/facebookresearch/SparseConvNet',
Benjamin Thomas Graham's avatar
Benjamin Thomas Graham committed
74
75
76
    package_data={
        'sparseconvnet': ['SCN/_SCN.so'],
    },
Benjamin Thomas Graham's avatar
Benjamin Thomas Graham committed
77
    packages=find_packages(),
Benjamin Thomas Graham's avatar
Benjamin Thomas Graham committed
78
79
    # Since the package includes a shared object, this is not zip-safe.
    zip_safe=False,
Benjamin Thomas Graham's avatar
Benjamin Thomas Graham committed
80
)