zoukankan      html  css  js  c++  java
  • CUDA Thread Indexing

    1D grid of 1D blocks
    
    __device__ int getGlobalIdx_1D_1D()
    {
    return blockIdx.x *blockDim.x + threadIdx.x;
    }
    
    
    
    1D grid of 2D blocks
    
    __device__ int getGlobalIdx_1D_2D()
    {
    return blockIdx.x * blockDim.x * blockDim.y + threadIdx.y * blockDim.x + threadIdx.x;
    }
    
    
    
    1D grid of 3D blocks
    
    __device__ int getGlobalIdx_1D_3D()
    {
    return blockIdx.x * blockDim.x * blockDim.y * blockDim.z 
    + threadIdx.z * blockDim.y * blockDim.x + threadIdx.y * blockDim.x + threadIdx.x;
    }
    
    {
    return blockIdx.x * blockDim.x * blockDim.y * blockDim.z 
    + threadIdx.z * blockDim.y * blockDim.x + threadIdx.y * blockDim.x + threadIdx.x;
    }
    
    
    
    2D grid of 1D blocks
    
     __device__ int getGlobalIdx_2D_1D()
    {
    int blockId   = blockIdx.y * gridDim.x + blockIdx.x; 
    int threadId = blockId * blockDim.x + threadIdx.x; 
    return threadId;
    }
    
    {
    int blockId   = blockIdx.y * gridDim.x + blockIdx.x; 
    int threadId = blockId * blockDim.x + threadIdx.x; 
    return threadId;
    }
    
    
    
    2D grid of 2D blocks  
    
    __device__ int getGlobalIdx_2D_2D()
    {
    int blockId = blockIdx.x + blockIdx.y * gridDim.x; 
    int threadId = blockId * (blockDim.x * blockDim.y) + (threadIdx.y * blockDim.x) + threadIdx.x;
    return threadId;
    }
    
    2D grid of 3D blocks
    
    __device__ int getGlobalIdx_2D_3D()
    {
    int blockId = blockIdx.x 
    + blockIdx.y * gridDim.x; 
    int threadId = blockId * (blockDim.x * blockDim.y * blockDim.z)
      + (threadIdx.z * (blockDim.x * blockDim.y))
      + (threadIdx.y * blockDim.x)
      + threadIdx.x;
    return threadId;
    }
    
    
    
    3D grid of 1D blocks
    
    __device__ int getGlobalIdx_3D_1D()
    {
    int blockId = blockIdx.x 
    + blockIdx.y * gridDim.x 
    + gridDim.x * gridDim.y * blockIdx.z; 
    int threadId = blockId * blockDim.x + threadIdx.x;
    return threadId;
    }
    
    
    
    3D grid of 2D blocks
    
    __device__ int getGlobalIdx_3D_2D()
    {
    int blockId = blockIdx.x 
            + blockIdx.y * gridDim.x 
    + gridDim.x * gridDim.y * blockIdx.z; 
    int threadId = blockId * (blockDim.x * blockDim.y)
     + (threadIdx.y * blockDim.x)
     + threadIdx.x;
    return threadId;
    }
    
    
    
    3D grid of 3D blocks
    
    __device__ int getGlobalIdx_3D_3D()
    {
    int blockId = blockIdx.x 
    + blockIdx.y * gridDim.x 
    + gridDim.x * gridDim.y * blockIdx.z; 
    int threadId = blockId * (blockDim.x * blockDim.y * blockDim.z)
     + (threadIdx.z * (blockDim.x * blockDim.y))
     + (threadIdx.y * blockDim.x)
     + threadIdx.x;
    return threadId;
    }
    

      

  • 相关阅读:
    Javascript知识汇总------手写图片上传插件
    Javascript知识汇总------面向对象手写弹窗插件
    Javascript知识汇总------面向对象手写拖拽插件
    Javascript知识汇总------获取构造函数constructor名称和一些字符串处理方法
    博客搬家啦
    NOI 2015 荷马史诗【BZOJ 4198】k叉Huffman树
    BZOJ 1044 木棍分割 解题报告(二分+DP)
    BZOJ 1051 最受欢迎的牛 解题报告
    BZOJ 2467 解题报告
    BZOJ 4619 Swap Space 解题报告
  • 原文地址:https://www.cnblogs.com/tibetanmastiff/p/4639194.html
Copyright © 2011-2022 走看看