|
docc 0.8.3 (0d44999b)
C++ API Reference
|
The metadata associated with a addressing a tensor in elements Meant to be used with TensorNodes to describe their input's and outputs layouts and ease handling of such descriptions If the TensorType will keep existing it should also be switched to use this. More...
#include <sdfg/data_flow/library_nodes/math/tensor/tensor_layout.h>
Public Types | |
| enum | TensorLayoutType { LAYOUT_OTHER = 0 , LAYOUT_ROW_MAJOR = 1 , LAYOUT_COL_MAJOR = 2 , LAYOUT_ROW_OR_COL_MAJOR = 3 } |
Public Member Functions | |
| TensorLayout (const symbolic::MultiExpression &shape, const symbolic::MultiExpression &strides={}, const symbolic::Expression offset=symbolic::integer(0)) | |
| const symbolic::MultiExpression & | shape () const |
| const symbolic::MultiExpression & | strides () const |
| const symbolic::Expression & | offset () const |
| void | serialize_to_json (nlohmann::json &j) const |
| std::string | toStr () const |
| symbolic::Expression | total_elements () const |
| symbolic::Expression | memory_span () const |
| symbolic::MultiExpression | linear_strides () const |
| symbolic::Expression | resolve_element (const symbolic::MultiExpression &indices, bool require_to_element=true) const |
| apply the index to the layout, returning an "element-address" | |
| std::optional< symbolic::MultiExpression > | partition_offset_into_dimensions () const |
| Partition the layout's offset() into one coordinate offset per dimension. | |
| symbolic::Expression | max_accessed_byte_offset_from_ptr (types::PrimitiveType element_type) const |
| For memory access ranges, this should return the maximum offset from the pointer that is possible, in elements. | |
| void | collect_symbols (symbolic::SymbolSet &set) const |
| void | replace_symbols (const symbolic::Expression &old, const symbolic::Expression &new_expr) |
| void | replace_symbols (const symbolic::ExpressionMapping &replacements) |
| const symbolic::Expression & | get_dim (int i) const |
| symbolic::Expression | get_dim_innermost (int i) const |
| symbolic::Expression | get_stride (int i) const |
| symbolic::Expression | get_stride_innermost (int i) const |
| int | dims () const |
| bool | is_scalar () const |
| bool | has_linear_accesses () const |
| bool | has_linear_accesses_no_padding () const |
| bool | has_transposed_strides_no_padding () const |
| bool | operator== (const TensorLayout &other) const |
| std::unique_ptr< TensorLayout > | newaxis (size_t axis) const |
| std::unique_ptr< TensorLayout > | flip (size_t axis) const |
| std::unique_ptr< TensorLayout > | unsqueeze (size_t axis) const |
| std::unique_ptr< TensorLayout > | squeeze (size_t axis) const |
| std::unique_ptr< TensorLayout > | squeeze () const |
| std::unique_ptr< TensorLayout > | reshape (const symbolic::MultiExpression &new_shape) const |
| std::unique_ptr< TensorLayout > | broadcast (const symbolic::MultiExpression &ref_shape) const |
| Broadcast this layout to a bigger shape with strides correctly set. | |
| TensorLayoutType | is_2d_col_or_row_major () const |
| Checks if the layout is 2D and either column-major or row-major. | |
| bool | is_last_dims_expressible_as_row_major () const |
| Whatever the dimesionality of the entire Tensor, if it has at least 2 dimensions, and the innermost has a stride of "1" Useful to check of certain (hardware) APIs that only support 1 stride parameter and implicitly expect the other stride to be 1 can be used with this Tensor. | |
Static Public Member Functions | |
| static symbolic::MultiExpression | linear_strides (const symbolic::MultiExpression &shape) |
| static TensorLayout | deserialize_from_json (const nlohmann::json &j) |
| static bool | has_linear_accesses (symbolic::MultiExpression shape, symbolic::MultiExpression strides) |
| static bool | has_linear_accesses_no_padding (symbolic::MultiExpression shape, symbolic::MultiExpression strides, symbolic::Expression offset) |
| static std::ostream & | emit_symbolic_list (std::ostream &stream, const symbolic::MultiExpression &list) |
| static types::PrimitiveType | get_tensor_indvar_type_for_shape (const std::vector< symbolic::Expression > &shape) |
| static TensorLayoutType | is_last_dims_col_or_row_major (const symbolic::MultiExpression &strides) |
| Checks if the given strides can be looked at as col-major or row-major. | |
The metadata associated with a addressing a tensor in elements Meant to be used with TensorNodes to describe their input's and outputs layouts and ease handling of such descriptions If the TensorType will keep existing it should also be switched to use this.
Datatype is not part of it, as that can change independent of the layout. As long as the layout is strictly in elements, not bytes, there is no conflict
| sdfg::math::tensor::TensorLayout::TensorLayout | ( | const symbolic::MultiExpression & | shape, |
| const symbolic::MultiExpression & | strides = {}, | ||
| const symbolic::Expression | offset = symbolic::integer(0) ) |
| std::unique_ptr< TensorLayout > sdfg::math::tensor::TensorLayout::broadcast | ( | const symbolic::MultiExpression & | ref_shape | ) | const |
Broadcast this layout to a bigger shape with strides correctly set.
| void sdfg::math::tensor::TensorLayout::collect_symbols | ( | symbolic::SymbolSet & | set | ) | const |
|
static |
|
inline |
|
static |
| std::unique_ptr< TensorLayout > sdfg::math::tensor::TensorLayout::flip | ( | size_t | axis | ) | const |
|
inline |
| i | the dimension / entry in shape. 0 is outermost |
|
inline |
| i | 0 is innermost dim, 1 next level out etc. |
|
inline |
| i | the dimension / entry in strides. 0 is outermost |
|
inline |
| i | 0 is innermost dim, 1 next level out etc. |
|
static |
| bool sdfg::math::tensor::TensorLayout::has_linear_accesses | ( | ) | const |
|
static |
| bool sdfg::math::tensor::TensorLayout::has_linear_accesses_no_padding | ( | ) | const |
|
static |
| bool sdfg::math::tensor::TensorLayout::has_transposed_strides_no_padding | ( | ) | const |
| TensorLayoutType sdfg::math::tensor::TensorLayout::is_2d_col_or_row_major | ( | ) | const |
Checks if the layout is 2D and either column-major or row-major.
A layout is considered column-major if the stride of the first dimension is 1, and row-major if the stride of the second dimension is 1. If neither condition is met, then it is not mappable to code that expects col/row major and the outer line size, like blas GEMM or MMA cores
|
static |
Checks if the given strides can be looked at as col-major or row-major.
A layout is considered column-major if the stride of the first dimension is 1, and row-major if the stride of the second dimension is 1. If neither condition is met, then it is not mappable to code that expects col/row major and the outer line size, like blas GEMM or MMA cores Only considers the last 2 dimensions
| strides | at least the innermost 2 strides |
| bool sdfg::math::tensor::TensorLayout::is_last_dims_expressible_as_row_major | ( | ) | const |
Whatever the dimesionality of the entire Tensor, if it has at least 2 dimensions, and the innermost has a stride of "1" Useful to check of certain (hardware) APIs that only support 1 stride parameter and implicitly expect the other stride to be 1 can be used with this Tensor.
| bool sdfg::math::tensor::TensorLayout::is_scalar | ( | ) | const |
| symbolic::MultiExpression sdfg::math::tensor::TensorLayout::linear_strides | ( | ) | const |
|
static |
| symbolic::Expression sdfg::math::tensor::TensorLayout::max_accessed_byte_offset_from_ptr | ( | types::PrimitiveType | element_type | ) | const |
For memory access ranges, this should return the maximum offset from the pointer that is possible, in elements.
This is used to determine the size of a pointer access
| symbolic::Expression sdfg::math::tensor::TensorLayout::memory_span | ( | ) | const |
| std::unique_ptr< TensorLayout > sdfg::math::tensor::TensorLayout::newaxis | ( | size_t | axis | ) | const |
|
inline |
| bool sdfg::math::tensor::TensorLayout::operator== | ( | const TensorLayout & | other | ) | const |
| std::optional< symbolic::MultiExpression > sdfg::math::tensor::TensorLayout::partition_offset_into_dimensions | ( | ) | const |
Partition the layout's offset() into one coordinate offset per dimension.
Attempts to express offset() as sum_d strides[d] * dim_offset[d] and returns the per-dimension dim_offset (same size as shape). Only possible when every stride is an integer immediate and every summand of the offset is imm * x with imm divisible by some stride (the largest such stride is used); returns nullopt otherwise. Resolving coordinates with these offsets added to them yields the same element address as this layout.
| void sdfg::math::tensor::TensorLayout::replace_symbols | ( | const symbolic::Expression & | old, |
| const symbolic::Expression & | new_expr ) |
| void sdfg::math::tensor::TensorLayout::replace_symbols | ( | const symbolic::ExpressionMapping & | replacements | ) |
| std::unique_ptr< TensorLayout > sdfg::math::tensor::TensorLayout::reshape | ( | const symbolic::MultiExpression & | new_shape | ) | const |
| symbolic::Expression sdfg::math::tensor::TensorLayout::resolve_element | ( | const symbolic::MultiExpression & | indices, |
| bool | require_to_element = true ) const |
apply the index to the layout, returning an "element-address"
| require_to_element | whether the result must be a single element or could just be a sub-tensor. If true, the indices must match the shape size |
| void sdfg::math::tensor::TensorLayout::serialize_to_json | ( | nlohmann::json & | j | ) | const |
|
inline |
| std::unique_ptr< TensorLayout > sdfg::math::tensor::TensorLayout::squeeze | ( | ) | const |
| std::unique_ptr< TensorLayout > sdfg::math::tensor::TensorLayout::squeeze | ( | size_t | axis | ) | const |
|
inline |
| std::string sdfg::math::tensor::TensorLayout::toStr | ( | ) | const |
| symbolic::Expression sdfg::math::tensor::TensorLayout::total_elements | ( | ) | const |
| std::unique_ptr< TensorLayout > sdfg::math::tensor::TensorLayout::unsqueeze | ( | size_t | axis | ) | const |