xgboost
公共类型 | 公共成员函数 | 静态公共属性 | 所有成员列表
xgboost::linalg::TensorView< T, kDim > 类模板参考

具有静态类型和维度的张量视图。它实现了索引和切片操作。更多...

#include <linalg.h>

xgboost::linalg::TensorView< T, kDim > 的协作图
Collaboration graph

公共类型

使用 ShapeT = std::size_t[kDim]
 
使用 StrideT = ShapeT
 
使用 element_type = T
 
使用 value_type = std::remove_cv_t< T >
 

公共成员函数

template<typename I , std::int32_t D>
LINALG_HD TensorView (common::Span< T > data, I const (&shape)[D], DeviceOrd device)
 使用数据和形状创建一个张量。更多...
 
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)
 使用数据、形状和步长创建一个张量。如果步长可以从形状计算得出,请勿使用此构造函数。更多...
 
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)
 索引张量以获取标量值。更多...
 
template<typename... Index, detail::EnableIfIntegral< Index... > * = nullptr>
LINALG_HD T const & operator() (Index &&...index) const
 索引张量以获取标量值。更多...
 
template<typename... S>
LINALG_HD auto Slice (S &&...slices) const
 对张量进行切片。返回的张量具有推断出的维度和形状。不支持标量结果。更多...
 
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
 张量中的元素数量。更多...
 
bool Empty () const
 
LINALG_HD bool Contiguous () const
 这是否是连续数组,C 连续和 F 连续都返回 true。更多...
 
LINALG_HD bool CContiguous () const
 这是否是 C 连续数组。更多...
 
LINALG_HD bool FContiguous () const
 这是否是 F 连续数组。更多...
 
LINALG_HD auto Values () const -> decltype(data_) const &
 获取原始数据的引用。更多...
 
LINALG_HD auto Device () const
 获取 CUDA 设备序号。更多...
 

静态公共属性

constexpr static size_t kValueSize = sizeof(T)
 
constexpr static size_t kDimension = kDim
 

详细描述

template<typename T, int32_t kDim>
class xgboost::linalg::TensorView< T, kDim >

具有静态类型和维度的张量视图。它实现了索引和切片操作。

XGBoost 中的大多数算法都针对 CPU 和 GPU 实现,没有使用太多线性代数例程。此类是一个辅助工具,旨在简化一些高级操作,例如索引到预测张量或梯度矩阵中。它可以作为普通参数传递给 CUDA 内核,用于 GPU 算法。

理想情况下,我们应该添加一个模板参数 bool on_host,以便编译器可以防止传递/访问错误的视图,但 XGBoost 中大量使用了继承,因此某些函数期望可以在任何地方使用的数据类型(例如更新预测缓存)。

成员类型定义文档

◆ element_type

template<typename T , int32_t kDim>
using xgboost::linalg::TensorView< T, kDim >::element_type = T

◆ ShapeT

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

◆ StrideT

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

◆ value_type

template<typename T , int32_t kDim>
using xgboost::linalg::TensorView< T, kDim >::value_type = std::remove_cv_t<T>

构造函数与析构函数文档

◆ TensorView() [1/4]

template<typename T , int32_t kDim>
template<typename I , std::int32_t D>
LINALG_HD xgboost::linalg::TensorView< T, kDim >::TensorView ( common::Span< T >  data,
I const (&)  shape[D],
DeviceOrd  device 
)
inline

使用数据和形状创建一个张量。

模板参数
I形状数组元素的类型。
D形状数组的大小,可以小于或等于张量维度。
参数
data原始数据输入,如果此张量的模板参数为 const 类型,则可以为 const。
shape张量的形状
device设备序号

◆ TensorView() [2/4]

template<typename T , int32_t kDim>
template<typename I , int32_t D>
LINALG_HD xgboost::linalg::TensorView< T, kDim >::TensorView ( common::Span< T >  data,
I const (&)  shape[D],
DeviceOrd  device,
Order  order 
)
inline

◆ TensorView() [3/4]

template<typename T , int32_t kDim>
template<typename I , std::int32_t D>
LINALG_HD xgboost::linalg::TensorView< T, kDim >::TensorView ( common::Span< T >  data,
I const (&)  shape[D],
I const (&)  stride[D],
DeviceOrd  device 
)
inline

使用数据、形状和步长创建一个张量。如果步长可以从形状计算得出,请勿使用此构造函数。

