Solved by ptrblck in post #2 
              
              
                Based on the description I would suspect a faulty or weak PSU, which is causing the reboot. 
However, could you run the code with 4 different GPUs and make sure that it works with all devices?