Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] reduce log verbosity & improve error reporting #755

Merged
merged 2 commits into from
Jul 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions csrc/mmdeploy/apis/c/mmdeploy/executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ mmdeploy_scheduler_t CreateScheduler(const char* type, const Value& config = Val
try {
auto creator = Registry<SchedulerType>::Get().GetCreator(type);
if (!creator) {
MMDEPLOY_ERROR("creator for {} not found.", type);
MMDEPLOY_ERROR("Creator for {} not found. Available schedulers: {}", type,
Registry<SchedulerType>::Get().List());
return nullptr;
}
return Cast(new SchedulerType(creator->Create(config)));
} catch (const std::exception& e) {
MMDEPLOY_ERROR("failed to create {}, error: {}", type, e.what());
MMDEPLOY_ERROR("failed to create Scheduler: {} ({}), config: {}", type, e.what(), config);
return nullptr;
}
}
Expand Down
5 changes: 3 additions & 2 deletions csrc/mmdeploy/apis/c/mmdeploy/handle.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ class AsyncHandle {
config["context"].update({{"device", device_}, {"stream", stream_}});
auto creator = Registry<graph::Node>::Get().GetCreator("Pipeline");
if (!creator) {
MMDEPLOY_ERROR("failed to find Pipeline creator");
MMDEPLOY_ERROR("Failed to find Pipeline creator. Available nodes: {}",
Registry<graph::Node>::Get().List());
throw_exception(eEntryNotFound);
}
pipeline_ = creator->Create(config);
if (!pipeline_) {
MMDEPLOY_ERROR("create pipeline failed");
MMDEPLOY_ERROR("Failed to create pipeline, config: {}", config);
throw_exception(eFail);
}
}
Expand Down
2 changes: 1 addition & 1 deletion csrc/mmdeploy/apis/java/native/mmdeploy_Classifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jlong Java_mmdeploy_Classifier_create(JNIEnv *env, jobject, jstring modelPath, j
}

void Java_mmdeploy_Classifier_destroy(JNIEnv *, jobject, jlong handle) {
MMDEPLOY_INFO("Java_mmdeploy_Classifier_destroy");
MMDEPLOY_DEBUG("Java_mmdeploy_Classifier_destroy");
mmdeploy_classifier_destroy((mmdeploy_classifier_t)handle);
}

Expand Down
2 changes: 1 addition & 1 deletion csrc/mmdeploy/apis/java/native/mmdeploy_Detector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jlong Java_mmdeploy_Detector_create(JNIEnv *env, jobject, jstring modelPath, jst
}

void Java_mmdeploy_Detector_destroy(JNIEnv *, jobject, jlong handle) {
MMDEPLOY_INFO("Java_mmdeploy_Detector_destroy"); // maybe use info?
MMDEPLOY_DEBUG("Java_mmdeploy_Detector_destroy"); // maybe use info?
mmdeploy_detector_destroy((mmdeploy_detector_t)handle);
}

Expand Down
2 changes: 1 addition & 1 deletion csrc/mmdeploy/apis/java/native/mmdeploy_PoseDetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jlong Java_mmdeploy_PoseDetector_create(JNIEnv *env, jobject, jstring modelPath,
}

void Java_mmdeploy_PoseDetector_destroy(JNIEnv *, jobject, jlong handle) {
MMDEPLOY_INFO("Java_mmdeploy_PoseDetector_destroy");
MMDEPLOY_DEBUG("Java_mmdeploy_PoseDetector_destroy");
mmdeploy_pose_detector_destroy((mmdeploy_pose_detector_t)handle);
}

Expand Down
2 changes: 1 addition & 1 deletion csrc/mmdeploy/apis/java/native/mmdeploy_Restorer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jlong Java_mmdeploy_Restorer_create(JNIEnv *env, jobject, jstring modelPath, jst
}

