xgboost
Public Types | Public Member Functions | List of all members
xgboost::linalg::Tensor< T, kDim > Class Template Reference

A tensor storage. To use it for other functionality like slicing one needs to obtain a view first. This way we can use it on both host and device. More...

#include <linalg.h>

Collaboration diagram for xgboost::linalg::Tensor< T, kDim >:
Collaboration graph

Public Types

using ShapeT = size_t[kDim]
 
using StrideT = ShapeT
 

Public Member Functions

 Tensor ()=default
 
template<typename I , int32_t D>
 Tensor (I const (&shape)[D], std::int32_t device, Order order=kC)
 Create a tensor with shape and device ordinal. The storage is initialized automatically. More...
 
template<typename I , size_t D>
 Tensor (common::Span< I const, D > shape, std::int32_t device, Order order=kC)
 
template<typename It , typename I , int32_t D>
 Tensor (It begin, It end, I const (&shape)[D], std::int32_t device, Order order=kC)
 
template<typename I , int32_t D>
 Tensor (std::initializer_list< T > data, I const (&shape)[D], std::int32_t device, Order order=kC)
 
template<typename... Index>
T & operator() (Index &&...idx)
 Index operator. Not thread safe, should not be used in performance critical region. For more efficient indexing, consider getting a view first. More...
 
template<typename... Index>
T const & operator() (Index &&...idx) const
 Index operator. Not thread safe, should not be used in performance critical region. For more efficient indexing, consider getting a view first. More...
 
TensorView< T, kDim > View (int32_t device)
 Get a TensorView for this tensor. More...
 
TensorView< T const, kDim > View (int32_t device) const
 
auto HostView () const
 
auto HostView ()
 
size_t Size () const
 
auto Shape () const
 
auto Shape (size_t i) const
 
HostDeviceVector< T > * Data ()
 
HostDeviceVector< T > const * Data () const
 
template<typename Fn >
void ModifyInplace (Fn &&fn)
 Visitor function for modification that changes shape and data. More...
 
template<typename... S, detail::EnableIfIntegral< S... > * = nullptr>
void Reshape (S &&...s)
 Reshape the tensor. More...
 
template<size_t D>
void Reshape (common::Span< size_t const, D > shape)
 Reshape the tensor. More...
 
template<size_t D>
void Reshape (size_t(&shape)[D])
 
template<typename... S>
auto Slice (S &&...slices) const
 Get a host view on the slice. More...
 
template<typename... S>
auto Slice (S &&...slices)
 Get a host view on the slice. More...
 
void SetDevice (int32_t device) const
 Set device ordinal for this tensor. More...
 
int32_t DeviceIdx () const
 

Detailed Description

template<typename T, int32_t kDim = 5>
class xgboost::linalg::Tensor< T, kDim >

A tensor storage. To use it for other functionality like slicing one needs to obtain a view first. This way we can use it on both host and device.

Member Typedef Documentation

◆ ShapeT

template<typename T , int32_t kDim = 5>
using xgboost::linalg::Tensor< T, kDim >::ShapeT = size_t[kDim]

◆ StrideT

template<typename T , int32_t kDim = 5>
using xgboost::linalg::Tensor< T, kDim >::StrideT = ShapeT

Constructor & Destructor Documentation

◆ Tensor() [1/5]

template<typename T , int32_t kDim = 5>
xgboost::linalg::Tensor< T, kDim >::Tensor ( )
default

◆ Tensor() [2/5]

template<typename T , int32_t kDim = 5>
template<typename I , int32_t D>
xgboost::linalg::Tensor< T, kDim >::Tensor ( I const (&)  shape[D],
std::int32_t  device,
Order  order = kC 
)
inlineexplicit

Create a tensor with shape and device ordinal. The storage is initialized automatically.

See TensorView for parameters of this constructor.

◆ Tensor() [3/5]

template<typename T , int32_t kDim = 5>
template<typename I , size_t D>
xgboost::linalg::Tensor< T, kDim >::Tensor ( common::Span< I const, D >  shape,
std::int32_t  device,
Order  order = kC 
)
inlineexplicit

◆ Tensor() [4/5]

template<typename T , int32_t kDim = 5>
template<typename It , typename I , int32_t D>
xgboost::linalg::Tensor< T, kDim >::Tensor ( It  begin,
It  end,
I const (&)  shape[D],
std::int32_t  device,
Order  order = kC 
)
inlineexplicit

Initialize from 2 host iterators.

◆ Tensor() [5/5]

