Hidden Data View Invalidation in VPI

I have come across an issue where if the data of a view of an image is unaligned, vpiImageLockData with cuda pitch linear secretly makes a local copy of that data which is aligned. If I were to make changes to the parent image, those changes are not reflected next time I use vpiImageLockData with cuda pitch linear on the view to use that data as it doesn’t automatically make another aligned copy of the new data, just keeps the old aligned data.

This is able to be resolved by recreating the view with vpiImageSetView (with the exact same xywh bounds) as next time vpiImageLockData is called, the aligned local copy is made again (with the updated data). I was only able to determine this as the root cause by using nsight-systems to view what is happening behind the scenes, otherwise this would be extremely difficult to resolve.

If the view is already aligned, then this problem does not occur, as there is no local copy made by vpiImageLockData with cuda pitch linear. Therefore, the same code may or may not work depending if the underlying image view is aligned.

If I try to access the data to debug with cpu pitch linear to write the picture to a file to check, there is no alignment process, so it writes the correct data, so it looks like the updated data is in the image, even though on gpu I am reading old data. I guess I could go the long way around and get a gpu pitch linear pointer, then copy to cpu and write the image, but that’s a non-intuitive long way around debugging an image.

I hope the explination of the scenario makes sense, as this could be a common issue and its resolution would probably save others a lot of debug time.