Version that works with CUDA