Cuda 从 black/white 图像创建纹理对象
Cuda create texture object from black/white image
我正在尝试逐帧处理视频。为此,我想创建一个包含当前帧的纹理并将其传递给内核。帧是 1440*1080 像素,每个像素由一个无符号字符表示,例如8 位。
我按照说明进行操作,但是我的程序总是在创建纹理时失败。错误代码 0x11:"invalid arguments"。
这是我的代码:
// 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);
知道了,我忘记了 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;
我正在尝试逐帧处理视频。为此,我想创建一个包含当前帧的纹理并将其传递给内核。帧是 1440*1080 像素,每个像素由一个无符号字符表示,例如8 位。
我按照说明进行操作,但是我的程序总是在创建纹理时失败。错误代码 0x11:"invalid arguments"。
这是我的代码:
// 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);
知道了,我忘记了 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;