def get_extensions(): extra_compile_args = {'cxx': ['-O3']} define_macros = [] include_dirs = [] sources = glob.glob('kaolin/csrc/**/*.cpp', recursive=True) # FORCE_CUDA is for cross-compilation in docker build if torch.cuda.is_available() or os.getenv('FORCE_CUDA', '0') == '1': with_cuda = True define_macros += [("WITH_CUDA", None), ("THRUST_IGNORE_CUB_VERSION_CHECK", None)] sources += glob.glob('kaolin/csrc/**/*.cu', recursive=True) extension = CUDAExtension extra_compile_args.update({ 'nvcc': ['-O3', '-DWITH_CUDA', '-DTHRUST_IGNORE_CUB_VERSION_CHECK'] }) include_dirs = get_include_dirs() else: extension = CppExtension with_cuda = False extensions = [] extensions.append( extension(name='kaolin._C', sources=sources, define_macros=define_macros, extra_compile_args=extra_compile_args, include_dirs=include_dirs)) # use cudart_static instead for extension in extensions: extension.libraries = [ 'cudart_static' if x == 'cudart' else x for x in extension.libraries ] use_cython = True ext = '.pyx' if use_cython else '.cpp' cython_extensions = [ CppExtension( 'kaolin.ops.mesh.triangle_hash', sources=[f'kaolin/cython/ops/mesh/triangle_hash{ext}'], include_dirs=[numpy.get_include()], ), CppExtension( 'kaolin.ops.conversions.mise', sources=[f'kaolin/cython/ops/conversions/mise{ext}'], ), ] if use_cython: from Cython.Build import cythonize from Cython.Compiler import Options compiler_directives = Options.get_directive_defaults() compiler_directives["emit_code_comments"] = False cython_extensions = cythonize(cython_extensions, language='c++', compiler_directives=compiler_directives) return extensions + cython_extensions
def get_extensions(): use_cython = os.getenv('USE_CYTHON') ext = '.pyx' if use_cython else '.cpp' cython_extensions = [ CppExtension( 'kaolin.triangle_hash', sources=[f'kaolin/cython/triangle_hash{ext}'], ), CppExtension( 'kaolin.triangle_hash', sources=[f'kaolin/cython/triangle_hash{ext}'], ), CppExtension( 'kaolin.mise', sources=[f'kaolin/cython/mise{ext}'], ), CppExtension( 'kaolin.mcubes', sources=[ f'kaolin/cython/mcubes{ext}', 'kaolin/cython/pywrapper.cpp', 'kaolin/cython/marchingcubes.cpp' ], extra_compile_args=['-std=c++11'], ), CppExtension( 'kaolin.nnsearch', sources=[f'kaolin/cython/nnsearch{ext}'], ), ] # If building with readthedocs, don't compile CUDA extensions if os.getenv('READTHEDOCS') != 'True': cuda_extensions = [ KaolinCUDAExtension('kaolin.cuda.load_textures', [ 'kaolin/cuda/load_textures_cuda.cpp', 'kaolin/cuda/load_textures_cuda_kernel.cu', ]), KaolinCUDAExtension('kaolin.cuda.sided_distance', [ 'kaolin/cuda/sided_distance.cpp', 'kaolin/cuda/sided_distance_cuda.cu', ]), KaolinCUDAExtension('kaolin.cuda.furthest_point_sampling', [ 'kaolin/cuda/furthest_point_sampling.cpp', 'kaolin/cuda/furthest_point_sampling_cuda.cu', ]), KaolinCUDAExtension('kaolin.cuda.ball_query', [ 'kaolin/cuda/ball_query.cpp', 'kaolin/cuda/ball_query_cuda.cu', ]), KaolinCUDAExtension('kaolin.cuda.three_nn', [ 'kaolin/cuda/three_nn.cpp', 'kaolin/cuda/three_nn_cuda.cu', ]), KaolinCUDAExtension('kaolin.cuda.tri_distance', [ 'kaolin/cuda/triangle_distance.cpp', 'kaolin/cuda/triangle_distance_cuda.cu', ]), KaolinCUDAExtension('kaolin.cuda.mesh_intersection', [ 'kaolin/cuda/mesh_intersection.cpp', 'kaolin/cuda/mesh_intersection_cuda.cu', ]), KaolinCUDAExtension('kaolin.graphics.nmr.cuda.rasterize_cuda', [ 'kaolin/graphics/nmr/cuda/rasterize_cuda.cpp', 'kaolin/graphics/nmr/cuda/rasterize_cuda_kernel.cu', ]), KaolinCUDAExtension('kaolin.graphics.softras.soft_rasterize_cuda', [ 'kaolin/graphics/softras/cuda/soft_rasterize_cuda.cpp', 'kaolin/graphics/softras/cuda/soft_rasterize_cuda_kernel.cu', ]), KaolinCUDAExtension( 'kaolin.graphics.dib_renderer.cuda.rasterizer', [ 'kaolin/graphics/dib_renderer/cuda/rasterizer.cpp', 'kaolin/graphics/dib_renderer/cuda/rasterizer_cuda.cu', 'kaolin/graphics/dib_renderer/cuda/rasterizer_cuda_back.cu', ]), ] else: cuda_extensions = [] if use_cython: from Cython.Build import cythonize from Cython.Compiler import Options compiler_directives = Options.get_directive_defaults() compiler_directives["emit_code_comments"] = False cython_extensions = cythonize(cython_extensions, language='c++', compiler_directives=compiler_directives) return cython_extensions + cuda_extensions
directives = { 'profile': False, 'cdivision': True, 'nonecheck': False, 'wraparound': DEBUG, 'boundscheck': DEBUG, 'embedsignature': True, 'warn.unused': True, 'warn.unreachable': True, 'warn.maybe_uninitialized': True, 'warn.undeclared': False, 'warn.unused_arg': False, 'warn.unused_result': False, } Options.fast_fail = True if 'auto_pickle' in Options.get_directive_defaults(): directives.update(auto_pickle=False) if __name__ == '__main__': if sys.version_info[:2] < (3, 3): raise RuntimeError('Python version 3.3+ required.') os.environ['GCC_COLORS'] = 'auto' extra_compile_args = [ '-Isparsepp/', '-Wno-strict-prototypes', '-Wno-unused-function', '-Wno-unreachable-code', '-Wno-sign-compare', '-D__STDC_LIMIT_MACROS' ] # http://stackoverflow.com/a/3233069 if DEBUG: directives.update(wraparound=True, boundscheck=True) extra_compile_args += [ '-g', '-O0',
import numpy except (ImportError, ModuleNotFoundError): raise ImportError('This package requires "numpy" to be installed. ' 'Install it first: "pip install numpy".') mock_install = os.environ.get('READTHEDOCS') == 'True' try: from Cython.Distutils import build_ext from Cython.Build import cythonize from Cython.Compiler import Options except ImportError: USE_CYTHON = False compiler_directives = {} else: compiler_directives = Options.get_directive_defaults() USE_CYTHON = True compiler_directives["emit_code_comments"] = False ext = '.pyx' if USE_CYTHON else '.c' # ------------------------------------------ # Get include and lib directories of libgsl # These are taken and adapted from # https://github.com/twiecki/CythonGSL # so we don't need to import cython_gsl here # ------------------------------------------ def get_gsl_include_dir():
def get_extensions(): extra_compile_args = {'cxx': ['-O3']} define_macros = [] # FORCE_CUDA is for cross-compilation in docker build if torch.cuda.is_available() or os.getenv('FORCE_CUDA', '0') == '1': with_cuda = True define_macros += [("WITH_CUDA", None)] extension = CUDAExtension extra_compile_args.update({'nvcc': ['-O3']}) else: extension = CppExtension with_cuda = False extensions = [] extensions.append( extension(name='kaolin.ops.packed_sum_cuda', sources=filters_cu([ 'kaolin/csrc/cuda/ops/packed_sum_cuda.cpp', 'kaolin/csrc/cuda/ops/packed_sum_cuda_kernel.cu' ], with_cuda), define_macros=define_macros, extra_compile_args=extra_compile_args)) extensions.append( extension(name='kaolin.ops.tile_to_packed_cuda', sources=filters_cu([ 'kaolin/csrc/cuda/ops/tile_to_packed_cuda.cpp', 'kaolin/csrc/cuda/ops/tile_to_packed_cuda_kernel.cu' ], with_cuda), define_macros=define_macros, extra_compile_args=extra_compile_args)) extensions.append( extension(name='kaolin.metrics.sided_distance_cuda', sources=filters_cu([ 'kaolin/csrc/cuda/metrics/sided_distance.cpp', 'kaolin/csrc/cuda/metrics/sided_distance_cuda.cu' ], with_cuda), define_macros=define_macros, extra_compile_args=extra_compile_args)) extensions.append( extension( name='kaolin.metrics.unbatched_triangle_distance_cuda', sources=filters_cu([ 'kaolin/csrc/cuda/metrics/unbatched_triangle_distance_cuda.cpp', 'kaolin/csrc/cuda/metrics/unbatched_triangle_distance_cuda_kernel.cu' ], with_cuda), define_macros=define_macros, extra_compile_args=extra_compile_args)) extensions.append( extension( name='kaolin.ops.mesh.mesh_intersection_cuda', sources=filters_cu([ 'kaolin/csrc/cuda/ops/mesh/mesh_intersection_cuda.cpp', 'kaolin/csrc/cuda/ops/mesh/mesh_intersection_cuda_kernel.cu' ], with_cuda), define_macros=define_macros, extra_compile_args=extra_compile_args)) extensions.append( extension(name='kaolin.render.mesh.dibr_rasterization_cuda', sources=filters_cu([ 'kaolin/csrc/cuda/render/dibr.cpp', 'kaolin/csrc/cuda/render/dibr_for.cu', 'kaolin/csrc/cuda/render/dibr_back.cu' ], with_cuda), define_macros=define_macros, extra_compile_args=extra_compile_args)) extensions.append( extension( name='kaolin.ops.conversions.unbatched_mcube_cuda', sources=filters_cu([ 'kaolin/csrc/cuda/ops/conversions/unbatched_mcube/unbatched_mcube_cuda.cpp', 'kaolin/csrc/cuda/ops/conversions/unbatched_mcube/unbatched_mcube_cuda_kernel.cu' ], with_cuda), define_macros=define_macros, extra_compile_args=extra_compile_args)) # use cudart_static instead for extension in extensions: extension.libraries = [ 'cudart_static' if x == 'cudart' else x for x in extension.libraries ] use_cython = True ext = '.pyx' if use_cython else '.cpp' cython_extensions = [ CppExtension( 'kaolin.ops.mesh.triangle_hash', sources=[f'kaolin/csrc/cpu/ops/mesh/triangle_hash{ext}'], include_dirs=[numpy.get_include()], ), CppExtension( 'kaolin.ops.conversions.mise', sources=[f'kaolin/csrc/cpu/ops/conversions/mise{ext}'], ), ] if use_cython: from Cython.Build import cythonize from Cython.Compiler import Options compiler_directives = Options.get_directive_defaults() compiler_directives["emit_code_comments"] = False cython_extensions = cythonize(cython_extensions, language='c++', compiler_directives=compiler_directives) return extensions + cython_extensions
directives = { 'profile': False, 'cdivision': True, 'nonecheck': False, 'wraparound': DEBUG, 'boundscheck': DEBUG, 'embedsignature': True, 'warn.unused': True, 'warn.unreachable': True, 'warn.maybe_uninitialized': True, 'warn.undeclared': False, 'warn.unused_arg': False, 'warn.unused_result': False, } Options.fast_fail = True if 'auto_pickle' in Options.get_directive_defaults(): directives.update(auto_pickle=False) if __name__ == '__main__': if sys.version_info[:2] < (3, 3): raise RuntimeError('Python version 3.3+ required.') os.environ['GCC_COLORS'] = 'auto' extra_compile_args = ['-Isparsepp/', '-Wno-strict-prototypes', '-Wno-unused-function', '-Wno-unreachable-code', '-Wno-sign-compare', '-D__STDC_LIMIT_MACROS'] # http://stackoverflow.com/a/3233069 if DEBUG: directives.update(wraparound=True, boundscheck=True) extra_compile_args += ['-g', '-O0', # '-fsanitize=address', '-fsanitize=undefined', '-fno-omit-frame-pointer']
# tell setuptools to build the Cython extension # only enable Cython line tracing if we're installing in Travis-CI! macros = [] try: if os.environ['TRAVIS'] == 'true' and os.environ['CI'] == 'true' \ and os.environ['TRAVIS_OS_NAME'] == 'linux' \ and 'TRAVIS_TEST_RESULT' not in os.environ: # note: linetracing is temporarily disabled # macros.append(('CYTHON_TRACE', '0')) # CythonOptions.directive_defaults['linetrace'] = False # only way of setting linetrace without cythonize? macros.append(('CYTHON_TRACE', '1')) #CythonOptions.directive_defaults['linetrace'] = True cython_defaults = CythonOptions.get_directive_defaults() cython_defaults['linetrace'] = True print('Warning: Enabling line tracing in cython extension.' 'This` will slow it down by a factor of 20 or so!') except (KeyError, ImportError): # KeyError if environment variable is not set, # ImportError if cython is not yet installed pass ext_modules.append( Extension(root + '.' + 'mhg_cython', [root + '/mhg_cython.pyx'], include_dirs=[np.get_include()], define_macros=macros)) cmdclass['build_ext'] = build_ext
if "all" in cython_options: cython_options |= {"annotate", "debug", "trace", "profile"} extension_extras = {} cythonize_extras = {} compiler_directives_extras = {} if "annotate" in cython_options: Options.annotate = True cythonize_extras['annotate'] = True if "debug" in cython_options: cythonize_extras['gdb_debug'] = True if "trace" in cython_options: # line_profiler / coverage directive_defaults = Options.get_directive_defaults() directive_defaults['linetrace'] = True directive_defaults['binding'] = True extension_extras['define_macros'] = [('CYTHON_TRACE', '1')] if "profile" in cython_options: # cProfile compiler_directives_extras["profile"] = True def generate_extensions(): extensions = [] for root, _, filenames in os.walk('src'): for filename in filenames: if filename.endswith('.pyx'): path = os.path.join(root, filename) module = path[4:].replace('/', '.').rsplit('.', 1)[0]
VERSION = "0.1.0" ext_macros = [] logger = logging.getLogger('scurl') try: from Cython.Compiler import Options as CythonOptions except ImportError as e: logger.debug('Cython is not installed on your env.\ Please get the latest version of Cython and try again!') if os.environ.get('CYTHON_TRACE'): if platform.python_implementation() != 'PyPy': # enable linetrace in Cython ext_macros.append(('CYTHON_TRACE', '1')) cython_defaults = CythonOptions.get_directive_defaults() cython_defaults['linetrace'] = True logger.warning('Warning: Enabling line tracing in Cython extension.\ This will make the performance of the library less effective!' ) cgurl_ext_sources = [ 'scurl/cgurl.pyx', 'third_party/chromium/base/callback_internal.cc', 'third_party/chromium/base/at_exit.cc', 'third_party/chromium/base/lazy_instance_helpers.cc', 'third_party/chromium/base/strings/utf_string_conversion_utils.cc', 'third_party/chromium/base/strings/string_piece.cc', 'third_party/chromium/base/strings/string16.cc', 'third_party/chromium/base/strings/string_util.cc', 'third_party/chromium/base/strings/utf_string_conversions.cc',