From f70b9ee5de594ddb681298ee3e32912c49d3068c Mon Sep 17 00:00:00 2001 From: Peter Bell Date: Tue, 17 Aug 2021 10:11:05 -0700 Subject: [PATCH] Advertise USE_PRECOMPILED_HEADERS in CONTRIBUTING.md (#62827) Summary: This option was added in https://github.com/pytorch/pytorch/issues/61940 and fits with this section's theme of improving build times. I've also changed it to a `cmake_dependent_option` instead of `FATAL_ERROR`ing for older CMake versions. Pull Request resolved: https://github.com/pytorch/pytorch/pull/62827 Reviewed By: astaff Differential Revision: D30342102 Pulled By: malfet fbshipit-source-id: 3095b44b7085aee8a884ec95cba9f8998d4442e7 --- CMakeLists.txt | 7 +++---- CONTRIBUTING.md | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 717de6e61a4..188f35a9981 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -241,10 +241,9 @@ option(USE_OBSERVERS "Use observers module." OFF) option(USE_OPENCL "Use OpenCL" OFF) option(USE_OPENCV "Use OpenCV" OFF) option(USE_OPENMP "Use OpenMP for parallel code" ON) -option(USE_PRECOMPILED_HEADERS "Use pre-compiled headers to accelerate build. Requires cmake >= 3.16." OFF) -if(USE_PRECOMPILED_HEADERS AND (CMAKE_VERSION VERSION_LESS "3.16")) - message(FATAL_ERROR "Precompiled headers require cmake >= 3.16") -endif() +cmake_dependent_option( + USE_PRECOMPILED_HEADERS "Use pre-compiled headers to accelerate build. Requires cmake >= 3.16." OFF + "CMAKE_VERSION VERSION_LESS \"3.16\"" OFF) option(USE_PROF "Use profiling" OFF) option(USE_QNNPACK "Use QNNPACK (quantized 8-bit operators)" ON) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 66dbec29870..7d8659a8bab 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -30,6 +30,7 @@ - [Use Ninja](#use-ninja) - [Use CCache](#use-ccache) - [Use a faster linker](#use-a-faster-linker) + - [Use pre-compiled headers](#use-pre-compiled-headers) - [C++ frontend development tips](#c-frontend-development-tips) - [GDB integration](#gdb-integration) - [CUDA development tips](#cuda-development-tips) @@ -850,6 +851,27 @@ The easiest way to use `lld` this is download the ln -s /path/to/downloaded/ld.lld /usr/local/bin/ld ``` +#### Use pre-compiled headers + +Sometimes there's no way of getting around rebuilding lots of files, for example +editing `native_functions.yaml` usually means 1000+ files being rebuilt. If +you're using CMake newer than 3.16, you can enable pre-compiled headers by +setting `USE_PRECOMPILED_HEADERS=1` either on first setup, or in the +`CMakeCache.txt` file. + +```sh +USE_PRECOMPILED_HEADERS=1 python setup.py develop +``` + +This adds a build step where the compiler takes `` and essentially +dumps it's internal AST to a file so the compiler can avoid repeating itself for +every `.cpp` file. + +One caveat is that when enabled, this header gets included in every file by default. +Which may change what code is legal, for example: +- internal functions can never alias existing names in `` +- names in `` will work even if you don't explicitly include it. + ### C++ frontend development tips We have very extensive tests in the [test/cpp/api](test/cpp/api) folder. The