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

avx512 for add_vectorexts #1613

Closed
xq114 opened this issue Aug 29, 2021 · 17 comments
Closed

avx512 for add_vectorexts #1613

xq114 opened this issue Aug 29, 2021 · 17 comments
Milestone

Comments

@xq114
Copy link
Contributor

xq114 commented Aug 29, 2021

你在什么场景下需要该功能?

当前的add_vectorexts("avx512")无法添加avx512的flag,只能手动加/arch:AVX512

描述可能的解决方案

add_vectorexts支持avx512

@waruqi
Copy link
Member

waruqi commented Aug 29, 2021

自己改下

function nf_vectorext(self, extension)

@xq114
Copy link
Contributor Author

xq114 commented Aug 29, 2021

看了下 https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html

MSVC的avx512就一个flag /arch:AVX512,但gcc的avx512有十几个flag;而且gcc推荐的方式是用-march=native开启所有可用的矢量扩展,不建议使用-mavx512f这样的flag,而不是msvc推荐的一个个设置扩展的flag、测试是否可用再加上。感觉这个差异太大,用add_vectorexts()来抽象avx512有点不太合适,应该有更好的设计。现在暂时用的判断

if is_plat("windows") then
	add_cxxflags("/arch:AVX512") -- leave detection to xmake
else
	add_cxxflags("-march=native")
end

@waruqi
Copy link
Member

waruqi commented Aug 29, 2021

不好抽象的话,就先外面设置下好了

@xq114
Copy link
Contributor Author

xq114 commented Apr 11, 2022

似乎有些cmake项目用-mavx512f -mavx512dq -mavx512bw -mavx512vl这几个flag同时存在来判断avx512,是否可以借鉴一下?

https://www.zhihu.com/question/433345697/answer/1611130480

根据这篇文章,这几个flag也是普通cpu主要支持的几个,其他很多是专业cpu才有

@waruqi
Copy link
Member

waruqi commented Apr 11, 2022

最近没啥空,如果好搞,就来个 pr 过来好了

@waruqi
Copy link
Member

waruqi commented Jul 26, 2023

gcc 用这个呢?-march=skylake-avx512

https://www.gnu.org/software/gcc/gcc-6/changes.html
https://stackoverflow.com/questions/57043592/compilation-error-for-avx512-is-it-a-gcc-issue

GCC now supports the Intel CPU named Skylake with AVX-512 extensions through -march=skylake-avx512. The switch enables the following ISA extensions: AVX-512F, AVX512VL, AVX-512CD, AVX-512BW, AVX-512DQ.

chatgpt 也推荐这个

@waruqi
Copy link
Member

waruqi commented Jul 26, 2023

我加上了,可以试试,sse4.2 顺带一起加了 #4012

xmake update -s github:xmake-io/xmake#avx512

@waruqi waruqi added this to the v2.8.2 milestone Jul 26, 2023
@xq114
Copy link
Contributor Author

xq114 commented Jul 26, 2023

gcc 用这个呢?-march=skylake-avx512

这个我觉得不太合适吧,arch指定为skylake-avx512意味着skylake-avx512之后的intrinsic都被禁用了,而且没法通过加flag开启,会有副作用。我觉得不如反向考虑,给windows加一个add_vectorexts("native")的选项,在非windows平台为-march=native,在windows上由xmake探测并加上支持到最高的simd扩展,类似set_languages("c++latest")。通用情况要avx512直接开native,有特殊需求手动加flag

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


What about gcc using this? -march=skylake-avx512

I don't think this is appropriate. The arch designation as skylake-avx512 means that the intrinsics after skylake-avx512 are disabled, and it cannot be enabled by adding a flag, which will have side effects. I think it is better to think in reverse, add an option of add_vectorexts("native") to windows, -march=native on non-windows platforms, and detect and add support to the highest simd extension on windows, similar to set_languages("c++latest"). In general, avx512 should be directly enabled native, and if there are special needs, manually add flag

@waruqi
Copy link
Member

waruqi commented Jul 26, 2023

gcc 用这个呢?-march=skylake-avx512

这个我觉得不太合适吧,arch指定为skylake-avx512意味着skylake-avx512之后的intrinsic都被禁用了,而且没法通过加flag开启,会有副作用。我觉得不如反向考虑,给windows加一个add_vectorexts("native")的选项,在非windows平台为-march=native,在windows上由xmake探测并加上支持到最高的simd扩展,类似set_languages("c++latest")。通用情况要avx512直接开native,有特殊需求手动加flag

那这个 native 的语义不是就是 all 么。。那直接用 add_vectorexts("all") 应该会更好些,也更直观。设置 vectorexts 本身就是 native 了,用 native 有点歧义。

@waruqi
Copy link
Member

waruqi commented Jul 26, 2023

我改了下,再看看呢。。

add_vectorexts("avx512")

默认 gcc 下,我暂时加了 "-mavx512f", "-mavx512dq", "-mavx512bw", "-mavx512vl" 这四个,实际会自动检测支持力度来过滤掉当前 gcc 不支持的。

然后额外加了个 all,gcc 下对标 -march=native,msvc 下,加上了全部

add_vectorexts("all")

@xq114
Copy link
Contributor Author

xq114 commented Jul 26, 2023

那这个 native 的语义不是就是 all 么。。

主要是有的avx指令当前平台不支持,-march=native只在支持avx512的平台开启avx512,就像c++latest也不一定是c++23

@waruqi
Copy link
Member

waruqi commented Jul 26, 2023

那这个 native 的语义不是就是 all 么。。

主要是有的avx指令当前平台不支持,-march=native只在支持avx512的平台开启avx512,就像c++latest也不一定是c++23

所以它这个 native 的语义很晦涩,xmake 里面还是用 all 更贴切直观。。就是尽可能开启全部能支持的 simd 指令。。内部到底用 -march:native ,或者改成其他的,或者加其他组合,都可以随时变,并不是跟 -march=native 强绑定的

@waruqi
Copy link
Member

waruqi commented Jul 26, 2023

如果现在这个 patch 没啥问题,我就先 merge 了

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Isn't the semantics of this native just all? .

The main reason is that some avx instructions are not supported by the current platform. -march=native only enables avx512 on platforms that support avx512, just like c++latest is not necessarily c++23

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Then the semantics of this native is not all. .

The main reason is that some avx instructions are not supported by the current platform, -march=native only enables avx512 on platforms that support avx512, just like c++latest is not necessarily c++23

So the semantics of its native is very obscure, and it is more appropriate and intuitive to use all in xmake. . It is to enable all supported simd instructions as much as possible. . Use -march:native internally, or change it to other, or add other combinations, it can be changed at any time, and it is not strongly bound to -march=native

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


If there is nothing wrong with this patch now, I will merge it first

@waruqi waruqi closed this as completed Jul 26, 2023
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

No branches or pull requests

3 participants