20#include <cuspatial/traits.hpp>
22#include <rmm/device_uvector.hpp>
24#include <thrust/for_each.h>
25#include <thrust/host_vector.h>
26#include <thrust/optional.h>
47template <
typename T,
typename Vector>
48thrust::host_vector<T> to_host(Vector
const& dvec)
50 if constexpr (std::is_same_v<Vector, rmm::device_uvector<T>>) {
51 thrust::host_vector<T> hvec(dvec.size());
52 cudaMemcpyAsync(hvec.data(),
54 dvec.size() *
sizeof(T),
55 cudaMemcpyKind::cudaMemcpyDeviceToHost,
57 dvec.stream().synchronize();
60 return thrust::host_vector<T>(dvec);
73template <
typename Iter,
typename T = cuspatial::iterator_value_type<Iter>>
74thrust::host_vector<T> to_host(Iter begin, Iter end)
76 return thrust::host_vector<T>(begin, end);
90template <
typename Iter>
91void print_device_range(Iter begin,
93 std::string_view pre =
"",
94 std::string_view post =
"\n")
96 auto hvec = to_host(begin, end);
99 std::for_each(hvec.begin(), hvec.end(), [](
auto const& x) { std::cout << x <<
" "; });
113template <
typename Vector>
114void print_device_vector(Vector
const& vec, std::string_view pre =
"", std::string_view post =
"\n")
116 using T =
typename Vector::value_type;
117 auto hvec = to_host<T>(vec);
120 std::for_each(hvec.begin(), hvec.end(), [](
auto const& x) { std::cout << x <<
" "; });