eyalroz / cuda-kat

CUDA kernel author's tools
BSD 3-Clause "New" or "Revised" License
105 stars 8 forks source link

Add a device-side-enabled version of gsl::span or std::span #6

Closed eyalroz closed 4 years ago

eyalroz commented 5 years ago

std::span / gsl::span are very useful in host-side code: A pointer+length pair with standard-library-container trappings (iterators, operators, usable in standard algorithms etc.)

Now, it's not as though you should just use spans willy-nilly; they can have some overhead, but - they can sometimes make sense. The may be particularly useful as kernel parameters - pay the overhead just once per thread, then in the kernel you do what you like. And it makes it easier to work with memory regions - device-side and host-side.

See also issue #17.

We can base ourselves on either an GSL or a standard-library implementation. But:

  1. We need it to work on the device side
  2. We need to detach it from the rest of the library (unless we want to import the entire GSL, which we probably don't): 2.1 Drop Expects, Requires -> No (?) need for <gsl/gsl_assert> 2.2 Roll our own byte or use unsigned char -> No(?) need for <gsl/gsl_byte> // for byte 2.3 narrowing cast, other stuff ??? in <gsl/gsl_util>
  3. We can assume at least C++11 (perhaps 14?)

.... edit: Going with std::span adapted for earlier C++ versions. Hope it's not too bad. Still not sure if I shouldn't just use gsl::span instead.