In the last article "Source Compiling MXNet C++ api with OpenBlas under Windows 10", it was mentioned that you can compile and generate libmxnet with Openblas. To be honest, in my personal opinion, the difficulty is a little bit more difficult. The compatibility of Openblas under windows is really worrying. If you compile it by yourself, there are many minor problems. I may not write it so comprehensively. Although it has been successfully compiled, it is not that easy to use. Start with openblas to compile libmxnet. Online Relative introductions are relatively few.
Here we try MKL. Personally, I can only say that this is easier. In windows desktop computers, I recommend using MKL to compile. Intel has maintained its consistent strong support and compatibility for windows.
reference
https://github.com/apache/incubator-mxnet/issues/15632
This configuration is for your reference, but I took a look, this version is relatively old, and the usage is quite different from mine. You can combine it for reference. I will not repeat the contents. What I want to write below is all about my own configuration at compile time.
The last time the path of the Openblas version of mxnet was D:\devMXNet\apache-mxnet-151, this time I added an a at the end of the mkl version to show the path difference, as follows,
D:\devMXNet\apache-mxnet-151a
Regarding how to install vs2019, opencv these old talks will not be put here. You can refer to my previous article.
Modify the source code
As mentioned in the previous article, first you have to modify the source code (version 1.5.1 and below), mainly here
apache-mxnet-151a\include\mxnet\tuple.h
which sentence about _MSV_VER, change It looks like this (otherwise op.h cannot be generated correctly later)
namespace dmlc {
/*! \brief description for optional TShape */
DMLC_DECLARE_TYPE_NAME(optional<mxnet::TShape>, "Shape or None");
DMLC_DECLARE_TYPE_NAME(optional<mxnet::Tuple<int>>, "Shape or None");
// avoid low version of MSVC
#if !(defined(_MSC_VER) && _MSC_VER < 1900) //#if !defined(_MSC_VER)
template<typename T>
struct type_name_helper<mxnet::Tuple<T> > {
static inline std::string value() {
return "tuple of <" + type_name<T>() + ">";
}
};
#endif
} // namespace dmlc
Cmake-gui placement
Configuration result
There are a few warnings, ignore them.
Of course, if you must understand, you can go to https://github.com/apache/incubator-mxnet/issues to search for related topics. Most of the issues have been encountered.
In this way, after generating done, you can start generating all projects in vs2019. This time-consuming is very long, I didn't take a closer look at it, it took about 2 hours. In this process, the basic libmxnet.dll is generally generated without problems.
Similarly, in the end, because of the lack of op.h, those samples cannot be successfully compiled. At this time, op.h must be generated first.
Generate op.h
Put all *.dll files from the mkl installation directory
C:\IntelSWTools\compilers_and_libraries_2020.1.216\windows\redist\intel64_win\mkl
Copy to
D:\devMXNet\apache-mxnet-151a\cpp-package\scripts>
Note that my OpenCV_world430.dll is in an unrelated folder, probably because this place is set to the environment variable Path, depedencies are first found here.
In short, you have to let OpWrapperGenerator.py be able to find all the related dll files. It doesn't matter where they are, as long as they can be found.
Then generate op.h file (mx36gpu is my anaconda mxnet-gpu development environment)
(mx36gpu) D:\devMXNet\apache-mxnet-151a>cd /d D:\devMXNet\apache-mxnet-151a\cpp-package\scripts
(mx36gpu) D:\devMXNet\apache-mxnet-151a\cpp-package\scripts>python OpWrapperGenerator.py libmxnet.dll
(mx36gpu) D:\devMXNet\apache-mxnet-151a\cpp-package\scripts>
As mentioned above, the directory structure shown by myself, the generated files are finally here,
D:\devMXNet\apache-mxnet-151a\cpp-package\include\mxnet-cpp\op.h
Generate samples project
Then go back to vs2019, click "Generate" directly, and be careful not to click "Regenerate", otherwise you have to start from scratch again, and it will be gone for at least an hour.
At this time, you may still encounter some errors, such as unable to link to "mxnet_static.lib" or something. At this time, it is a BUG, similar to the following,
(Reference: https://github.com/apache/incubator-mxnet/issues/11628 )
13>LINK : fatal error LNK1104: cannot open file 'mxnet_static.lib'
15>LINK : fatal error LNK1104: cannot open file 'mxnet_static.lib'
14>LINK : fatal error LNK1104: cannot open file 'mxnet_static.lib'
16>LINK : fatal error LNK1104: cannot open file 'mxnet_static.lib'
18>LINK : fatal error LNK1104: cannot open file 'mxnet_static.lib'
19>LINK : fatal error LNK1104: cannot open file 'mxnet_static.lib'
17>LINK : fatal error LNK1104: cannot open file 'mxnet_static.lib'
20>LINK : fatal error LNK1104: cannot open file 'mxnet_static.lib'
12>LINK : fatal error LNK1104: cannot open file 'mxnet_static.lib'
Solution:
Put the file directly
D:\devMXNet\apache-mxnet-151a\dev\Release\libmxnet.lib
Copy to
D:\devMXNet\apache-mxnet-151a\devcpp\cpp-package\example\mxnet_static.lib
Note that the file name has been changed to mxnet_static.lib
Of course, you can go to the cmake configuration file to change it without too much trouble.
Successfully generated
Finally, I will cut a picture of all the 12 samples successfully generated for everyone, and I wish you all a successful compilation!