CANN/asc-devkit Tensor API Coshape布局函数

发布时间:2026/7/15 15:21:22

CANN/asc-devkit Tensor API Coshape布局函数 Coshape产品支持情况产品是否支持Ascend 950PR/Ascend 950DT√功能说明需要包含的头文件为#include tensor_api/tensor.h。Coshape表示Layout陪域codomain区间的标量大小即逻辑坐标映射到一维索引后所有可能的索引值构成的区间大小。其计算公式为Coshape Σ( (shape[i] - 1) × stride[i] ) 1函数原型template size_t... Is, typename Shape, typename Stride __aicore__ inline constexpr auto Coshape(const LayoutShape, Stride layout)参数说明表1模板参数说明参数名类型描述Shape输入组成Layout的shape的类型即元组tuple类型。Stride输入组成Layout的stride的类型即元组tuple类型。Is...size_t...索引序列指定子维度范围仅对选定维度进行计算。表2参数说明参数名类型描述layout输入Layout用于描述张量的布局。返回值说明返回Layout的陪域codomain的形状。约束说明Is...必须为有效范围内的索引。调用示例using namespace AscendC::Te; // 示例1基础计算 auto layout MakeLayout(MakeShape(10, 20), MakeStride(1, 100)); auto coshape Coshape(layout); // (10-1)*1 (20-1)*100 1 9 1900 1 1910 // 示例2指定子维度 auto coshape0 Coshape0(layout); // (10-1)*1 1 9 1 10 auto coshape1 Coshape1(layout); // (20-1)*100 1 1900 1 1901创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

相关新闻