Notes about using mxnet-cpp and libtorch

Get mxnet-cpp library without building from source

Download the mxnet python package and extract .so libraries

For example, CUDA10 is installed in my computer, so I download the mxnet-cu100(1.4.0.post0) package from pip and extract all .so files from the python wheel file.

Generate the mxnet-cpp include files

1
2
git clone --recursive https://github.com/apache/incubator-mxnet mxnet
cd mxnet

Checkout the source version same with the python package download before. Then, follow the instruction in official building mxnet-cpp package guide

You don’t have to do the whole building process. After run the cmake command, some mxnet-cpp inlcude files are generated, then you can stop the building process.

copy inlcude files

1
2
3
4
5
6
7
8
9
# under mxnet source root
mkdir ../inlcude
cp -r cpp-package/include/mxnet-cpp ../include
cp -r include/mxnet ../include
cp -r 3rdparty/tvm/nnvm/include/nnvm ../include
cp -r 3rdparty/dmlc-core/include/dmlc ../include
cp -r 3rdparty/dlpack/include/dlpack ../include
cp -r 3rdparty/mkldnn/include ../include/mkldnn
cp -r 3rdparty/mshadow/mshadow ../include

Glog does not logging correctly after adding mxnet

After reading the file(mxnet/include/dmlc/logging.h), the solution is to
add the following codes before include any mxnet include files:

1
2
#define DMLC_USE_GLOG
#define LG LOG(INFO)

Glog does not logging correctly after adding libtorch

After reading the file(libtorch/include/c10/util/Logging.h), the solution is to
define C10_USE_GLOG before include any torch include files.