Skip to content

Commit 7c3853a

Browse files
pymumutau233
authored andcommitted
modelbox: move implimentation to .cpp file
1 parent 2ea85d6 commit 7c3853a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1229
-713
lines changed

src/libmodelbox/base/config/configuration.cc

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
* limitations under the License.
1515
*/
1616

17-
1817
#include "modelbox/base/configuration.h"
1918

2019
#include <toml.hpp>
@@ -96,6 +95,32 @@ std::unique_ptr<ConfigStore> ConfigStore::GetSubConfigStore(
9695
return sub_store;
9796
}
9897

98+
size_t ConfigStore::Size() const { return properties_.size(); }
99+
100+
bool ConfigStore::Contain(const std::string &key) const {
101+
auto item = properties_.find(key);
102+
return item != properties_.end();
103+
}
104+
105+
void ConfigStore::Add(const ConfigStore &store) {
106+
for (const auto &iter : store.properties_) {
107+
properties_[iter.first] = iter.second;
108+
}
109+
110+
for (const auto &iter : store.sub_key_index_) {
111+
sub_key_index_[iter.first] = iter.second;
112+
}
113+
}
114+
115+
void ConfigStore::Copy(const ConfigStore &store, const std::string &key) {
116+
if (store.Contain(key) == false) {
117+
return;
118+
}
119+
std::string property;
120+
store.ReadProperty(key, &property);
121+
WriteProperty(key, property);
122+
}
123+
99124
void ConfigStore::AddSubConfig(const std::string &prefix_key,
100125
ConfigStore *store, size_t key_offset) const {
101126
auto sub_keys = GetSubKeys(prefix_key);

src/libmodelbox/base/device/device.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,23 @@ Device::Device(size_t thread_count,
4040
}
4141
}
4242

43+
std::string Device::GetDeviceID() const {
44+
if (device_desc_ != nullptr) {
45+
return device_desc_->GetDeviceId();
46+
}
47+
48+
return "";
49+
}
50+
51+
std::shared_ptr<Executor> Device::GetDeviceExecutor() { return executor_; }
52+
53+
Status Device::DeviceExecute(const DevExecuteCallBack &fun, int32_t priority,
54+
size_t count) {
55+
return STATUS_NOTSUPPORT;
56+
}
57+
58+
std::string Device::GetType() const { return ""; }
59+
4360
bool Device::NeedResourceNice() { return false; }
4461

