-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ComputeEngine Property for choosing Engine #2849
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -130,20 +130,49 @@ class SharedFrom : public Name { | |||
*/ | ||||
LayerNode::~LayerNode() = default; | ||||
|
||||
/** | ||||
* @brief get the compute engine property from property string vector | ||||
* : default is CPU | ||||
* @return LayerComputeEngine Enum : CPU, GPU, QNN | ||||
* | ||||
*/ | ||||
ml::train::LayerComputeEngine | ||||
getComputeEngine(const std::vector<std::string> &props) { | ||||
Comment on lines
+139
to
+140
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function prototype for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for your comment. This getComputeEngine function will be removed in PR #2849. |
||||
for (auto &prop : props) { | ||||
std::string key, value; | ||||
int status = nntrainer::getKeyValue(prop, key, value); | ||||
if (nntrainer::istrequal(key, "engine")) { | ||||
constexpr const auto data = | ||||
std::data(props::ComputeEngineTypeInfo::EnumList); | ||||
for (uint i = 0; i < props::ComputeEngineTypeInfo::EnumList.size(); ++i) { | ||||
if (nntrainer::istrequal(value.c_str(), | ||||
props::ComputeEngineTypeInfo::EnumStr[i])) { | ||||
return data[i]; | ||||
} | ||||
} | ||||
} | ||||
} | ||||
|
||||
return ml::train::LayerComputeEngine::CPU; | ||||
} | ||||
|
||||
/** | ||||
* @brief Layer factory creator with constructor | ||||
*/ | ||||
std::unique_ptr<LayerNode> | ||||
createLayerNode(const ml::train::LayerType &type, | ||||
const std::vector<std::string> &properties, | ||||
const ml::train::LayerComputeEngine &compute_engine) { | ||||
const std::vector<std::string> &properties) { | ||||
|
||||
if (getComputeEngine(properties) == ml::train::LayerComputeEngine::GPU) { | ||||
#ifdef ENABLE_OPENCL | ||||
if (compute_engine == ml::train::LayerComputeEngine::GPU) { | ||||
auto &cc = nntrainer::ClContext::Global(); | ||||
return createLayerNode(cc.createObject<nntrainer::Layer>(type), properties, | ||||
compute_engine); | ||||
} | ||||
return createLayerNode(cc.createObject<nntrainer::Layer>(type), properties); | ||||
#else | ||||
throw std::invalid_argument( | ||||
"opencl layer creation without enable-opencl option"); | ||||
#endif | ||||
} | ||||
|
||||
auto &ac = nntrainer::AppContext::Global(); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you think it holds for both There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No. it doesn't. This will changed in PR #2848 too. nntrainer/nntrainer/layers/layer_node.cpp Line 140 in dbbde82
|
||||
return createLayerNode(ac.createObject<nntrainer::Layer>(type), properties); | ||||
} | ||||
|
@@ -153,15 +182,18 @@ createLayerNode(const ml::train::LayerType &type, | |||
*/ | ||||
std::unique_ptr<LayerNode> | ||||
createLayerNode(const std::string &type, | ||||
const std::vector<std::string> &properties, | ||||
const ml::train::LayerComputeEngine &compute_engine) { | ||||
const std::vector<std::string> &properties) { | ||||
|
||||
if (getComputeEngine(properties) == ml::train::LayerComputeEngine::GPU) { | ||||
#ifdef ENABLE_OPENCL | ||||
if (compute_engine == ml::train::LayerComputeEngine::GPU) { | ||||
auto &cc = nntrainer::ClContext::Global(); | ||||
return createLayerNode(cc.createObject<nntrainer::Layer>(type), properties, | ||||
compute_engine); | ||||
} | ||||
return createLayerNode(cc.createObject<nntrainer::Layer>(type), properties); | ||||
#else | ||||
throw std::invalid_argument( | ||||
"opencl layer creation without enable-opencl option"); | ||||
#endif | ||||
} | ||||
|
||||
auto &ac = nntrainer::AppContext::Global(); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto. |
||||
return createLayerNode(ac.createObject<nntrainer::Layer>(type), properties); | ||||
} | ||||
|
@@ -171,16 +203,11 @@ createLayerNode(const std::string &type, | |||
*/ | ||||
std::unique_ptr<LayerNode> | ||||
createLayerNode(std::unique_ptr<nntrainer::Layer> &&layer, | ||||
const std::vector<std::string> &properties, | ||||
const ml::train::LayerComputeEngine &compute_engine) { | ||||
const std::vector<std::string> &properties) { | ||||
auto lnode = std::make_unique<LayerNode>(std::move(layer)); | ||||
|
||||
lnode->setProperty(properties); | ||||
|
||||
if (compute_engine == ml::train::LayerComputeEngine::GPU) { | ||||
lnode->setComputeEngine(compute_engine); | ||||
} | ||||
|
||||
return lnode; | ||||
} | ||||
|
||||
|
@@ -192,10 +219,10 @@ LayerNode::LayerNode(std::unique_ptr<nntrainer::Layer> &&l) : | |||
|
||||
output_connections(), | ||||
run_context(nullptr), | ||||
layer_node_props( | ||||
new PropsType(props::Name(), props::Distribute(), props::Trainable(), {}, | ||||
{}, props::SharedFrom(), props::ClipGradByGlobalNorm(), | ||||
props::Packed(), props::LossScaleForMixed())), | ||||
layer_node_props(new PropsType( | ||||
props::Name(), props::Distribute(), props::Trainable(), {}, {}, | ||||
props::SharedFrom(), props::ClipGradByGlobalNorm(), props::Packed(), | ||||
props::LossScaleForMixed(), props::ComputeEngine())), | ||||
layer_node_props_realization( | ||||
new RealizationPropsType(props::Flatten(), props::Activation())), | ||||
loss(new props::Loss()), | ||||
|
@@ -670,6 +697,10 @@ InitLayerContext LayerNode::finalize(const std::vector<TensorDim> &input_dims, | |||
if (!std::get<props::LossScaleForMixed>(*layer_node_props).empty()) | ||||
loss_scale = std::get<props::LossScaleForMixed>(*layer_node_props).get(); | ||||
|
||||
if (!std::get<props::ComputeEngine>(*layer_node_props).empty()) { | ||||
compute_engine = std::get<props::ComputeEngine>(*layer_node_props).get(); | ||||
} | ||||
|
||||
if (!std::get<props::Packed>(*layer_node_props).empty()) { | ||||
bool isPacked = std::get<props::Packed>(*layer_node_props); | ||||
if (!isPacked) { | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's remove it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it might be better to remove this after evaluating the cl_context.