simplified algorithm working with nvcc (full of semantic bugs)