Compiling TVM with MKLDNN Code Emit fails

I tried to compile TVM on Xubuntu 20.04 LTS with MKL and MKLDNN (DNNL) support.

To get it to work with the intel provided MKL I had to add another include directory to the CMakeList.

But the compilation fails with

/home/max/tvm_mkl/src/runtime/contrib/dnnl/dnnl_json_runtime.cc:52:15: warning: 'type_key' overrides a member function but is not marked 'override' [-Winconsistent-missing-override]
  const char* type_key() const { return "dnnl_json"; }
              ^

/home/max/tvm_mkl/src/runtime/contrib/dnnl/../json/json_runtime.h:58:15: note: overridden virtual function is here
  const char* type_key() const { return "json"; }
              ^

/home/max/tvm_mkl/src/runtime/contrib/dnnl/dnnl_json_runtime.cc:231:18: error: variable-sized object may not be initialized
      float bias[OC] = {0};
                 ^~

/home/max/tvm_mkl/src/runtime/contrib/dnnl/dnnl_json_runtime.cc:283:16: error: variable-sized object may not be initialized
    float bias[OC] = {0};
               ^~

1 warning and 2 errors generated.

Did you compile with C++11? The warnings and errors do not make sense to me.

I used LLVM10 with the provided cmake.config and make -j4 afterwards

I built it with LLVM 10 on Ubuntu 18.04 without any issue. Could you double check your environment? Here is my cmake log:

-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Build compiler with Relay VM profiler support...
-- Build with RPC support...
-- Build with Graph runtime support...
-- Build with Graph runtime debug support...
-- Build with Relay VM profiler support...
-- Build VTA runtime with target: sim
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Use llvm-config=/home/ubuntu/llvm10/bin/llvm-config
-- /home/ubuntu/llvm10/include
-- Found LLVM_INCLUDE_DIRS=/home/ubuntu/llvm10/include
-- Found LLVM_DEFINITIONS= -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
-- Found TVM_LLVM_VERSION=100
-- Build with LLVM
-- Set TVM_LLVM_VERSION=100
-- JAVA_HOME is not defined. Set it to ensure proper use
-- Using Java at /usr/bin/java
-- ANTLR4=/usr/bin/java;-jar;/usr/local/lib/antlr-4.7.1-complete.jar
-- Use BLAS library /opt/intel/mkl/lib/intel64/libmkl_rt.so
-- Build with DNNL JSON runtime: /usr/local/lib/libdnnl.so
-- Build with micro.standalone_runtime
-- Build with contrib.sort
-- Build with contrib.hybriddump
-- Performing Test SUPPORT_CXX14
-- Performing Test SUPPORT_CXX14 - Success
-- Building Relay in debug mode...
-- Building with TVM Map...
-- Build with thread support...
-- Check if compiler accepts -pthread
-- Check if compiler accepts -pthread - yes
-- Configuring done
-- Generating done

I forced CXX14 in CMake, but ended up with the same result

-- The C compiler identification is Clang 8.0.1
-- The CXX compiler identification is Clang 8.0.1
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Build with RPC support...
-- Build with Graph runtime support...
-- VTA build with VTA_HW_PATH=/home/max/tvm_mkl/3rdparty/vta-hw
-- Build VTA runtime with target: sim
-- Not found - LLVM_LIBS
-- Fall back to using llvm-config
-- Use llvm-config=llvm-config
-- /usr/lib/llvm-10/include
-- Found LLVM_INCLUDE_DIRS=/usr/lib/llvm-10/include
-- Found LLVM_DEFINITIONS= -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
-- Found TVM_LLVM_VERSION=100
-- Build with LLVM 10.0.0
-- Set TVM_LLVM_VERSION=100
-- Use BLAS library /usr/lib/x86_64-linux-gnu/libmkl_rt.so
-- Use MKLDNN library /usr/local/lib/libdnnl.so
-- Build with DNNL JSON runtime: /usr/local/lib/libdnnl.so
-- Build with contrib.sort
-- Build with contrib.hybriddump
-- Performing Test SUPPORT_CXX14
-- Performing Test SUPPORT_CXX14 - Success
-- Building with TVM Map...
-- Build with thread support...
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Check if compiler accepts -pthread
-- Check if compiler accepts -pthread - yes
-- Found Threads: TRUE  
-- Configuring done
-- Generating done
-- Build files have been written to: /home/max/tvm_mkl/build

but, the make process still fails with the same error message. I am on git c9c77c6b7, because I had some troubles with the latest changes regarding the runtime, which changed the bundle_deploy example (which I modified for some tests)

Ok, i retried it on a new Xubuntu 18.04 LTS installation and it seems to work flawless with MKL, MKL-DNN and DNNL codegen.

1 Like