首页 > 解决方案 > 如果我们在 CUDA/GPU 中为每个 warp 划分一个块,那么一个块中的所有 warp 都使用相同的共享内存

问题描述

如果我们在 CUDA/GPU 中为每个 warp 划分一个块,那么一个块中的所有 warp 都使用相同的共享内存。任何人都举一个例子或解释如何通过编码来编写它。像下面的代码是让线程确定它在网格和块中的位置。现在,我们如何将它划分为每个块的扭曲?

> @cuda.jit def my_kernel(io_array):
>     # Thread id in a 1D block
>     tx = cuda.threadIdx.x
>     # Block id in a 1D grid
>     ty = cuda.blockIdx.x
>     # Block width, i.e. number of threads per block
>     bw = cuda.blockDim.x
>     # Compute flattened index inside the array
>     pos = tx + ty * bw
>     if pos < io_array.size:  # Check array boundaries
>         io_array[pos] *= 2 # do the computation

标签: gpupycuda

解决方案


推荐阅读