提交 1c89d40c 编写于 作者: W wxyu

MS-390 Update resource construct function


Former-commit-id: 1f87f3e285798b2bf3dda78537fdb2b0fc7cc6ef
上级 a79017ef
...@@ -35,6 +35,7 @@ Please mark all change in change log and use the ticket from JIRA. ...@@ -35,6 +35,7 @@ Please mark all change in change log and use the ticket from JIRA.
- MS-383 - Modify condition variable usage in scheduler - MS-383 - Modify condition variable usage in scheduler
- MS-384 - Add global instance of ResourceMgr and Scheduler - MS-384 - Add global instance of ResourceMgr and Scheduler
- MS-389 - Add clone interface in Task - MS-389 - Add clone interface in Task
- MS-390 - Update resource construct function
## New Feature ## New Feature
- MS-343 - Implement ResourceMgr - MS-343 - Implement ResourceMgr
......
...@@ -12,13 +12,16 @@ namespace milvus { ...@@ -12,13 +12,16 @@ namespace milvus {
namespace engine { namespace engine {
std::shared_ptr<Resource> std::shared_ptr<Resource>
ResourceFactory::Create(const std::string &name, const std::string &alias) { ResourceFactory::Create(const std::string &name,
const std::string &alias,
bool enable_loader,
bool enable_executor) {
if (name == "disk") { if (name == "disk") {
return std::make_shared<DiskResource>(alias); return std::make_shared<DiskResource>(alias, enable_loader, enable_executor);
} else if (name == "cpu") { } else if (name == "cpu") {
return std::make_shared<CpuResource>(alias); return std::make_shared<CpuResource>(alias, enable_loader, enable_executor);
} else if (name == "gpu") { } else if (name == "gpu") {
return std::make_shared<GpuResource>(alias); return std::make_shared<GpuResource>(alias, enable_loader, enable_executor);
} else { } else {
return nullptr; return nullptr;
} }
......
...@@ -21,7 +21,10 @@ namespace engine { ...@@ -21,7 +21,10 @@ namespace engine {
class ResourceFactory { class ResourceFactory {
public: public:
static std::shared_ptr<Resource> static std::shared_ptr<Resource>
Create(const std::string &name, const std::string &alias = ""); Create(const std::string &name,
const std::string &alias = "",
bool enable_loader = true,
bool enable_executor = true);
}; };
......
...@@ -16,8 +16,8 @@ std::ostream &operator<<(std::ostream &out, const CpuResource &resource) { ...@@ -16,8 +16,8 @@ std::ostream &operator<<(std::ostream &out, const CpuResource &resource) {
return out; return out;
} }
CpuResource::CpuResource(std::string name) CpuResource::CpuResource(std::string name, bool enable_loader, bool enable_executor)
: Resource(std::move(name), ResourceType::CPU) {} : Resource(std::move(name), ResourceType::CPU, enable_loader, enable_executor) {}
void CpuResource::LoadFile(TaskPtr task) { void CpuResource::LoadFile(TaskPtr task) {
task->Load(LoadType::DISK2CPU, 0); task->Load(LoadType::DISK2CPU, 0);
...@@ -29,4 +29,4 @@ void CpuResource::Process(TaskPtr task) { ...@@ -29,4 +29,4 @@ void CpuResource::Process(TaskPtr task) {
} }
} }
} }
\ No newline at end of file
...@@ -17,7 +17,7 @@ namespace engine { ...@@ -17,7 +17,7 @@ namespace engine {
class CpuResource : public Resource { class CpuResource : public Resource {
public: public:
explicit explicit
CpuResource(std::string name); CpuResource(std::string name, bool enable_loader, bool enable_executor);
inline std::string inline std::string
Dump() const override { Dump() const override {
......
...@@ -15,8 +15,8 @@ std::ostream &operator<<(std::ostream &out, const DiskResource &resource) { ...@@ -15,8 +15,8 @@ std::ostream &operator<<(std::ostream &out, const DiskResource &resource) {
return out; return out;
} }
DiskResource::DiskResource(std::string name) DiskResource::DiskResource(std::string name, bool enable_loader, bool enable_executor)
: Resource(std::move(name), ResourceType::DISK, true, false) { : Resource(std::move(name), ResourceType::DISK, enable_loader, enable_executor) {
} }
void DiskResource::LoadFile(TaskPtr task) { void DiskResource::LoadFile(TaskPtr task) {
......
...@@ -16,7 +16,7 @@ namespace engine { ...@@ -16,7 +16,7 @@ namespace engine {
class DiskResource : public Resource { class DiskResource : public Resource {
public: public:
explicit explicit
DiskResource(std::string name); DiskResource(std::string name, bool enable_loader, bool enable_executor);
inline std::string inline std::string
Dump() const override { Dump() const override {
......
...@@ -16,8 +16,8 @@ std::ostream &operator<<(std::ostream &out, const GpuResource &resource) { ...@@ -16,8 +16,8 @@ std::ostream &operator<<(std::ostream &out, const GpuResource &resource) {
return out; return out;
} }
GpuResource::GpuResource(std::string name) GpuResource::GpuResource(std::string name, bool enable_loader, bool enable_executor)
: Resource(std::move(name), ResourceType::GPU) {} : Resource(std::move(name), ResourceType::GPU, enable_loader, enable_executor) {}
void GpuResource::LoadFile(TaskPtr task) { void GpuResource::LoadFile(TaskPtr task) {
task->Load(LoadType::CPU2GPU, 0); task->Load(LoadType::CPU2GPU, 0);
......
...@@ -16,7 +16,7 @@ namespace engine { ...@@ -16,7 +16,7 @@ namespace engine {
class GpuResource : public Resource { class GpuResource : public Resource {
public: public:
explicit explicit
GpuResource(std::string name); GpuResource(std::string name, bool enable_loader, bool enable_executor);
inline std::string inline std::string
Dump() const override { Dump() const override {
......
...@@ -45,8 +45,30 @@ enum class RegisterType { ...@@ -45,8 +45,30 @@ enum class RegisterType {
class Resource : public Node, public std::enable_shared_from_this<Resource> { class Resource : public Node, public std::enable_shared_from_this<Resource> {
public: public:
/* /*
* Event function MUST be a short function, never blocking; * Start loader and executor if enable;
*/ */
void
Start();
/*
* Stop loader and executor, join it, blocking util thread exited;
*/
void
Stop();
/*
* wake up loader;
*/
void
WakeupLoader();
/*
* wake up executor;
*/
void
WakeupExecutor();
public:
template<typename T> template<typename T>
void Register_T(const RegisterType &type) { void Register_T(const RegisterType &type) {
register_table_.emplace(type, [] { return std::make_shared<T>(); }); register_table_.emplace(type, [] { return std::make_shared<T>(); });
...@@ -65,11 +87,17 @@ public: ...@@ -65,11 +87,17 @@ public:
return type_; return type_;
} }
void // TODO: better name?
Start(); inline bool
HasLoader() {
return enable_loader_;
}
void // TODO: better name?
Stop(); inline bool
HasExecutor() {
return enable_executor_;
}
TaskTable & TaskTable &
task_table(); task_table();
...@@ -81,24 +109,11 @@ public: ...@@ -81,24 +109,11 @@ public:
friend std::ostream &operator<<(std::ostream &out, const Resource &resource); friend std::ostream &operator<<(std::ostream &out, const Resource &resource);
public:
/*
* wake up loader;
*/
void
WakeupLoader();
/*
* wake up executor;
*/
void
WakeupExecutor();
protected: protected:
Resource(std::string name, Resource(std::string name,
ResourceType type, ResourceType type,
bool enable_loader = true, bool enable_loader,
bool enable_executor = true); bool enable_executor);
// TODO: SearchContextPtr to TaskPtr // TODO: SearchContextPtr to TaskPtr
/* /*
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册