自CUDA 9以来,shfl指令已被弃用,应该用shfl_sync替换。但是它们的行为不同,我该如何替换它们呢?
代码示例:
代码示例:
__global__
static void shflTest(){
int tid = threadIdx.x;
float value = tid + 0.1f;
int* ivalue = reinterpret_cast<int*>(&value);
//use the integer shfl
int ix = __shfl(ivalue[0],5,32);
int iy = __shfl_sync(ivalue[0],5,32);
float x = reinterpret_cast<float*>(&ix)[0];
float y = reinterpret_cast<float*>(&iy)[0];
if(tid == 0){
printf("shfl tmp %d %d\n",ix,iy);
printf("shfl final %f %f\n",x,y);
}
}
int main()
{
shflTest<<<1,32>>>();
cudaDeviceSynchronize();
return 0;
}
输出:
shfl tmp 1084437299 5
shfl final 5.100000 0.000000
shfl_xx_sync(0xFFFFFFFF,...)
替换所有的shfl_xx(...)
是否安全? - dari0xFFFFFFFF
。简而言之,掩码参数和宽度参数大多是相互独立的。 - Robert Crovella