Files
rocr/rusto-rs/crates/mnn-sys/include/MNN/plugin/PluginKernel.hpp
T
ssw c303c315e5 rocr: rusto-rs 源码入库(上游 v0.2.5 基线 57609fc + 本地补丁)
- 源码 316 文件收编为 rusto-rs/ 文件夹,随本仓库管理
- 移除内部 .git(补丁已存档 docs/rusto-rs-metal-patch-20260912.patch,上游可随时 re-clone)
- target/ 与 docs/.yarn 缓存不入库;本地改动:ROCR_* 环境变量调优 + Metal 链接修复 + 预处理测试脚本
2026-09-12 17:30:04 +08:00

78 lines
2.2 KiB
C++

//
// ShapeInference.h
// MNN
//
// Created by MNN on 2020/04/05.
// Copyright © 2018, Alibaba Group Holding Limited
//
#ifndef MNN_PLUGIN_PLUGIN_KERNEL_HPP_
#define MNN_PLUGIN_PLUGIN_KERNEL_HPP_
#include <functional>
#include <string>
#include <unordered_map>
#include <MNN/plugin/PluginContext.hpp>
namespace MNN {
namespace plugin {
template <typename KernelContextT>
class MNN_PUBLIC ComputeKernel {
public:
ComputeKernel() = default;
virtual ~ComputeKernel() = default;
virtual bool compute(KernelContextT* ctx) = 0;
};
class MNN_PUBLIC CPUComputeKernel : public ComputeKernel<CPUKernelContext> {
public:
using ContextT = CPUKernelContext;
using KernelT = CPUComputeKernel;
CPUComputeKernel() = default;
virtual ~CPUComputeKernel() = default;
virtual bool init(CPUKernelContext* ctx) = 0;
virtual bool compute(CPUKernelContext* ctx) = 0;
virtual bool resize(CPUKernelContext* ctx) {
return true;
}
inline bool needAllocIO() const {
return mNeedAllocIO;
}
protected:
bool mNeedAllocIO = true;
};
template <typename PluginKernelT>
class MNN_PUBLIC ComputeKernelRegistry {
public:
typedef std::function<PluginKernelT*()> Factory;
static std::unordered_map<std::string, Factory>* getFactoryMap();
static bool add(const std::string& name, Factory factory);
static PluginKernelT* get(const std::string& name);
};
template <typename PluginKernelT>
struct ComputeKernelRegistrar {
ComputeKernelRegistrar(const std::string& name) {
ComputeKernelRegistry<typename PluginKernelT::KernelT>::add(name, []() { // NOLINT
return new PluginKernelT; // NOLINT
});
}
};
#define REGISTER_PLUGIN_COMPUTE_KERNEL(name, computeKernel) \
namespace { \
static auto _plugin_compute_kernel_##name##_ __attribute__((unused)) = \
ComputeKernelRegistrar<computeKernel>(#name); \
} // namespace
} // namespace plugin
} // namespace MNN
#endif // MNN_PLUGIN_PLUGIN_KERNEL_HPP_