Generalize alloc device array.
Initial reimplementation of KPM to avoid
dynamic allocation of big arrays.
Refactor to use ArrayBuf
More updates to KPM