refactoring GPU code