mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
reduce header file to boost cpp_wrapper build. (#107585)
1. Reduce cpp_wrapper un-used header files. 2. Clean pch cache, when use_pch is False. The first change will reduce the build time from 7.35s to 4.94s. Before change:  After change:  Pull Request resolved: https://github.com/pytorch/pytorch/pull/107585 Approved by: https://github.com/ezyang, https://github.com/jansel, https://github.com/jgong5
This commit is contained in:
@ -650,6 +650,10 @@ def cpp_flags():
|
||||
return "-std=c++17 -Wno-unused-variable"
|
||||
|
||||
|
||||
def cpp_wrapper_flags():
|
||||
return "-DTORCH_INDUCTOR_CPP_WRAPPER"
|
||||
|
||||
|
||||
def optimization_flags():
|
||||
base_flags = "-O3 -ffast-math -fno-finite-math-only"
|
||||
if config.is_fbcode():
|
||||
@ -1138,8 +1142,10 @@ class CppWrapperCodeCache:
|
||||
cuda=cuda,
|
||||
)
|
||||
_use_custom_generated_macros = use_custom_generated_macros()
|
||||
_cpp_wrapper_flags = cpp_wrapper_flags()
|
||||
|
||||
extra_cflags = f"{_cpp_flags} {_opt_flags} {_warning_all_flag} {_macros} {_use_custom_generated_macros}"
|
||||
extra_cflags = f"{_cpp_flags} {_opt_flags} {_warning_all_flag} {_macros} {_cpp_wrapper_flags} \
|
||||
{_use_custom_generated_macros}"
|
||||
# For CPP wrapper, add -ffast-math during linking to make CPU flush denormals.
|
||||
# CPP wrapper leverages cpp_extension which will do the compilation and linking in two stages.
|
||||
# We need to explicitly add -ffast-math as a linking flag.
|
||||
|
@ -1,6 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef TORCH_INDUCTOR_CPP_WRAPPER
|
||||
// All pure C++ headers for the C++ frontend.
|
||||
#include <torch/all.h>
|
||||
#endif
|
||||
|
||||
// Python bindings for the C++ frontend (includes Python.h).
|
||||
#include <torch/python.h>
|
||||
|
@ -1593,6 +1593,8 @@ def load_inline(name,
|
||||
if use_pch is True:
|
||||
# Using PreCompile Header('torch/extension.h') to reduce compile time.
|
||||
_check_and_build_extension_h_precompiler_headers(extra_cflags, extra_include_paths)
|
||||
else:
|
||||
remove_extension_h_precompiler_headers()
|
||||
|
||||
# If `functions` is supplied, we create the pybind11 bindings for the user.
|
||||
# Here, `functions` is (or becomes, after some processing) a map from
|
||||
|
Reference in New Issue
Block a user