我一直在努力解决一个我似乎无法找到解决方案的问题。 问题是,当我尝试在Visual Studio 2008下使用Nvidia Nsight调试我的CUDA代码时,使用共享内存时会得到奇怪的结果。
我的代码是:
template<typename T>
__device__
T integrate()
{
extern __shared__ T s_test[]; // Dynamically allocated shared memory
/**** Breakpoint (1) here ****/
int index = threadIdx.x + threadIdx.y * blockDim.x; // Local index in block. Column major ordering
if(index < 64 && blockIdx.x==0) { // Only work on a few values. Just testing
s_test[index] = (T)index;
/* Some other irelevant code here */
}
return v;
}
当我到达断点1并检查Visual Studio Watch窗口内的共享内存时,只有数组的前8个值发生变化,其他值保持为空。我希望所有前64名都这样做。
我认为它可能与所有不同时执行的warp有关。所以我尝试了同步它们。我在integrate()
template<typename T>
__device__
T integrate()
{
/* Old code is still here */
__syncthreads();
/**** Breakpoint (2) here ****/
if(index < 64 && blockIdx.x==0) {
T tmp = s_test[index]; // Write to tmp variable so I can inspect it inside Nsight Watch window
v = tmp + index; // Use `tmp` and `index` somehow so that the compiler doesn't optimize it out of existence
}
return v;
}
但问题仍然存在。此外,tmp中的其余值不是0
,因为监视窗口形式VS指示。
我必须提到跨步__syncthreads()
需要很多步骤,所以当我到达它时,我只是跳到断点2.发生什么事了!?
编辑有关系统/启动配置的信息
系统
设备 GeForce 9500 GT
IDE
编译器命令
1&GT; “C:\ Program Files \ NVIDIA GPU Computing Toolkit \ CUDA \ v4.2 \ bin \ nvcc.exe”-G -gencode = arch = compute_10,code = \“sm_10,compute_10 \” - machine 32 -ccbin“C :\ Program Files \ Microsoft Visual Studio 9.0 \ VC \ bin“-D_NEXUS_DEBUG -g -D_DEBUG -Xcompiler”/ EHsc / W3 / nologo / Od / Zi / RTC1 / MDd“-I”inc“-I”C:\ Program Files \ NVIDIA GPU Computing Toolkit \ CUDA \ v4.2 \ include“-maxrregcount = 0 --compile -o”Debug / process_f2f.cu.obj“process_f2f.cu
启动配置。共享内存大小似乎并不重要。我试过几个版本。我与之合作最多的是:
答案 0 :(得分:1)
您在分配值后是否尝试过 __ syncthreads()?
template<typename T>
__device__
T integrate()
{
extern __shared__ T s_test[]; // Dynamically allocated shared memory
int index = threadIdx.x + threadIdx.y * blockDim.x; // Local index in block. Column major ordering
if(index < 64 && blockIdx.x==0) { // Only work on a few values. Just testing
s_test[index] = (T)index;
/* Some other irelevant code here */
}
__syncthreads();
/**** Breakpoint (1) here ****/
return v;
}
尝试在此断点处查看值。