Fix ifelse crash and gpu support

- [x] fix ifelse crash
- [x] gpu/cpu support