Repository: pytorch
Issue: Caffe2 compiled with MKLDNN doesn't have device_type = MKLDNN
Labels: caffe2

## Issue description

Cannot use device_type = MKLDNN adter building Caffe2 from source with MKL and MKLDNN support.

```
self._device_opts = caffe2_pb2.DeviceOption()
self._device_opts.device_type = caffe2_pb2.MKLDNN
```

Then, when using RunNetOnce:

```
RuntimeError: [enforce fail at operator.cc:90] gDeviceTypeRegistry()->count(type). Device type mkldnn not registered.
```

Also
```
workspace.C.has_mkldnn
```

returns False.

## Installation process
1. Latest MKL installation:
```
wget https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS-2019.PUB \
    && apt-key add GPG-PUB-KEY-INTEL-SW-PRODUCTS-2019.PUB \
    && echo deb https://apt.repos.intel.com/mkl all main > /etc/apt/sources.list.d/intel-mkl.list \
    && apt-get update \
    && apt-get install -y intel-mkl-64bit-2019.0-045
```

2. Installing MKL-DNN from master to "/usr/local/mkl-dnn":
```
 git clone --depth 1 https://github.com/01org/mkl-dnn.git \
    && cd mkl-dnn/scripts && ./prepare_mkl.sh && cd .. \
    && mkdir -p build && cd build && mkdir -p /usr/local/mkl-dnn \
    && cmake -DCMAKE_INSTALL_PREFIX="/usr/local/mkl-dnn" .. \
    && make -j"$(nproc)" && make install \
    && cd ../../ && rm -rf mkl-dnn
```

```
ln -s /usr/local/mkl-dnn/lib/libmklml_intel.so /usr/local/lib/libmklml_intel.so \
    && ln -s /usr/local/mkl-dnn/lib/libmkldnn.so /usr/local/lib/libmkldnn.so \
    && ln -s /usr/local/mkl-dnn/lib/libiomp5.so /usr/local/lib/libiomp5.so \
    && ldconfig
```

3. Installing PyTorch & Caffe2 from master for CPU inference (without CUDA):
```
git clone --depth 1 --recursive https://github.com/pytorch/pytorch.git \
    && cd pytorch \
    && MKLDNN_HOME="/usr/local/mkl-dnn" FULL_CAFFE2=ON NO_CUDA=TRUE python3 setup.py install \
    && cd .. && rm -rf pytorch
```

4. Seems like MKL-DNN is correctly found:
```
-- Found a library with BLAS API (mkl).
-- Found a library with LAPACK API. (mkl)
disabling CUDA because NOT USE_CUDA is set
-- CuDNN not found. Compiling without CuDNN support
-- MIOpen not found. Compiling without MIOpen support
disabling ROCM because NOT USE_ROCM is set
-- Found MKLDNN: /usr/local/mkl-dnn/include  
-- Found MKLDNN      (include: /usr/local/mkl-dnn/include, library: /usr/local/mkl-dnn/lib/libmkldnn.so)
```

5. Whole summary:
```
-- 
-- ******** Summary ********
-- General:
--   CMake version         : 3.5.1
--   CMake command         : /usr/bin/cmake
--   Git version           : 76ab26c
--   System                : Linux
--   C++ compiler          : /usr/bin/c++
--   C++ compiler version  : 5.4.0
--   BLAS                  : MKL
--   CXX flags             : -msse3 -msse4.1 -msse4.2   --std=c++11  -fvisibility-inlines-hidden -D_FORCE_INLINES -D_MWAITXINTRIN_H_INCLUDED -D__STRICT_ANSI__ -fopenmp -O2 -fPIC -Wno-narrowing -Wall -Wextra -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wno-unused-function -Wno-unused-result -Wno-strict-overflow -Wno-strict-aliasing -Wno-error=deprecated-declarations -Wno-error=pedantic -Wno-error=redundant-decls -Wno-error=old-style-cast -Wno-unused-but-set-variable -Wno-maybe-uninitialized
--   Build type            : Release
--   Compile definitions   : ONNX_NAMESPACE=onnx_torch;USE_GCC_ATOMICS=1;TH_BLAS_MKL;HAVE_MMAP=1;_FILE_OFFSET_BITS=64;HAVE_SHM_OPEN=1;HAVE_SHM_UNLINK=1;HAVE_MALLOC_USABLE_SIZE=1
--   CMAKE_PREFIX_PATH     : /usr/lib/python3/dist-packages
--   CMAKE_INSTALL_PREFIX  : /pytorch/torch/lib/tmp_install
-- 
--   BUILD_ATEN_MOBILE     : OFF
--   BUILD_BINARY          : OFF
--   BUILD_CUSTOM_PROTOBUF : ON
--     Link local protobuf : ON
--   BUILD_DOCS            : OFF
--   BUILD_PYTHON          : ON
--     Python version      : 3.5.2
--     Python executable   : /usr/bin/python3
--     Pythonlibs version  : 3.5.2
--     Python library      : /usr/lib/python3.5
--     Python includes     : /usr/include/python3.5m
--     Python site-packages: lib/python3/dist-packages
--   BUILD_CAFFE2_OPS      : ON
--   BUILD_SHARED_LIBS     : ON
--   BUILD_TEST            : ON
--   USE_ASAN              : OFF
--   USE_CUDA              : 0
--   USE_ROCM              : OFF
--   USE_EIGEN_FOR_BLAS    : 
--   USE_FFMPEG            : OFF
--   USE_GFLAGS            : OFF
--   USE_GLOG              : OFF
--   USE_LEVELDB           : OFF
--   USE_LITE_PROTO        : OFF
--   USE_LMDB              : OFF
--   USE_METAL             : OFF
--   USE_MKL               : 
--   USE_MOBILE_OPENGL     : OFF
--   USE_NCCL              : OFF
--   USE_NERVANA_GPU       : OFF
--   USE_NNPACK            : 1
--   USE_OBSERVERS         : ON
--   USE_OPENCL            : OFF
--   USE_OPENCV            : OFF
--   USE_OPENMP            : OFF
--   USE_PROF              : OFF
--   USE_REDIS             : OFF
--   USE_ROCKSDB           : OFF
--   USE_ZMQ               : OFF
--   USE_DISTRIBUTED       : ON
--     USE_MPI             : ON
--     USE_GLOO            : ON
--     USE_GLOO_IBVERBS    : OFF
--   Public Dependencies  : Threads::Threads;caffe2::mkl
--   Private Dependencies : nnpack;cpuinfo;/usr/lib/x86_64-linux-gnu/libnuma.so;/usr/lib/openmpi/lib/libmpi_cxx.so;/usr/lib/openmpi/lib/libmpi.so;gloo;aten_op_header_gen;onnxifi_loader;rt;gcc_s;gcc;dl
-- Configuring done
-- Generating done
```

## System Info
PyTorch version: 1.0.0a0+76ab26c
Is debug build: No
CUDA used to build PyTorch: None

OS: Ubuntu 16.04.5 LTS
GCC version: (Ubuntu 5.4.0-6ubuntu1~16.04.10) 5.4.0 20160609
CMake version: version 3.5.1

Python version: 3.5
Is CUDA available: No
CUDA runtime version: No CUDA
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA

Versions of relevant libraries:
[pip] Could not collect
[conda] Could not collect