cuda-api-wrappers icon indicating copy to clipboard operation
cuda-api-wrappers copied to clipboard

Consider using gsl::span's

Open eyalroz opened this issue 7 years ago • 5 comments

We currently have more than a few wrappers taking a void* and a num_bytes or size_in_bytes etc. Instead, why not use spans?

And if we do that, perhaps we could/should use spans elsewhere, where we now just use pointers.

eyalroz avatar Feb 02 '18 11:02 eyalroz

The GSL implementation here https://github.com/microsoft/GSL does not consider to be CUDA compatible (https://github.com/microsoft/GSL/issues/544). But the GSL-Lite https://github.com/martinmoene/gsl-lite is currently open for changes and development and fully CUDA compatible. So if you plan to use spans I recommend using GSL-Lite. Nevertheless I would really think about if this project should have this dependency.

codecircuit avatar Jan 02 '20 16:01 codecircuit

@codecircuit : I think I got the gsl-lite guy to make it CUDA-compatible, actually. But I vaguely recall there was some issue with it. At the very least, it's a single huge header file one would need to include.

If we were to do this, it would probably be with a sort of a back-porting of C++20 spans to be CUDA C++11-compatible...

eyalroz avatar Jan 02 '20 16:01 eyalroz

Me and my collegue work on the gsl-lite. I use it in every project and it should be fully CUDA compatible right now. No porting of any kind should be necessary.

I would not include the complete header of the gsl-lite into this project, but rather write it down as a CMake dependency:

find_package(gsl-lite REQUIRED)
target_link_libraries(cuda-api-wrappers PUBLIC gsl::gsl-lite)

see here https://github.com/martinmoene/gsl-lite#as-cmake-package

codecircuit avatar Jan 02 '20 17:01 codecircuit

Is gsl-lite's span, as of right now, a conformant implementation of C++20's std::span ?

eyalroz avatar Jan 03 '20 00:01 eyalroz

It isn't: it doesn't yet support fixed-size spans, it has operations that were deliberately left out for std::span<> (e.g. comparison), and some small things are missing or named differently.

I plan to make it conformant, but that will be an ABI-breaking change (because we need a second template parameter), and hence something that will probably happen in the next major-version release.

mbeutel avatar Jan 30 '20 16:01 mbeutel