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 
41  public:
42  static StaticResource* getInstance() noexcept {
43  static StaticResource instance;
44  return &instance;
45  }
46 
47  Device* device = nullptr;
48  Engine* engine = nullptr;
49  Executor* executor = nullptr;
50 
51  std::atomic<std::size_t> current_task_id = 0;
52  size_t current_model_id = 0;
53  size_t current_sensor_id = 0;
54  size_t current_algorithm_id = 0;
55 
56  float shared_threshold_score = 0.25;
57  float shared_threshold_nms = 0.45;
58 
59  std::atomic<bool> is_ready = false;
60  std::atomic<bool> is_sample = false;
61  std::atomic<bool> is_invoke = false;
62 };
63 
64 #define static_resource StaticResource::getInstance()
65 
66 } // 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:42