Init
====

#### 功能说明

初始化内存和用于同步流水事件的EventID的初始化。

#### 函数原型

\_\_aicore\_\_ inline void TPipe::Init()

#### 支持的型号

Kirin9020系列处理器

KirinX90系列处理器

#### 注意事项

重复申请释放TPipe，要与[Destroy](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-destroy)接口成对使用，TPipe如果要重复申请需要先Destroy释放后再Init。

#### 返回值

无

#### 调用示例

template <typename srcType> 
class KernelAsin {
public:
    \_\_aicore\_\_ inline KernelAsin()
    {}
    \_\_aicore\_\_ inline void Init(GM\_ADDR src\_gm, GM\_ADDR dst\_gm, uint32\_t srcSize, TPipe \*pipe)
    {
        src\_global.SetGlobalBuffer(reinterpret\_cast<\_\_gm\_\_ srcType \*>(src\_gm), srcSize);
        dst\_global.SetGlobalBuffer(reinterpret\_cast<\_\_gm\_\_ srcType \*>(dst\_gm), srcSize);
        pipe->InitBuffer(inQueueX, 1, srcSize \* sizeof(srcType));
        pipe->InitBuffer(outQueue, 1, srcSize \* sizeof(srcType));
        bufferSize = srcSize;
    }
    \_\_aicore\_\_ inline void Process()
    {
        CopyIn();
        Compute();
        CopyOut();
    }
private:
    \_\_aicore\_\_ inline void CopyIn()
    {
        AscendC::LocalTensor<srcType> srcLocal = inQueueX.AllocTensor<srcType>();
        AscendC::DataCopy(srcLocal, src\_global, bufferSize);
        inQueueX.EnQue(srcLocal);
    }
    \_\_aicore\_\_ inline void Compute()
    {
        AscendC::LocalTensor<srcType> dstLocal = outQueue.AllocTensor<srcType>();
        AscendC::LocalTensor<srcType> srcLocal = inQueueX.DeQue<srcType>();
        int16\_t scalar\_value = 3;
        AscendC::Muls(dstLocal, srcLocal, (srcType)scalar\_value, bufferSize);
        outQueue.EnQue<srcType>(dstLocal);
        inQueueX.FreeTensor(srcLocal);
    }
    \_\_aicore\_\_ inline void CopyOut(uint32\_t offset)
    {
        AscendC::LocalTensor<srcType> dstLocal = outQueue.DeQue<srcType>();
        AscendC::DataCopy(dst\_global, dstLocal, bufferSize);
        outQueue.FreeTensor(dstLocal);
    }
private:
    AscendC::GlobalTensor<srcType> src\_global;
    AscendC::GlobalTensor<srcType> dst\_global;
    AscendC::TQue<AscendC::QuePosition::VECIN, 1> inQueueX;
    AscendC::TQue<AscendC::QuePosition::VECOUT, 1> outQueue;
    uint32\_t bufferSize = 0;
};
template <typename dataType> 
\_\_aicore\_\_ void kernel\_Test\_operator(GM\_ADDR src\_gm, GM\_ADDR dst\_gm, uint32\_t srcSize)
{
    KernelAsin<dataType> op;
    AscendC::TPipe pipeIn;
    for (uint32\_t index =0; index < 1; index++) {
        if (index != 0) {
            pipeIn.Init();
        }
        op.Process();
        pipeIn.Destroy();
        AscendC::TPipe pipeCast;
        op.Init(src\_gm, dst\_gm, srcSize, &pipeCast);
        op.Process();
        pipeCast.Destroy();
    }
}