Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set -march/mcpu to native when building the runtime if no targets are set #50031

Merged
merged 2 commits into from
Aug 14, 2023

Conversation

gbaraldi
Copy link
Member

@gbaraldi gbaraldi commented Jun 1, 2023

@vchuravy noted that we don't set these flags even when building locally, even though we set the sysimg to native. This probably doesn't make too much of a difference but it might save a couple % on from source builds.

Also add the option to set mtune which is what GCC wants

@gbaraldi gbaraldi requested a review from staticfloat June 1, 2023 18:12
@gbaraldi gbaraldi changed the title Set march and friends to native when no targets are set Set -march/mcpu to native when building the runtime if no targets are set Jun 1, 2023
CC += -mtune=$(MTUNE)
CXX += -mtune=$(MTUNE)
FC += -mtune=$(MTUNE)
JULIA_CPU_TARGET ?= $(MTUNE)
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only thing I'm unsure about; can JULIA_CPU_TARGET take anything MTUNE can? Also, if the user set MARCH but not MTUNE, should we set JULIA_CPU_TARGET to something?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MTUNE behaves the same as MCPU so I assume so. And also maybe incorrectly if we set MARCH we just pass it to JULIA_CPU_TARGET.
I think they're all supported because it get's passed into a clang like command line.


#If nothing is set default to native
ifeq ($(MARCH)$(MCPU)$(MTUNE)$(JULIA_CPU_TARGET),)
MARCH=native
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think march=native doesn't exist on aarch64?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was an M1 issue but I have to check.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I don't have a reference at hand on the phone, but on aarch64 you shouldn't set march at all, that's wrong (besides march=native specifically giving an error)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is about mtune Vs march in general: https://lemire.me/blog/2018/07/25/it-is-more-complicated-than-i-thought-mtune-march-in-gcc/. But I'm pretty sure there was something about aarch64 specifically. In BinaryBuilder we don't use march for many arm targets https://github.com/JuliaPackaging/BinaryBuilderBase.jl/blob/8ce1e2700dae921aff69cd12b9aef4429913e90c/src/Platforms.jl#L118-L173

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From ARM itself they say march is fine.

As long as you’re not cross compiling, the simplest and easiest way to get the best performance on Arm with both GNU compilers and LLVM-compilers is to use only -mcpu=native and actively avoid using -mtune or -march.

-march=X: Tells the compiler that X is the minimal architecture the binary must run on. The compiler is free to use architecture-specific instructions. This flag behaves differently on Arm and x86. On Arm, -march does not override -mtune, but on x86 -march will override both -mtune and -mcpu.
-mtune=X: Tells the compiler to optimize for microarchitecture X but does not allow the compiler to change the ABI or make assumptions about available instructions. This flag has the more-or-less the same meaning on Arm and x86.
-mcpu=X: On Arm, this flag is a combination of -march and -mtune. It simultaneously specifies the target architecture and optimizes for a given microarchitecture. On x86 this flag is a deprecated synonym for -mtune.

@KristofferC
Copy link
Sponsor Member

Good to go?

@gbaraldi
Copy link
Member Author

IMO yes, it's probably not going to affect many people, but for those who build from source it might.

@KristofferC KristofferC merged commit 513336a into JuliaLang:master Aug 14, 2023
@KristofferC
Copy link
Sponsor Member

Let's try it then

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants