#include "bev_pool.h"
using namespace AscendC;
namespace BEVPool {
template<typename T, bool Align32B>
__aicore__ inline void BEVPoolGradKernel<T, Align32B>::DoProcess()
{
LocalTensor<T> gradOutT = que_.AllocTensor<T>();
DataCopy(gradOutT, this->oGm_[this->outOffset_], this->cpFeatParams_);
que_.EnQue(gradOutT);
gradOutT = que_.DeQue<T>();
for (int32_t i = 0; i < this->length_; ++i) {
if (Align32B) {
DataCopy(this->fGm_[this->featOffset_], gradOutT, this->cpFeatParams_);
} else {
DataCopyPad(this->fGm_[this->featOffset_], gradOutT, this->cpPadParams_);
}
this->featOffset_ += this->stride0_;
}
que_.FreeTensor(gradOutT);
}
}
extern "C" __global__ __aicore__ void bev_pool_grad(GM_ADDR gradOut, GM_ADDR geomFeat, GM_ADDR intervalLengths,
GM_ADDR intervalStarts, GM_ADDR gradFeat, GM_ADDR workspace, GM_ADDR tiling)
{
GET_TILING_DATA(bevPoolTiling, tiling);
int32_t blkIdx = GetBlockIdx();
int32_t c = bevPoolTiling.stride0;
#if __CCE_AICORE__ == 220
KERNEL_TASK_TYPE_DEFAULT(KERNEL_TYPE_AIV_ONLY);
#endif
if (TILING_KEY_IS(3)) {
const int32_t cBytes = c * sizeof(float);
const int32_t divCeilC = DivCeil(cBytes, ONE_BLK_SIZE);
const int32_t alignUpCBytes = divCeilC * ONE_BLK_SIZE;
BEVPool::BEVPoolGradKernel<float, true> op(blkIdx, cBytes, divCeilC, alignUpCBytes, gradOut, geomFeat,
intervalLengths, intervalStarts, gradFeat, bevPoolTiling);
op.Process();
} else if (TILING_KEY_IS(2)) {
const int32_t cBytes = c * sizeof(float);
const int32_t divCeilC = DivCeil(cBytes, ONE_BLK_SIZE);
const int32_t alignUpCBytes = divCeilC * ONE_BLK_SIZE;
BEVPool::BEVPoolGradKernel<float, false> op(blkIdx, cBytes, divCeilC, alignUpCBytes, gradOut, geomFeat,
intervalLengths, intervalStarts, gradFeat, bevPoolTiling);
op.Process();
}
PipeBarrier<PIPE_ALL>();
}