什么是量化呢? [英] What does vectorization mean?
问题描述
这是个好主意,矢量化code?什么是在什么时候做方面的良好做法?下面会发生什么?
Is it a good idea to vectorize the code? What are good practices in terms of when to do it? What happens underneath?
推荐答案
矢量意味着编译器检测到您的独立指令为一体的 SIMD指令。通常的例子是,如果你做类似
Vectorization means that the compiler detects that your independent instructions can be executed as one SIMD instruction. Usual example is that if you do something like
for(i=0; i<N; i++){
a[i] = a[i] + b[i];
}
这将作为矢量(使用矢量标记)
It will be vectorized as (using vector notation)
for (i=0; i<(N-N%VF); i+=VF){
a[i:i+VF] = a[i:i+VF] + b[i:i+VF];
}
基本上编译挑选一人操作,可以对数组的元素VF在同一时间进行,这是否N / VF倍,而不是做单一的操作N次。
Basically the compiler picks one operation that can be done on VF elements of the array at the same time and does this N/VF times instead of doing the single operation N times.
这提高了性能,但穿上体系结构的详细要求。
It increases performance, but puts more requirement on the architecture.
这篇关于什么是量化呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!