在 CUDA 文档中,特别是在设备管理部分的 CUDA Runtime API 中cudaSetDevice,它是这样写的
使用 cudaMallocHost() 或 cudaHostAlloc() 或 cudaHostRegister() 从该主机线程分配的任何主机内存都将具有与设备关联的生命周期
所以我的问题是:如果我使用cudaHostAlloc当前设备分配一个主机内存为 dev 0,然后将该主机内存传输到 dev 1 中的设备内存,是否有任何限制或问题?
当我阅读 Cuda-SDK 中的 nbody 代码时,我浏览了代码中的一些行,我发现它与他们在 GPUGems3“Fast N-Body Simulation with CUDA”中的论文有点不同。
我的问题是:首先,为什么blockIdx.x仍然涉及从全局加载内存到共享内存,如以下代码所示?
for (int tile = blockIdx.y; tile < numTiles + blockIdx.y; tile++)
{
sharedPos[threadIdx.x+blockDim.x*threadIdx.y] =
multithreadBodies ?
positions[WRAP(blockIdx.x + q * tile + threadIdx.y, gridDim.x) * p + threadIdx.x] : //this line
positions[WRAP(blockIdx.x + tile, gridDim.x) * p + threadIdx.x]; //this line
__syncthreads();
// This is the "tile_calculation" function from the GPUG3 article.
acc = gravitation(bodyPos, acc);
__syncthreads();
}
Run Code Online (Sandbox Code Playgroud)
根据论文,它不应该是这样的吗?我想知道为什么
sharedPos[threadIdx.x+blockDim.x*threadIdx.y] =
multithreadBodies ?
positions[WRAP(q * tile + threadIdx.y, gridDim.x) …Run Code Online (Sandbox Code Playgroud) cuda ×2