昇腾社区首页
中文
注册

aclnnRepeatInterleave

支持的产品型号

  • Atlas 训练系列产品。
  • Atlas A2训练系列产品。

接口原型

每个算子分为,必须先调用“aclnnRepeatInterleaveGetWorkspaceSize”接口获取计算所需workspace大小以及包含了算子计算流程的执行器,再调用“aclnnRepeatInterleave”接口执行计算。

  • aclnnStatus aclnnRepeatInterleaveGetWorkspaceSize(const aclTensor *self, const aclTensor *repeats, int64_t outputSize, aclTensor *out, uint64_t *workspaceSize, aclOpExecutor **executor)
  • aclnnStatus aclnnRepeatInterleave(void *workspace, uint64_t workspaceSize, aclOpExecutor *executor, const aclrtStream stream)

功能描述

算子功能:将tensor self进行flatten后,重复Tensor repeats中的相应次数。示例: 假设input tensor是 ([[a, b], [c, d], [e, f]]), repeats为([1, 2, 2, 1, 1, 1])。 那么最后生成的tensor为 tensor([a, b, b, c, c, d, e, f]) 将tensor进行flatten后,input转变为 ([a, b, c, d, e, f])。该tensor与repeats一一对应进行复制,a重复1次、b重复2次、c重复2次,以此类推。

假设input tensor是 ([[a, b], [c, d], [e, f]]), repeats为([2])。 那么最后生成的tensor为 tensor([a, a, b, b, c, c, d, d, e, e, f, f])。 将tensor进行flatten后,input转变为 ([a, b, c, d, e, f])。该tensor中的每个元素复制repeats中的元素次数,也就是每个元素复制2次。 注意:该场景等效于 repeats为(2)。

在计算时需要满足以下要求:

  • repeats只能为0D / 1D tensor。 如果为1D tensor,那么repeats的size必须为1或self的元素个数。 repeats tensor中的值必须为自然数。
  • outputSize的值必须符合以下计算结果: 当repeats中只有一个元素时,outputSize = self的元素个数 * repeats的值。 当repeats中有多个值时,outputSize = repeats的值之和。

aclnnRepeatInterleaveGetWorkspaceSize

  • 参数说明:

    • self(aclTensor*, 计算输入):数据类型支持UINT8、INT8、INT16、INT32、INT64、BOOL、FLOAT16、FLOAT32类型。支持空tensor, 支持非连续的tensor。支持ND。

    • repeats(aclTensor*, 计算输入):数据类型支持INT64。repeats只能为0D / 1D Tensor。如果为1D Tensor,那么repeats的size必须为1或self的元素个数。支持空tensor,支持非连续的tensor。支持ND。

    • outputSize(int64_t, 计算输入):进行重复后的tensor最终大小。数据类型为INT64。当repeats中只有一个元素时,outputSize = self的元素个数 * repeats的值。当repeats中有多个值时,outputSize = repeats的值之和。

    • out(aclTensor*, 计算输出): 数据类型支持UINT8、INT8、INT16、INT32、INT64、BOOL、FLOAT16、FLOAT32类型。数据类型需要与self一致。

    • workspaceSize(uint64_t *,出参):返回用户需要在Device侧申请的workspace大小。

    • executor(aclOpExecutor **,出参) :返回op执行器,包含了算子计算流程。

  • 返回值:

    aclnnStatus:返回状态码,具体参见

[object Object]

aclnnRepeatInterleave

  • 参数说明:

    • workspace(void*,入参):在Device侧申请的workspace内存地址。

    • workspaceSize(uint64_t*,入参):在Device侧申请的workspace大小,由第一段接口aclnnRepeatInterleaveGetWorkspaceSize获取。

    • executor(aclOpExecutor *,入参):op执行器,包含了算子计算流程。

    • stream(aclrtStream,入参):指定执行任务的 AscendCL Stream流。

  • 返回值:

    aclnnStatus:返回状态码,具体参见

约束与限制

无。

调用示例

示例代码如下,仅供参考,具体编译和执行过程请参考

[object Object]