平台:atlas 200I DK A2
版本:8.0.0.alpha003
问题:编写selectv2算子,使用DataCopyPad进行数据搬运,使用select API进行计算,但是结果错误,不明白是什么原因导致的

(输入数据:condition,x1,x2)


输出的结果:

我的核函数代码如下:
以输入数据的shape为{1}为例: 下面代码中的progress =0; length=1;TYPE_Y=half
__aicore__ inline void Process() {
int32_t loopCount = this->tileNum;
//整数次搬运
for (int32_t i = 0; i < loopCount-1; i++) {
// printf("搬运整数次的数据长度");
CopyIn(i, this->tileLength);
Compute(i, this->tileLength);
CopyOut(i, this->tileLength);
}
//如果单核上处理的元素总数不能整数次搬运,下面代码则经过整数次搬运后剩余的元素数量
if(remain_Length!=0)
{
// printf("搬运剩余的非整数次的数据长度");
CopyIn(loopCount - 1, remain_Length);
Compute(loopCount - 1, remain_Length);
CopyOut(loopCount - 1, remain_Length);
}
}
private:
__aicore__ inline void CopyIn(int32_t progress, uint32_t length) {
LocalTensor<uint8_t> condition = Q_condition.AllocTensor<uint8_t>();
LocalTensor<TYPE_X1> x1 = Q_x1.AllocTensor<TYPE_X1>();
LocalTensor<TYPE_X2> x2 = Q_x2.AllocTensor<TYPE_X2>();
//计算需要搬运次数
uint16_t blockCount = length/(256/sizeof(TYPE_Y));
blockCount = length%(256/sizeof(TYPE_Y))?blockCount+1:blockCount;
printf("ccopyin stage: blockCount= %d\n",blockCount);
//如果一次搬运的输入数据长度小于256/sizeof(TYPE_Y),则只搬运原始输入数据长度
uint16_t onceecopy_length;
onceecopy_length= length>(256/sizeof(TYPE_Y))?256:(length*sizeof(TYPE_Y));
printf("ccopyin stage: onceecopy_length = %d\n",onceecopy_length);
this->copyin_repeatParams={blockCount,onceecopy_length,0,0};
this->condition_copyin_padExtParams={true,0,0,0};
this->copyin_padExtParams={true,0,0,0};
DataCopyPad(condition, Gm_condition[progress * length], this->copyin_repeatParams, this->condition_copyin_padExtParams);
DataCopyPad( x1, Gm_x1 [progress * length], this->copyin_repeatParams, this->copyin_padExtParams);
DataCopyPad( x2, Gm_x2 [progress * length], this->copyin_repeatParams, this->copyin_padExtParams);
Q_condition.EnQue(condition);
Q_x1.EnQue(x1);
Q_x2.EnQue(x2);
}
__aicore__ inline void Compute(int32_t progress, uint32_t length) {
LocalTensor<uint8_t> condition = Q_condition.DeQue<uint8_t>();
LocalTensor<TYPE_X1> x1 = Q_x1.DeQue<TYPE_X1>();
LocalTensor<TYPE_X2> x2 = Q_x2.DeQue<TYPE_X2>();
LocalTensor<TYPE_Y> y = Q_y.AllocTensor<TYPE_Y>();
//计算mask,用于控制每次迭代内参与计算的元素。
uint16_t cal_length = 256/sizeof(TYPE_Y);
// this->mask = length>cal_length?cal_length:(((length+16-1)/16)*16);
this->mask = length>cal_length?cal_length:length;
// 计算repeatTimes,重复迭代次数
this->repeatTimes = length/(256/sizeof(TYPE_Y));
this->repeatTimes = length%(256/sizeof(TYPE_Y))? this->repeatTimes+1:this->repeatTimes;
this->cast_repeatParams = {1,1,8,8};
this->select_repeatParams = { 1, 1, 1, 8, 8, 8 };
{
Select(y,condition,x1,x2,SELMODE::VSEL_TENSOR_TENSOR_MODE,this->mask, this->repeatTimes,this->select_repeatParams);
}
Q_condition.FreeTensor(condition);
Q_x1.FreeTensor(x1);
Q_x2.FreeTensor(x2);
Q_y.EnQue<TYPE_Y>(y);
}
__aicore__ inline void CopyOut(int32_t progress, uint32_t length) {
LocalTensor<TYPE_Y> y = Q_y.DeQue<TYPE_Y>();
uint16_t blockCount = length/(256/sizeof(TYPE_Y));
blockCount = length%(256/sizeof(TYPE_Y))?blockCount+1:blockCount;
uint16_t onceecopy_length;
onceecopy_length= length>(256/sizeof(TYPE_Y))?256:(length*sizeof(TYPE_Y));
this->copyout_repeatParams={blockCount,onceecopy_length,0,0};
DataCopyPad(Gm_y[progress * length], y, this->copyout_repeatParams);
Q_y.FreeTensor(y);
} 如果需要,可提供完成工程用于问题定位,感谢。
平台:atlas 200I DK A2
版本:8.0.0.alpha003
问题:编写selectv2算子,使用DataCopyPad进行数据搬运,使用select API进行计算,但是结果错误,不明白是什么原因导致的
(输入数据:condition,x1,x2)

