当前位置: 首页 > news >正文

浦东新区建设工程安全质量监督站网站做设计找图片的网站

浦东新区建设工程安全质量监督站网站,做设计找图片的网站,手机影视网站制作,中国互联网信息中心官网在CC3.0以上#xff0c;支持了shuffle指令#xff0c;允许thread直接读其他thread的寄存器值#xff0c;只要两个thread在 同一个warp中#xff0c;这种比通过shared Memory进行thread间的通讯效果更好#xff0c;latency更低#xff0c;同时也不消耗额外的内存资源来执行…在CC3.0以上支持了shuffle指令允许thread直接读其他thread的寄存器值只要两个thread在 同一个warp中这种比通过shared Memory进行thread间的通讯效果更好latency更低同时也不消耗额外的内存资源来执行数据交换。 这里介绍warp中的一个概念lane一个lane就是一个warp中的一个thread每个lane在同一个warp中由lane索引唯一确定因此其范围为[0,31]。在一个一维的block中可以通过下面两个公式计算索引 laneID threadIdx.x % 32 warpID threadIdx.x / 32 例如在同一个block中的thread1和33拥有相同的lane索引1。 Variants of the Warp Shuffle Instruction 有两种设置shuffle的指令一种针对整型变量另一种针对浮点型变量。每种设置都包含四种shuffle指令变量。为了交换整型变量使用过如下函数 参考书籍《cuda专家手册|GPU编程权威》 1_shfl_xor 首先介绍__shfl_xor因为最先用到它。 __shfl_xorvar,laneMaskCopy from a lane based on bitwise XOR of own lane ID 意思就是从当前的线程id与laneMak异或运算的值作为线程号的把这个线程号的var值取出来。 演示图 举例 tid 0 laneMask 16 tid xor laneMask(0000 xor 1000)011115 所有取到的值为15号线程的var 那我们看下完成测试代码 __global__ void test_shfl_xor(int A[], int B[]) {int tid threadIdx.x;int best B[tid];//best subgroup_min32(best, 0xffffffffu);best __shfl_xor(best, 8);A[tid] best; }int main() {int *A,*Ad, *B, *Bd;int n 32;int size n * sizeof(int);// CPU端分配内存A (int*)malloc(size);B (int*)malloc(size);for (int i 0; i n; i){B[i] rand()%101;std::cout B[i] std::endl;}std::cout ---------------------------- std::endl;// GPU端分配内存cudaMalloc((void**)Ad, size);cudaMalloc((void**)Bd, size);cudaMemcpy(Bd, B, size, cudaMemcpyHostToDevice);// 定义kernel执行配置1024*1024/512个block每个block里面有512个线程dim3 dimBlock(128);dim3 dimGrid(1000);// 执行kernelconst auto t1 std::chrono::system_clock::now();test__shfl_xor 1, 32 (Ad,Bd);cudaMemcpy(A, Ad, size, cudaMemcpyDeviceToHost);// 校验误差float max_error 0.0;for (int i 0; i 32; i){std::cout A[i] std::endl;}// 释放CPU端、GPU端的内存free(A); cudaFree(Ad);free(B);cudaFree(Bd); return 0; }运行结果 41 85 72 38 80 69 65 68 96 22 49 67 51 61 63 87 66 24 80 83 71 60 64 52 90 60 49 31 23 99 94 11 ---------------------------- 66 24 80 83 71 60 64 52 90 60 49 31 23 99 94 11 41 85 72 38 80 69 65 68 96 22 49 67 51 61 63 87 -------------------------------- 再高阶的用法求取线程束中最大值 template typename T, unsigned int GROUP_SIZE, unsigned int STEP struct subgroup_min_impl {static __device__ T call(T x, uint32_t mask) { #if CUDA_VERSION 9000x min(x, __shfl_xor_sync(mask, x, STEP / 2, GROUP_SIZE)); #elsex min(x, __shfl_xor(x, STEP / 2, GROUP_SIZE)); #endifreturn subgroup_min_implT, GROUP_SIZE, STEP / 2::call(x, mask);} }; template typename T, unsigned int GROUP_SIZE struct subgroup_min_implT, GROUP_SIZE, 1u {static __device__ T call(T x, uint32_t) {return x;} };template unsigned int GROUP_SIZE, typename T __device__ inline T subgroup_min(T x, uint32_t mask) {return subgroup_min_implT, GROUP_SIZE, GROUP_SIZE::call(x, mask); }__global__ void test__shfl_xor(int A[], int B[]) {int tid threadIdx.x;int best B[tid];best subgroup_min32(best, 0xffffffffu);//best __shfl_xor(best, 16);A[tid] best; }int main() {int *A,*Ad, *B, *Bd;int n 32;int size n * sizeof(int);// CPU端分配内存A (int*)malloc(size);B (int*)malloc(size);for (int i 0; i n; i){ B[i] rand()%101;std::cout B[i] std::endl;}std::cout ---------------------------- std::endl;// GPU端分配内存cudaMalloc((void**)Ad, size);cudaMalloc((void**)Bd, size);cudaMemcpy(Bd, B, size, cudaMemcpyHostToDevice); // 定义kernel执行配置1024*1024/512个block每个block里面有512个线程dim3 dimBlock(128);dim3 dimGrid(1000);// 执行kernelconst auto t1 std::chrono::system_clock::now();test_shfl_xor 1, 32 (Ad,Bd);cudaMemcpy(A, Ad, size, cudaMemcpyDeviceToHost);// 校验误差float max_error 0.0;for (int i 0; i 32; i){std::cout A[i] std::endl;}cout max error is max_error endl;// 释放CPU端、GPU端的内存free(A);free(B); cudaFree(Ad);cudaFree(Bd);return 0; } 运行结果 41 85 72 38 80 69 65 68 96 22 49 67 51 61 63 87 66 24 80 83 71 60 64 52 90 60 49 31 23 99 94 11 ---------------------------- 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 _shfl_xor介绍完毕 -------------------------------------- 2.__shfl() Direct copy from indexed lane复制lane id数据 __shfl(int var,int srclane,int width 32) 这个就是比较简单咱们直接上代码 __global__ void test_shfl(int A[], int B[]) {int tid threadIdx.x;int best B[tid];best __shfl(best, 3);A[tid] best; }int main() {int *A,*Ad, *B, *Bd;int n 32;int size n * sizeof(int);// CPU端分配内存A (int*)malloc(size);B (int*)malloc(size);for (int i 0; i n; i){ B[i] rand()%101;std::cout B[i] std::endl;}std::cout ---------------------------- std::endl;// GPU端分配内存cudaMalloc((void**)Ad, size);cudaMalloc((void**)Bd, size);cudaMemcpy(Bd, B, size, cudaMemcpyHostToDevice); // 定义kernel执行配置1024*1024/512个block每个block里面有512个线程dim3 dimBlock(128);dim3 dimGrid(1000);// 执行kernelconst auto t1 std::chrono::system_clock::now();test_shfl 1, 32 (Ad,Bd);cudaMemcpy(A, Ad, size, cudaMemcpyDeviceToHost);// 校验误差float max_error 0.0;for (int i 0; i 32; i){std::cout A[i] std::endl;}cout max error is max_error endl;// 释放CPU端、GPU端的内存free(A);free(B); cudaFree(Ad);cudaFree(Bd);return 0; } 按以上代码逻辑取得数据全是第3号线程的数 运行结果 41 85 72 38 80 69 65 68 96 22 49 67 51 61 63 87 66 24 80 83 71 60 64 52 90 60 49 31 23 99 94 11 ---------------------------- 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 -------------------------------------------------------------------------------------------------------------------------------- 3.__shfl_up() __shfl_up(int var,unsigned int delta,int width 32)Copy from a lane with lower ID relative to caller 把tid-delta的线程好的var复制给tid的 var如果tid-delta0var保持原来的值 见代码 __global__ void test_shfl_up(int A[], int B[]) {int tid threadIdx.x;int best B[tid];best __shfl_up(best, 3);A[tid] best; } 运行结果 41 85 72 38 80 69 65 68 96 22 49 67 51 61 63 87 66 24 80 83 71 60 64 52 90 60 49 31 23 99 94 11 ---------------------------- 41 85 72 41 85 72 38 80 69 65 68 96 22 49 67 51 61 63 87 66 24 80 83 71 60 64 52 90 60 49 31 23 -------------------------------------------------------------------------------------- 4.__shfl_down __shfl_down(int var,unsigned int delta,int width 32) 把tiddelta的线程好的var复制给tid的 var如果tiddelta32var保持原来的值 测试代码: __global__ void test_shfl_down(int A[], int B[]) {int tid threadIdx.x;int best B[tid];best __shfl_down(best, 3);A[tid] best; } 运行结果 41 85 72 38 80 69 65 68 96 22 49 67 51 61 63 87 66 24 80 83 71 60 64 52 90 60 49 31 23 99 94 11 ---------------------------- 38 80 69 65 68 96 22 49 67 51 61 63 87 66 24 80 83 71 60 64 52 90 60 49 31 23 99 94 11 99 94 11
http://www.yutouwan.com/news/426213/

