setup.py 3.67 KB
Newer Older
facebook-github-bot's avatar
facebook-github-bot committed
1
2
3
4
5
#!/usr/bin/env python
# Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.

import glob
import os
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
6
import runpy
Christoph Lassner's avatar
Christoph Lassner committed
7
import warnings
8

facebook-github-bot's avatar
facebook-github-bot committed
9
import torch
10
from setuptools import find_packages, setup
facebook-github-bot's avatar
facebook-github-bot committed
11
12
13
14
15
16
from torch.utils.cpp_extension import CUDA_HOME, CppExtension, CUDAExtension


def get_extensions():
    this_dir = os.path.dirname(os.path.abspath(__file__))
    extensions_dir = os.path.join(this_dir, "pytorch3d", "csrc")
17
18
    sources = glob.glob(os.path.join(extensions_dir, "**", "*.cpp"), recursive=True)
    source_cuda = glob.glob(os.path.join(extensions_dir, "**", "*.cu"), recursive=True)
facebook-github-bot's avatar
facebook-github-bot committed
19
20
    extension = CppExtension

21
    extra_compile_args = {"cxx": ["-std=c++14"]}
facebook-github-bot's avatar
facebook-github-bot committed
22
23
    define_macros = []

24
25
    force_cuda = os.getenv("FORCE_CUDA", "0") == "1"
    if (torch.cuda.is_available() and CUDA_HOME is not None) or force_cuda:
facebook-github-bot's avatar
facebook-github-bot committed
26
27
28
        extension = CUDAExtension
        sources += source_cuda
        define_macros += [("WITH_CUDA", None)]
29
        cub_home = os.environ.get("CUB_HOME", None)
30
        nvcc_args = [
31
            "-std=c++14",
facebook-github-bot's avatar
facebook-github-bot committed
32
33
34
35
36
            "-DCUDA_HAS_FP16=1",
            "-D__CUDA_NO_HALF_OPERATORS__",
            "-D__CUDA_NO_HALF_CONVERSIONS__",
            "-D__CUDA_NO_HALF2_OPERATORS__",
        ]
Christoph Lassner's avatar
Christoph Lassner committed
37
38
39
40
41
42
43
44
45
46
47
48
        if cub_home is None:
            warnings.warn(
                "The environment variable `CUB_HOME` was not found. "
                "NVIDIA CUB is required for compilation and can be downloaded "
                "from `https://github.com/NVIDIA/cub/releases`. You can unpack "
                "it to a location of your choice and set the environment variable "
                "`CUB_HOME` to the folder containing the `CMakeListst.txt` file."
            )
        else:
            nvcc_args.insert(
                0, "-I%s" % (os.path.realpath(cub_home).replace("\\ ", " "))
            )
49
50
51
        nvcc_flags_env = os.getenv("NVCC_FLAGS", "")
        if nvcc_flags_env != "":
            nvcc_args.extend(nvcc_flags_env.split(" "))
facebook-github-bot's avatar
facebook-github-bot committed
52
53
54
55

        # It's better if pytorch can do this by default ..
        CC = os.environ.get("CC", None)
        if CC is not None:
56
57
58
59
60
61
62
            CC_arg = "-ccbin={}".format(CC)
            if CC_arg not in nvcc_args:
                if any(arg.startswith("-ccbin") for arg in nvcc_args):
                    raise ValueError("Inconsistent ccbins")
                nvcc_args.append(CC_arg)

        extra_compile_args["nvcc"] = nvcc_args
facebook-github-bot's avatar
facebook-github-bot committed
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80

    sources = [os.path.join(extensions_dir, s) for s in sources]

    include_dirs = [extensions_dir]

    ext_modules = [
        extension(
            "pytorch3d._C",
            sources,
            include_dirs=include_dirs,
            define_macros=define_macros,
            extra_compile_args=extra_compile_args,
        )
    ]

    return ext_modules


81
# Retrieve __version__ from the package.
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
82
__version__ = runpy.run_path("pytorch3d/__init__.py")["__version__"]
83

84
85
86
87
88
89
90
91
92
93
94
95

if os.getenv("PYTORCH3D_NO_NINJA", "0") == "1":

    class BuildExtension(torch.utils.cpp_extension.BuildExtension):
        def __init__(self, *args, **kwargs):
            super().__init__(use_ninja=False, *args, **kwargs)


else:
    BuildExtension = torch.utils.cpp_extension.BuildExtension


facebook-github-bot's avatar
facebook-github-bot committed
96
97
setup(
    name="pytorch3d",
98
    version=__version__,
facebook-github-bot's avatar
facebook-github-bot committed
99
100
    author="FAIR",
    url="https://github.com/facebookresearch/pytorch3d",
101
    description="PyTorch3D is FAIR's library of reusable components "
facebook-github-bot's avatar
facebook-github-bot committed
102
103
104
105
106
107
108
109
    "for deep Learning with 3D data.",
    packages=find_packages(exclude=("configs", "tests")),
    install_requires=["torchvision>=0.4", "fvcore"],
    extras_require={
        "all": ["matplotlib", "tqdm>4.29.0", "imageio", "ipywidgets"],
        "dev": ["flake8", "isort", "black==19.3b0"],
    },
    ext_modules=get_extensions(),
110
    cmdclass={"build_ext": BuildExtension},
facebook-github-bot's avatar
facebook-github-bot committed
111
)