【有奖问答】cuda 与 显卡 之间有相互制约吗?

cuda 程序的运行与显卡之间有相互影响吗?我的cuda Toolkit是2.0的, 而以前的程序似乎也没有发现过这种bug,不解中,望高手指点

现在程序的问题是: 同样的函数(仅包含数据处理段,包含了二三十个核函数的处理过程,所有的显存分配及释放在程序启动和退出时进行)在华硕GT240以及丽台GTS250上循环运行(以每秒调用15次的速率进行,)。
安装250的平台上在运行一段时间之后(时间不固定,可能1-2小时,可能3-4小时)报unspecified launch failure的错误,而该错误一旦出现,该核函数以后所有的cuda函数(包括cudaMemcpy)都将报错,且报错相同为:unspecified launch failure。
而GT240还没有发现此bug(最长一次测试运行了超过两天的时间)。

检查错误的函数如下:
bool CheckCudaErr(char* info)
{
cudaError_t cudaErr = cudaSuccess;
cudaErr = cudaGetLastError();
if (cudaErr != cudaSuccess)
{
CString str;
str.Format(“%s : %s \n”,info,cudaGetErrorString(cudaErr));
TRACE0(str);
g_AlgLog.Write(str);
return true;
}
cudaErr = cudaThreadSynchronize();
if (cudaErr != cudaSuccess)
{
CString str;
str.Format(“%s : %s\n”,info,cudaGetErrorString(cudaErr));
TRACE0(str);
g_AlgLog.Write(str);
return true;
}
return false;
}

检查错误的时机是每个核函数之后及需要的地方调用:
CheckCudaErr(“positonXX”);

比较常见的报错的核函数及使用方式是:(注Expand是处理段中的一个流程)
void Expand(float* pSrc, float* pDest
,float* pIntpZero, float* pExpandX
,int nHeightDest, int nWidthDest)
{
dim3 ts(16,16);
dim3 bsExpand(iDivUp(nWidthDest,ts.x),iDivUp(nHeightDest,ts.y));

cudaBindTexture(0, texReduce, pSrc);
IntpZero_1<<<bsExpand,ts>>>(pIntpZero, nHeightDest, nWidthDest);
CheckCudaErr(“IntpZero_1::”);
cudaUnbindTexture(texReduce);

cudaBindTexture(0, texReduce, pIntpZero);
Expandx_2<<<bsExpand,ts>>>(pExpandX, nHeightDest, nWidthDest);
CheckCudaErr("Expandx_2:: ");
cudaUnbindTexture(texReduce);

cudaBindTexture(0, texReduce, pExpandX);
Expandy_2<<<bsExpand,ts>>>(pDest, nHeightDest, nWidthDest);
CheckCudaErr("Expandy_2:: ");
cudaUnbindTexture(texReduce);

}

texture<float, 1, cudaReadModeElementType> texReduce;

global static void IntpZero_1(float* d_intpZero, int nHeight, int nWidth)
{
const int ix = blockIdx.x * blockDim.x + threadIdx.x;
const int iy = blockIdx.y * blockDim.y + threadIdx.y;

if(ix<nWidth && iy<nHeight)
{
float temp = 0;
if( (ix&1) && (iy&1))
{
temp = tex1Dfetch(texReduce, (int(iy0.5))(int(nWidth0.5))+(int(ix0.5)));
}
//__syncthreads();
d_intpZero[iy*nWidth+ix] = temp;
}
}

global static void Expandx_2(float* d_Expandx, int nHeight, int nWidth)
{
const int ix = blockIdx.x * blockDim.x + threadIdx.x;
const int iy = blockIdx.y * blockDim.y + threadIdx.y;

int ix_1 = ((ix==0)? 1 : (ix-1));//max(0,ix-1);
int ix1 = ((ix==(nWidth-1))? (nWidth-2) : (ix+1));//min(nWidth-1,ix+1);

if(ix<nWidth && iy<nHeight)
{
float temp = 0.25 * tex1Dfetch(texReduce, iynWidth+ix_1) +
0.5 * tex1Dfetch(texReduce, iy
nWidth+ix) +
0.25 * tex1Dfetch(texReduce, iynWidth+ix1);
d_Expandx[iy
nWidth + ix] = temp;
}
//__syncthreads();
}
global static void Expandy_2(float* d_Expandy, int nHeight, int nWidth)
{
const int ix = blockIdx.x * blockDim.x + threadIdx.x;
const int iy = blockIdx.y * blockDim.y + threadIdx.y;

int iy_1 = ((iy==0)? 1 : (iy-1));//max(0,iy-1);
int iy1 = ((iy==(nHeight-1))? (nHeight-2) : (iy+1));//min(nHeight-1,iy+1);

if(ix<nWidth && iy<nHeight)
{
float temp = 0.25 * tex1Dfetch(texReduce, (iy_1)nWidth+ix) +
0.5 * tex1Dfetch(texReduce, iy
nWidth+ix) +
0.25 * tex1Dfetch(texReduce, (iy1 )nWidth+ix);
//__syncthreads();
d_Expandy[ iy
nWidth + ix] = 4*temp;
}

}

另外需要请教的是:在核函数中的if(ix<nWidth && iy<nHeight)中加入“ __syncthreads();”会影响程序执行吗?会影响程序的效率吗?
在测试的过程中,似乎把它屏蔽掉之后,开始说的bug的出现时间有所延长。

[ 本帖最后由 llh0415 于 2010-7-8 16:33 编辑 ]