Repository: pytorch
Issue: Failed to run 'bash ../tools/build_pytorch_libs.sh --use-nnpack --use-mkldnn --use-qnnpack caffe2'
Labels: module: build,triaged

## 🐛 Bug

I've scanned through the other issues and saw similar ones, yet I saw my environment slightly differs so i decided to open a separate report. Feel free to disagree.

After trying to build pytorch inside a virtualenv, I ran into this error:

`Makefile:138: recipe for target 'all' failed`
`make: *** [all] Error 2`
`Failed to run 'bash ../tools/build_pytorch_libs.sh --use-nnpack --use-mkldnn --use-qnnpack caffe2'`

## To Reproduce

Steps to reproduce the behavior:

`git clone --recursive https://github.com/pytorch/pytorch`
`cd pytorch`
`python setup.py install`

<!-- If you have a code sample, error messages, stack traces, please provide it here as well -->

## Expected behavior

A compilation success

## Environment

Please copy and paste the output from our
[environment collection script](https://raw.githubusercontent.com/pytorch/pytorch/master/torch/utils/collect_env.py)
(or fill out the checklist below manually).

You can get the script and run it with:
```
wget https://raw.githubusercontent.com/pytorch/pytorch/master/torch/utils/collect_env.py
# For security purposes, please check the contents of collect_env.py before running it.
python collect_env.py
```

 - PyTorch Version (e.g., 1.0): https://github.com/pytorch/pytorch , master
 - OS (e.g., Linux): Raspbian stretch 4.14.34-v7+ armv7l GNU/Linux
 - How you installed PyTorch (`conda`, `pip`, source): source
 - Build command you used (if compiling from source): see above
 - Python version: Python 2.7.13
 - CUDA/cuDNN version: NA
 - GPU models and configuration: NA
 - Any other relevant information: NA

## Additional context

The ouput from where it started going south;
```
(...) Scanning dependencies of target ATEN_CPU_FILES_GEN_TARGET                                                                                                                                                                                                                                                                                                                                    
[ 12%] Generating ../aten/src/ATen/CPUByteType.cpp, ../aten/src/ATen/CPUByteType.h, ../aten/src/ATen/CPUCharType.cpp, ../aten/src/ATen/CPUCharType.h, ../aten/src/ATen/CPUCopy.cpp, ../aten/src/ATen/CPUDoubleType.cpp, ../aten/src/ATen/CPUDoubleType.h, ../aten/src/ATen/CPUFloatType.cpp, ../aten/src/ATen/CPUFloatType.h, ../aten/src/ATen/CPUGenerator.h, ../aten/src/ATen/CPUHalfType.cpp, ../aten/src/ATen/CPUHalfType.h, ../aten/src/ATen/CPUIntType.cpp, ../aten/src/ATen/CPUIntType.h, ../aten/src/ATen/CPULongType.cpp, ../aten/src/ATen/CPULongType.h, ../aten/src/ATen/CPUShortType.cpp, ../aten/src/ATen/CPUShortType.h, ../aten/src/ATen/Declarations.yaml, ../aten/src/ATen/Functions.h, ../aten/src/ATen/NativeFunctions.h, ../aten/src/ATen/RegisterCPU.cpp, ../aten/src/ATen/RegisterCPU.h, ../aten/src/ATen/SparseCPUByteType.cpp, ../aten/src/ATen/SparseCPUByteType.h, ../aten/src/ATen/SparseCPUCharType.cpp, ../aten/src/ATen/SparseCPUCharType.h, ../aten/src/ATen/SparseCPUDoubleType.cpp, ../aten/src/ATen/SparseCPUDoubleType.h, ../aten/src/ATen/SparseCPUFloatType.cpp, ../aten/src/ATen/SparseCPUFloatType.h, ../aten/src/ATen/SparseCPUIntType.cpp, ../aten/src/ATen/SparseCPUIntType.h, ../aten/src/ATen/SparseCPULongType.cpp, ../aten/src/ATen/SparseCPULongType.h, ../aten/src/ATen/SparseCPUShortType.cpp, ../aten/src/ATen/SparseCPUShortType.h, ../aten/src/ATen/TypeDefault.cpp, ../aten/src/ATen/TypeDefault.h, ../aten/src/ATen/TypeExtendedInterface.h, ../aten/src/ATen/CUDAByteType.cpp, ../aten/src/ATen/CUDAByteType.h, ../aten/src/ATen/CUDACharType.cpp, ../aten/src/ATen/CUDACharType.h, ../aten/src/ATen/CUDACopy.cpp, ../aten/src/ATen/CUDADoubleType.cpp, ../aten/src/ATen/CUDADoubleType.h, ../aten/src/ATen/CUDAFloatType.cpp, ../aten/src/ATen/CUDAFloatType.h, ../aten/src/ATen/CUDAGenerator.h, ../aten/src/ATen/CUDAHalfType.cpp, ../aten/src/ATen/CUDAHalfType.h, ../aten/src/ATen/CUDAIntType.cpp, ../aten/src/ATen/CUDAIntType.h, ../aten/src/ATen/CUDALongType.cpp, ../aten/src/ATen/CUDALongType.h, ../aten/src/ATen/CUDAShortType.cpp, ../aten/src/ATen/CUDAShortType.h, ../aten/src/ATen/RegisterCUDA.cpp, ../aten/src/ATen/RegisterCUDA.h, ../aten/src/ATen/SparseCUDAByteType.cpp, ../aten/src/ATen/SparseCUDAByteType.h, ../aten/src/ATen/SparseCUDACharType.cpp, ../aten/src/ATen/SparseCUDACharType.h, ../aten/src/ATen/SparseCUDADoubleType.cpp, ../aten/src/ATen/SparseCUDADoubleType.h, ../aten/src/ATen/SparseCUDAFloatType.cpp, ../aten/src/ATen/SparseCUDAFloatType.h, ../aten/src/ATen/SparseCUDAIntType.cpp, ../aten/src/ATen/SparseCUDAIntType.h, ../aten/src/ATen/SparseCUDALongType.cpp, ../aten/src/ATen/SparseCUDALongType.h, ../aten/src/ATen/SparseCUDAShortType.cpp, ../aten/src/ATen/SparseCUDAShortType.h                                                                                                                                                                                                                                                                                                                                                                      
[ 12%] Building CXX object third_party/ideep/mkl-dnn/src/CMakeFiles/mkldnn.dir/common/batch_normalization.cpp.o                                                                                                                                                                                                                                                                              
Scanning dependencies of target mkalias                                                                                                                                                                                                                                                                                                                                                      
Scanning dependencies of target mkrename                                                                                                                                                                                                                                                                                                                                                     
[ 12%] Building C object sleef/src/libm/CMakeFiles/mkalias.dir/mkalias.c.o                                                                                                                                                                                                                                                                                                                   
[ 12%] Building C object sleef/src/libm/CMakeFiles/mkrename.dir/mkrename.c.o                                                                                                                                                                                                                                                                                                                 
[ 12%] Linking C executable ../../bin/mkalias                                                                                                                                                                                                                                                                                                                                                
[ 12%] Linking C executable ../../bin/mkrename                                                                                                                                                                                                                                                                                                                                               
[ 12%] Built target mkalias                                                                                                                                                                                                                                                                                                                                                                  
[ 12%] Building CXX object third_party/ideep/mkl-dnn/src/CMakeFiles/mkldnn.dir/common/convolution.cpp.o                                                                                                                                                                                                                                                                                      
[ 12%] Built target mkrename                                                                                                                                                                                                                                                                                                                                                                 
[ 12%] Building CXX object third_party/ideep/mkl-dnn/src/CMakeFiles/mkldnn.dir/common/convolution_relu.cpp.o                                                                                                                                                                                                                                                                                 
In file included from /home/w/mpdj/pytorch/third_party/ideep/mkl-dnn/src/common/type_helpers.hpp:29:0,                                                                                                                                                                                                                                                                                       
                 from /home/w/mpdj/pytorch/third_party/ideep/mkl-dnn/src/common/batch_normalization.cpp:21:                                                                                                                                                                                                                                                                                  
/home/w/mpdj/pytorch/third_party/ideep/mkl-dnn/src/common/math_utils.hpp: In function ?int mkldnn::impl::math::ilog2q(size_t)?:                                                                                                                                                                                                                                                              
/home/w/mpdj/pytorch/third_party/ideep/mkl-dnn/src/common/math_utils.hpp:84:8: error: right shift count >= width of type [-Werror=shift-count-overflow]                                                                                                                                                                                                                                      
     CP(32); CP(16); CP(8); CP(4); CP(2); CP(1);                                                                                                                                                                                                                                                                                                                                             
        ^                                                                                                                                                                                                                                                                                                                                                                                    
/home/w/mpdj/pytorch/third_party/ideep/mkl-dnn/src/common/math_utils.hpp:83:55: note: in definition of macro ?CP?                                                                                                                                                                                                                                                                            
 #   define CP(pw) do { if (v >= (1ull << pw)) { v >>= pw; p += pw; } } while(0)                                                                                                                                                                                                                                                                                                             
                                                       ^~                                                                                                                                                                                                                                                                                                                                    
cc1plus: all warnings being treated as errors                                                                                                                                                                                                                                                                                                                                                
third_party/ideep/mkl-dnn/src/CMakeFiles/mkldnn.dir/build.make:62: recipe for target 'third_party/ideep/mkl-dnn/src/CMakeFiles/mkldnn.dir/common/batch_normalization.cpp.o' failed                                                                                                                                                                                                           
make[2]: *** [third_party/ideep/mkl-dnn/src/CMakeFiles/mkldnn.dir/common/batch_normalization.cpp.o] Error 1                                                                                                                                                                                                                                                                                  
make[2]: *** Waiting for unfinished jobs....                                                                                                                                                                                                                                                                                                                                                 
Scanning dependencies of target python_copy_files                                                                                                                                                                                                                                                                                                                                            
In file included from /home/w/mpdj/pytorch/third_party/ideep/mkl-dnn/src/common/type_helpers.hpp:29:0,                                                                                                                                                                                                                                                                                       
                 from /home/w/mpdj/pytorch/third_party/ideep/mkl-dnn/src/common/convolution.cpp:21:                                                                                                                                                                                                                                                                                          
/home/w/mpdj/pytorch/third_party/ideep/mkl-dnn/src/common/math_utils.hpp: In function ?int mkldnn::impl::math::ilog2q(size_t)?:                                                                                                                                                                                                                                                              
/home/w/mpdj/pytorch/third_party/ideep/mkl-dnn/src/common/math_utils.hpp:84:8: error: right shift count >= width of type [-Werror=shift-count-overflow]                                                                                                                                                                                                                                      
     CP(32); CP(16); CP(8); CP(4); CP(2); CP(1);                                                                                                                                                                                                                                                                                                                                             
        ^                                                                                                                                                                                                                                                                                                                                                                                    
/home/w/mpdj/pytorch/third_party/ideep/mkl-dnn/src/common/math_utils.hpp:83:55: note: in definition of macro ?CP?                                                                                                                                                                                                                                                                            
 #   define CP(pw) do { if (v >= (1ull << pw)) { v >>= pw; p += pw; } } while(0)                                                                                                                                                                                                                                                                                                             
                                                       ^~                                                                                                                                                                                                                                                                                                                                    
In file included from /home/w/mpdj/pytorch/third_party/ideep/mkl-dnn/src/common/type_helpers.hpp:29:0,                                                                                                                                                                                                                                                                                       
                 from /home/w/mpdj/pytorch/third_party/ideep/mkl-dnn/src/common/convolution_relu.cpp:21:                                                                                                                                                                                                                                                                                     
/home/w/mpdj/pytorch/third_party/ideep/mkl-dnn/src/common/math_utils.hpp: In function ?int mkldnn::impl::math::ilog2q(size_t)?:                                                                                                                                                                                                                                                              
/home/w/mpdj/pytorch/third_party/ideep/mkl-dnn/src/common/math_utils.hpp:84:8: error: right shift count >= width of type [-Werror=shift-count-overflow]                                                                                                                                                                                                                                      
     CP(32); CP(16); CP(8); CP(4); CP(2); CP(1);                                                                                                                                                                                                                                                                                                                                             
        ^                                                                                                                                                                                                                                                                                                                                                                                    
/home/w/mpdj/pytorch/third_party/ideep/mkl-dnn/src/common/math_utils.hpp:83:55: note: in definition of macro ?CP?                                                                                                                                                                                                                                                                            
 #   define CP(pw) do { if (v >= (1ull << pw)) { v >>= pw; p += pw; } } while(0)                                                                                                                                                                                                                                                                                                             
                                                       ^~                                                                                                                                                                                                                                                                                                                                    
cc1plus: all warnings being treated as errors                                                                                                                                                                                                                                                                                                                                                
third_party/ideep/mkl-dnn/src/CMakeFiles/mkldnn.dir/build.make:110: recipe for target 'third_party/ideep/mkl-dnn/src/CMakeFiles/mkldnn.dir/common/convolution_relu.cpp.o' failed                                                                                                                                                                                                             
make[2]: *** [third_party/ideep/mkl-dnn/src/CMakeFiles/mkldnn.dir/common/convolution_relu.cpp.o] Error 1                                                                                                                                                                                                                                                                                     
Scanning dependencies of target mkmasked_gnuabi                                                                                                                                                                                                                                                                                                                                              
[ 12%] Building C object sleef/src/libm/CMakeFiles/mkmasked_gnuabi.dir/mkmasked_gnuabi.c.o                                                                                                                                                                                                                                                                                                   
[ 12%] Linking C executable ../../bin/mkmasked_gnuabi                                                                                                                                                                                                                                                                                                                                        
cc1plus: all warnings being treated as errors                                                                                                                                                                                                                                                                                                                                                
third_party/ideep/mkl-dnn/src/CMakeFiles/mkldnn.dir/build.make:86: recipe for target 'third_party/ideep/mkl-dnn/src/CMakeFiles/mkldnn.dir/common/convolution.cpp.o' failed                                                                                                                                                                                                                   
make[2]: *** [third_party/ideep/mkl-dnn/src/CMakeFiles/mkldnn.dir/common/convolution.cpp.o] Error 1                                                                                                                                                                                                                                                                                          
CMakeFiles/Makefile2:1263: recipe for target 'third_party/ideep/mkl-dnn/src/CMakeFiles/mkldnn.dir/all' failed                                                                                                                                                                                                                                                                                
make[1]: *** [third_party/ideep/mkl-dnn/src/CMakeFiles/mkldnn.dir/all] Error 2                                                                                                                                                                                                                                                                                                               
make[1]: *** Waiting for unfinished jobs....                                                                                                                                                                                                                                                                                                                                                 
[ 12%] Built target mkmasked_gnuabi                                                                                                                                                                                                                                                                                                                                                          
[ 12%] Built target python_copy_files                                                                                                                                                                                                                                                                                                                                                        
[ 12%] Built target ATEN_CPU_FILES_GEN_TARGET                                                                                                                                                                                                                                                                                                                                                
Makefile:138: recipe for target 'all' failed                                                                                                                                                                                                                                                                                                                                                 
make: *** [all] Error 2                                                                                                                                                                                                                                                                                                                                                                      
Failed to run 'bash ../tools/build_pytorch_libs.sh --use-nnpack --use-mkldnn --use-qnnpack caffe2'     
```
---

Hopefully this report can be helpful, and ideas on how to work around be would much appreaciated :).


cc @malfet