相关文章:

  • 东莞网站推广推广软件多语言网站怎么实现的
  • 中建南方建设集团网站贵州省建设厅建筑质监站网站
  • 建好网站后访问科技成果转化平台
  • 江苏省住房和城市建设厅网站app手机网站建设
  • app网站开发者网站优化的文章
  • 网站建设开票项目是什么无极兼职网
  • 国内做的好看的网站设计德州app开发公司
  • wordpress 指定网站做优化的好处
  • 重庆江北网站建设如何用手机做钓鱼网站
  • 澧县网站设计企业基本信息查询系统
  • 学校建设网站的目的和意义杭州网站做的好公司哪家好
  • 襄樊门户网站建设学术网站建设
  • ipv6网站如何做设计模板怎么设置
  • 临沧永德网站建设电子商务公司在线平面设计软件免费版
  • 祥云户网站ps做网站时画布宽度
  • 基层建设检索网站代理网关app未运行
  • 手机网站营销中国机械工业建设集团有限公司网站
  • 东至网站制作wordpress中php代码只能一行一行写
  • 长沙做网站设计网站备案信息是什么
  • 网站开发和程序员网站建设如何去找客户
  • .net如何做网站三星官网网站
  • wordpress费用安卓系统优化软件
  • 大理网站推广网页模版是已经做好的
  • 上海企业网站建设费用小型网站的建设与开发
  • 手机网站 设置济南全包圆装修400电话
  • 建湖县建设局网站食品包装设计特点
  • 绮思网站建设qswoowordpress 结构解析
  • 做爰网站名称网站做短视频业务许可
  • 华为网站建设招聘做纺织外贸哪个贸易网站好
  • 北京网站建设报价明细软件设计说明书