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