         cuda_check(cudaMalloc((void**)&x_tmp, n * incx));
         cuda_check(cudaMalloc((void**)&y_tmp, n * incy));
 
-        cuda_check(cudaMemcpy(x_flat, x_tmp, n * incx, cudaMemcpyDeviceToDevice));
-        cuda_check(cudaMemcpy(y_flat, y_tmp, n * incy, cudaMemcpyDeviceToDevice));
+        cuda_check(cudaMemcpy(x_tmp, x_flat, n * incx, cudaMemcpyDeviceToDevice));
+        cuda_check(cudaMemcpy(y_tmp, y_flat, n * incy, cudaMemcpyDeviceToDevice));
 
         size_t* permutation;
         cuda_check(cudaMalloc((void**)&permutation, n * sizeof(size_t)));


        uint64_t* x_tmp;
        cuda_check(cudaMalloc((void**)&x_tmp, n * incx));
        cuda_check(cudaMemcpy(x_flat, x_tmp, n * incx, cudaMemcpyDeviceToDevice));

        size_t* permutation;
        cuda_check(cudaMalloc((void**)&permutation, n * sizeof(size_t)));

        cuda_check(cudaMalloc((void**)&x_tmp, n * incx));
        cuda_check(cudaMalloc((void**)&y_tmp, n * incy));

        cuda_check(cudaMemcpy(x_tmp, x_flat, n * incx, cudaMemcpyDeviceToDevice));
        cuda_check(cudaMemcpy(y_tmp, y_flat, n * incy, cudaMemcpyDeviceToDevice));

        size_t* permutation;
        cuda_check(cudaMalloc((void**)&permutation, n * sizeof(size_t)));
