AVX512CD 指令系列包括:VPCONFLICT、VPLZCNT 和 VPBROADCASTM。
The Wikipedia section about these instruction说:
The instructions in AVX-512 conflict detection (AVX-512CD) are designed to help efficiently calculate conflict-free subsets of elements in loops that normally could not be safely vectorized.
有哪些示例表明这些指令在矢量化循环中很有用?如果答案包含标量循环及其矢量化对应部分,将会很有帮助。
谢谢!
最佳答案
CD 指令可能有用的一个示例是直方图。对于标量代码,直方图只是一个简单的循环,如下所示:
load bin index
load bin count at index
increment bin count
store updated bin count at index
通常你不能矢量化直方图,因为你可能在一个向量中多次具有相同的 bin 索引 - 你可能会天真地尝试这样的事情:
load vector of N bin indices
perform gathered load using N bin indices to get N bin counts
increment N bin counts
store N updated bin counts using scattered store
但如果向量中的任何索引相同,则会出现冲突,并且生成的 bin 更新将不正确。
所以,CD 指令可以解决这个问题:
load vector of N bin indices
use CD instruction to test for duplicate indices
set mask for all unique indices
while mask not empty
perform masked gathered load using <N bin indices to get <N bin counts
increment <N bin counts
store <N updated bin counts using masked scattered store
remove non-masked indices and update mask
end
实际上,这个示例效率很低,并不比标量代码更好,但还有其他计算密集型示例,在这些示例中使用 CD 指令似乎是值得的。通常,这些都是模拟,其中数据元素将以非确定性方式更新。 LAMMPS Molecular Dynamics Simulator 中引用了一个示例(来自 KNL book by Jeffers et al ) .
关于x86 - 冲突检测指令如何使循环矢量化变得更容易?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39913707/