Compiling mxnet for C++ from source on Windows

My goal is to compile mxnet from source to get the mxnet.dll and mxnet.lib and then use mxnet with C++ under Windows. I have to note that this is the first time I am trying to compile a library from source and so far it hasn’t been much fun.

The compilation takes about 5-6 hours. When it’s complete i get the following error:

LINK : fatal error LNK1248: image size (97588000) exceeds maximum allowable size (80000000)

After researching about this error i found out that this is a limit the Windows compiler sets and i don’t think I can do anything about it.

There is another issue here with a similar question, but i don’t know what to do with the answer “try buildingin in the Release configuration”

Does this reduce the size of the image and where can i find the “Release configuration”.

I have done some research on the internet, but couldn’t find much information/resources about compiling for C++ on Window so this is forum is my last resort.

Here are the steps i have gone through with my attempts an compiling from source:

  • Downloaded CMake
  • Downloaded OpenCV
  • Downloaded OpenBlas
  • Set the environment variables: set OpenCV_DIR=C:\Program Files\opencv\build and
    set OpenBLAS_HOME=C:\Program Files\OpenBLAS
  • Downloaded CUDA and cuDNN
  • Cloned the git-repository: git clone https://github.com/apache/incubator-mxnet.git --recursive
  • Set the environment variables for cuDNN: set DCUDNN_INCLUDE=C:\Program Files\cuda\include and set DCUDNN_LIBRARY=C:\Program Files\cuda\lib\x64\cudnn.lib and set LD_LIBRARY_PATH=D:\.....\mxnet\lib
  • Created a “build” directory in the folder
  • Use Cmake: cmake -G "Visual Studio 15 2017 Win64" -T cuda=10.1,host=x64 -DUSE_CPP_PACKAGE=1 -DUSE_CUDA=1 -DUSE_CUDNN=1 -DUSE_NVRTC=1 -DUSE_OPENCV=1 -DUSE_OPENMP=1 -DUSE_BLAS=open -DUSE_LAPACK=1 -DUSE_DIST_KVSTORE=0 -DCUDA_ARCH_LIST=Common -DCUDA_TOOLSET=10.1 -DCUDNN_INCLUDE="C:\Program Files\cuda\include" -DCUDNN_LIBRARY="C:\Program Files\cuda\lib\x64\cudnn.lib" "D:\.....\mxnet"
  • Building the library with msbuild mxnet.sln /p:Configuration=Release;Platform=x64 /maxcpucount

So my questions are:

  • What is the “Release configuration” and where can i get it?
  • Is it possible to get the libmxnet.dll without compiling the source myself?
  • The fact that i can’t change some windows settings to successfully compile the library with my given steps seems strange to me. Have i interpreted this error wrong? and can i do something about it?

Any help would be much appreciated!

Hey PhilippeS. !
I also had a headache when trying to compile MXnet from source with C++ under Windows. I succeeded once one month ago without understanding why and how…

Comparing the steps you have done and thoose listed there, I do not know if you have M. Visual Studio 2015 or 2017.

Then, I used Cmake GUI (more user friendly to set your params and to follow if all is ok or not). It creates in the build dir a mxnet.sln, Visual Studio project.
By opening the project in Visual you can choose your configuration (Release or Debug). Normally the compilation, if ok, gives you the libmxnet.dll or .lib

I hope it can help you a bit.

1 Like

Understandable, it took me some time as well to compile MXNet in Windows, but it was much easier in Linux. I suggested a while back that MXNet should provide official nightly and release builds of the MXNet C++ library, like other DL frameworks: Why no C++ love

Your error seems like you’re running out of disk space.
If you run out of RAM during compilation, then you can try to reduce the number of build threads.

If you are fine with using docker, then you can try out the official NVIDIA MXNet docker image.
The shared library within the docker container supports the C++ API as well as tensorRT.

The libmxnet.dll with C++ support (MXNet 1.4.1, CUDA 10.1, cuDNN v7.5.1.10, openBlas, no OpenCV) is also included in the latest CrazyAra release 0.6.0.

In the following you can find additional build instructions for Windows:

Best regards,
~QueensGambit

1 Like

Thanks for the answers @MarieL and @QueensGambit. Sadly i had to temporarily stop the project, because it is part of my diploma thesis and I had already invested too much time trying to set it up and had to focus on other parts. I will eventually have come back to it in a few weeks and try it again with the tips you gave me.

If I eventually succeed to get it to run on windows i am going to reply to this post and explain the steps I have done to maybe help people who run into the same issues in the future.

Till then wish me luck :slight_smile:

Thanks againg to @MarieL and @QueensGambit for taking the time to reply to my post!

I finally succeeded in building the library from source thanks to the link @QueensGambit provided: https://github.com/QueensGambit/CrazyAra-Engine/wiki/Compile-instructions-for-Windows

In my original attempt I used a CMAKE configuration, which was not optimized to my system.

I added the option -DCMAKE_BUILD_TYPE=Release to only build the Release configuration.

I also added -DCUDA_ARCH_LIST=Pascal and this solved my original issue with the LNK1248 error. With this option the library gets built only for the specific GPU architecture I am using. Thus the resulting .dll is a lot smaller.

My final CMAKE command looked like this:

cmake -G "Visual Studio 15 2017 Win64" -T cuda=10.1,host=x64^ -DCMAKE_BUILD_TYPE=Release -DUSE_CUDA=1 -DUSE_CUDNN=1 -DUSE_CPP_PACKAGE=1^ -DUSE_NVRTC=1 -DUSE_OPENCV=0 -DUSE_OPENMP=1 -DUSE_BLAS=open -DUSE_LAPACK=1^ -DUSE_DIST_KVSTORE=0 -DCUDA_ARCH_LIST=Pascal -DCUDA_TOOLSET=10.1^ -DCUDNN_INCLUDE="C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\include"^ -DCUDNN_LIBRARY="C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\lib\x64\cudnn.lib" ..

Then I built it with the following command:
msbuild mxnet.sln /p:Configuration=Release;Platform=x64 /maxcpucount

It took about 5 hours and the build was complete.

Then I ran into the issue that the op.h, which should be in mxnet/cpp-package/include/mxnet-cpp/op.h, was not generated when building the library.

To do this manually I went through the following steps:

  1. Use the tool dumpbin to analyze the dependecies of libmxnet.dll: dumpbin /dependents libmxnet.dll
  2. Making sure every library was reachable by including their directories into my PATH variable
  3. Executing mxnet\cpp-package\scripts\OpWrapperGenerator.py: python OpWrapperGenerator ..\..\build\Release\libmxnet.dll

Then I made a Visal Studio Project, included needed the libraries and include directories and it was finally working!