2021-12-07 10:57:55 +08:00
|
|
|
// Copyright (c) OpenMMLab. All rights reserved.
|
|
|
|
|
|
|
|
#ifndef MMDEPLOY_TRANSFORM_H
|
|
|
|
#define MMDEPLOY_TRANSFORM_H
|
|
|
|
|
|
|
|
#include "core/device.h"
|
|
|
|
#include "core/module.h"
|
|
|
|
#include "core/registry.h"
|
|
|
|
|
|
|
|
namespace mmdeploy {
|
|
|
|
|
2022-02-24 20:08:44 +08:00
|
|
|
class MMDEPLOY_API TransformImpl : public Module {
|
2021-12-07 10:57:55 +08:00
|
|
|
public:
|
|
|
|
TransformImpl() = default;
|
|
|
|
explicit TransformImpl(const Value& args);
|
|
|
|
~TransformImpl() override = default;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
std::vector<std::string> GetImageFields(const Value& input);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
Device device_;
|
|
|
|
Stream stream_;
|
|
|
|
};
|
|
|
|
|
2022-02-24 20:08:44 +08:00
|
|
|
class MMDEPLOY_API Transform : public Module {
|
2021-12-07 10:57:55 +08:00
|
|
|
public:
|
2022-02-24 20:08:44 +08:00
|
|
|
~Transform() override = default;
|
|
|
|
|
2021-12-07 10:57:55 +08:00
|
|
|
Transform() = default;
|
|
|
|
explicit Transform(const Value& args);
|
2022-02-24 20:08:44 +08:00
|
|
|
Transform(const Transform&) = delete;
|
|
|
|
Transform& operator=(const Transform&) = delete;
|
2021-12-07 10:57:55 +08:00
|
|
|
|
|
|
|
const std::string& RuntimePlatform() const { return runtime_platform_; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
template <typename T>
|
2022-02-24 20:08:44 +08:00
|
|
|
[[deprecated]] std::unique_ptr<T> Instantiate(const char* transform_type, const Value& args,
|
|
|
|
int version = 0) {
|
2021-12-07 10:57:55 +08:00
|
|
|
std::unique_ptr<T> impl(nullptr);
|
|
|
|
auto impl_creator = Registry<T>::Get().GetCreator(specified_platform_, version);
|
|
|
|
if (nullptr == impl_creator) {
|
2022-02-24 20:08:44 +08:00
|
|
|
MMDEPLOY_WARN("cannot find {} implementation on specific platform {} ", transform_type,
|
|
|
|
specified_platform_);
|
2021-12-07 10:57:55 +08:00
|
|
|
for (auto& name : candidate_platforms_) {
|
|
|
|
impl_creator = Registry<T>::Get().GetCreator(name);
|
|
|
|
if (impl_creator) {
|
2022-02-24 20:08:44 +08:00
|
|
|
MMDEPLOY_INFO("fallback {} implementation to platform {}", transform_type, name);
|
2021-12-07 10:57:55 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (nullptr == impl_creator) {
|
2022-02-24 20:08:44 +08:00
|
|
|
MMDEPLOY_ERROR("cannot find {} implementation on any registered platform ", transform_type);
|
2021-12-07 10:57:55 +08:00
|
|
|
return nullptr;
|
|
|
|
} else {
|
|
|
|
return impl_creator->Create(args);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
std::string specified_platform_;
|
|
|
|
std::string runtime_platform_;
|
|
|
|
std::vector<std::string> candidate_platforms_;
|
|
|
|
};
|
|
|
|
|
2022-02-24 20:08:44 +08:00
|
|
|
MMDEPLOY_DECLARE_REGISTRY(Transform);
|
|
|
|
|
2021-12-07 10:57:55 +08:00
|
|
|
} // namespace mmdeploy
|
|
|
|
|
|
|
|
#endif // MMDEPLOY_TRANSFORM_H
|