setup_linux.py
Go to the documentation of this file.
00001 # --------------------------------------------------------
00002 # Deformable Convolutional Networks
00003 # Copyright (c) 2016 by Contributors
00004 # Copyright (c) 2017 Microsoft
00005 # Licensed under The Apache-2.0 License [see LICENSE for details]
00006 # Modified from py-faster-rcnn (https://github.com/rbgirshick/py-faster-rcnn)
00007 # --------------------------------------------------------
00008 
00009 
00010 import os
00011 from os.path import join as pjoin
00012 from setuptools import setup
00013 from distutils.extension import Extension
00014 from Cython.Distutils import build_ext
00015 import numpy as np
00016 
00017 # Obtain the numpy include directory.  This logic works across numpy versions.
00018 try:
00019     numpy_include = np.get_include()
00020 except AttributeError:
00021     numpy_include = np.get_numpy_include()
00022 
00023 
00024 def customize_compiler_for_nvcc(self):
00025     """inject deep into distutils to customize how the dispatch
00026     to gcc/nvcc works.
00027     If you subclass UnixCCompiler, it's not trivial to get your subclass
00028     injected in, and still have the right customizations (i.e.
00029     distutils.sysconfig.customize_compiler) run on it. So instead of going
00030     the OO route, I have this. Note, it's kindof like a wierd functional
00031     subclassing going on."""
00032 
00033     # tell the compiler it can processes .cu
00034     self.src_extensions.append('.cu')
00035 
00036     # save references to the default compiler_so and _comple methods
00037     default_compiler_so = self.compiler_so
00038     super = self._compile
00039 
00040     # now redefine the _compile method. This gets executed for each
00041     # object but distutils doesn't have the ability to change compilers
00042     # based on source extension: we add it.
00043     def _compile(obj, src, ext, cc_args, extra_postargs, pp_opts):
00044         if os.path.splitext(src)[1] == '.cu':
00045             # use the cuda for .cu files
00046             self.set_executable('compiler_so', CUDA['nvcc'])
00047             # use only a subset of the extra_postargs, which are 1-1 translated
00048             # from the extra_compile_args in the Extension class
00049             postargs = extra_postargs['nvcc']
00050         else:
00051             postargs = extra_postargs['gcc']
00052 
00053         super(obj, src, ext, cc_args, postargs, pp_opts)
00054         # reset the default compiler_so, which we might have changed for cuda
00055         self.compiler_so = default_compiler_so
00056 
00057     # inject our redefined _compile method into the class
00058     self._compile = _compile
00059 
00060 
00061 # run the customize_compiler
00062 class custom_build_ext(build_ext):
00063     def build_extensions(self):
00064         customize_compiler_for_nvcc(self.compiler)
00065         build_ext.build_extensions(self)
00066 
00067 
00068 ext_modules = [
00069     Extension(
00070         "bbox",
00071         ["bbox.pyx"],
00072         extra_compile_args={'gcc': ["-Wno-cpp", "-Wno-unused-function"]},
00073         include_dirs=[numpy_include]
00074     ),
00075 ]
00076 
00077 setup(
00078     name='bbox_cython',
00079     ext_modules=ext_modules,
00080     # inject our custom trigger
00081     cmdclass={'build_ext': custom_build_ext},
00082 )


rail_object_detector
Author(s):
autogenerated on Sat Jun 8 2019 20:26:30