mirror of https://github.com/milvus-io/milvus.git
MS-390 Update resource construct function
Former-commit-id: 1f87f3e285798b2bf3dda78537fdb2b0fc7cc6efpull/191/head
parent
a79017ef8f
commit
1c89d40c94
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
/*
|
||||
|
|
Loading…
Reference in New Issue