template<typename T , int32_t kDim = 5>
template<typename I , int32_t D>
xgboost::linalg::Tensor< T, kDim >::Tensor ( std::initializer_list< T >  data,
I const (&)  shape[D],
std::int32_t  device,
Order  order = kC 
)
inlineexplicit

Member Function Documentation

◆ Data() [1/2]

template<typename T , int32_t kDim = 5>
HostDeviceVector<T>* xgboost::linalg::Tensor< T, kDim >::Data ( )
inline

◆ Data() [2/2]

template<typename T , int32_t kDim = 5>
HostDeviceVector<T> const* xgboost::linalg::Tensor< T, kDim >::Data ( ) const
inline

◆ DeviceIdx()

template<typename T , int32_t kDim = 5>
int32_t xgboost::linalg::Tensor< T, kDim >::DeviceIdx ( ) const
inline

◆ HostView() [1/2]

template<typename T , int32_t kDim = 5>
auto xgboost::linalg::Tensor< T, kDim >::HostView ( )
inline

◆ HostView() [2/2]

template<typename T , int32_t kDim = 5>
auto xgboost::linalg::Tensor< T, kDim >::HostView ( ) const
inline

◆ ModifyInplace()

template<typename T , int32_t kDim = 5>
template<typename Fn >
void xgboost::linalg::Tensor< T, kDim >::ModifyInplace ( Fn &&  fn)
inline

Visitor function for modification that changes shape and data.

Template Parameters
Fnfunction that takes a pointer to HostDeviceVector and a static sized span as parameters.

◆ operator()() [1/2]

template<typename T , int32_t kDim = 5>
template<typename... Index>
T& xgboost::linalg::Tensor< T, kDim >::operator() ( Index &&...  idx)
inline

Index operator. Not thread safe, should not be used in performance critical region. For more efficient indexing, consider getting a view first.

◆ operator()() [2/2]

template<typename T , int32_t kDim = 5>
template<typename... Index>
T const& xgboost::linalg::Tensor< T, kDim >::operator() ( Index &&...  idx) const
inline

Index operator. Not thread safe, should not be used in performance critical region. For more efficient indexing, consider getting a view first.

◆ Reshape() [1/3]

template<typename T , int32_t kDim = 5>
template<size_t D>
void xgboost::linalg::Tensor< T, kDim >::Reshape ( common::Span< size_t const, D >  shape)
inline

Reshape the tensor.

If the total size is changed, then data in this tensor is no longer valid.

◆ Reshape() [2/3]

template<typename T , int32_t kDim = 5>
template<typename... S, detail::EnableIfIntegral< S... > * = nullptr>
void xgboost::linalg::Tensor< T, kDim >::Reshape ( S &&...  s)
inline

Reshape the tensor.

If the total size is changed, then data in this tensor is no longer valid.

◆ Reshape() [3/3]

template<typename T , int32_t kDim = 5>
template<size_t D>
void xgboost::linalg::Tensor< T, kDim >::Reshape ( size_t(&)  shape[D])
inline

◆ SetDevice()

template<typename T , int32_t kDim = 5>
void xgboost::linalg::Tensor< T, kDim >::SetDevice ( int32_t  device) const
inline

Set device ordinal for this tensor.

◆ Shape() [1/2]

template<typename T , int32_t kDim = 5>
auto xgboost::linalg::Tensor< T, kDim >::Shape ( ) const
inline

◆ Shape() [2/2]

template<typename T , int32_t kDim = 5>
auto xgboost::linalg::Tensor< T, kDim >::Shape ( size_t  i) const
inline

◆ Size()

template<typename T , int32_t kDim = 5>
size_t xgboost::linalg::Tensor< T, kDim >::Size ( ) const
inline

◆ Slice() [1/2]

template<typename T , int32_t kDim = 5>
template<typename... S>
auto xgboost::linalg::Tensor< T, kDim >::Slice ( S &&...  slices)
inline

Get a host view on the slice.

◆ Slice() [2/2]

template<typename T , int32_t kDim = 5>
template<typename... S>
auto xgboost::linalg::Tensor< T, kDim >::Slice ( S &&...  slices) const
inline

Get a host view on the slice.

◆ View() [1/2]

template<typename T , int32_t kDim = 5>
TensorView<T, kDim> xgboost::linalg::Tensor< T, kDim >::View ( int32_t  device)
inline

Get a TensorView for this tensor.

◆ View() [2/2]

template<typename T , int32_t kDim = 5>
TensorView<T const, kDim> xgboost::linalg::Tensor< T, kDim >::View ( int32_t  device) const
inline

The documentation for this class was generated from the following file: