Revised and redesigned cuda support.