Hi, I want to replace texture reference with texture object APIs in a piece of legacy code.
I did a experiment, the result is expected to be exactly the same. But a bit diff always appear.
texture reference parameters
texture<unsigned char, cudaTextureType2D, cudaReadModeNormalizedFloat> tex_I8U(
false, cudaFilterModeLinear, cudaAddressModeClamp);
void bindTexture(const void* dataPtr, const uint width, const uint height,
const uint pitchSize) {
cudaChannelFormatDesc desc = cudaCreateChannelDesc<unsigned char>();
cudaBindTexture2D(
0, &tex_I8U, dataPtr, &desc, static_cast<size_t>(width),
static_cast<size_t>(height), static_cast<size_t>(pitchSize));
}
texture object parameters
void createTexObj(cudaTextureObject_t& tex, void* srcptr, const int width,
const int height, const int pitchWidth) {
cudaResourceDesc resDesc;
memset(&resDesc, 0, sizeof(resDesc));
resDesc.resType = cudaResourceTypePitch2D;
resDesc.res.pitch2D.devPtr = srcptr;
resDesc.res.pitch2D.height = height;
resDesc.res.pitch2D.width = width;
resDesc.res.pitch2D.pitchInBytes = pitchWidth;
resDesc.res.pitch2D.desc = cudaCreateChannelDesc<unsigned char>();
cudaTextureDesc texDesc;
memset(&texDesc, 0, sizeof(texDesc));
texDesc.readMode = cudaReadModeNormalizedFloat;
texDesc.addressMode[0] = cudaTextureAddressMode::cudaAddressModeClamp;
texDesc.addressMode[1] = cudaTextureAddressMode::cudaAddressModeClamp;
texDesc.filterMode = cudaFilterModeLinear;
texDesc.normalizedCoords = false;
cudaCreateTextureObject(&tex, &resDesc, &texDesc, NULL);
}
then I wrote 2 kernels reading data via tex and tex_I8U, just write data to a buffer, then dump to files seperately.
the input img width is 1920 * 1080 * 1(grey), pitch width 2048
the result data show there are exactly 1920 diffs, I don’t why?, plz help.