A tensor view with static type and dimension. It implements indexing and slicing.
More...
|
template<typename I , std::int32_t D> |
LINALG_HD | TensorView (common::Span< T > data, I const (&shape)[D], DeviceOrd device) |
| Create a tensor with data and shape. More...
|
|
template<typename I , int32_t D> |
LINALG_HD | TensorView (common::Span< T > data, I const (&shape)[D], DeviceOrd device, Order order) |
|
template<typename I , std::int32_t D> |
LINALG_HD | TensorView (common::Span< T > data, I const (&shape)[D], I const (&stride)[D], DeviceOrd device) |
| Create a tensor with data, shape and strides. Don't use this constructor if stride can be calculated from shape. More...
|
|
template<typename U , std::enable_if_t< common::detail::IsAllowedElementTypeConversion< U, T >::value > * = nullptr> |
LINALG_HD | TensorView (TensorView< U, kDim > const &that) |
|
template<typename... Index, detail::EnableIfIntegral< Index... > * = nullptr> |
LINALG_HD T & | operator() (Index &&...index) |
| Index the tensor to obtain a scalar value. More...
|
|
template<typename... Index, detail::EnableIfIntegral< Index... > * = nullptr> |
LINALG_HD T const & | operator() (Index &&...index) const |
| Index the tensor to obtain a scalar value. More...
|
|
template<typename... S> |
LINALG_HD auto | Slice (S &&...slices) const |
| Slice the tensor. The returned tensor has inferred dim and shape. Scalar result is not supported. More...
|
|
LINALG_HD auto | Shape () const |
|
LINALG_HD auto | Shape (size_t i) const |
|
LINALG_HD auto | Stride () const |
|
LINALG_HD auto | Stride (size_t i) const |
|
LINALG_HD std::size_t | Size () const |
| Number of items in the tensor. More...
|
|
bool | Empty () const |
|
LINALG_HD bool | Contiguous () const |
| Whether this is a contiguous array, both C and F contiguous returns true. More...
|
|
LINALG_HD bool | CContiguous () const |
| Whether it's a c-contiguous array. More...
|
|
LINALG_HD bool | FContiguous () const |
| Whether it's a f-contiguous array. More...
|
|
LINALG_HD auto | Values () const -> decltype(data_) const & |
| Obtain a reference to the raw data. More...
|
|
LINALG_HD auto | Device () const |
| Obtain the CUDA device ordinal. More...
|
|
template<typename T, int32_t kDim>
class xgboost::linalg::TensorView< T, kDim >
A tensor view with static type and dimension. It implements indexing and slicing.
Most of the algorithms in XGBoost are implemented for both CPU and GPU without using much linear algebra routines, this class is a helper intended to ease some high level operations like indexing into prediction tensor or gradient matrix. It can be passed into CUDA kernel as normal argument for GPU algorithms.
Ideally we should add a template parameter bool on_host
so that the compiler can prevent passing/accessing the wrong view, but inheritance is heavily used in XGBoost so some functions expect data types that can be used in everywhere (update prediction cache for example).