昇腾AI原生创新算子挑战赛(S1赛季)复盘-LessEqual算子
发表于2024-05-12 21:30:47
0 查看
- 正文前感谢昇腾各位工作人员,没有你们的辛勤就没有我们的进步
- 本文立意交流大赛LessEqual算子编译过程
- 这道题考究的其实就是两个API的应用


- 只要掌握了这两个API,这道题就解了
- 当然也有一些细节问题需要考量
- 第一个问题,DT_BOOL应该如何输出?
- 这里我把输出全改成了UINT8
- 如有有人知道DT_BOOL可以提供下思路,不胜感激
- 第二个难点,找了文档很久都没看到compare和select的联合应用案例
- 这里贴half 类型input 的 compute 思路,以供参考
- 第三个难点,支持多类型计算,所以需要在compute里面做类型分类处理和类型转换
- 这里就不具体贴信息了,大家自己踊跃做尝试







this->Output("y") .ParamType(REQUIRED) .DataType({ge::DT_BOOL, ge::DT_BOOL, ge::DT_BOOL, ge::DT_BOOL}) .Format({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND}) .UnknownShapeFormat({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND});this->Output("y") .ParamType(REQUIRED) .DataType({ge::DT_UINT8, ge::DT_UINT8, ge::DT_UINT8, ge::DT_UINT8}) .Format({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND}) .UnknownShapeFormat({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND});__aicore__ inline void Compute_half(int32_t progress) { LocalTensor<half> inLocal = inQueueIN.DeQue<half>(); LocalTensor<half> x1Local = inLocal; LocalTensor<half> x2Local = inLocal[this->inQueueINAlignSize]; LocalTensor<half> tempTensor1 = calcBuf1.Get<half>(this->tileLength); LocalTensor<half> tempTensor2 = calcBuf2.Get<half>(this->tileLength); LocalTensor<half> tempTensor3 = calcBuf3.Get<half>(this->tileLength); LocalTensor<DTYPE_Y> outLocal = outQueueOUT.AllocTensor<DTYPE_Y>(); Muls(outLocal,outLocal,static_cast<DTYPE_Y>(0),this->tileLength); Muls(tempTensor1,tempTensor1,static_cast<half>(0),this->tileLength);//全0 Adds(tempTensor2,tempTensor1,static_cast<half>(1),this->tileLength);//全1 Compare(outLocal, x1Local, x2Local, CMPMODE::LE, this->tileLength); Select(tempTensor3,outLocal,tempTensor2,tempTensor1,SELMODE::VSEL_CMPMASK_SPR,this->tileLength); Cast(outLocal, tempTensor3, RoundMode::CAST_ROUND , this->tileLength); outQueueOUT.EnQue<DTYPE_Y>(outLocal);//64bytes - 8个bytes inQueueIN.FreeTensor(inLocal); }