MNN/source/backend/cpu/CPUAttention.hpp

45 lines
1.2 KiB
C++
Raw Normal View History

2024-05-11 19:17:02 +08:00
//
// CPUAttention.hpp
// MNN
//
// Created by MNN on 2024/03/19.
// Copyright © 2018, Alibaba Group Holding Limited
//
#ifdef MNN_SUPPORT_TRANSFORMER_FUSE
#ifndef CPUATTENTION_HPP
#define CPUATTENTION_HPP
#include <functional>
#include "core/Execution.hpp"
2024-08-24 15:46:21 +08:00
#include "MNN/ErrorCode.hpp"
#include "KVCacheManager.hpp"
2024-05-11 19:17:02 +08:00
namespace MNN {
class CPUAttention : public Execution {
public:
CPUAttention(Backend *backend, bool kv_cache);
2024-08-24 15:46:21 +08:00
virtual ~CPUAttention();
2024-05-11 19:17:02 +08:00
virtual ErrorCode onResize(const std::vector<Tensor *> &inputs, const std::vector<Tensor *> &outputs) override;
virtual ErrorCode onExecute(const std::vector<Tensor *> &inputs, const std::vector<Tensor *> &outputs) override;
virtual bool onClone(Backend* bn, const Op* op, Execution** dst) override;
private:
2024-08-24 15:46:21 +08:00
bool mIsPrefill = true;
2024-07-22 19:51:53 +08:00
bool mIsFirstPrefill = true;
2024-08-24 15:46:21 +08:00
bool mKVCache = true;
int bytes = 4;
int mThreadNum = 1;;
int eP, lP, hP, unit;
int mNumHead, mKvNumHead, mHeadDim;
2024-07-04 11:53:45 +08:00
std::shared_ptr<Tensor> mPackQ, mPackQKV;
2024-08-24 15:46:21 +08:00
std::shared_ptr<KVCacheManager> mKVCacheManager = nullptr;
2024-05-11 19:17:02 +08:00
};
2024-08-24 15:46:21 +08:00
2024-05-11 19:17:02 +08:00
} // namespace MNN
#endif // CPUATTENTION_HPP
2024-08-24 15:46:21 +08:00
#endif // MNN_SUPPORT_TRANSFORMER_FUSE