SSCMA-Micro CPP SDK  v2.0.0
SSCMA-Micro is a cross-platform machine learning inference framework designed for embedded devices.
resource.hpp
Go to the documentation of this file.
1 #pragma once
2 
4 #include <core/ma_core.h>
5 #include <porting/ma_porting.h>
6 
7 #include <ma_config_board.h>
8 
9 #include <atomic>
10 
11 using namespace ma;
12 
13 namespace ma::server::callback {
14 
15 using namespace ma::engine;
16 
17 struct StaticResource final {
18  private:
19  StaticResource() {
20  device = Device::getInstance();
21 
22  MA_LOGD(MA_TAG, "Initializing engine");
23 #if MA_USE_ENGINE_TFLITE
24  static EngineTFLite engine_default;
25 #elif MA_USE_ENGINE_CVI
26  static EngineCVI engine_default;
27 #else
28  #error "No engine is defined"
29 #endif
30  engine = &engine_default;
31  int ret = engine->init();
32  if (ret != MA_OK) {
33  MA_LOGE(MA_TAG, "Engine init failed: %d", ret);
34  }
35 
36  MA_LOGD(MA_TAG, "Initializing executor");
37  static Executor executor_default;
38  executor = &executor_default;
39 
40  MA_STORAGE_GET_POD(device->getStorage(), "ma#score_threshold", shared_threshold_score, shared_threshold_score);
41  MA_STORAGE_GET_POD(device->getStorage(), "ma#nms_threshold", shared_threshold_nms, shared_threshold_nms);
42  }
43 
44  public:
45  static StaticResource* getInstance() noexcept {
46  static StaticResource instance;
47  return &instance;
48  }
49 
50  Device* device = nullptr;
51  Engine* engine = nullptr;
52  Executor* executor = nullptr;
53 
54  std::atomic<std::size_t> current_task_id = 0;
55  size_t current_model_id = 0;
56  size_t current_sensor_id = 0;
57  size_t current_algorithm_id = 0;
58 
59  float shared_threshold_score = 0.25;
60  float shared_threshold_nms = 0.45;
61 
62  std::atomic<bool> is_ready = false;
63  std::atomic<bool> is_sample = false;
64  std::atomic<bool> is_invoke = false;
65 };
66 
67 #define static_resource StaticResource::getInstance()
68 
69 } // namespace ma::server::callback
Definition: ma_device.h:15
static Device * getInstance() noexcept
Definition: ma_executor.hpp:17
Definition: ma_engine_base.h:17
#define MA_LOGD(TAG,...)
Definition: ma_debug.h:79
#define MA_LOGE(TAG,...)
Definition: ma_debug.h:30
#define MA_TAG
Definition: ma_debug.h:9
@ MA_OK
Definition: ma_types.h:23
Definition: ma_engine_base.h:15
Definition: algorithm.hpp:11
Definition: ma_cv.cpp:7
Definition: resource.hpp:17
static StaticResource * getInstance() noexcept
Definition: resource.hpp:45