void Java_mmdeploy_Restorer_destroy(JNIEnv *, jobject, jlong handle) {
MMDEPLOY_INFO("Java_mmdeploy_Restorer_destroy");
MMDEPLOY_DEBUG("Java_mmdeploy_Restorer_destroy");
mmdeploy_restorer_destroy((mmdeploy_restorer_t)handle);
}

Expand Down
2 changes: 1 addition & 1 deletion csrc/mmdeploy/apis/java/native/mmdeploy_Segmentor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jlong Java_mmdeploy_Segmentor_create(JNIEnv *env, jobject, jstring modelPath, js
}

void Java_mmdeploy_Segmentor_destroy(JNIEnv *, jobject, jlong handle) {
MMDEPLOY_INFO("Java_mmdeploy_Segmentor_destroy");
MMDEPLOY_DEBUG("Java_mmdeploy_Segmentor_destroy");
mmdeploy_segmentor_destroy((mmdeploy_segmentor_t)handle);
}

Expand Down
2 changes: 1 addition & 1 deletion csrc/mmdeploy/apis/java/native/mmdeploy_TextDetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jlong Java_mmdeploy_TextDetector_create(JNIEnv *env, jobject, jstring modelPath,
}

void Java_mmdeploy_TextDetector_destroy(JNIEnv *, jobject, jlong handle) {
MMDEPLOY_INFO("Java_mmdeploy_TextDetector_destroy");
MMDEPLOY_DEBUG("Java_mmdeploy_TextDetector_destroy");
mmdeploy_text_detector_destroy((mmdeploy_text_detector_t)handle);
}

Expand Down
2 changes: 1 addition & 1 deletion csrc/mmdeploy/apis/java/native/mmdeploy_TextRecognizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jlong Java_mmdeploy_TextRecognizer_create(JNIEnv *env, jobject, jstring modelPat
}

void Java_mmdeploy_TextRecognizer_destroy(JNIEnv *, jobject, jlong handle) {
MMDEPLOY_INFO("Java_mmdeploy_TextRecognizer_destroy"); // maybe use info?
MMDEPLOY_DEBUG("Java_mmdeploy_TextRecognizer_destroy"); // maybe use info?
mmdeploy_text_recognizer_destroy((mmdeploy_text_recognizer_t)handle);
}

