cuda to cpp refactoring