Skip to content

[Caffe2/Bug] Cannot enable MKL-DNN #11850

@jiecaoyu

Description

@jiecaoyu

Solution

A solution is found for the problem, but maybe a bug in Caffe2

MKL-DNN can be enabled by first compiling the PyTorch. Then turn on MKL by

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 827121b1f..235d00bd6 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -111,6 +111,7 @@ option(USE_SYSTEM_EIGEN_INSTALL
 option(USE_TENSORRT "Using Nvidia TensorRT library" OFF)
 option(USE_ZMQ "Use ZMQ" OFF)
 option(USE_ZSTD "Use ZSTD" OFF)
+option(USE_MKL "Use MKL" ON)
 option(USE_MKLDNN "Use MKLDNN" OFF)
 option(USE_IDEEP "Use IDEEP interface in MKL BLAS" ON)
 option(USE_MKLML "Use MKLML interface in MKL BLAS" ON)

and recompile PyTorch. Then MKL-DNN is enabled.

Issue description

Trying to accelerate caffe2 inference with MKL-DNN.

The MKL-DNN lib can be detected:

-- Found MKLDNN: /home/jiecaoyu/.local/include  
-- Found MKLDNN      (include: /home/jiecaoyu/.local/include, library: /home/jiecaoyu/.local/lib/libmkldnn.so)

But mkl operators are not compiled

-- Excluding mkl operators as we are not using mkl

And MKL-DNN cannot be found after installation since

from caffe2.python import workspace
workspace.C.has_mkldnn

returns False.

Also, I try to enable MKL by changing the CMakeLists.txt:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 827121b1f..235d00bd6 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -111,6 +111,7 @@ option(USE_SYSTEM_EIGEN_INSTALL
 option(USE_TENSORRT "Using Nvidia TensorRT library" OFF)
 option(USE_ZMQ "Use ZMQ" OFF)
 option(USE_ZSTD "Use ZSTD" OFF)
+option(USE_MKL "Use MKL" ON)
 option(USE_MKLDNN "Use MKLDNN" OFF)
 option(USE_IDEEP "Use IDEEP interface in MKL BLAS" ON)
 option(USE_MKLML "Use MKLML interface in MKL BLAS" ON)

It acutally cause an error:

...
/home/jiecaoyu/LIBS/pytorch/aten/src/TH/THAllocator.cpp:397:1: error: prototype for ‘THMapAllocator::THMapAllocator(WithFd, const char*, int, int)’ does not match any in class ‘THMapAllocator’
 THMapAllocator::THMapAllocator(WithFd, const char *filename, int fd, int flags) {
 ^~~~~~~~~~~~~~
In file included from /home/jiecaoyu/LIBS/pytorch/aten/src/TH/THAllocator.cpp:1:0:
/home/jiecaoyu/LIBS/pytorch/aten/src/TH/THAllocator.h:41:3: error: candidates are: THMapAllocator::THMapAllocator(THMapAllocator&&)
   THMapAllocator(THMapAllocator&&) = delete;
   ^~~~~~~~~~~~~~
/home/jiecaoyu/LIBS/pytorch/aten/src/TH/THAllocator.h:39:3: error:                 THMapAllocator::THMapAllocator(const THMapAllocator&)
   THMapAllocator(const THMapAllocator&) = delete;
   ^~~~~~~~~~~~~~
/home/jiecaoyu/LIBS/pytorch/aten/src/TH/THAllocator.h:38:3: error:                 THMapAllocator::THMapAllocator(WithFd, const char*, int, int, size_t)
   THMapAllocator(WithFd, const char *filename, int fd, int flags, size_t size);
   ^~~~~~~~~~~~~~
/home/jiecaoyu/LIBS/pytorch/aten/src/TH/THAllocator.cpp:393:1: error:                 THMapAllocator::THMapAllocator(const char*, int, size_t)
 THMapAllocator::THMapAllocator(const char *filename, int flags, size_t size) {
 ^~~~~~~~~~~~~~
/home/jiecaoyu/LIBS/pytorch/aten/src/TH/THAllocator.cpp:401:52: error: destructors may not have parameters
 THMapAllocator::~THMapAllocator(THMapAllocator* ctx) {}
                                                    ^
/home/jiecaoyu/LIBS/pytorch/aten/src/TH/THAllocator.cpp:401:1: error: redefinition of ‘THMapAllocator::~THMapAllocator()’
 THMapAllocator::~THMapAllocator(THMapAllocator* ctx) {}
 ^~~~~~~~~~~~~~
In file included from /home/jiecaoyu/LIBS/pytorch/aten/src/TH/THAllocator.cpp:1:0:
...

System Info

PyTorch version: 1.0.0a0+98aebed
Is debug build: No
CUDA used to build PyTorch: None

OS: Ubuntu 18.04.1 LTS
GCC version: (Ubuntu 7.3.0-16ubuntu3) 7.3.0
CMake version: version 3.10.2

Python version: 2.7
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] numpy (1.15.1)
[pip] torch (1.0.0a0+98aebed)
[conda] Could not collect

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions