Descriptor for tensors in host memory.
More...
#include <host_tensor.hpp>
|
| | HostTensorDescriptor ()=default |
| void | CalculateStrides () |
| template<typename X, typename = std::enable_if_t<std::is_convertible_v<X, std::size_t>>> |
| | HostTensorDescriptor (const std::initializer_list< X > &lens) |
| template<typename Lengths, typename = std::enable_if_t< std::is_convertible_v<ck_tile::ranges::range_value_t<Lengths>, std::size_t>>> |
| | HostTensorDescriptor (const Lengths &lens) |
| template<typename X, typename Y, typename = std::enable_if_t<std::is_convertible_v<X, std::size_t> && std::is_convertible_v<Y, std::size_t>>> |
| | HostTensorDescriptor (const std::initializer_list< X > &lens, const std::initializer_list< Y > &strides) |
| template<typename Lengths, typename Strides, typename = std::enable_if_t< std::is_convertible_v<ck_tile::ranges::range_value_t<Lengths>, std::size_t> && std::is_convertible_v<ck_tile::ranges::range_value_t<Strides>, std::size_t>>> |
| | HostTensorDescriptor (const Lengths &lens, const Strides &strides) |
| std::size_t | get_num_of_dimension () const |
| std::size_t | get_element_size () const |
| | Calculates the total number of elements in the tensor.
|
| std::size_t | get_element_space_size () const |
| | Calculates the total element space required for the tensor in memory.
|
| std::size_t | get_length (std::size_t dim) const |
| const std::vector< std::size_t > & | get_lengths () const |
| std::size_t | get_stride (std::size_t dim) const |
| const std::vector< std::size_t > & | get_strides () const |
| template<typename... Is> |
| std::size_t | GetOffsetFromMultiIndex (Is... is) const |
| | Calculates the linear offset from multi-dimensional indices.
|
| std::size_t | GetOffsetFromMultiIndex (const std::vector< std::size_t > &iss) const |
| | Calculates the linear memory offset from a multi-dimensional index.
|
Descriptor for tensors in host memory.
HostTensorDescriptor manages the shape (dimensions) and memory layout (strides) of a tensor in host memory. It provides functionality to:
- Store tensor dimensions and strides
- Calculate default strides for contiguous memory layout
- Convert multi-dimensional indices to linear memory offsets
- Query tensor metadata (dimensions, element counts, etc.)
The class supports both automatic stride calculation for contiguous memory layout and custom strides for more complex memory patterns.
◆ HostTensorDescriptor() [1/5]
| ck_tile::HostTensorDescriptor::HostTensorDescriptor |
( |
| ) |
|
|
default |
◆ HostTensorDescriptor() [2/5]
template<typename X, typename = std::enable_if_t<std::is_convertible_v<X, std::size_t>>>
| ck_tile::HostTensorDescriptor::HostTensorDescriptor |
( |
const std::initializer_list< X > & | lens | ) |
|
|
inline |
◆ HostTensorDescriptor() [3/5]
template<typename Lengths, typename = std::enable_if_t< std::is_convertible_v<ck_tile::ranges::range_value_t<Lengths>, std::size_t>>>
| ck_tile::HostTensorDescriptor::HostTensorDescriptor |
( |
const Lengths & | lens | ) |
|
|
inline |
◆ HostTensorDescriptor() [4/5]
template<typename X, typename Y, typename = std::enable_if_t<std::is_convertible_v<X, std::size_t> && std::is_convertible_v<Y, std::size_t>>>
| ck_tile::HostTensorDescriptor::HostTensorDescriptor |
( |
const std::initializer_list< X > & | lens, |
|
|
const std::initializer_list< Y > & | strides ) |
|
inline |
◆ HostTensorDescriptor() [5/5]
template<typename Lengths, typename Strides, typename = std::enable_if_t< std::is_convertible_v<ck_tile::ranges::range_value_t<Lengths>, std::size_t> && std::is_convertible_v<ck_tile::ranges::range_value_t<Strides>, std::size_t>>>
| ck_tile::HostTensorDescriptor::HostTensorDescriptor |
( |
const Lengths & | lens, |
|
|
const Strides & | strides ) |
|
inline |
◆ CalculateStrides()
| void ck_tile::HostTensorDescriptor::CalculateStrides |
( |
| ) |
|
|
inline |
◆ get_element_size()
| std::size_t ck_tile::HostTensorDescriptor::get_element_size |
( |
| ) |
const |
|
inline |
Calculates the total number of elements in the tensor.
Computes the product of all dimension lengths to determine the total element count in the tensor.
- Precondition
- The lengths array (mLens) and strides array (mStrides) must have the same size.
- Returns
- The total number of elements in the tensor.
◆ get_element_space_size()
| std::size_t ck_tile::HostTensorDescriptor::get_element_space_size |
( |
| ) |
const |
|
inline |
Calculates the total element space required for the tensor in memory.
This method computes the minimum size of contiguous memory needed to store all elements of the tensor, taking into account the tensor's dimensions and strides. The calculation is based on the formula: 1 + max((length_i - 1) * stride_i) across all dimensions.
Dimensions with length 0 are skipped in this calculation.
- Returns
- The size of the tensor's element space (number of elements).
◆ get_length()
| std::size_t ck_tile::HostTensorDescriptor::get_length |
( |
std::size_t | dim | ) |
const |
|
inline |
◆ get_lengths()
| const std::vector< std::size_t > & ck_tile::HostTensorDescriptor::get_lengths |
( |
| ) |
const |
|
inline |
◆ get_num_of_dimension()
| std::size_t ck_tile::HostTensorDescriptor::get_num_of_dimension |
( |
| ) |
const |
|
inline |
◆ get_stride()
| std::size_t ck_tile::HostTensorDescriptor::get_stride |
( |
std::size_t | dim | ) |
const |
|
inline |
◆ get_strides()
| const std::vector< std::size_t > & ck_tile::HostTensorDescriptor::get_strides |
( |
| ) |
const |
|
inline |
◆ GetOffsetFromMultiIndex() [1/2]
| std::size_t ck_tile::HostTensorDescriptor::GetOffsetFromMultiIndex |
( |
const std::vector< std::size_t > & | iss | ) |
const |
|
inline |
Calculates the linear memory offset from a multi-dimensional index.
Computes the linear offset by performing an inner product between the provided multi-dimensional indices and the tensor's strides.
- Parameters
-
| iss | Vector containing the multi-dimensional indices |
- Returns
- The calculated linear offset as a size_t
◆ GetOffsetFromMultiIndex() [2/2]
template<typename... Is>
| std::size_t ck_tile::HostTensorDescriptor::GetOffsetFromMultiIndex |
( |
Is... | is | ) |
const |
|
inline |
Calculates the linear offset from multi-dimensional indices.
Converts a set of N-dimensional indices into a single linear offset by computing the inner product of the indices with the tensor's strides.
- Template Parameters
-
| Is | Parameter pack of index types (should be convertible to std::size_t) |
- Parameters
-
| is | Variable number of indices, one for each dimension of the tensor |
- Returns
- std::size_t Linear offset corresponding to the given multi-dimensional indices
- Precondition
- The number of indices must match the number of dimensions in the tensor
◆ operator<<
The documentation for this struct was generated from the following file: