Go to the documentation of this file.00001
00002
00003 import numpy as np
00004 import os
00005
00006 PATH = os.environ.get('PATH') + ';C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\bin'
00007 from distutils.spawn import spawn, find_executable
00008 from setuptools import setup, find_packages, Extension
00009 from setuptools.command.build_ext import build_ext
00010 import sys
00011
00012
00013
00014 nvcc_compile_args = ['-O', '--ptxas-options=-v', '-arch=compute_35', '-code=sm_35,sm_52,sm_61', '-c', '--compiler-options=-fPIC']
00015 nvcc_compile_args = os.environ.get('NVCCFLAGS', '').split() + nvcc_compile_args
00016 cuda_libs = ['cublas']
00017 nvcc_bin = 'nvcc.exe'
00018 lib_dir = 'lib/x64'
00019
00020
00021 import distutils.msvc9compiler
00022 distutils.msvc9compiler.VERSION = 14.0
00023
00024
00025 try:
00026 numpy_include = np.get_include()
00027 except AttributeError:
00028 numpy_include = np.get_numpy_include()
00029
00030
00031 cudamat_ext = Extension('gpu_nms',
00032 sources=[
00033 'gpu_nms.cu'
00034 ],
00035 language='c++',
00036 libraries=cuda_libs,
00037 extra_compile_args=nvcc_compile_args,
00038 include_dirs = [numpy_include, 'C:\\Programming\\CUDA\\v8.0\\include'])
00039
00040
00041 class CUDA_build_ext(build_ext):
00042 """
00043 Custom build_ext command that compiles CUDA files.
00044 Note that all extension source files will be processed with this compiler.
00045 """
00046 def build_extensions(self):
00047 self.compiler.src_extensions.append('.cu')
00048 self.compiler.set_executable('compiler_so', 'nvcc')
00049 self.compiler.set_executable('linker_so', 'nvcc --shared')
00050 if hasattr(self.compiler, '_c_extensions'):
00051 self.compiler._c_extensions.append('.cu')
00052 self.compiler.spawn = self.spawn
00053 build_ext.build_extensions(self)
00054
00055 def spawn(self, cmd, search_path=1, verbose=0, dry_run=0):
00056 """
00057 Perform any CUDA specific customizations before actually launching
00058 compile/link etc. commands.
00059 """
00060 if (sys.platform == 'darwin' and len(cmd) >= 2 and cmd[0] == 'nvcc' and
00061 cmd[1] == '--shared' and cmd.count('-arch') > 0):
00062
00063
00064
00065 while True:
00066 try:
00067 index = cmd.index('-arch')
00068 del cmd[index:index+2]
00069 except ValueError:
00070 break
00071 elif self.compiler.compiler_type == 'msvc':
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081 cmd[:1] = ['nvcc', '--compiler-bindir',
00082 os.path.dirname(find_executable("cl.exe", PATH))
00083 or cmd[0]]
00084
00085 for idx, c in enumerate(cmd):
00086
00087
00088
00089 if c == '/c': cmd[idx] = '-c'
00090
00091 elif c == '/DLL': cmd[idx] = '--shared'
00092
00093 elif '-fPIC' in c: del cmd[idx]
00094
00095 elif c.startswith('/Tc'): cmd[idx] = c[3:]
00096
00097 elif c.startswith('/Fo'): cmd[idx:idx+1] = ['-o', c[3:]]
00098
00099 elif c.startswith('/LIBPATH:'): cmd[idx] = '-L' + c[9:]
00100
00101 elif c.startswith('/OUT:'): cmd[idx:idx+1] = ['-o', c[5:]]
00102
00103 elif c.startswith('/EXPORT:'): del cmd[idx]
00104
00105 elif c == 'cublas.lib': cmd[idx] = '-lcublas'
00106
00107
00108 if '--shared' in cmd:
00109 pass_on = '--linker-options='
00110
00111 cmd.append('/NODEFAULTLIB:libcmt.lib')
00112 else:
00113 pass_on = '--compiler-options='
00114 cmd = ([c for c in cmd if c[0] != '/'] +
00115 [pass_on + ','.join(c for c in cmd if c[0] == '/')])
00116
00117
00118
00119
00120
00121
00122 spawn(cmd, search_path, verbose, dry_run)
00123
00124 setup(name="py_fast_rcnn_gpu",
00125 description="Performs linear algebra computation on the GPU via CUDA",
00126 ext_modules=[cudamat_ext],
00127 cmdclass={'build_ext': CUDA_build_ext},
00128 )