The*_*ine 2 optimization performance cuda
我有两个大向量,我试图进行某种元素乘法,其中第一个向量中的偶数元素乘以第二个向量中的下一个奇数元素...并且奇数元素的位置第一个向量中的第一个向量乘以第二个向量中的前一个偶数元素.
例如:
向量1是V1(1)V1(2)V1(3)V1(4)
向量2是V2(1)V2(2)V2(3)V2(4)
V1(1)*V2(2)
V1(3) )*V2(4)
V1(2)*V2(1)
V1(4)*V2(3)
我已经编写了Cuda代码来执行此操作(Pds具有共享内存中第一个向量的元素,Nds是第二个向量):
// instead of % 2, checking the first bit to decide if a number
// is odd/even is faster
if ((tx & 0x0001) == 0x0000)
Nds[tx+1] = Pds[tx] * Nds[tx+1];
else
Nds[tx-1] = Pds[tx] * Nds[tx-1];
__syncthreads();
Run Code Online (Sandbox Code Playgroud)
反正是否有进一步加速此代码或避免分歧?
你应该能够像这样消除分支:
int tx_index = tx ^ 1; // equivalent to: tx_index = (tx & 1) ? tx - 1 : tx + 1
Nds[tx_index] = Pds[tx] * Nds[tx_index];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
661 次 |
| 最近记录: |