eyalroz / cuda-api-wrappers

Thin, unified, C++-flavored wrappers for the CUDA APIs
BSD 3-Clause "New" or "Revised" License
786 stars 80 forks source link

Support copying from standard-library containers with contiguous storage #606

Closed eyalroz closed 6 months ago

eyalroz commented 7 months ago

At the moment (on the development branch), when one wants to copy from or to a standard library container with contiguous storage, e.g. a vector, one has to use the .data() method (or .begin() iterator), and actually copy to a pointer. This is both a bit verbose, and sometimes requires that one also specify the size as an argument, which is slightly more error prone. It would be nice if we could say:

std::vector<float> v = get_my_vector();
auto d_sp = cuda::memory::make_unique_span<float>(device, v.size());
cuda::memory::copy(d_sp, v_host);