- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
从 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
最佳答案
如果您阅读随 CUDA 9RC 副本安装的 CUDA 9RC 编程指南(第 B.15 节),您将看到新的 __shfl_sync()
函数有一个额外的 mask
您没有考虑的参数:
CUDA 8:
int __shfl(int var, int srcLane, int width=warpSize);
T __shfl_sync(unsigned mask, T var, int srcLane, int width=warpSize);
^^^^^^^^^^^^^
The new *_sync shfl intrinsics take in a mask indicating the threads participating in the call. A bit, representing the thread's lane id, must be set for each participating thread to ensure they are properly converged before the intrinsic is executed by the hardware. All non-exited threads named in mask must execute the same intrinsic with the same mask, or the result is undefined.
$ cat t419.cu
#include <stdio.h>
__global__
static void shflTest(int lid){
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(0xFFFFFFFF, ivalue[0],5,32);
float x = reinterpret_cast<float*>(&ix)[0];
float y = reinterpret_cast<float*>(&iy)[0];
if(tid == lid){
printf("shfl tmp %d %d\n",ix,iy);
printf("shfl final %f %f\n",x,y);
}
}
int main()
{
shflTest<<<1,32>>>(0);
cudaDeviceSynchronize();
return 0;
}
$ nvcc -arch=sm_61 -o t419 t419.cu
t419.cu(10): warning: function "__shfl(int, int, int)"
/usr/local/cuda/bin/..//include/sm_30_intrinsics.hpp(152): here was declared deprecated ("__shfl() is deprecated in favor of __shfl_sync() and may be removed in a future release (Use -Wno-deprecated-declarations to suppress this warning).")
$ cuda-memcheck ./t419
========= CUDA-MEMCHECK
shfl tmp 1084437299 1084437299
shfl final 5.100000 5.100000
========= ERROR SUMMARY: 0 errors
$
关于CUDA 9 shfl 与 shfl_sync,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46345811/
从 CUDA 9 开始,不推荐使用 shfl 指令,应将其替换为 shfl_sync。 但是,当它们的行为不同时,我应该如何更换它们? 代码示例: __global__ static void shf
我读过 Shuffle Tips and Tricks论文,但我不确定如何将它应用到我继承的一些狡猾的代码中: extern __shared__ unsigned int lpSharedMem[]
我是一名优秀的程序员,十分优秀!