Expand Down
3 changes: 2 additions & 1 deletion csrc/mmdeploy/codebase/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ class CodebaseCreator : public Creator<Module> {
auto postprocess_type = cfg[key].get<std::string>();
auto creator = Registry<Tag>::Get().GetCreator(postprocess_type);
if (creator == nullptr) {
MMDEPLOY_ERROR("could not found entry '{}' in {}", postprocess_type, Tag::name);
MMDEPLOY_ERROR("Could not found entry '{}' in {}. Available components: {}", postprocess_type,
Tag::name, Registry<Tag>::Get().List());
throw_exception(eEntryNotFound);
}
return creator->Create(cfg);
Expand Down
4 changes: 3 additions & 1 deletion csrc/mmdeploy/codebase/mmocr/dbnet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ class DBHead : public MMOCR {
auto platform = Platform(device_.platform_id()).GetPlatformName();
auto creator = Registry<DbHeadImpl>::Get().GetCreator(platform);
if (!creator) {
MMDEPLOY_ERROR("DBHead: implementation for platform \"{}\" not found", platform);
MMDEPLOY_ERROR(
"DBHead: implementation for platform \"{}\" not found. Available platforms: {}", platform,
Registry<DbHeadImpl>::Get().List());
throw_exception(eEntryNotFound);
}
impl_ = creator->Create(nullptr);
Expand Down
4 changes: 3 additions & 1 deletion csrc/mmdeploy/codebase/mmocr/panet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ class PANHead : public MMOCR {
auto platform = Platform(device_.platform_id()).GetPlatformName();
auto creator = Registry<PaHeadImpl>::Get().GetCreator(platform);
if (!creator) {
MMDEPLOY_ERROR("PANHead: implementation for platform \"{}\" not found", platform);
MMDEPLOY_ERROR(
"PANHead: implementation for platform \"{}\" not found. Available platforms: {}",
platform, Registry<PaHeadImpl>::Get().List());
throw_exception(eEntryNotFound);
}
impl_ = creator->Create(nullptr);
Expand Down
4 changes: 3 additions & 1 deletion csrc/mmdeploy/codebase/mmocr/psenet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ class PSEHead : public MMOCR {
auto platform = Platform(device_.platform_id()).GetPlatformName();
auto creator = Registry<PseHeadImpl>::Get().GetCreator(platform);
if (!creator) {
MMDEPLOY_ERROR("PSEHead: implementation for platform \"{}\" not found", platform);
MMDEPLOY_ERROR(
"PSEHead: implementation for platform \"{}\" not found. Available platforms: {}",
platform, Registry<PseHeadImpl>::Get().List());
throw_exception(eEntryNotFound);
}
impl_ = creator->Create(nullptr);
Expand Down
6 changes: 3 additions & 3 deletions csrc/mmdeploy/core/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ Result<void> Model::Init(const std::string& model_path) {
}
OUTCOME_TRY(auto meta, impl->ReadMeta());

MMDEPLOY_INFO("{} successfully load sdk model {}", entry.name, model_path);
MMDEPLOY_INFO("{} successfully load model {}", entry.name, model_path);
impl_ = std::move(impl);
meta_ = std::move(meta);
return success();
}

MMDEPLOY_ERROR("no ModelImpl can read sdk_model {}", model_path);
MMDEPLOY_ERROR("no ModelImpl can read model {}", model_path);
return Status(eNotSupported);
}

Expand All @@ -56,7 +56,7 @@ Result<void> Model::Init(const void* buffer, size_t size) {
}
OUTCOME_TRY(auto meta, impl->ReadMeta());

MMDEPLOY_INFO("successfully load sdk model {}", entry.name);
MMDEPLOY_INFO("Successfully load model {}", entry.name);
impl_ = std::move(impl);
meta_ = std::move(meta);
return success();
Expand Down
12 changes: 10 additions & 2 deletions csrc/mmdeploy/core/registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Registry<void>::Registry() = default;

Registry<void>::~Registry() = default;

bool Registry<void>::AddCreator(Creator<void> &creator) {
bool Registry<void>::AddCreator(Creator<void>& creator) {
MMDEPLOY_DEBUG("Adding creator: {}", creator.GetName());
auto key = creator.GetName();
if (entries_.find(key) == entries_.end()) {
Expand All @@ -26,7 +26,7 @@ bool Registry<void>::AddCreator(Creator<void> &creator) {
return true;
}

Creator<void> *Registry<void>::GetCreator(const std::string &type, int version) {
Creator<void>* Registry<void>::GetCreator(const std::string& type, int version) {
auto iter = entries_.find(type);
if (iter == entries_.end()) {
return nullptr;
Expand All @@ -43,4 +43,12 @@ Creator<void> *Registry<void>::GetCreator(const std::string &type, int version)
return nullptr;
}

std::vector<std::string> Registry<void>::List() {
std::vector<std::string> list;
for (const auto& [name, _] : entries_) {
list.push_back(name);
}
return list;
}

} // namespace mmdeploy
28 changes: 15 additions & 13 deletions csrc/mmdeploy/core/registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ template <>
class Creator<void> {
public:
virtual ~Creator() = default;
virtual const char *GetName() const = 0;
virtual const char* GetName() const = 0;
virtual int GetVersion() const { return 0; }
};

Expand All @@ -48,7 +48,7 @@ class Creator : public Creator<void> {
using ReturnType = detail::get_return_type_t<EntryType>;

public:
virtual ReturnType Create(const Value &args) = 0;
virtual ReturnType Create(const Value& args) = 0;
};

template <class EntryType>
Expand All @@ -61,25 +61,27 @@ class MMDEPLOY_API Registry<void> {

~Registry();

bool AddCreator(Creator<void> &creator);
bool AddCreator(Creator<void>& creator);

Creator<void> *GetCreator(const std::string &type, int version = 0);
Creator<void>* GetCreator(const std::string& type, int version = 0);

std::vector<std::string> List();

private:
std::multimap<std::string, Creator<void> *> entries_;
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); }
bool AddCreator(Creator<EntryType>& creator) { return Registry<void>::AddCreator(creator); }

Creator<EntryType> *GetCreator(const std::string &type, int version = 0) {
Creator<EntryType>* GetCreator(const std::string& type, int version = 0) {
auto creator = Registry<void>::GetCreator(type, version);
return static_cast<Creator<EntryType> *>(creator);
return static_cast<Creator<EntryType>*>(creator);
}

static Registry &Get();
static Registry& Get();

private:
Registry() = default;
Expand All @@ -98,11 +100,11 @@ class Registerer {

#define MMDEPLOY_DECLARE_REGISTRY(EntryType) \
template <> \
Registry<EntryType> &Registry<EntryType>::Get();
Registry<EntryType>& Registry<EntryType>::Get();

#define MMDEPLOY_DEFINE_REGISTRY(EntryType) \
template <> \
MMDEPLOY_EXPORT Registry<EntryType> &Registry<EntryType>::Get() { \
MMDEPLOY_EXPORT Registry<EntryType>& Registry<EntryType>::Get() { \
static Registry v; \
return v; \
}
Expand All @@ -115,10 +117,10 @@ class Registerer {
public: \
module_name##Creator() = default; \
~module_name##Creator() = default; \
const char *GetName() const override { return #module_name; } \
const char* GetName() const override { return #module_name; } \
int GetVersion() const override { return version; } \
\
std::unique_ptr<base_type> Create(const Value &value) override { \
std::unique_ptr<base_type> Create(const Value& value) override { \
return std::make_unique<module_name>(value); \
} \
}; \
Expand Down
5 changes: 5 additions & 0 deletions csrc/mmdeploy/core/status_code.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "mmdeploy/core/status_code.h"

#include "mmdeploy/core/logger.h"
#include "mmdeploy/core/utils/source_location.h"

namespace mmdeploy {

Expand All @@ -21,7 +22,11 @@ string_ref Status::message() const {
std::string ret;
try {
#if MMDEPLOY_STATUS_USE_SOURCE_LOCATION
#if MMDEPLOY_HAS_SOURCE_LOCATION
ret = fmt::format("{} ({}) @ {}:{}", to_string(ec), (int32_t)ec, file, line);
#else
ret = fmt::format("{} ({})", to_string(ec), (int32_t)ec);
#endif
#elif MMDEPLOY_STATUS_USE_STACKTRACE
ret = fmt::format("{} ({}), stacktrace:\n{}", to_string(ec), (int32_t)ec, st.to_string());
#else
Expand Down
2 changes: 1 addition & 1 deletion csrc/mmdeploy/device/cuda/cuda_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Allocator CreateDefaultAllocator() {
AllocatorImplPtr allocator = std::make_shared<Mallocator>();
allocator = std::make_shared<Tree>(allocator, -1, .5);
allocator = std::make_shared<Locked>(allocator);
MMDEPLOY_INFO("Default CUDA allocator initialized");
MMDEPLOY_DEBUG("Default CUDA allocator initialized");
return Access::create<Allocator>(allocator);
}

Expand Down
2 changes: 1 addition & 1 deletion csrc/mmdeploy/execution/bulk.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct _Receiver<Receiver, Shape, Func>::type {

template <class... As>
friend void tag_invoke(set_value_t, type&& self, As&&... as) noexcept {
MMDEPLOY_WARN("fallback Bulk implementation");
MMDEPLOY_DEBUG("fallback Bulk implementation");
for (Shape i = 0; i < self.shape_; ++i) {
self.func_(i, as...);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ struct Context : context_base_t {
delay_(scheduler_.timeout_),
timer_(scheduler_.timer_) {}

~Context() { MMDEPLOY_INFO("~Context()"); }
~Context() { MMDEPLOY_DEBUG("~Context()"); }

using _operation_t = operation_t<Sender, Scheduler, Receiver, Func>;

Expand Down
7 changes: 4 additions & 3 deletions csrc/mmdeploy/graph/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,17 @@ inline std::true_type Check(T&&) {

template <typename EntryType, typename RetType = typename Creator<EntryType>::ReturnType>
inline Result<RetType> CreateFromRegistry(const Value& config, const char* key = "type") {
MMDEPLOY_INFO("config: {}", config);
MMDEPLOY_DEBUG("config: {}", config);
auto type = config[key].get<std::string>();
auto creator = Registry<EntryType>::Get().GetCreator(type);
if (!creator) {
MMDEPLOY_ERROR("failed to find module creator: {}", type);
MMDEPLOY_ERROR("Failed to find creator: {}. Available: {}", type,
Registry<EntryType>::Get().List());
return Status(eEntryNotFound);
}
auto inst = creator->Create(config);
if (!Check(inst)) {
MMDEPLOY_ERROR("failed to create module: {}", type);
MMDEPLOY_ERROR("Failed to create module: {}, config: {}", type, config);
return Status(eFail);
}
return std::move(inst);
Expand Down
12 changes: 6 additions & 6 deletions csrc/mmdeploy/graph/pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ Result<unique_ptr<Pipeline>> PipelineParser::Parse(const Value& config) {

use_count_.resize(size + 1);

// MMDEPLOY_INFO("pipeline->inputs: {}", pipeline->inputs());
OUTCOME_TRY(UpdateOutputCoords(static_cast<int>(size), pipeline->inputs()));
for (auto task_config : task_configs) {
auto index = static_cast<int>(nodes.size());
Expand All @@ -143,7 +142,7 @@ Result<unique_ptr<Pipeline>> PipelineParser::Parse(const Value& config) {
OUTCOME_TRY(UpdateOutputCoords(index, node->outputs()));
nodes.push_back(std::move(node));
} else {
MMDEPLOY_ERROR("could not create {}: {}", name, type);
MMDEPLOY_ERROR("Could not create {}: {}", type, name);
return Status(eFail);
}
}
Expand All @@ -163,7 +162,6 @@ Result<unique_ptr<Pipeline>> PipelineParser::Parse(const Value& config) {
}

Result<vector<Pipeline::Coords>> PipelineParser::GetInputCoords(const vector<string>& names) {
// MMDEPLOY_INFO("GetInputCoords: {}", names);
vector<Pipeline::Coords> ret;
ret.reserve(names.size());
for (int i = 0; i < names.size(); ++i) {
Expand Down Expand Up @@ -192,7 +190,6 @@ Result<void> PipelineParser::UpdateOutputCoords(int index, const vector<string>&
MMDEPLOY_ERROR("duplicate output: ", output);
return Status(eNotSupported);
} else {
// MMDEPLOY_ERROR("insert: {}", output);
output_name_to_coords_.insert({output, {index, i}});
}
}
Expand All @@ -202,9 +199,12 @@ Result<void> PipelineParser::UpdateOutputCoords(int index, const vector<string>&
class PipelineCreator : public Creator<Node> {
public:
const char* GetName() const override { return "Pipeline"; }
int GetVersion() const override { return 0; }
std::unique_ptr<Node> Create(const Value& value) override {
return PipelineParser{}.Parse(value).value();
try {
return PipelineParser{}.Parse(value).value();
} catch (...) {
}
return nullptr;
}
};

Expand Down
Loading