CANN/asc-devkit张量布局API文档
Layout【免费下载链接】asc-devkit本项目是CANN 推出的昇腾AI处理器专用的算子程序开发语言原生支持C和C标准规范主要由类库和语言扩展层构成提供多层级API满足多维场景算子开发诉求。项目地址: https://gitcode.com/cann/asc-devkit功能说明Layout用于定义张量的布局包含Shape和Stride信息描述张量在内存中的组织方式。结构体定义template typename T, typename U struct Layout : private Std::tupleT, U { static constexpr auto size StaticLayoutSizeT, U::size; static constexpr auto depth nesting_depth_vT; static constexpr auto rank Std::tuple_size_vT; __aicore__ inline constexpr Layout(const T shape {}, const U stride {}); __aicore__ inline constexpr decltype(auto) Capacity() const; __aicore__ inline constexpr decltype(auto) layout(); __aicore__ inline constexpr decltype(auto) layout() const; template size_t... I __aicore__ inline constexpr decltype(auto) Shape(); template size_t... I __aicore__ inline constexpr decltype(auto) Shape() const; template size_t... I __aicore__ inline constexpr decltype(auto) Stride(); template size_t... I __aicore__ inline constexpr decltype(auto) Stride() const; template typename S __aicore__ inline constexpr auto operator()(const S coord) const; template size_t... I __aicore__ inline constexpr decltype(auto) Rank() const; template size_t... I __aicore__ inline constexpr decltype(auto) Size() const; };模板参数参数名描述TStd::tuple结构类型用于定义数据的逻辑形状例如二维矩阵的行数和列数或多维张量的各维度大小。UStd::tuple结构类型用于定义各维度在内存中的步长即同维度相邻元素在内存中的间隔间隔的单位为元素与Shape的维度信息一一对应。成员函数说明Layout(const T shape, const U stride)功能说明使用给定shape和stride构造Layout对象。构造Layout对象时传入的Shape和Stride结构需是Std::tuple结构类型且满足Std::tuple结构类型的使用约束。函数原型__aicore__ inline constexpr Layout(const T shape {}, const U stride {});参数说明shape布局形状信息。stride布局步长信息。返回值说明构造函数无返回值。Capacity()功能说明返回Layout的容量。函数原型__aicore__ inline constexpr decltype(auto) Capacity() const;返回值说明返回Layout对象能够覆盖的容量上界。Shape()功能说明返回shape中按指定维度选择出来的子结构。函数原型template size_t... I __aicore__ inline constexpr decltype(auto) Shape(); template size_t... I __aicore__ inline constexpr decltype(auto) Shape() const;返回值说明返回shape中按指定维度选择出来的子结构类型为Shape。Stride()功能说明返回stride中按指定维度选择出来的子结构。函数原型template size_t... I __aicore__ inline constexpr decltype(auto) Stride(); template size_t... I __aicore__ inline constexpr decltype(auto) Stride() const;返回值说明返回stride中按指定维度选择出来的子结构类型为Stride。layout()功能说明返回当前Layout对象本身。函数原型__aicore__ inline constexpr decltype(auto) layout(); __aicore__ inline constexpr decltype(auto) layout() const;返回值说明返回当前Layout对象的引用或const引用。operator()(const S coord)功能说明根据输入坐标coord通过布局(Layout)转换为内存位置的索引(Index)。函数原型template typename S __aicore__ inline constexpr auto operator()(const S coord) const;参数说明coord坐标信息通常为与shape维度匹配的坐标tuple。返回值说明返回由坐标映射得到的内存位置索引值。Rank()功能说明返回Layout的秩信息支持指定的维度I...提取子结构的秩。函数原型template size_t... I __aicore__ inline constexpr decltype(auto) Rank() const;返回值说明返回完整结构或对应子结构的秩。Size()功能说明返回Layout的有效元素个数支持按索引路径提取子结构的有效元素个数。函数原型template size_t... I __aicore__ inline constexpr decltype(auto) Size() const;返回值说明返回Layout的有效元素个数支持按索引路径提取子结构的有效元素个数。静态成员常量说明size功能说明表示Layout展平后的静态元素个数编译期常量。定义原型static constexpr auto size StaticLayoutSizeT, U::size;depth功能说明表示shape的嵌套深度编译期常量。定义原型static constexpr auto depth nesting_depth_vT;rank功能说明表示shape顶层维度个数编译期常量。定义原型static constexpr auto rank Std::tuple_size_vT;【免费下载链接】asc-devkit本项目是CANN 推出的昇腾AI处理器专用的算子程序开发语言原生支持C和C标准规范主要由类库和语言扩展层构成提供多层级API满足多维场景算子开发诉求。项目地址: https://gitcode.com/cann/asc-devkit创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考