Skip to content

Add C++ ops to torchvision #826

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

Merged
merged 47 commits into from
May 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
3582bd5
Initial layout for layers with cpp extensions
fmassa Apr 20, 2018
5a31ba6
Move files around
fmassa Apr 20, 2018
5a1bf0a
Fix import after move
fmassa Apr 20, 2018
54b1a83
Add support for multiple types to ROIAlign
fmassa Apr 25, 2018
62ff237
Different organization
fmassa Apr 25, 2018
111c061
Cleanups
fmassa Apr 25, 2018
703bdc8
Reduce memory requirements for backwards
fmassa Apr 25, 2018
92f8b0b
Replace runtime_error by AT_ERROR
fmassa Apr 25, 2018
b774857
Add nms test
fmassa Apr 25, 2018
6dc43f4
Add support for compilation using CPP extensions
fmassa Apr 26, 2018
1bfa146
Change folder structure
fmassa Apr 26, 2018
d9cca24
Add ROIPool cuda
fmassa Apr 26, 2018
c109881
Cleanups
fmassa Apr 26, 2018
89e586f
Add roi_pool.py
fmassa Apr 27, 2018
1ef5730
Fix lint
fmassa Apr 27, 2018
fa34749
Add initial structures folder for bounding boxes
fmassa May 2, 2018
366f493
Assertion macros compatible with pytorch master (#540)
ahirner Jul 3, 2018
563604c
Support for ROI Pooling (#592)
varunagrawal Sep 3, 2018
5092606
remove .type().tensor() calls in favor of the new approach to tensor …
varunagrawal Oct 13, 2018
52d938f
Consistent naming for rois variable (#627)
varunagrawal Oct 13, 2018
2ca772d
ROIPool: Support for all datatypes (#632)
varunagrawal Oct 18, 2018
e318b63
Fix rebase problem
fmassa Mar 31, 2019
a9e0365
Remove structures folder
fmassa Mar 31, 2019
97c7474
Improve cleanup and bugfix in test_layers
fmassa Mar 31, 2019
0187587
Update C++ headers
fmassa Mar 31, 2019
710bbfc
Add CUDAGuard to cu files
fmassa Mar 31, 2019
7368771
Add more checks to layers
fmassa Mar 31, 2019
563cafb
Add CUDA NMS and tests
fmassa Mar 31, 2019
e0ed266
Add multi-type support for NMS CUDA
fmassa Mar 31, 2019
ed3cd79
Avoid using THCudaMalloc
fmassa Mar 31, 2019
249082c
Add clang-format and reformat c++ code
fmassa Apr 1, 2019
175d754
Remove THC includes
fmassa Apr 1, 2019
4e1f1e4
Rename layers to ops
fmassa Apr 1, 2019
1df206d
Add documentation and rename functions
fmassa Apr 1, 2019
f020ede
Improve the documentation a bit
fmassa Apr 1, 2019
1d4dd1a
Fix some lint errors
fmassa Apr 1, 2019
cad6bb5
Fix remaining lint inssues
fmassa Apr 1, 2019
5767c80
Area computation doesn't add +1 in NMS
fmassa Apr 1, 2019
a0bf9e4
Update CI to use PyTorch nightly
fmassa Apr 1, 2019
89d3de9
Make NMS return indices sorted according to the score
fmassa Apr 24, 2019
ee65c9c
Address reviewer comments
fmassa Apr 24, 2019
f4a9536
Lint fixes
fmassa Apr 24, 2019
4ee79d6
Improve doc for roi_align and roi_pool
fmassa Apr 24, 2019
bf5c1d1
move to xenial
soumith Apr 25, 2019
dfe8ec1
Fix bug pointed by @lopuhin
fmassa Apr 26, 2019
4bdc54c
Fix RoIPool reference implementation in Python 2
fmassa Apr 26, 2019
06fd8ae
Remove change in .travis
fmassa May 7, 2019
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
88 changes: 88 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
---
AccessModifierOffset: -1
AlignAfterOpenBracket: AlwaysBreak
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlinesLeft: true
AlignOperands: false
AlignTrailingComments: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: true
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: false
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
#CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ForEachMacros: [ FOR_EACH_RANGE, FOR_EACH, ]
IncludeCategories:
- Regex: '^<.*\.h(pp)?>'
Priority: 1
- Regex: '^<.*'
Priority: 2
- Regex: '.*'
Priority: 3
IndentCaseLabels: true
IndentWidth: 2
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: false
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 2000000
PointerAlignment: Left
ReflowComments: true
SortIncludes: true
SpaceAfterCStyleCast: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 8
UseTab: Never
...
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,19 @@ dist/
torchvision.egg-info/
torchvision/version.py
*/**/__pycache__
*/__pycache__
*/*.pyc
*/**/*.pyc
*/**/**/*.pyc
*/**/*~
*~
docs/build
.coverage
htmlcov
.*.swp
*.so*
*.dylib*
*/*.so*
*/*.dylib*
*.swp
*.swo
57 changes: 57 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
from setuptools import setup, find_packages
from pkg_resources import get_distribution, DistributionNotFound
import subprocess
import distutils.command.clean
import glob
import shutil

import torch
from torch.utils.cpp_extension import CppExtension, CUDAExtension, CUDA_HOME


def read(*names, **kwargs):
Expand Down Expand Up @@ -69,6 +75,55 @@ def write_version_file():
requirements.append(pillow_req + pillow_ver)


def get_extensions():
this_dir = os.path.dirname(os.path.abspath(__file__))
extensions_dir = os.path.join(this_dir, 'torchvision', 'csrc')

main_file = glob.glob(os.path.join(extensions_dir, '*.cpp'))
source_cpu = glob.glob(os.path.join(extensions_dir, 'cpu', '*.cpp'))
source_cuda = glob.glob(os.path.join(extensions_dir, 'cuda', '*.cu'))

sources = main_file + source_cpu
extension = CppExtension

define_macros = []

if torch.cuda.is_available() and CUDA_HOME is not None:
extension = CUDAExtension
sources += source_cuda
define_macros += [('WITH_CUDA', None)]

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

include_dirs = [extensions_dir]

ext_modules = [
extension(
'torchvision._C',
sources,
include_dirs=include_dirs,
define_macros=define_macros,
)
]

return ext_modules


class clean(distutils.command.clean.clean):
def run(self):
with open('.gitignore', 'r') as f:
ignores = f.read()
for wildcard in filter(None, ignores.split('\n')):
for filename in glob.glob(wildcard):
try:
os.remove(filename)
except OSError:
shutil.rmtree(filename, ignore_errors=True)

# It's an old-style class in Python 2.7...
distutils.command.clean.clean.run(self)


setup(
# Metadata
name=package_name,
Expand All @@ -88,4 +143,6 @@ def write_version_file():
extras_require={
"scipy": ["scipy"],
},
ext_modules=get_extensions(),
cmdclass={'build_ext': torch.utils.cpp_extension.BuildExtension, 'clean': clean}
)
Loading