[WIP] Fix cuda

Various fixes and improvements for CUDA backend.
Some leftover commented code here.