def build_deps(): report('-- Building version ' + version) def check_file(f): if bool(os.getenv("USE_SYSTEM_LIBS", False)): return if not os.path.exists(f): report("Could not find {}".format(f)) report("Did you run 'git submodule update --init --recursive'?") sys.exit(1) check_file(os.path.join(third_party_path, "gloo", "CMakeLists.txt")) check_file(os.path.join(third_party_path, 'cpuinfo', 'CMakeLists.txt')) check_file(os.path.join(third_party_path, 'tbb', 'Makefile')) check_file(os.path.join(third_party_path, 'onnx', 'CMakeLists.txt')) check_file(os.path.join(third_party_path, 'foxi', 'CMakeLists.txt')) check_file(os.path.join(third_party_path, 'QNNPACK', 'CMakeLists.txt')) check_file(os.path.join(third_party_path, 'fbgemm', 'CMakeLists.txt')) check_file( os.path.join(third_party_path, 'fbgemm', 'third_party', 'asmjit', 'CMakeLists.txt')) check_file( os.path.join(third_party_path, 'onnx', 'third_party', 'benchmark', 'CMakeLists.txt')) check_pydep('yaml', 'pyyaml') build_caffe2(version=version, cmake_python_library=cmake_python_library, build_python=True, rerun_cmake=RERUN_CMAKE, cmake_only=CMAKE_ONLY, cmake=cmake) if CMAKE_ONLY: report('Finished running cmake. Run "ccmake build" or ' '"cmake-gui build" to adjust build options and ' '"python setup.py install" to build.') sys.exit() # Use copies instead of symbolic files. # Windows has very poor support for them. sym_files = [ 'tools/shared/_utils_internal.py', 'torch/utils/benchmark/utils/valgrind_wrapper/callgrind.h', 'torch/utils/benchmark/utils/valgrind_wrapper/valgrind.h', ] orig_files = [ 'torch/_utils_internal.py', 'third_party/valgrind-headers/callgrind.h', 'third_party/valgrind-headers/valgrind.h', ] for sym_file, orig_file in zip(sym_files, orig_files): same = False if os.path.exists(sym_file): if filecmp.cmp(sym_file, orig_file): same = True else: os.remove(sym_file) if not same: shutil.copyfile(orig_file, sym_file)
def build_deps(): report('-- Building version ' + version) version_path = os.path.join(cwd, 'torch', 'version.py') with open(version_path, 'w') as f: f.write("__version__ = '{}'\n".format(version)) # NB: This is not 100% accurate, because you could have built the # library code with DEBUG, but csrc without DEBUG (in which case # this would claim to be a release build when it's not.) f.write("debug = {}\n".format(repr(build_type.is_debug()))) f.write("cuda = {}\n".format(repr(CUDA_VERSION))) f.write("git_version = {}\n".format(repr(sha))) def check_file(f): if not os.path.exists(f): report("Could not find {}".format(f)) report("Did you run 'git submodule update --init --recursive'?") sys.exit(1) check_file(os.path.join(third_party_path, "gloo", "CMakeLists.txt")) check_file(os.path.join(third_party_path, "pybind11", "CMakeLists.txt")) check_file(os.path.join(third_party_path, 'cpuinfo', 'CMakeLists.txt')) check_file(os.path.join(third_party_path, 'tbb', 'Makefile')) check_file(os.path.join(third_party_path, 'onnx', 'CMakeLists.txt')) check_file(os.path.join(third_party_path, 'foxi', 'CMakeLists.txt')) check_file(os.path.join(third_party_path, 'QNNPACK', 'CMakeLists.txt')) check_file(os.path.join(third_party_path, 'fbgemm', 'CMakeLists.txt')) check_file(os.path.join(third_party_path, 'fbgemm', 'third_party', 'asmjit', 'CMakeLists.txt')) check_file(os.path.join(third_party_path, 'onnx', 'third_party', 'benchmark', 'CMakeLists.txt')) check_pydep('yaml', 'pyyaml') check_pydep('typing', 'typing') build_caffe2(version=version, cmake_python_library=cmake_python_library, build_python=True, rerun_cmake=RERUN_CMAKE, cmake_only=CMAKE_ONLY, cmake=cmake) if CMAKE_ONLY: report('Finished running cmake. Run "ccmake build" or ' '"cmake-gui build" to adjust build options and ' '"python setup.py install" to build.') sys.exit() # Use copies instead of symbolic files. # Windows has very poor support for them. sym_files = ['tools/shared/cwrap_common.py', 'tools/shared/_utils_internal.py'] orig_files = ['aten/src/ATen/common_with_cwrap.py', 'torch/_utils_internal.py'] for sym_file, orig_file in zip(sym_files, orig_files): same = False if os.path.exists(sym_file): if filecmp.cmp(sym_file, orig_file): same = True else: os.remove(sym_file) if not same: shutil.copyfile(orig_file, sym_file) dir_util.copy_tree('third_party/pybind11/include/pybind11/', 'torch/include/pybind11')
# modules even when run as a standalone script. i.e., it's okay either you # do `python build_libtorch.py` or `python -m tools.build_libtorch`. pytorch_root = dirname(dirname(abspath(__file__))) sys.path.append(pytorch_root) from tools.build_pytorch_libs import build_caffe2 from tools.setup_helpers.cmake import CMake if __name__ == "__main__": # Placeholder for future interface. For now just gives a nice -h. parser = argparse.ArgumentParser(description="Build libtorch") parser.add_argument("--rerun-cmake", action="store_true", help="rerun cmake") parser.add_argument( "--cmake-only", action="store_true", help= "Stop once cmake terminates. Leave users a chance to adjust build options", ) options = parser.parse_args() build_caffe2( version=None, cmake_python_library=None, build_python=False, rerun_cmake=options.rerun_cmake, cmake_only=options.cmake_only, cmake=CMake(), )
import argparse from os.path import dirname, abspath import sys # By appending pytorch_root to sys.path, this module can import other torch # modules even when run as a standalone script. i.e., it's okay either you # do `python build_libtorch.py` or `python -m tools.build_libtorch`. pytorch_root = dirname(dirname(abspath(__file__))) sys.path.append(pytorch_root) # If you want to modify flags or environmental variables that is set when # building torch, you should do it in tools/setup_helpers/configure.py. # Please don't add it here unless it's only used in LibTorch. from tools.build_pytorch_libs import build_caffe2 from tools.setup_helpers.cmake import CMake if __name__ == '__main__': # Placeholder for future interface. For now just gives a nice -h. parser = argparse.ArgumentParser(description='Build libtorch') options = parser.parse_args() build_caffe2(version=None, cmake_python_library=None, build_python=False, rerun_cmake=True, cmake_only=False, cmake=CMake('build'))
import argparse from os.path import dirname, abspath import sys # By appending pytorch_root to sys.path, this module can import other torch # modules even when run as a standalone script. i.e., it's okay either you # do `python build_libtorch.py` or `python -m tools.build_libtorch`. pytorch_root = dirname(dirname(abspath(__file__))) sys.path.append(pytorch_root) # If you want to modify flags or environmental variables that is set when # building torch, you should do it in tools/setup_helpers/configure.py. # Please don't add it here unless it's only used in LibTorch. from tools.build_pytorch_libs import build_caffe2 if __name__ == '__main__': # Placeholder for future interface. For now just gives a nice -h. parser = argparse.ArgumentParser(description='Build libtorch') options = parser.parse_args() build_caffe2(version=None, cmake_python_library=None, build_python=False, rerun_cmake=True, cmake_only=False, build_dir='.')