mxnet icon indicating copy to clipboard operation
mxnet copied to clipboard

Add -march=native -mtune=native to config/config.cmake

Open leezu opened this issue 4 years ago • 9 comments

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

leezu avatar Jan 29 '20 05:01 leezu

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.

TaoLv avatar Jan 29 '20 13:01 TaoLv

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

leezu avatar Jan 29 '20 17:01 leezu

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?

TaoLv avatar Jan 30 '20 01:01 TaoLv

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 avatar Jan 30 '20 02:01 leezu

@leezu Could you please rebase? Then we can merge if CI passes. Because I see the last validation is 7 days ago.

TaoLv avatar Feb 05 '20 15:02 TaoLv

I plan to merge this after the static build instructions are improved.

leezu avatar Feb 21 '20 19:02 leezu

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

leezu avatar Sep 25 '20 19:09 leezu

@mxnet-bot run ci [windows-gpu]

leezu avatar Sep 28 '20 18:09 leezu

Jenkins CI successfully triggered : [windows-gpu]

mxnet-bot avatar Sep 28 '20 18:09 mxnet-bot