Libtorch 2.1.1 crashing when predicting from DLL

I’m using Libtorch 2.1.1 with CUDA 11.8 and GPU NVIDIA RTX A2000 12GB. To build code I’m using cmake with Visual studio code.

When I build app in debug or release version in Visual studio it works fine, but when I put the same code in DLL to use it in C# or any other language it crashes in the middle of prediction. I also use try catch to return error so it wouldn’t crash, but it still freeze the program and crashes. I’m using same DLL on different PCs with different GPUs and there the DLL works fine. Right now I’m out of ides on what to do. Models are used for image segmentation. I also used different models if the size of them would be problem, but still the same error.

In C# works only in Release.

Is it possible that the problem is GPU?

I fixed the problem.
In NVIDIA control panel I:

  • Enabled ECC state for the GPU
  • Set power management mode to Prefer maximum performance
  • Set CUDA – Sysmem Fallback Policy to Prefer Sysmem Fallback
  • Set Adjust image settings with preview to Use the advanced 3D image settings
  • For video output (LCD) I used internal (Intel) GPU output.