mirror of
https://github.com/open-mmlab/mmdeploy.git
synced 2025-01-14 08:09:43 +08:00
* minor changes * support windows * fix GCC build * fix lint * reformat * fix Windows build * fix GCC build * search backend ops for onnxruntime * fix lint * fix lint * code clean-up * code clean-up * fix clang build * fix trt support * fix cmake for ncnn * fix cmake for openvino * fix SDK Python API * handle ops for other backends (ncnn, trt) * handle SDK Python API library location * robustify linkage * fix cuda * minor fix for openvino & ncnn * use CMAKE_CUDA_ARCHITECTURES if set * fix cuda preprocessor * fix misc * fix pplnn & pplcv, drop support for pplcv<0.6.0 * robustify cmake * update build.md (#2) * build dynamic modules as module library & fix demo (partially) * fix candidate path for mmdeploy_python * move "enable CUDA" to cmake config for demo * refine demo cmake * add comment * fix ubuntu build * revert docs/en/build.md * fix C API * fix lint * Windows build doc (#3) * check in docs related to mmdeploy build on windows * update build guide on windows platform * update build guide on windows platform * make path of thirdparty libraries consistent * make path consistency * correct build command for custom ops * correct build command for sdk * update sdk build instructions * update doc * correct build command * fix lint * correct build command and fix lint Co-authored-by: lvhan <lvhan@pjlab.org> * trailing whitespace (#4) * minor fix * fix sr sdk model * fix type deduction * fix cudaFree after driver shutting down * update ppl.cv installation warning (#5) * fix device allocator threshold & fix lint * update doc (#6) * update ppl.cv installation warning * missing 'git clone' Co-authored-by: chenxin <chenxin2@sensetime.com> Co-authored-by: zhangli <zhangli@sensetime.com> Co-authored-by: lvhan028 <lvhan_028@163.com> Co-authored-by: lvhan <lvhan@pjlab.org>
128 lines
3.6 KiB
C++
128 lines
3.6 KiB
C++
// Copyright (c) OpenMMLab. All rights reserved.
|
|
|
|
#ifndef MMDEPLOY_REGISTRY_H
|
|
#define MMDEPLOY_REGISTRY_H
|
|
|
|
#include <iostream>
|
|
#include <map>
|
|
#include <memory>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "macro.h"
|
|
#include "value.h"
|
|
|
|
namespace mmdeploy {
|
|
|
|
namespace detail {
|
|
|
|
template <typename EntryType, typename = void>
|
|
struct get_return_type {
|
|
using type = std::unique_ptr<EntryType>;
|
|
};
|
|
|
|
template <typename EntryType>
|
|
struct get_return_type<EntryType, std::void_t<typename EntryType::type>> {
|
|
using type = typename EntryType::type;
|
|
};
|
|
|
|
template <typename EntryType>
|
|
using get_return_type_t = typename get_return_type<EntryType>::type;
|
|
|
|
} // namespace detail
|
|
|
|
template <class EntryType>
|
|
class Creator;
|
|
|
|
template <>
|
|
class Creator<void> {
|
|
public:
|
|
virtual ~Creator() = default;
|
|
virtual const char *GetName() const = 0;
|
|
virtual int GetVersion() const { return 0; }
|
|
};
|
|
|
|
template <typename EntryType>
|
|
class Creator : public Creator<void> {
|
|
public:
|
|
using ReturnType = detail::get_return_type_t<EntryType>;
|
|
|
|
public:
|
|
virtual ReturnType Create(const Value &args) = 0;
|
|
};
|
|
|
|
template <class EntryType>
|
|
class Registry;
|
|
|
|
template <>
|
|
class MMDEPLOY_API Registry<void> {
|
|
public:
|
|
Registry();
|
|
|
|
~Registry();
|
|
|
|
bool AddCreator(Creator<void> &creator);
|
|
|
|
Creator<void> *GetCreator(const std::string &type, int version = 0);
|
|
|
|
private:
|
|
std::multimap<std::string, Creator<void> *> entries_;
|
|
};
|
|
|
|
template <class EntryType>
|
|
class Registry : public Registry<void> {
|
|
public:
|
|
bool AddCreator(Creator<EntryType> &creator) { return Registry<void>::AddCreator(creator); }
|
|
|
|
Creator<EntryType> *GetCreator(const std::string &type, int version = 0) {
|
|
auto creator = Registry<void>::GetCreator(type, version);
|
|
return static_cast<Creator<EntryType> *>(creator);
|
|
}
|
|
|
|
static Registry &Get();
|
|
|
|
private:
|
|
Registry() = default;
|
|
};
|
|
|
|
template <typename EntryType, typename CreatorType>
|
|
class Registerer {
|
|
public:
|
|
Registerer() { Registry<EntryType>::Get().AddCreator(inst_); }
|
|
|
|
private:
|
|
CreatorType inst_;
|
|
};
|
|
|
|
} // namespace mmdeploy
|
|
|
|
#define MMDEPLOY_DECLARE_REGISTRY(EntryType) \
|
|
template <> \
|
|
Registry<EntryType> &Registry<EntryType>::Get();
|
|
|
|
#define MMDEPLOY_DEFINE_REGISTRY(EntryType) \
|
|
template <> \
|
|
MMDEPLOY_EXPORT Registry<EntryType> &Registry<EntryType>::Get() { \
|
|
static Registry v; \
|
|
return v; \
|
|
}
|
|
|
|
#define REGISTER_MODULE(EntryType, CreatorType) \
|
|
static ::mmdeploy::Registerer<EntryType, CreatorType> g_register_##EntryType##_##CreatorType{};
|
|
|
|
#define DECLARE_AND_REGISTER_MODULE(base_type, module_name, version) \
|
|
class module_name##Creator : public ::mmdeploy::Creator<base_type> { \
|
|
public: \
|
|
module_name##Creator() = default; \
|
|
~module_name##Creator() = default; \
|
|
const char *GetName() const override { return #module_name; } \
|
|
int GetVersion() const override { return version; } \
|
|
\
|
|
std::unique_ptr<base_type> Create(const Value &value) override { \
|
|
return std::make_unique<module_name>(value); \
|
|
} \
|
|
}; \
|
|
REGISTER_MODULE(base_type, module_name##Creator);
|
|
|
|
#endif // MMDEPLOY_REGISTRY_H
|