我试图逐帧处理视频。为此,我想创建一个包含当前帧的纹理并将其传递给内核。帧是1440×1080像素,每个像素由无符号字符表示,例如, 8位。
我按照说明操作,但是我的程序总是在创建纹理的位置失败。错误代码0x11:"无效的参数"。
这是我的代码:
// allocate cuda array in device memory
cudaChannelFormatDesc channelDesc =
cudaCreateChannelDesc(8, 0, 0, 0, cudaChannelFormatKindUnsigned);
cudaArray* cuArray;
cudaMallocArray(&cuArray, &channelDesc, width, height);
// copy frame_in to device memory
int size = width * height * sizeof(char);
cudaMemcpyToArray(cuArray, 0, 0, frame_in.data, size, cudaMemcpyHostToDevice);
// specify texture
cudaResourceDesc resDesc;
memset(&resDesc, 0, sizeof(resDesc));
resDesc.resType = cudaResourceTypeArray;
resDesc.res.array.array = cuArray;
// specify texture object parameters
cudaTextureDesc texDesc;
texDesc.addressMode[0] = cudaAddressModeWrap;
texDesc.addressMode[1] = cudaAddressModeWrap;
texDesc.filterMode = cudaFilterModePoint;
texDesc.readMode = cudaReadModeElementType;
texDesc.normalizedCoords = 1;
// !FAILS! create texture object
cudaTextureObject_t texObj = NULL;
cudaCreateTextureObject(&texObj, &resDesc, &texDesc, NULL);
答案 0 :(得分:1)
知道了,我忘记了cudaTextureDesc的memset()。应该阅读:
// specify texture object parameters
cudaTextureDesc texDesc;
memset(&texDesc, 0, sizeof(texDesc));
texDesc.addressMode[0] = cudaAddressModeWrap;
texDesc.addressMode[1] = cudaAddressModeWrap;
texDesc.filterMode = cudaFilterModePoint;
texDesc.readMode = cudaReadModeElementType;
texDesc.normalizedCoords = 1;