Files
pytorch/scripts/build_windows.bat
Edward Yang c56464d13e Turn off warnings on Windows CI. (#24331)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/24331

Currently our logs are something like 40M a pop.  Turning off warnings and turning on verbose makefiles (to see the compile commands) reduces this to more like 8M. We could probably reduce log size more but verbose makefile is really useful and we'll keep it turned on for Windows.

Some findings:

1. Setting `CMAKE_VERBOSE_MAKEFILE` inside CMakelists.txt itself as suggested in https://github.com/ninja-build/ninja/issues/900#issuecomment-417917630 does not work on Windows. Setting `-DCMAKE_VERBOSE_MAKEFILE=1` does work (and we respect this environment variable.)
2. The high (`/W3`) warning level is by default on MSVC is due to cmake inserting this in the default flags. On recent versions of cmake, CMP0092 can be used to disable this flag in the default set. The string replace trick sort of works, but the standard snippet you'll find on the internet won't disable the flag from nvcc. I inspected the CUDA cmake code and verified it does respect CMP0092
3. `EHsc` is also in the default flags; this one cannot be suppressed via a policy. The string replace trick seems to work...
4. ... however, it seems nvcc implicitly inserts an `/EHs` after `-Xcompiler` specified flags, which means that if we add `/EHa` to our set of flags, you'll get a warning from nvcc. So we probably have to figure out how to exclude EHa from the nvcc flags set (EHs does seem to work fine.)
5. To suppress warnings in nvcc, you must BOTH pass `-w` and `-Xcompiler /w`. Individually these are not enough.

The patch applies these things; it also fixes a bug where nvcc verbose command printing doesn't work with `-GNinja`.

Signed-off-by: Edward Z. Yang <ezyang@fb.com>

Test Plan: Imported from OSS

Differential Revision: D17131746

Pulled By: ezyang

fbshipit-source-id: fb142f8677072a5430664b28155373088f074c4b
2019-08-30 07:11:07 -07:00

85 lines
1.7 KiB
Batchfile

:: #############################################################################
:: Example command to build on Windows.
:: #############################################################################
:: This script shows how one can build a Caffe2 binary for windows.
@echo off
setlocal
SET ORIGINAL_DIR=%cd%
SET CAFFE2_ROOT=%~dp0%..
if NOT DEFINED BUILD_BINARY (
set BUILD_BINARY=OFF
)
if NOT DEFINED BUILD_SHARED_LIBS (
:: On CI, we test with BUILD_SHARED_LIBS=OFF.
:: By default, it will be BUILD_SHARED_LIBS=ON.
if NOT DEFINED BUILD_ENVIRONMENT (
set BUILD_SHARED_LIBS=OFF
)
)
IF NOT DEFINED BUILDING_WITH_TORCH_LIBS (
set BUILDING_WITH_TORCH_LIBS=OFF
)
if NOT DEFINED CAFFE2_STATIC_LINK_CUDA (
set CAFFE2_STATIC_LINK_CUDA=OFF
)
if NOT DEFINED CMAKE_BUILD_TYPE (
set CMAKE_BUILD_TYPE=Release
)
if NOT DEFINED ONNX_NAMESPACE (
set ONNX_NAMESPACE=onnx_c2
)
if NOT DEFINED TORCH_CUDA_ARCH_LIST (
set TORCH_CUDA_ARCH_LIST=5.0
)
if NOT DEFINED USE_CUDA (
set USE_CUDA=OFF
)
if NOT DEFINED USE_OBSERVERS (
set USE_OBSERVERS=OFF
)
if NOT DEFINED MSVC_Z7_OVERRIDE (
set MSVC_Z7_OVERRIDE=OFF
)
if NOT DEFINED CMAKE_GENERATOR (
set CMAKE_GENERATOR=Ninja
)
set CMAKE_VERBOSE_MAKEFILE=1
:: Install pyyaml for Aten codegen
pip install pyyaml ninja
echo CAFFE2_ROOT=%CAFFE2_ROOT%
echo CMAKE_GENERATOR=%CMAKE_GENERATOR%
echo CMAKE_BUILD_TYPE=%CMAKE_BUILD_TYPE%
:: Set up cmake. We will skip building the test files right now.
pushd %CAFFE2_ROOT%
python tools\build_libtorch.py || goto :label_error
popd
echo "Caffe2 built successfully"
cd %ORIGINAL_DIR%
endlocal
exit /b 0
:label_error
echo "Caffe2 building failed"
cd %ORIGINAL_DIR%
endlocal
exit /b 1