Query

功能说明

查询handleId对应的通信任务已经完成的轮次,最多返回repeat轮。该接口默认在所有核上工作,用户也可以在调用前通过GetBlockIdx指定其在某一个核上运行。

函数原型

1
__aicore__ inline int32_t Query(HcclHandle handleId)

参数说明

表1 接口参数说明

参数名

输入/输出

描述

handleId

输入

对应通信任务的标识ID,只能使用Prepare原语接口的返回值。

1
using HcclHandle = int8_t;

返回值

支持的型号

Atlas A2 训练系列产品/Atlas 800I A2 推理产品/A200I A2 Box 异构组件

约束说明

调用示例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
REGISTER_TILING_DEFAULT(ReduceScatterCustomTilingData); //ReduceScatterCustomTilingData为对应算子头文件定义的结构体
auto tiling = (__gm__ ReduceScatterCustomTilingData*)tilingGM;
Hccl hccl;
GM_ADDR contextGM = AscendC::GetHcclContext<0>();  // AscendC自定义算子kernel中,通过此方式获取Hccl context
__gm__ void *mc2InitTiling = (__gm__ void *)(&tiling->mc2InitTiling);
__gm__ void *mc2CcTiling = (__gm__ void *)(&(tiling->mc2CcTiling));
hccl.Init(contextGM, mc2InitTiling);
auto ret = hccl.SetCcTiling(mc2CcTiling);
if (ret != HCCL_SUCCESS) {
  return;
}
if (AscendC::g_coreType == AIC) {
    auto repeat = 10;
    HcclHandle handleId = hccl.ReduceScatter(sendBuf, recvBuf, 100, HcclDataType::HCCL_DATA_TYPE_INT8, HcclReduceOp::HCCL_REDUCE_SUM, repeat);
    hccl.Commit(handleId ); // 通知服务端可以执行上述的ReduceScatter任务
    int32_t finishedCount = hccl.Query(handleId);
    while (hccl.Query(handleId) < repeat) {} // 等待查询到handleId对应的通信任务执行repeat次
    hccl.Finalize(); // 后续无其他通信任务,通知服务端执行上述ReduceScatter任务之后即可以退出
}