昨天发的帖子被移到灌水专区,不知为何。
我想请教各位大牛,我有两个核函数a和b,分别被函数A和B调用,函数A中已经给各个全局变量申请显存
核函数b要处理核函数a生成的数据
经检查,核函数a生成的数据无错误,并且在函数A中并没有释放显存,且数据是全局变量,为什么函数B中的核函数b不能访问核函数a生成的数据?
cudaDeviceSynchronize函数显示核函数b出错,给出的错误代号是30,unknow error
出错的核函数b代码:
global void removeRedundantTrianglesKernel(bool *triangles1, float *triCenters1, float *triCenters2, size_t width, size_t height,float *K1, float *R1, float *T1, float *K2, float *R2, float *T2, float threshhold_r)
{
int x = threadIdx.x; // 得到线程索引
int y = blockIdx.x; // 得到块索引
// 首先判断是否是三角形
if (triangles1[y * width + x])
{
// 判断是否是边缘三角形,若是则投影到相邻深度图平面
if ((x == 0) || (y == 0) || !(triangles1[height * width + y * width + x] && triangles1[height * width + y * width + x - 1] && triangles1[height * width + (y - 1) * width + x]))
{
float depth = triCenters1[y * width + x];
float c1x = (x - K1[0]) * depth / K1[2] - T1[0];
float c1y = (y - K1[1]) * depth / K1[3] - T1[1];
float c1z = depth - T1[2];
float wx = R1[0] * c1x + R1[1] * c1y + R1[2] * c1z;
float wy = R1[3] * c1x + R1[4] * c1y + R1[5] * c1z;
float wz = R1[6] * c1x + R1[7] * c1y + R1[8] * c1z;
float d = R2[0] * R2[4] * R2[8] + R2[1] * R2[5] * R2[6] + R2[2] * R2[3] * R2[7] - R2[2] * R2[4] * R2[6] - R2[1] * R2[3] * R2[8] - R2[0] * R2[5] * R2[7];
float c2x = (wx * R2[4] * R2[8] + R2[1] * R2[5] * wz + R2[2] * wy * R2[7] - R2[2] * R2[4] * wz - R2[1] * wy * R2[8] - wx * R2[5] * R2[7]) / d;
float c2y = (R2[0] * wy * R2[8] + wx * R2[5] * R2[6] + R2[2] * R2[3] * wz - R2[2] * wy * R2[6] - wx * R2[3] * R2[8] - R2[0] * R2[5] * wz) / d;
float c2z = (R2[0] * R2[4] * wz + R2[1] * wy * R2[6] + wx * R2[3] * R2[7] - wx * R2[4] * R2[6] - R2[1] * R2[3] * wz - R2[0] * wy * R2[7]) / d;
float depth2 = c2z + T2[2];
int x2 = int((c2x + T2[0]) * K2[2] / depth2 + K2[0]);
int y2 = int((c2y + T2[1]) * K2[3] / depth2 + K2[1]);
// 投影到相机坐标系计算欧式距离
for (int i = y2 - 8; i <= y2 + 7; i++)
{
for (int j = x2 - 8; j <= x2 + 7; j++)
{
if (i >= 0 && i < 480 && j >= 0 && j < 640)
{
float tempDepth = triCenters2[i * width + j];
float tempx = (x2 + 0.5 - K2[0]) * tempDepth / K2[2] - T2[0];
float tempy = (y2 + 0.5 - K2[1]) * tempDepth / K2[3] - T2[1];
float tempz = tempDepth - T2[2];
if (getDistance(c2x, c2y, c2z, tempx, tempy, tempz) < threshhold_r)
{
triangles1[y * width + x] = false;
break;
}
}
}
}
}
}
}
调试发现,核函数中的矩阵数据均无法访问