Ensure kernel/memcpy are complete before using the results. Also fixes a memory-overuse issue in CUDA6.0, as device_primes wasn't free'd before the next cudaMalloc was executed.