#include "TRTScatterNd.hpp" #include #include "TRTBackend.hpp" #include "schema/current/MNNPlugin_generated.h" using namespace std; namespace MNN { TRTScatterNd::TRTScatterNd(Backend *b, const Op *op, const std::vector &inputs, const std::vector &outputs) : MNN::TRTCommonExecution(b, op) { // Do nothing } std::vector TRTScatterNd::onEncode(const std::vector &xOp) { #ifdef TRT_LOG MNN_PRINT("\n\nTRTScatterNd in\n\n"); #endif auto plu = createPluginWithOutput(mOutputs); plu->main.type = MNNTRTPlugin::Parameter_ScatterNdInfo; plu->main.value = new MNNTRTPlugin::ScatterNdInfoT; auto scatter = plu->main.AsScatterNdInfo(); MNN_ASSERT(mInputs.size() == 3); auto indices = mInputs[0]; auto updates = mInputs[1]; auto shape = mInputs[2]; auto output = mOutputs[0]; const int indicesDimension = indices->dimensions(); scatter->indicesLastDim = indices->length(indicesDimension - 1); scatter->indexes = indices->elementSize() / scatter->indicesLastDim; scatter->accNumber = 1; for (int i = indicesDimension - 1; i < updates->dimensions(); ++i) { scatter->accNumber *= updates->length(i); } const int outputElementSize = output->elementSize(); scatter->outElementSize = outputElementSize; int remainSize = outputElementSize; std::vector temp(scatter->indicesLastDim, 0); for (int i = 0; i < scatter->indicesLastDim; ++i) { temp[i] = remainSize / output->length(i); remainSize = temp[i]; } scatter->dimsToCount.assign(temp.begin(), temp.end()); auto scatterNdPlugin = (nvinfer1::IPluginExt *)MNNTRTCreatePlugion(mOp, plu.get()); nvinfer1::IPluginLayer *plugin = mTrtBackend->getNetwork()->addPluginExt(&xOp[0], 2, *((nvinfer1::IPluginExt *)scatterNdPlugin)); if (plugin == nullptr) { MNN_PRINT("scatterNd plugin == nullptr !!!\n"); } mTrtBackend->pushReleaseLayer(scatterNdPlugin); return {plugin->getOutput(0)}; } TRTCreatorRegister> __scatterNd_op(OpType_ScatterNd); }