Refactor compilation; cache also CUDA compilation.