forked from mapillary/inplace_abn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
77 lines (66 loc) · 2.22 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# Copyright (c) Facebook, Inc. and its affiliates.
from os import path, walk, getenv
import setuptools
import torch
from torch.utils.cpp_extension import BuildExtension, CUDAExtension, CppExtension
def find_sources(root_dir, with_cuda=True):
extensions = [".cpp", ".cu"] if with_cuda else [".cpp"]
sources = []
for subdir, _, files in walk(root_dir):
for filename in files:
_, ext = path.splitext(filename)
if ext in extensions:
sources.append(path.join(subdir, filename))
return sources
here = path.abspath(path.dirname(__file__))
with open(path.join(here, "README.md"), encoding="utf-8") as f:
long_description = f.read()
if torch.has_cuda or getenv("IABN_FORCE_CUDA") == "1":
ext_modules = [
CUDAExtension(
name="inplace_abn._backend",
sources=find_sources("src"),
extra_compile_args={"cxx": ["-O3"], "nvcc": []},
include_dirs=[path.join(here, "include")],
define_macros=[("WITH_CUDA", 1)],
)
]
else:
ext_modules = [
CppExtension(
name="inplace_abn._backend",
sources=find_sources("src", False),
extra_compile_args=["-O3"],
include_dirs=[path.join(here, "include")],
)
]
setuptools.setup(
# Meta-data
name="inplace-abn",
author="Lorenzo Porzi",
author_email="[email protected]",
description="In-Place Activate BatchNorm for Pytorch",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/mapillary/inplace_abn",
classifiers=[
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
],
# Versioning
use_scm_version={
"root": ".",
"relative_to": __file__,
"write_to": "inplace_abn/_version.py",
},
# Requirements
setup_requires=["setuptools_scm"],
python_requires=">=3, <4",
# Package description
packages=["inplace_abn"],
ext_modules=ext_modules,
cmdclass={"build_ext": BuildExtension},
)