文档
注册

GetBlockIdx

功能说明

获取当前core的index,用于代码内部的多核逻辑控制及多核偏移量计算等。

函数原型

__aicore__ inline int64_t GetBlockIdx()

参数说明

返回值

当前core的index,index的范围为[0, 用户配置的block_dim数量 - 1]

支持的型号

Atlas 训练系列产品

Atlas推理系列产品(Ascend 310P处理器)AI Core

Atlas A2训练系列产品

约束说明

GetBlockIdx为一个系统内置函数,返回当前核的index。

调用示例

#include "kernel_operator.h"
namespace AscendC {
constexpr int32_t SINGLE_CORE_OFFSET = 256;
class KernelGetBlockIdx {
public:
    __aicore__ inline KernelGetBlockIdx () {}
    __aicore__ inline void Init(__gm__ uint8_t* src0Gm, __gm__ uint8_t* src1Gm, __gm__ uint8_t* dstGm)
    {
        // 根据index对每个核进行地址偏移
        src0Global.SetGlobalBuffer((__gm__ float*)src0Gm + GetBlockIdx() * SINGLE_CORE_OFFSET);
        src1Global.SetGlobalBuffer((__gm__ float*)src1Gm + GetBlockIdx() * SINGLE_CORE_OFFSET);
        dstGlobal.SetGlobalBuffer((__gm__ float*)dstGm + GetBlockIdx() * SINGLE_CORE_OFFSET);
        pipe.InitBuffer(inQueueSrc0, 1, 256 * sizeof(float));
        pipe.InitBuffer(inQueueSrc1, 1, 256 * sizeof(float));
        pipe.InitBuffer(selMask, 1, 256);
        pipe.InitBuffer(outQueueDst, 1, 256 * sizeof(float));
    }
    ......
};
} // namespace AscendC
搜索结果
找到“0”个结果

当前产品无相关内容

未找到相关内容,请尝试其他搜索词