4562
std::list<std::future<Status>> Device::DeviceExecuteAsync(

src/libmodelbox/base/device/device_manager.cc

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
* limitations under the License.
1515
*/
1616

17-
1817
#include <stdio.h>
1918

2019
#include <string>
@@ -27,6 +26,26 @@
2726
#include "modelbox/base/status.h"
2827

2928
namespace modelbox {
29+
30+
DeviceFactory::DeviceFactory() = default;
31+
DeviceFactory::~DeviceFactory() = default;
32+
33+
std::map<std::string, std::shared_ptr<DeviceDesc>>
34+
DeviceFactory::DeviceProbe() {
35+
return std::map<std::string, std::shared_ptr<DeviceDesc>>();
36+
}
37+
38+
std::shared_ptr<Device> DeviceFactory::CreateDevice(
39+
const std::string &device_id) {
40+
return nullptr;
41+
}
42+
43+
std::string DeviceFactory::GetDeviceFactoryType() { return ""; }
44+
45+
std::vector<std::string> DeviceFactory::GetDeviceList() {
46+
return std::vector<std::string>();
47+
}
48+
3049
DeviceManager::DeviceManager() = default;
3150
DeviceManager::~DeviceManager() = default;
3251

@@ -149,12 +168,12 @@ std::shared_ptr<Device> DeviceManager::CreateDevice(
149168

150169
auto id_desc = device_desc_list_[device_type].find(device_id);
151170
if (id_desc == device_desc_list_[device_type].end()) {
152-
StatusError = {STATUS_NOTFOUND,
153-
"Can't find device, type " + device_type + " id: " + device_id};
171+
StatusError = {STATUS_NOTFOUND, "Can't find device, type " + device_type +
172+
" id: " + device_id};
154173
MBLOG_ERROR << StatusError.Errormsg();
155174
return nullptr;
156175
}
157-
176+
158177
auto iter = device_factory_.find(device_type);
159178
if (iter == device_factory_.end()) {
160179
StatusError = {STATUS_NOTFOUND, "device type not found: " + device_type};
@@ -173,7 +192,6 @@ std::shared_ptr<Device> DeviceManager::CreateDevice(
173192
return nullptr;
174193
}
175194

176-
177195
device->SetDeviceDesc(device_desc_list_[device_type][device_id]);
178196
auto &id_map = device_list_[device_type];
179197
id_map[device_id] = device;

src/libmodelbox/base/device/device_memory.cc

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
* limitations under the License.
1515
*/
1616

17-
#include <utility>
18-
1917
#include "modelbox/base/device_memory.h"
2018

19+
#include <utility>
20+
2121
#include "modelbox/base/device.h"
2222
#include "modelbox/base/log.h"
2323
#include "modelbox/base/slab.h"
@@ -54,6 +54,30 @@ void DeviceMemory::UpdateMemID(void *device_mem_ptr) {
5454
memory_id_ = std::to_string((uintptr_t)device_mem_ptr);
5555
}
5656

57+
Status DeviceMemory::SetContentMutable(bool content_mutable) {
58+
is_content_mutable_ = content_mutable;
59+
// TODO: Protect memory in device
60+
return STATUS_SUCCESS;
61+
}
62+
63+
size_t DeviceMemory::GetSize() const { return size_; };
64+
65+
size_t DeviceMemory::GetCapacity() const { return capacity_; };
66+
67+
std::string DeviceMemory::GetMemoryID() const { return memory_id_; }
68+
69+
std::shared_ptr<Device> DeviceMemory::GetDevice() const { return device_; }
70+
71+
uint32_t DeviceMemory::GetMemFlags() const { return mem_flags_; }
72+
73+
bool DeviceMemory::IsHost() const { return is_host_mem_; }
74+
75+
bool DeviceMemory::IsSameDevice(const std::shared_ptr<DeviceMemory> &dev_mem) {
76+
return dev_mem ? (device_ == dev_mem->device_ &&
77+
mem_flags_ == dev_mem->mem_flags_)
78+
: false;
79+
}
80+
5781
bool DeviceMemory::IsContiguous(
5882
const std::vector<std::shared_ptr<DeviceMemory>> &mem_list,
5983
bool with_order) {
@@ -199,6 +223,8 @@ Status DeviceMemory::CountMemSize(
199223
return STATUS_SUCCESS;
200224
}
201225

226+
Status DeviceMemory::Verify() const { return STATUS_SUCCESS; }
227+
202228
Status DeviceMemory::Resize(size_t new_size) {
203229
if (new_size > capacity_) {
204230
MBLOG_ERROR << "New size " << new_size << " > capacity " << capacity_;

src/libmodelbox/base/drivers/driver.cc

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,8 @@ std::shared_ptr<DriverFactory> Driver::CreateFactory() {
407407

408408
auto holder = shared_from_this();
409409
std::shared_ptr<DriverFactory> child_factory(
410-
factory_.get(), [&, holder](DriverFactory *child_factory) { holder->CloseFactory(); });
410+
factory_.get(),
411+
[&, holder](DriverFactory *child_factory) { holder->CloseFactory(); });
411412

412413
return child_factory;
413414
}
@@ -418,6 +419,15 @@ void Driver::SetDriverDesc(std::shared_ptr<DriverDesc> desc) {
418419
desc_ = std::move(desc);
419420
}
420421

422+
DriverFactory::DriverFactory() = default;
423+
DriverFactory::~DriverFactory() = default;
424+
425+
std::shared_ptr<Driver> DriverFactory::GetDriver() {
426+
return std::make_shared<Driver>();
427+
};
428+
429+
void DriverFactory::SetDriver(const std::shared_ptr<Driver> &driver) {}
430+
421431
// DriverDesc
422432
std::string DriverDesc::GetClass() { return driver_class_; }
423433

@@ -505,7 +515,25 @@ void DriverDesc::SetFilePath(const std::string &file_path) {
505515
driver_file_path_ = file_path;
506516
}
507517

518+
DriversScanResultInfo::DriversScanResultInfo() = default;
519+
DriversScanResultInfo::~DriversScanResultInfo() {
520+
load_success_info_.clear();
521+
load_failed_info_.clear();
522+
}
523+
524+
std::list<std::string> &DriversScanResultInfo::GetLoadSuccessInfo() {
525+
return load_success_info_;
526+
}
527+
528+
std::map<std::string, std::string> &DriversScanResultInfo::GetLoadFailedInfo() {
529+
return load_failed_info_;
530+
}
531+
508532
// Drivers
533+
Drivers::Drivers()
534+
: drivers_scan_result_info_(std::make_shared<DriversScanResultInfo>()){};
535+
Drivers::~Drivers() = default;
536+
509537
std::shared_ptr<Drivers> Drivers::GetInstance() {
510538
static std::shared_ptr<Drivers> drivers = std::make_shared<Drivers>();
511539
return drivers;

src/libmodelbox/base/drivers/register_flowunit.cc

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
* limitations under the License.
1515
*/
1616

17-
#include <utility>
18-
1917
#include "modelbox/base/register_flowunit.h"
2018

19+
#include <utility>
20+
2121
constexpr const char *VIRTUAL_TYPE = "register_flowunit";
2222

2323
namespace modelbox {
@@ -62,6 +62,15 @@ RegisterFlowUnitFactory::RegisterFlowUnitFactory(
6262
}
6363
}
6464

65+
std::map<std::string, std::shared_ptr<FlowUnitDesc>>
66+
RegisterFlowUnitFactory::FlowUnitProbe() {
67+
return desc_map_;
68+
}
69+
70+
std::string RegisterFlowUnitFactory::GetFlowUnitFactoryType() {
71+
return FLOWUNIT_TYPE;
72+
}
73+
6574
std::shared_ptr<FlowUnit> RegisterFlowUnitFactory::CreateFlowUnit(
6675
const std::string &name, const std::string &unit_type) {
6776
auto register_flowunit = std::make_shared<RegisterFlowUnit>(name);

src/libmodelbox/base/drivers/virtual_driver.cc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17-
18-
#include <modelbox/base/config.h>
1917
#include <dlfcn.h>
18+
#include <modelbox/base/config.h>
2019

2120
#include <memory>
2221
#include <utility>
@@ -50,9 +49,7 @@ Status VirtualDriverManager::Scan(const std::vector<std::string> &scan_dirs) {
5049
return ret;
5150
}
5251

53-
Status VirtualDriverManager::Scan(const std::string &path) {
54-
return STATUS_OK;
55-
}
52+
Status VirtualDriverManager::Scan(const std::string &path) { return STATUS_OK; }
5653

5754
std::vector<std::shared_ptr<VirtualDriver>>
5855
VirtualDriverManager::GetAllDriverList() {
@@ -70,6 +67,10 @@ void VirtualDriver::SetVirtualDriverDesc(
7067
virtual_driver_desc_ = std::move(desc);
7168
}
7269

70+
std::vector<std::shared_ptr<Driver>> VirtualDriver::GetBindDriver() {
71+
return std::vector<std::shared_ptr<Driver>>();
72+
}
73+
7374
std::shared_ptr<DriverFactory> VirtualDriver::CreateFactory() {
7475
return nullptr;
7576
}

src/libmodelbox/base/include/modelbox/base/any.h

Lines changed: 6 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -167,18 +167,16 @@ ValueType any_cast(Any& any) {
167167

168168
class Collection {
169169
public:
170-
Collection() = default;
170+
Collection();
171171

172-
virtual ~Collection() = default;
172+
virtual ~Collection();
173173

174174
template <typename T>
175175
void Set(const std::string& key, T&& value) {
176176
entrys_[key] = Any(value);
177177
}
178178

179-
void Set(const std::string& key, const char* value) {
180-
entrys_[key] = Any(std::string(value));
181-
}
179+
void Set(const std::string& key, const char* value);
182180

183181
template <typename T>
184182
bool Get(const std::string& key, T&& value) {
@@ -200,43 +198,10 @@ class Collection {
200198
return true;
201199
}
202200

203-
std::tuple<Any*, bool> Get(const std::string& key) {
204-
auto iter = entrys_.find(key);
205-
if (iter != entrys_.end()) {
206-
return std::make_tuple(&(iter->second), true);
207-
}
208-
209-
return std::make_tuple(nullptr, false);
210-
}
211-
212-
void Merge(const Collection& other, bool is_override = false) {
213-
if (!is_override) {
214-
entrys_.insert(other.entrys_.begin(), other.entrys_.end());
215-
} else {
216-
for (auto& iter : entrys_) {
217-
entrys_[iter.first] = iter.second;
218-
}
219-
}
220-
}
201+
std::tuple<Any*, bool> Get(const std::string& key);
221202

222-
bool CanConvert(size_t cast_code, size_t origin_code) {
223-
if (cast_code == origin_code) {
224-
return true;
225-
}
226-
227-
auto iter = type_hash_code_map.find(origin_code);
228-
if (iter == type_hash_code_map.end()) {
229-
return false;
230-
}
231-
232-
if (type_hash_code_map[origin_code] == cast_code) {
233-
MBLOG_DEBUG
234-
<< "origin type is not match cast type, maybe loss the accuracy.";
235-
return true;
236-
}
237-
238-
return false;
239-
}
203+
void Merge(const Collection& other, bool is_override = false);
204+
bool CanConvert(size_t cast_code, size_t origin_code);
240205

241206
private:
242207
std::map<std::string, Any> entrys_;

0 commit comments

Comments
 (0)