#include "bev_pool_v2.h"
using namespace AscendC;
namespace BEVPoolV2 {
template<typename T, bool Align32B>
__aicore__ inline void BEVPoolV2Kernel<T, Align32B>::DoProcess()
{
LocalTensor<T> outT = outQue_.AllocTensor<T>();
Duplicate(outT, T(0.f), this->alignUpCCount_);
this->outOffset_ = this->rBGm_.GetValue(this->start_) * this->stride0_;
for (int32_t i = 0; i < this->length_; ++i) {
this->depthOffset_ = this->rDGm_.GetValue(this->start_ + i);
this->featOffset_ = this->rFGm_.GetValue(this->start_ + i) * this->stride0_;
T depth = this->dGm_.GetValue(this->depthOffset_);
LocalTensor<T> featT = this->featQue_.template AllocTensor<T>();
DataCopy(featT, this->fGm_[this->featOffset_], this->cpFeatParams_);
this->featQue_.EnQue(featT);
featT = this->featQue_.template DeQue<T>();
Muls(featT, featT, depth, this->alignUpCCount_);
Add(outT, featT, outT, this->alignUpCCount_);
this->featQue_.FreeTensor(featT);
}
outQue_.EnQue(outT);
outT = outQue_.DeQue<T>();
if (Align32B) {
DataCopy(this->oGm_[this->outOffset_], outT, this->cpFeatParams_);
} else {
DataCopyPad(this->oGm_[this->outOffset_], outT, this->cpPadParams_);
}
outQue_.FreeTensor(outT);
}
}
extern "C" __global__ __aicore__ void bev_pool_v2(GM_ADDR depth, GM_ADDR feat, GM_ADDR ranksDepth, GM_ADDR ranksFeat,
GM_ADDR ranksBev, GM_ADDR intervalLengths, GM_ADDR intervalStarts, GM_ADDR out, 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;
BEVPoolV2::BEVPoolV2Kernel<float, true> op(blkIdx, cBytes, divCeilC, alignUpCBytes, depth, feat, ranksDepth,
ranksFeat, ranksBev, intervalLengths, intervalStarts, out, 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;
BEVPoolV2::BEVPoolV2Kernel<float, false> op(blkIdx, cBytes, divCeilC, alignUpCBytes, depth, feat, ranksDepth,
ranksFeat, ranksBev, intervalLengths, intervalStarts, out, bevPoolTiling);
op.Process();
}
PipeBarrier<PIPE_ALL>();
}