finished advance kernel. TODO: fix bugs in device pointer passing.