Overview

Coordinate is essentially a tuple, used to represent the position information of a tensor in different dimensions, that is, the coordinate value. There is a close relationship between coordinates, layouts, and indexes:

  • Conversion from coordinates to indexes: The layout defines the shape of a tensor and the stride of each dimension. Based on this information and the given coordinates, the memory index corresponding to the coordinates can be calculated.
  • Conversion from indexes to coordinates: Based on the shape and stride information defined in the layout, for a known memory location index, the corresponding coordinates can be obtained through calculation.

Prototype

template <typename... Coords>
using Coord = Std::tuple<Coords...>

Template Parameters

Table 1 Template parameters

Parameter

Description

Coords

Formal parameter package of the input data type. The number of parameters ranges from 0 to 64.

The input data type can be size_t or Std::Int.

Related APIs

// Coord construction method
template <typename... Ts>
__aicore__ inline constexpr Coord<Ts...> MakeCoord(Ts const&... t)

// Layout input, converting coordinates to memory location indexes
template <typename CoordType, typename ShapeType, typename StrideType>
__aicore__ inline constexpr auto Crd2Idx(const CoordType& coord, const Layout<ShapeType, StrideType>& layout)

// Shape and stride input, converting coordinates to memory location indexes
template <typename CoordType, typename ShapeType, typename StrideType>
__aicore__ inline constexpr auto Crd2Idx(const CoordType& coord, const ShapeType& shape, const StrideType& stride)