输出的结果:

我的核函数代码如下:
以输入数据的shape为{1}为例: 下面代码中的progress =0; length=1;TYPE_Y=half
__aicore__ inline void Process() { int32_t loopCount = this->tileNum; //整数次搬运 for (int32_t i = 0; i < loopCount-1; i++) { // printf("搬运整数次的数据长度"); CopyIn(i, this->tileLength); Compute(i, this->tileLength); CopyOut(i, this->tileLength); } //如果单核上处理的元素总数不能整数次搬运,下面代码则经过整数次搬运后剩余的元素数量 if(remain_Length!=0) { // printf("搬运剩余的非整数次的数据长度"); CopyIn(loopCount - 1, remain_Length); Compute(loopCount - 1, remain_Length); CopyOut(loopCount - 1, remain_Length); } } private: __aicore__ inline void CopyIn(int32_t progress, uint32_t length) { LocalTensor<uint8_t> condition = Q_condition.AllocTensor<uint8_t>(); LocalTensor<TYPE_X1> x1 = Q_x1.AllocTensor<TYPE_X1>(); LocalTensor<TYPE_X2> x2 = Q_x2.AllocTensor<TYPE_X2>(); //计算需要搬运次数 uint16_t blockCount = length/(256/sizeof(TYPE_Y)); blockCount = length%(256/sizeof(TYPE_Y))?blockCount+1:blockCount; printf("ccopyin stage: blockCount= %d\n",blockCount); //如果一次搬运的输入数据长度小于256/sizeof(TYPE_Y),则只搬运原始输入数据长度 uint16_t onceecopy_length; onceecopy_length= length>(256/sizeof(TYPE_Y))?256:(length*sizeof(TYPE_Y)); printf("ccopyin stage: onceecopy_length = %d\n",onceecopy_length); this->copyin_repeatParams={blockCount,onceecopy_length,0,0}; this->condition_copyin_padExtParams={true,0,0,0}; this->copyin_padExtParams={true,0,0,0}; DataCopyPad(condition, Gm_condition[progress * length], this->copyin_repeatParams, this->condition_copyin_padExtParams); DataCopyPad( x1, Gm_x1 [progress * length], this->copyin_repeatParams, this->copyin_padExtParams); DataCopyPad( x2, Gm_x2 [progress * length], this->copyin_repeatParams, this->copyin_padExtParams); Q_condition.EnQue(condition); Q_x1.EnQue(x1); Q_x2.EnQue(x2); } __aicore__ inline void Compute(int32_t progress, uint32_t length) { LocalTensor<uint8_t> condition = Q_condition.DeQue<uint8_t>(); LocalTensor<TYPE_X1> x1 = Q_x1.DeQue<TYPE_X1>(); LocalTensor<TYPE_X2> x2 = Q_x2.DeQue<TYPE_X2>(); LocalTensor<TYPE_Y> y = Q_y.AllocTensor<TYPE_Y>(); //计算mask,用于控制每次迭代内参与计算的元素。 uint16_t cal_length = 256/sizeof(TYPE_Y); // this->mask = length>cal_length?cal_length:(((length+16-1)/16)*16); this->mask = length>cal_length?cal_length:length; // 计算repeatTimes,重复迭代次数 this->repeatTimes = length/(256/sizeof(TYPE_Y)); this->repeatTimes = length%(256/sizeof(TYPE_Y))? this->repeatTimes+1:this->repeatTimes; this->cast_repeatParams = {1,1,8,8}; this->select_repeatParams = { 1, 1, 1, 8, 8, 8 }; { Select(y,condition,x1,x2,SELMODE::VSEL_TENSOR_TENSOR_MODE,this->mask, this->repeatTimes,this->select_repeatParams); } Q_condition.FreeTensor(condition); Q_x1.FreeTensor(x1); Q_x2.FreeTensor(x2); Q_y.EnQue<TYPE_Y>(y); } __aicore__ inline void CopyOut(int32_t progress, uint32_t length) { LocalTensor<TYPE_Y> y = Q_y.DeQue<TYPE_Y>(); uint16_t blockCount = length/(256/sizeof(TYPE_Y)); blockCount = length%(256/sizeof(TYPE_Y))?blockCount+1:blockCount; uint16_t onceecopy_length; onceecopy_length= length>(256/sizeof(TYPE_Y))?256:(length*sizeof(TYPE_Y)); this->copyout_repeatParams={blockCount,onceecopy_length,0,0}; DataCopyPad(Gm_y[progress * length], y, this->copyout_repeatParams); Q_y.FreeTensor(y); }如果需要,可提供完成工程用于问题定位,感谢。