How to avoid black screen when i run my CUDA code?

Once my image process code runs for more than two seconds, my screen will go black and i will get an error.
i know it is useful to adjust TDR value. but i want to know if there is a way to run my code, and in the meantime my screen would not go black?
Why some frameworks using CUDA, like pytorch and tensorflow, can run their code so long without getting black screen?

because their kernels are not longer than 2 seconds. There is no magic here. (use a profiler to confirm it if you wish)

If you have a GPU that can be placed in TCC mode, then you can run kernels for longer than 2 seconds that way.

i used pytorch on windows10 and ubuntu last year, pytorch can run python code for one or two days with almost loaded GPU. both systems have desktop, which is not TCC mode. i am wondering how they do that.

I don’t have any idea on how to profile CUDA code in Python, but my first guess would be that this computation you mention, of days, is made of multiple kernel calls and not just 1 run.