-
Notifications
You must be signed in to change notification settings - Fork 8
Compile C/C++ with march=native #118
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
Comments
I can add See https://stackoverflow.com/a/54163496 and https://stackoverflow.com/a/10134204 |
|
If
No, I wasn't worried about performance much. I'll try explaining my thoughts based on my limited knowledge around this area. Please bear with me and let me know if I'm misunderstanding. Assumptions:
I guess my third assumption was incorrect? Concern: Having code that depends on the current host VM CPU type. I don't change VM types often, but it's another variable that needs to be kept in mind if it was depended on, so I wanted to avoid it if possible (remember, I thought Just for an example, on Google Cloud, there are VM machine types that trades cost for less control, for example E2 that doesn't guarantee the processor types. If we used this machine type with I guess my point is that
Instead of |
To be clear, if you think |
I've never used it for anything serious, I've never even used C++ for anything serious, so don't just trust me. Yes, code compiled with
Partially... Now that I've found the
Yes, if it uses functions that use instruction sets that may of may not be available, but...
Things that work or don't work depending on the CPU model are already possible, even without the |
There should be no worrying about adding flags
|
@uniapi I don't see how any other
What circumstances are you talking about? It will only fail when there really is no AVX/AVX2 support. |
@error256
But everything is ok when i do compile with: Yes |
@uniapi First, it looks like you're using gcc. But the behavior should be the same: https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html
So I don't know how you got that error. Are you using a VM? Does |
This is not truth! Here is the option for
And this one for
So |
The OS should have support for AVX enabled. |
Interesting observation, but it doesn't change the fact that, according to the documentation, |
It's not a bug! It's because the OS support is not enabled for AVX2. And here the output you asked from
|
It means the behavior of |
Exactly! |
Here was the hack for old ubuntu and i try to find the similar hack for my os. |
Interesting topic and interesting find. Phoronix sometimes does benchmarks on compiler optimizations: C++ is a beast (not just) when it comes to optimizations. It is already annoying when challenge code passes or fails because of time constraint and being on a faster or slower machine. |
@Urfoex i just shared the link for those who may have similar problems... |
My suggestion is about enabling whatever the compiler thinks is available for the current system, not specifically about AVX/AVX2, which was supposed to be enabled automatically by that for any modern CPU. But it turns out it not necessarily is.
Does it even happen on Linux? (=> Is this observation even important in this context?) What exactly the OS support for AVX2 is and why can it even be turned off? Surely there must be a valid reason... |
Also this scenario is observed when running on Virtual Machines even though you have a cool CPU. But i have the same opinion that all instructions should be enabled but at least AVX/AVX2. So then (according to you) the best scenario is to parse the target architecture and inject it to the compiler -march flag. And it seems this is the best that we could have from the running CPU! |
OS, VM, whatever, the question still holds. Why doesn't the virtual machine report AVX2? Is there a reason? Is it an option? |
@error256 'm not sure about that for 100%. I do know that you won't be able to use XSAVE if using Hyper-V and also know that it's possible (at least it seems possible) to turn on AVX2 support with VboxManage. And yet! How did you succeed to use AVX2 intrinsics on Codewars? What constructions or attributes did you use? |
#118 (comment) |
@error256 thanks for your link! |
#113 reminded me about this thing... The target instruction set or architecture isn't specified now, so AVX intrinsics don't work in C++ and C
I think it would be reasonable to use
march=native
, which allows using available intrinsics and optimization for the current CPU architecture as well.The text was updated successfully, but these errors were encountered: