mxnet
mxnet copied to clipboard
Add -march=native -mtune=native to config/config.cmake
Description
Add settings to config/config.cmake
to optimize for local CPU architecture.
Changes
- [X] Add -march=native -mtune=native to config/config.cmake
Comments
Related https://github.com/apache/incubator-mxnet/pull/17047
@TaoLv would providing different default config/config.cmake
files for different architectures with the respective compiler flags be an easier way forward than adding flags like USE_X86_ARCH
to the CMakeLists.txt
. What do you think?
For example, for ARM, the config file would instead contain
# CPU Architecture to optimize for. With default settings, your build may not
# work on earlier CPUs than the one used by the system you are compiling on.
# To work with older CPU, set the -march, -mtune variables below to the
# respective architecture name of the target CPU (see GCC documentation).
set(CMAKE_C_FLAGS "-mcpu=native" CACHE STRING "C compiler flags")
set(CMAKE_CXX_FLAGS "-mcpu=native" CACHE STRING "C++ compiler flags")
as per https://github.com/apache/incubator-mxnet/pull/17047#issuecomment-565274798, https://community.arm.com/developer/tools-software/tools/b/tools-software-ides-blog/posts/compiler-flags-across-architectures-march-mtune-and-mcpu
Thank you for adding this! This needs to modify the config.cmake carefully if we want to build binary for another platform, ie. using cmake for the convenient releases.
For the binary distribution I suggest to use another set of config files. Please take a look at https://github.com/apache/incubator-mxnet/pull/17448
It would also change the default behavior of cmake build - previously it can be built on a machine and run on a lower end machine, but now it probably will lead to illegal instruction error?
cmake -C ../config.cmake
didn't exist previously, in that sense we don't break the default behavior. The config file is a new feature in MXNet 1.7 and we're free to set the defaults (IMO).
You are right that there may be people that copy the config.cmake
file, don't read it and run into this issue when copying libmxnet.so
to a different computer.
We can comment out the lines introduced by this PR by default to decrease the likelihood of running into the issue you describe. Even thene https://github.com/apache/incubator-mxnet/issues/14664 would mean that libmxnet.so
would stop working on CPU without AVX.
Would you recommend to comment out the -march=native -mtune=native
by default?
@leezu Could you please rebase? Then we can merge if CI passes. Because I see the last validation is 7 days ago.
I plan to merge this after the static build instructions are improved.
As the staticbuild is now easy to do via python ci/build.py --platform centos7_cpu /work/runtime_functions.sh build_static_libmxnet cpu
, this PR is ready
@mxnet-bot run ci [windows-gpu]
Jenkins CI successfully triggered : [windows-gpu]