cannot correctly set value to device memory strange error, four statements, remove any three can wo

My first guess would be the kernel runs to long because of all the cosf and it gets aborted or something.

Perhaps you should check if runtime limit for kernels is off in device capabilities (also known as kernel exec timeout).

For debugging purposes the watchdog also needed to be turned off, I think it was in nsight monitor.