Skip to content

Use span instead of bare pointers in Allen::datatype.

Daniel Hugo Campora Perez requested to merge dcampora_use_span_in_datatype into master

This MR changes the underlying type of datatype from a pointer to a span. This implies that all Allen kernels by default will get the size as part of the datatype. This applies to all existing Allen kernels as well.

The following list of operations become available from a datatype:

get() - returns a span of the type and size.
data() - returns a pointer to the beginning of the datatype.
operator->() - returns a pointer to the beginning of the datatype.
operator type*() - casts to pointer, pointing to the beginning of the datatype.
operator[](index) - accesses element "index" in the datatype.
empty() - returns true if container is empty (size is 0), false otherwise.
size() - returns the size of the container.
size_bytes() - returns the size of the container in bytes.
subspan(offset) - creates a subspan starting from offset, with a proper size according to the remainder of the container.
subspan(offset, count) - creates a subspan starting from offset with count elements.

From the tests, it does not impact throughput.

Some code should be adapted in the following to using spans. This includes:

  • Device utils code (under device/utils), such as binary searches, shared_or_global, etc.
  • Function calls within kernels (all still use pointers and can be safely moved to spans).
  • Concretely, some kernels were getting the size as a separate parameter, which would not be needed anymore.

The concrete type of the span depends on the backend and is compatible (gsl::span for CPU and CUDA builds, Allen::device::span for HIP). Possibly HIP 5.4.3 supports gsl::span, this would allow erasing some compatibility code.

FYI @graven @raaij

Edited by Daniel Hugo Campora Perez

Merge request reports

Loading