MNN/source/backend/cpu/CPULayerNorm.hpp

44 lines
1.3 KiB
C++
Raw Normal View History

2023-09-04 10:42:11 +08:00
//
// CPULayerNorm.hpp
// MNN
//
// Created by MNN on 2023/07/11
// Copyright © 2018, Alibaba Group Holding Limited
//
#ifndef CPULayerNorm_hpp
#define CPULayerNorm_hpp
#include "core/Execution.hpp"
#include "core/Macro.h"
2024-06-03 20:09:34 +08:00
#include "core/BufferAllocator.hpp"
2023-09-04 10:42:11 +08:00
namespace MNN {
class CPULayerNorm : public Execution {
public:
2024-04-19 11:58:21 +08:00
struct Resource {
int mGroup = 1;
float mEpsilon = 0.001;
std::unique_ptr<Tensor> mGamma;
std::unique_ptr<Tensor> mBeta;
bool mIniGammaBeta = false;
bool mRMSNorm = false;
int mAxis = 0;
};
CPULayerNorm(std::shared_ptr<Resource> res, Backend* backend);
2023-09-04 10:42:11 +08:00
virtual ~CPULayerNorm();
2024-04-19 11:58:21 +08:00
virtual ErrorCode onExecute(const std::vector<Tensor*> &inputs, const std::vector<Tensor*> &outputs) override;
virtual ErrorCode onResize(const std::vector<Tensor*> &inputs, const std::vector<Tensor*> &outputs) override;
virtual bool onClone(Backend* bn, const Op* op, Execution** dst) override;
static std::shared_ptr<Resource> makeResource(const MNN::Op* op, Backend* backend);
2023-09-04 10:42:11 +08:00
private:
2024-04-19 11:58:21 +08:00
std::shared_ptr<Resource> mResource;
2023-09-04 10:42:11 +08:00
int mInnerSize = 1;
int mOutterSize = 1;
2024-06-03 20:09:34 +08:00
MemChunk mTmpInputFloat;
MemChunk mTmpOutputFloat;
2023-09-04 10:42:11 +08:00
};
} // namespace MNN
#endif /* CPULayerNorm_hpp */