◆ TensorView() [4/4]

template<typename T , int32_t kDim>
template<typename U , std::enable_if_t< common::detail::IsAllowedElementTypeConversion< U, T >::value > * = nullptr>
LINALG_HD xgboost::linalg::TensorView< T, kDim >::TensorView ( TensorView< U, kDim > const &  that)
inline

成员函数文档

◆ CContiguous()

template<typename T , int32_t kDim>
LINALG_HD bool xgboost::linalg::TensorView< T, kDim >::CContiguous ( ) const
inline

这是否是 C 连续数组。

◆ Contiguous()

template<typename T , int32_t kDim>
LINALG_HD bool xgboost::linalg::TensorView< T, kDim >::Contiguous ( ) const
inline

这是否是连续数组,C 连续和 F 连续都返回 true。

◆ Device()

template<typename T , int32_t kDim>
LINALG_HD auto xgboost::linalg::TensorView< T, kDim >::Device ( ) const
inline

获取 CUDA 设备序号。

◆ Empty()

template<typename T , int32_t kDim>
bool xgboost::linalg::TensorView< T, kDim >::Empty ( ) const
inline

◆ FContiguous()

template<typename T , int32_t kDim>
◆ FContiguous() ( ) const
inline

LINALG_HD bool xgboost::linalg::TensorView< T, kDim >::FContiguous

◆ operator()() [1/2]

template<typename T , int32_t kDim>
template<typename... Index, detail::EnableIfIntegral< Index... > * = nullptr>
LINALG_HD T& xgboost::linalg::TensorView< T, kDim >::operator() ( Index &&...  index)
inline

索引张量以获取标量值。

// 创建一个 3 维张量。
Tensor<float, 3> t {data, shape, 0};
float pi = 3.14159;
t(1, 2, 3) = pi;
ASSERT_EQ(t(1, 2, 3), pi);

◆ operator()() [2/2]

template<typename T , int32_t kDim>
template<typename... Index, detail::EnableIfIntegral< Index... > * = nullptr>
LINALG_HD T const& xgboost::linalg::TensorView< T, kDim >::operator() ( Index &&...  index) const
inline

索引张量以获取标量值。

◆ Shape() [1/2]

template<typename T , int32_t kDim>
◆ Shape() [1/2] ( ) const
inline

LINALG_HD auto xgboost::linalg::TensorView< T, kDim >::Shape

template<typename T , int32_t kDim>
◆ Shape() [1/2] ( ◆ Shape() [2/2] size_t ) const
inline

i

获取第 i 维度的形状

template<typename T , int32_t kDim>
◆ Size() ( ) const
inline

LINALG_HD std::size_t xgboost::linalg::TensorView< T, kDim >::Size

张量中的元素数量。

template<typename T , int32_t kDim>
template<typename... S>
◆ Slice() ( LINALG_HD auto xgboost::linalg::TensorView< T, kDim >::Slice S &&... ) const
inline

slices

// 创建一个 3 维张量。
Tensor<float, 3> t {data, shape, 0};
对张量进行切片。返回的张量具有推断出的维度和形状。不支持标量结果。
// s 是二维的(矩阵)
xgboost::linalg::All
constexpr detail::AllTag All()
指定切片时轴上的所有元素。

定义: linalg.h:266

template<typename T , int32_t kDim>
◆ Stride() [1/2] ( ) const
inline

LINALG_HD auto xgboost::linalg::TensorView< T, kDim >::Stride

template<typename T , int32_t kDim>
◆ Stride() [1/2] ( ◆ Shape() [2/2] size_t ) const
inline

◆ Stride() [2/2]

获取第 i 维度的步长,步长指定为元素数量而不是字节数。

template<typename T , int32_t kDim>
◆ Values() ( ) LINALG_HD auto xgboost::linalg::TensorView< T, kDim >::Values
inline

const -> decltype(data_) const &

获取原始数据的引用。

成员数据文档

template<typename T , int32_t kDim>
◆ kDimension
constexpr static size_t xgboost::linalg::TensorView< T, kDim >::kDimension = kDim

staticconstexpr

template<typename T , int32_t kDim>
◆ kValueSize
constexpr static size_t xgboost::linalg::TensorView< T, kDim >::kDimension = kDim

constexpr static size_t xgboost::linalg::TensorView< T, kDim >::kValueSize = sizeof(T)