2023-07-18 09:36:26 +08:00
|
|
|
//
|
|
|
|
// LayerNormExecution.hpp
|
|
|
|
// MNN
|
|
|
|
//
|
|
|
|
// Created by MNN on 2023/07/05.
|
|
|
|
// Copyright © 2018, Alibaba Group Holding Limited
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef LayerNormExecution_hpp
|
|
|
|
#define LayerNormExecution_hpp
|
|
|
|
|
2024-04-19 11:58:21 +08:00
|
|
|
#include "CommonExecution.hpp"
|
2023-07-18 09:36:26 +08:00
|
|
|
|
|
|
|
namespace MNN {
|
|
|
|
namespace OpenCL {
|
2025-03-12 11:35:16 +08:00
|
|
|
struct LayernormResource {
|
|
|
|
std::shared_ptr<cl::Buffer> mGammaBuffer;
|
|
|
|
std::shared_ptr<cl::Buffer> mBetaBuffer;
|
2025-03-28 18:42:08 +08:00
|
|
|
bool has_gamma_beta_ = false;
|
2025-03-12 11:35:16 +08:00
|
|
|
uint32_t mMaxWorkGroupSize;
|
|
|
|
int axis_size ;
|
|
|
|
int group_ ;
|
|
|
|
float epsilon_;
|
|
|
|
bool RMSNorm;
|
|
|
|
};
|
2024-04-19 11:58:21 +08:00
|
|
|
class LayerNormExecution : public CommonExecution {
|
2023-07-18 09:36:26 +08:00
|
|
|
public:
|
|
|
|
LayerNormExecution(const std::vector<Tensor *> &inputs, const MNN::Op *op, Backend *backend);
|
2025-03-12 11:35:16 +08:00
|
|
|
LayerNormExecution(std::shared_ptr<LayernormResource> resource, const Op* op, Backend* backend);
|
2023-07-18 09:36:26 +08:00
|
|
|
virtual ~LayerNormExecution() = default;
|
|
|
|
|
2024-04-19 11:58:21 +08:00
|
|
|
virtual ErrorCode onEncode(const std::vector<Tensor *> &inputs, const std::vector<Tensor *> &outputs) override;
|
2025-03-12 11:35:16 +08:00
|
|
|
virtual bool onClone(Backend* bn, const Op* op, Execution** dst) override;
|
2023-07-18 09:36:26 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
int getLocalSize(int size, int maxGroupSize);
|
|
|
|
OpenCLBackend *mOpenCLBackend;
|
2025-03-12 11:35:16 +08:00
|
|
|
std::shared_ptr<LayernormResource> mResource;
|
2023-07-18 09:36:26 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace OpenCL
|
|
|
|
} // namespace MNN
|
|
|
|
#endif /* LayerNormExecution_hpp */
|