aclnnMultiScaleDeformableAttnFunction
支持的产品型号
- Atlas A2训练系列产品/Atlas 800I A2推理产品。
接口原型
每个算子分为undefined,必须先调用“aclnnMultiScaleDeformableAttnFunctionGetWorkspaceSize”接口获取计算所需workspace大小以及包含了算子计算流程的执行器,再调用“aclnnMultiScaleDeformableAttnFunction”接口执行计算。
aclnnStatus aclnnMultiScaleDeformableAttnFunctionGetWorkspaceSize(const aclTensor *value, const aclTensor *spatialShape, const aclTensor *levelStartIndex, const aclTensor *location, const aclTensor *attnWeight, aclTensor *output, uint64_t *workspaceSize, aclOpExecutor **executor)
aclnnStatus aclnnMultiScaleDeformableAttnFunction(void *workspace, uint64_t workspaceSize, aclOpExecutor *executor, aclrtStream stream)
功能描述
- 功能描述: MultiScaleDeformableAttention算子功能主要通过采样位置(sample location)、注意力权重(attention weights)、映射后的value特征、多尺度特征起始索引位置、多尺度特征图的空间大小(便于将采样位置由归一化的值变成绝对位置)等参数来遍历不同尺寸特征图的不同采样点。
aclnnMultiScaleDeformableAttnFunctionGetWorkspaceSize
参数说明:
- value(aclTensor*, 计算输入):特征图的特征值,Device侧的aclTensor,数据类型支持FLOAT、FLOAT16、BFLOAT16,shape为(bs, spatial_size, mum_heads, channels),支持undefined,undefined支持ND
- spatialShape(aclTensor*, 计算输入):存储每个尺度特征图的高和宽,Device侧的aclTensor,数据类型支持INT32、INT64,shape为(num_levels, 2),支持undefined,undefined支持ND
- levelStartIndex(aclTensor*, 计算输入):每张特征图的起始索引,Device侧的aclTensor,数据类型支持INT32、INT64,shape为(num_levels,),支持undefined,undefined支持ND
- location(aclTensor*, 计算输入):采样点位置tensor,存储每个采样点的坐标位置,Device侧的aclTensor,数据类型支持FLOAT、FLOAT16、BFLOAT16,数据类型需要和value保持一致,shape为(bs, num_queries, num_heads, num_levels, num_points, 2),支持undefined,undefined支持ND
- attnWeight(aclTensor*, 计算输入):采样点权重tensor,Device侧的aclTensor,数据类型支持FLOAT、FLOAT16、BFLOAT16,数据类型需要和value保持一致,shape为(bs, num_queries, num_heads, num_levels, num_points),支持undefined,undefined支持ND
- output(aclTensor*, 计算输入):算子计算输出,Device侧的aclTensor,数据类型支持FLOAT、FLOAT16、BFLOAT16,数据类型需要和value保持一致,shape为(bs, num_queries, num_heads, channels),支持undefined,undefined支持ND
- workspaceSize(uint64_t*, 出参):返回需要在Device侧申请的workspace大小。
- executor(aclOpExecutor**, 出参):返回op执行器,包含了算子计算流程。
返回值:
aclnnStatus:返回状态码,具体参见undefined。
[object Object]
aclnnMultiScaleDeformableAttnFunction
参数说明:
- workspace(void*, 入参):在Device侧申请的workspace内存地址。
- workspaceSize(uint64_t, 入参):在Device侧申请的workspace大小,由第一段接口aclnnMultiScaleDeformableAttnFunctionGetWorkspaceSize获取。
- executor(aclOpExecutor*, 入参):op执行器,包含了算子计算流程。
- stream(aclrtStream, 入参):指定执行任务的AscendCL Stream流。
返回值:
aclnnStatus:返回状态码,具体参见undefined。
约束与限制
channels % 8 == 0,且channels<=256 32 <= num_queries < 500000 num_level <= 16 mum_heads <= 16 num_points <= 16
调用示例
示例代码如下,仅供参考,具体编译和执行过程请参考undefined。
[object Object]