def make_extensions(options, compiler): """Produce a list of Extension instances which passed to cythonize().""" no_cuda = options['no_cuda'] settings = build.get_compiler_setting() include_dirs = settings['include_dirs'] settings['include_dirs'] = [ x for x in include_dirs if path.exists(x)] settings['library_dirs'] = [ x for x in settings['library_dirs'] if path.exists(x)] if sys.platform != 'win32': settings['runtime_library_dirs'] = settings['library_dirs'] if sys.platform == 'darwin': settings.setdefault('extra_link_args', []).append( '-Wl,' + ','.join('-rpath,' + path for path in settings['library_dirs'])) if options['linetrace']: settings['define_macros'].append(('CYTHON_TRACE', '1')) settings['define_macros'].append(('CYTHON_TRACE_NOGIL', '1')) if no_cuda: settings['define_macros'].append(('CUPY_NO_CUDA', '1')) ret = [] for module in MODULES: print('Include directories:', settings['include_dirs']) print('Library directories:', settings['library_dirs']) if not no_cuda: if not check_library(compiler, includes=module['include'], include_dirs=settings['include_dirs']): utils.print_warning( 'Include files not found: %s' % module['include'], 'Skip installing %s support' % module['name'], 'Check your CPATH environment variable') continue if not check_library(compiler, libraries=module['libraries'], library_dirs=settings['library_dirs']): utils.print_warning( 'Cannot link libraries: %s' % module['libraries'], 'Skip installing %s support' % module['name'], 'Check your LIBRARY_PATH environment variable') continue if 'check_method' in module and \ not module['check_method'](compiler, settings): continue s = settings.copy() if not no_cuda: s['libraries'] = module['libraries'] ret.extend([ setuptools.Extension(f, [path.join(*f.split('.')) + '.pyx'], **s) for f in module['file']]) return ret
def make_extensions(options, compiler): """Produce a list of Extension instances which passed to cythonize().""" no_cuda = options['no_cuda'] settings = build.get_compiler_setting() include_dirs = settings['include_dirs'] settings['include_dirs'] = [x for x in include_dirs if path.exists(x)] settings['library_dirs'] = [ x for x in settings['library_dirs'] if path.exists(x) ] if sys.platform != 'win32': settings['runtime_library_dirs'] = settings['library_dirs'] if options['linetrace']: settings['define_macros'].append(('CYTHON_TRACE', '1')) settings['define_macros'].append(('CYTHON_TRACE_NOGIL', '1')) if no_cuda: settings['define_macros'].append(('CUPY_NO_CUDA', '1')) ret = [] for module in MODULES: print('Include directories:', settings['include_dirs']) print('Library directories:', settings['library_dirs']) if not no_cuda: if not check_library(compiler, includes=module['include'], include_dirs=settings['include_dirs']): utils.print_warning( 'Include files not found: %s' % module['include'], 'Skip installing %s support' % module['name'], 'Check your CPATH environment variable') continue if not check_library(compiler, libraries=module['libraries'], library_dirs=settings['library_dirs']): utils.print_warning( 'Cannot link libraries: %s' % module['libraries'], 'Skip installing %s support' % module['name'], 'Check your LIBRARY_PATH environment variable') continue if 'check_method' in module and \ not module['check_method'](compiler, settings): continue s = settings.copy() if not no_cuda: s['libraries'] = module['libraries'] ret.extend([ setuptools.Extension(f, [path.join(*f.split('.')) + '.pyx'], **s) for f in module['file'] ]) return ret
def make_extensions(options, compiler): """Produce a list of Extension instances which passed to cythonize().""" no_cuda = options["no_cuda"] settings = build.get_compiler_setting() include_dirs = settings["include_dirs"] settings["include_dirs"] = [x for x in include_dirs if path.exists(x)] settings["library_dirs"] = [x for x in settings["library_dirs"] if path.exists(x)] if sys.platform != "win32": settings["runtime_library_dirs"] = settings["library_dirs"] if sys.platform == "darwin": args = settings.setdefault("extra_link_args", []) args.append("-Wl," + ",".join("-rpath," + path for path in settings["library_dirs"])) # -rpath is only supported when targetting Mac OS X 10.5 or later args.append("-mmacosx-version-min=10.5") if options["linetrace"]: settings["define_macros"].append(("CYTHON_TRACE", "1")) settings["define_macros"].append(("CYTHON_TRACE_NOGIL", "1")) if no_cuda: settings["define_macros"].append(("CUPY_NO_CUDA", "1")) ret = [] for module in MODULES: print("Include directories:", settings["include_dirs"]) print("Library directories:", settings["library_dirs"]) if not no_cuda: if not check_library(compiler, includes=module["include"], include_dirs=settings["include_dirs"]): utils.print_warning( "Include files not found: %s" % module["include"], "Skip installing %s support" % module["name"], "Check your CPATH environment variable", ) continue if not check_library(compiler, libraries=module["libraries"], library_dirs=settings["library_dirs"]): utils.print_warning( "Cannot link libraries: %s" % module["libraries"], "Skip installing %s support" % module["name"], "Check your LIBRARY_PATH environment variable", ) continue if "check_method" in module and not module["check_method"](compiler, settings): continue s = settings.copy() if not no_cuda: s["libraries"] = module["libraries"] ret.extend([setuptools.Extension(f, [path.join(*f.split(".")) + ".pyx"], **s) for f in module["file"]]) return ret
def make_extensions(options, compiler, use_cython): """Produce a list of Extension instances which passed to cythonize().""" no_cuda = options['no_cuda'] settings = build.get_compiler_setting() include_dirs = settings['include_dirs'] settings['include_dirs'] = [ x for x in include_dirs if path.exists(x)] settings['library_dirs'] = [ x for x in settings['library_dirs'] if path.exists(x)] # Adjust rpath to use CUDA libraries in `cupy/_lib/*.so`) from CuPy. use_wheel_libs_rpath = ( 0 < len(options['wheel_libs']) and not PLATFORM_WIN32) # This is a workaround for Anaconda. # Anaconda installs libstdc++ from GCC 4.8 and it is not compatible # with GCC 5's new ABI. settings['define_macros'].append(('_GLIBCXX_USE_CXX11_ABI', '0')) # In the environment with CUDA 7.5 on Ubuntu 16.04, gcc5.3 does not # automatically deal with memcpy because string.h header file has # been changed. This is a workaround for that environment. # See details in the below discussions: # https://github.com/BVLC/caffe/issues/4046 # https://groups.google.com/forum/#!topic/theano-users/3ihQYiTRG4E settings['define_macros'].append(('_FORCE_INLINES', '1')) if options['linetrace']: settings['define_macros'].append(('CYTHON_TRACE', '1')) settings['define_macros'].append(('CYTHON_TRACE_NOGIL', '1')) if no_cuda: settings['define_macros'].append(('CUPY_NO_CUDA', '1')) available_modules = [] if no_cuda: available_modules = [m['name'] for m in MODULES] else: available_modules = preconfigure_modules(compiler, settings) if 'cuda' not in available_modules: raise Exception('Your CUDA environment is invalid. ' 'Please check above error log.') ret = [] for module in MODULES: if module['name'] not in available_modules: continue s = settings.copy() if not no_cuda: s['libraries'] = module['libraries'] compile_args = s.setdefault('extra_compile_args', []) link_args = s.setdefault('extra_link_args', []) if module['name'] == 'cusolver': compile_args = s.setdefault('extra_compile_args', []) link_args = s.setdefault('extra_link_args', []) # openmp is required for cusolver if compiler.compiler_type == 'unix' and not PLATFORM_DARWIN: # In mac environment, openmp is not required. compile_args.append('-fopenmp') link_args.append('-fopenmp') elif compiler.compiler_type == 'msvc': compile_args.append('/openmp') for f in module['file']: name = module_extension_name(f) rpath = [] if not options['no_rpath']: # Add library directories (e.g., `/usr/local/cuda/lib64`) to # RPATH. rpath += s['library_dirs'] if use_wheel_libs_rpath: # Add `cupy/_lib` (where shared libraries included in wheels # reside) to RPATH. # The path is resolved relative to the module, e.g., use # `$ORIGIN/_lib` for `cupy/cudnn.so` and `$ORIGIN/../_lib` for # `cupy/cuda/cudnn.so`. depth = name.count('.') - 1 rpath.append('{}{}/_lib'.format(_rpath_base(), '/..' * depth)) if not PLATFORM_WIN32: s['runtime_library_dirs'] = rpath if PLATFORM_DARWIN: args = s.setdefault('extra_link_args', []) args.append( '-Wl,' + ','.join('-rpath,' + p for p in s['library_dirs'])) # -rpath is only supported when targetting Mac OS X 10.5 or # later args.append('-mmacosx-version-min=10.5') sources = module_extension_sources(f, use_cython, no_cuda) extension = setuptools.Extension(name, sources, **s) ret.append(extension) return ret
def make_extensions(options, compiler, use_cython): """Produce a list of Extension instances which passed to cythonize().""" no_cuda = options['no_cuda'] use_hip = not no_cuda and options['use_hip'] settings = build.get_compiler_setting(use_hip) include_dirs = settings['include_dirs'] settings['include_dirs'] = [x for x in include_dirs if path.exists(x)] settings['library_dirs'] = [ x for x in settings['library_dirs'] if path.exists(x) ] # Adjust rpath to use CUDA libraries in `cupy/.data/lib/*.so`) from CuPy. use_wheel_libs_rpath = (0 < len(options['wheel_libs']) and not PLATFORM_WIN32) # In the environment with CUDA 7.5 on Ubuntu 16.04, gcc5.3 does not # automatically deal with memcpy because string.h header file has # been changed. This is a workaround for that environment. # See details in the below discussions: # https://github.com/BVLC/caffe/issues/4046 # https://groups.google.com/forum/#!topic/theano-users/3ihQYiTRG4E settings['define_macros'].append(('_FORCE_INLINES', '1')) if options['linetrace']: settings['define_macros'].append(('CYTHON_TRACE', '1')) settings['define_macros'].append(('CYTHON_TRACE_NOGIL', '1')) if no_cuda: settings['define_macros'].append(('CUPY_NO_CUDA', '1')) if use_hip: settings['define_macros'].append(('CUPY_USE_HIP', '1')) settings['define_macros'].append(('__HIP_PLATFORM_HCC__', '1')) available_modules = [] if no_cuda: available_modules = [m['name'] for m in MODULES] else: available_modules, settings = preconfigure_modules(compiler, settings) required_modules = get_required_modules() if not (set(required_modules) <= set(available_modules)): raise Exception('Your CUDA environment is invalid. ' 'Please check above error log.') ret = [] for module in MODULES: if module['name'] not in available_modules: continue s = copy.deepcopy(settings) if not no_cuda: s['libraries'] = module['libraries'] compile_args = s.setdefault('extra_compile_args', []) link_args = s.setdefault('extra_link_args', []) if module['name'] == 'cusolver': # cupy_backends/cupy_lapack.h has C++ template code compile_args.append('--std=c++11') # openmp is required for cusolver if use_hip: pass elif compiler.compiler_type == 'unix': compile_args.append('-fopenmp') link_args.append('-fopenmp') elif compiler.compiler_type == 'msvc': compile_args.append('/openmp') if module['name'] == 'jitify': # this fixes RTD (no_cuda) builds... compile_args.append('--std=c++11') # if any change is made to the Jitify header, we force recompiling s['depends'] = ['./cupy/core/include/cupy/jitify/jitify.hpp'] if module['name'] == 'dlpack': # if any change is made to the DLPack header, we force recompiling s['depends'] = ['./cupy/core/include/cupy/dlpack/dlpack.h'] for f in module['file']: s_file = copy.deepcopy(s) name = module_extension_name(f) if name.endswith('fft._callback') and not PLATFORM_LINUX: continue rpath = [] if not options['no_rpath']: # Add library directories (e.g., `/usr/local/cuda/lib64`) to # RPATH. rpath += s_file['library_dirs'] if use_wheel_libs_rpath: # Add `cupy/.data/lib` (where shared libraries included in # wheels reside) to RPATH. # The path is resolved relative to the module, e.g., use # `$ORIGIN/../cupy/.data/lib` for `cupy/cudnn.so` and # `$ORIGIN/../../../cupy/.data/lib` for # `cupy_backends/cuda/libs/cudnn.so`. depth = name.count('.') rpath.append('{}{}/cupy/.data/lib'.format( _rpath_base(), '/..' * depth)) if not PLATFORM_WIN32 and not PLATFORM_LINUX: assert False, "macOS is no longer supported" if (PLATFORM_LINUX and len(rpath) != 0): ldflag = '-Wl,' if PLATFORM_LINUX: ldflag += '--disable-new-dtags,' ldflag += ','.join('-rpath,' + p for p in rpath) args = s_file.setdefault('extra_link_args', []) args.append(ldflag) sources = module_extension_sources(f, use_cython, no_cuda) extension = setuptools.Extension(name, sources, **s_file) ret.append(extension) return ret
def setUp(self): self.compiler = ccompiler.new_compiler() sysconfig.customize_compiler(self.compiler) self.settings = build.get_compiler_setting()
def make_extensions(options, compiler, use_cython): """Produce a list of Extension instances which passed to cythonize().""" no_cuda = options['no_cuda'] settings = build.get_compiler_setting() include_dirs = settings['include_dirs'] settings['include_dirs'] = [x for x in include_dirs if path.exists(x)] settings['library_dirs'] = [ x for x in settings['library_dirs'] if path.exists(x) ] if sys.platform != 'win32': settings['runtime_library_dirs'] = settings['library_dirs'] if sys.platform == 'darwin': args = settings.setdefault('extra_link_args', []) args.append('-Wl,' + ','.join('-rpath,' + p for p in settings['library_dirs'])) # -rpath is only supported when targetting Mac OS X 10.5 or later args.append('-mmacosx-version-min=10.5') # This is a workaround for Anaconda. # Anaconda installs libstdc++ from GCC 4.8 and it is not compatible # with GCC 5's new ABI. settings['define_macros'].append(('_GLIBCXX_USE_CXX11_ABI', '0')) # In the environment with CUDA 7.5 on Ubuntu 16.04, gcc5.3 does not # automatically deal with memcpy because string.h header file has # been changed. This is a workaround for that environment. # See details in the below discussions: # https://github.com/BVLC/caffe/issues/4046 # https://groups.google.com/forum/#!topic/theano-users/3ihQYiTRG4E settings['define_macros'].append(('_FORCE_INLINES', '1')) if options['linetrace']: settings['define_macros'].append(('CYTHON_TRACE', '1')) settings['define_macros'].append(('CYTHON_TRACE_NOGIL', '1')) if no_cuda: settings['define_macros'].append(('CUPY_NO_CUDA', '1')) ret = [] for module in MODULES: print('Include directories:', settings['include_dirs']) print('Library directories:', settings['library_dirs']) if not no_cuda: err = False if not check_library(compiler, includes=module['include'], include_dirs=settings['include_dirs']): utils.print_warning( 'Include files not found: %s' % module['include'], 'Skip installing %s support' % module['name'], 'Check your CFLAGS environment variable') err = True elif not check_library(compiler, libraries=module['libraries'], library_dirs=settings['library_dirs']): utils.print_warning( 'Cannot link libraries: %s' % module['libraries'], 'Skip installing %s support' % module['name'], 'Check your LDFLAGS environment variable') err = True elif ('check_method' in module and not module['check_method'](compiler, settings)): err = True if err: if module['name'] == 'cuda': raise Exception('Your CUDA environment is invalid. ' 'Please check above error log.') else: # Other modules are optional. They are skipped. continue s = settings.copy() if not no_cuda: s['libraries'] = module['libraries'] if module['name'] == 'cusolver': compile_args = s.setdefault('extra_compile_args', []) link_args = s.setdefault('extra_link_args', []) # openmp is required for cusolver if compiler.compiler_type == 'unix' and sys.platform != 'darwin': # In mac environment, openmp is not required. compile_args.append('-fopenmp') link_args.append('-fopenmp') elif compiler.compiler_type == 'msvc': compile_args.append('/openmp') if not no_cuda and module['name'] == 'thrust': if build.get_nvcc_path() is None: utils.print_warning('Cannot find nvcc in PATH.', 'Skip installing thrust support.') continue for f in module['file']: name = module_extension_name(f) sources = module_extension_sources(f, use_cython, no_cuda) extension = setuptools.Extension(name, sources, **s) ret.append(extension) return ret
def make_extensions(options, compiler, use_cython): """Produce a list of Extension instances which passed to cythonize().""" no_cuda = options['no_cuda'] settings = build.get_compiler_setting() include_dirs = settings['include_dirs'] settings['include_dirs'] = [ x for x in include_dirs if path.exists(x)] settings['library_dirs'] = [ x for x in settings['library_dirs'] if path.exists(x)] if sys.platform != 'win32': settings['runtime_library_dirs'] = settings['library_dirs'] if sys.platform == 'darwin': args = settings.setdefault('extra_link_args', []) args.append( '-Wl,' + ','.join('-rpath,' + p for p in settings['library_dirs'])) # -rpath is only supported when targetting Mac OS X 10.5 or later args.append('-mmacosx-version-min=10.5') # This is a workaround for Anaconda. # Anaconda installs libstdc++ from GCC 4.8 and it is not compatible # with GCC 5's new ABI. settings['define_macros'].append(('_GLIBCXX_USE_CXX11_ABI', '0')) if options['linetrace']: settings['define_macros'].append(('CYTHON_TRACE', '1')) settings['define_macros'].append(('CYTHON_TRACE_NOGIL', '1')) if no_cuda: settings['define_macros'].append(('CUPY_NO_CUDA', '1')) ret = [] ext = '.pyx' if use_cython else '.cpp' for module in MODULES: print('Include directories:', settings['include_dirs']) print('Library directories:', settings['library_dirs']) if not no_cuda: if not check_library(compiler, includes=module['include'], include_dirs=settings['include_dirs']): utils.print_warning( 'Include files not found: %s' % module['include'], 'Skip installing %s support' % module['name'], 'Check your CFLAGS environment variable') continue if not check_library(compiler, libraries=module['libraries'], library_dirs=settings['library_dirs']): utils.print_warning( 'Cannot link libraries: %s' % module['libraries'], 'Skip installing %s support' % module['name'], 'Check your LDFLAGS environment variable') continue if 'check_method' in module and \ not module['check_method'](compiler, settings): continue s = settings.copy() if not no_cuda: s['libraries'] = module['libraries'] ret.extend([ setuptools.Extension(f, [path.join(*f.split('.')) + ext], **s) for f in module['file']]) return ret
def setUp(self): self.compiler = ccompiler.new_compiler() sysconfig.customize_compiler(self.compiler) self.settings = build.get_compiler_setting(False)
def setUp(self): self.compiler = ccompiler.new_compiler() self.settings = build.get_compiler_setting()