From: 이춘석/On-Device Lab(SR)/Staff Engineer/삼성전자 Date: Tue, 17 Sep 2019 05:27:23 +0000 (+0900) Subject: Use string as backend configuration arg (#7500) X-Git-Tag: accepted/tizen/unified/20190918.102349~34 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cfacbb413f54c34f55b02ddc1442d735ea973708;p=platform%2Fcore%2Fml%2Fnnfw.git Use string as backend configuration arg (#7500) * Use string as backend configuration arg - remove unness. enums for backend/operation - Use string as backend api arguments Signed-off-by: Chunseok Lee * Fix backend conf api - Remove unness. functions - Reflect new backend conf api Signed-off-by: Chunseok Lee * Use const char* in c++ header --- diff --git a/runtimes/include/nnfw.h b/runtimes/include/nnfw.h index 5c73a41..320b7b1 100644 --- a/runtimes/include/nnfw.h +++ b/runtimes/include/nnfw.h @@ -57,44 +57,6 @@ struct nnfw_tensorinfo }; /* - * (Partial) List of runtime's operations - */ -typedef enum { - NNFW_OP_AddNode, - NNFW_OP_SubNode, - NNFW_OP_Conv2DNode, - NNFW_OP_DepthwiseConv2DNode, - NNFW_OP_AvgPool2DNode, - NNFW_OP_MaxPool2DNode, - NNFW_OP_ConcatNode, - NNFW_OP_FullyConnectedNode, - NNFW_OP_ReshapeNode, - NNFW_OP_MulNode, - NNFW_OP_SoftmaxNode, - NNFW_OP_TanhNode, - NNFW_OP_DivNode, - NNFW_OP_TransposeNode, - NNFW_OP_RSQRTNode, - NNFW_OP_ReLUNode, - NNFW_OP_ReLU6Node, - NNFW_OP_TransposeConvNode, - NNFW_OP_SQRTNode, - NNFW_OP_SquaredDifferenceNode, - NNFW_OP_MeanNode, - NNFW_OP_CustomNode, -} NNFW_OP; - -/* - * List of available backends - */ -typedef enum { - NNFW_BACKEND_ACL_CL, // ARM Compute Library's OpenCL backend - NNFW_BACKEND_ACL_NEON, // ARM Compute Library's NEON backend - NNFW_BACKEND_CPU, // cpu backend - NNFW_BACKEND_SRCN, // Samsung SRC-N's backend -} NNFW_BACKEND; - -/* * Create a new session instance * * @param[out] session the session to be created @@ -217,7 +179,7 @@ NNFW_STATUS nnfw_output_tensorinfo(nnfw_session *session, uint32_t index, * @param[in] session session to which a default backend is set * @param[in] backend default backend */ -NNFW_STATUS nnfw_set_default_backend(nnfw_session *session, NNFW_BACKEND backend); +NNFW_STATUS nnfw_set_default_backend(nnfw_session *session, const char *backend); /* * Set the operation's backend @@ -228,7 +190,7 @@ NNFW_STATUS nnfw_set_default_backend(nnfw_session *session, NNFW_BACKEND backend * * @return NNFW_STATUS_NO_ERROR if successful */ -NNFW_STATUS nnfw_set_op_backend(nnfw_session *session, NNFW_OP op, NNFW_BACKEND backend); +NNFW_STATUS nnfw_set_op_backend(nnfw_session *session, const char *op, const char *backend); #ifdef __cplusplus } diff --git a/runtimes/neurun/frontend/api/nnfw_dev.cc b/runtimes/neurun/frontend/api/nnfw_dev.cc index ad53d44..e7ee7a2 100644 --- a/runtimes/neurun/frontend/api/nnfw_dev.cc +++ b/runtimes/neurun/frontend/api/nnfw_dev.cc @@ -183,7 +183,7 @@ NNFW_STATUS nnfw_register_custom_op_info(nnfw_session *session, const char *id, * @param[in] session session to which a default backend is set * @param[in] backend default backend */ -NNFW_STATUS nnfw_set_default_backend(nnfw_session *session, NNFW_BACKEND backend) +NNFW_STATUS nnfw_set_default_backend(nnfw_session *session, const char *backend) { return session->set_default_backend(backend); } @@ -197,7 +197,7 @@ NNFW_STATUS nnfw_set_default_backend(nnfw_session *session, NNFW_BACKEND backend * * @return NNFW_STATUS_NO_ERROR if successful */ -NNFW_STATUS nnfw_set_op_backend(nnfw_session *session, NNFW_OP op, NNFW_BACKEND backend) +NNFW_STATUS nnfw_set_op_backend(nnfw_session *session, const char *op, const char *backend) { return session->set_op_backend(op, backend); } diff --git a/runtimes/neurun/frontend/api/wrapper/nnfw_api.cc b/runtimes/neurun/frontend/api/wrapper/nnfw_api.cc index eb8aef0..80a768e 100644 --- a/runtimes/neurun/frontend/api/wrapper/nnfw_api.cc +++ b/runtimes/neurun/frontend/api/wrapper/nnfw_api.cc @@ -275,38 +275,16 @@ NNFW_STATUS nnfw_session::register_custom_operation(const std::string &id, return NNFW_STATUS_NO_ERROR; } -static std::string get_backend_string(NNFW_BACKEND backend) -{ - static std::unordered_map backend_map = { - {NNFW_BACKEND_ACL_CL, "acl_cl"}, - {NNFW_BACKEND_ACL_NEON, "acl_neon"}, - {NNFW_BACKEND_CPU, "cpu"}, - {NNFW_BACKEND_SRCN, "srcn"}, - }; - - auto b = backend_map.find(backend); - - if (b == backend_map.end()) - { - // this return value is handled by a caller to return error code - return std::string(""); - } - else - { - return b->second; - } -} - -static std::string get_op_backend_string(NNFW_OP op) +static std::string get_op_backend_string(std::string op) { // TODO: Provide complete set of operations - static std::unordered_map operation_map = { - {NNFW_OP_TransposeConvNode, "OP_BACKEND_TransposeConvNode"}, - {NNFW_OP_Conv2DNode, "OP_BACKEND_Conv2DNode"}, - {NNFW_OP_DepthwiseConv2DNode, "OP_BACKEND_DepthwiseConv2DNode"}, - {NNFW_OP_MeanNode, "OP_BACKEND_MeanNode"}, - {NNFW_OP_AvgPool2DNode, "OP_BACKEND_AvgPool2DNode"}, - {NNFW_OP_MaxPool2DNode, "OP_BACKEND_MaxPool2DNode"}, + static std::unordered_map operation_map = { + {"TRANSPOSE_CONV", "OP_BACKEND_TransposeConvNode"}, + {"CONV_2D", "OP_BACKEND_Conv2DNode"}, + {"DEPTHWISE_CONV_2D", "OP_BACKEND_DepthwiseConv2DNode"}, + {"MEAN", "OP_BACKEND_MeanNode"}, + {"AVERAGE_POOL_2D", "OP_BACKEND_AvgPool2DNode"}, + {"MAX_POOL_2D", "OP_BACKEND_MaxPool2DNode"}, }; auto n = operation_map.find(op); @@ -322,19 +300,11 @@ static std::string get_op_backend_string(NNFW_OP op) } } -NNFW_STATUS nnfw_session::set_default_backend(NNFW_BACKEND backend) +NNFW_STATUS nnfw_session::set_default_backend(std::string backend) { try { - std::string bs = get_backend_string(backend); - if (bs.empty()) - { - return NNFW_STATUS_ERROR; - } - else - { - _source->set("OP_BACKEND_ALLOPS", bs); - } + _source->set("OP_BACKEND_ALLOPS", backend); } catch (...) { @@ -344,21 +314,19 @@ NNFW_STATUS nnfw_session::set_default_backend(NNFW_BACKEND backend) return NNFW_STATUS_NO_ERROR; } -NNFW_STATUS nnfw_session::set_op_backend(NNFW_OP op, NNFW_BACKEND backend) +NNFW_STATUS nnfw_session::set_op_backend(std::string op, std::string backend) { try { - std::string key, value; - value = get_backend_string(backend); - key = get_op_backend_string(op); + auto key = get_op_backend_string(op); - if (key.empty() || value.empty()) + if (key.empty()) { return NNFW_STATUS_ERROR; } - _source->set(key, value); + _source->set(key, backend); } catch (...) { diff --git a/runtimes/neurun/frontend/api/wrapper/nnfw_api.hpp b/runtimes/neurun/frontend/api/wrapper/nnfw_api.hpp index 8cc956e..5b44650 100644 --- a/runtimes/neurun/frontend/api/wrapper/nnfw_api.hpp +++ b/runtimes/neurun/frontend/api/wrapper/nnfw_api.hpp @@ -64,8 +64,8 @@ public: NNFW_STATUS register_custom_operation(const std::string &id, nnfw_custom_eval eval_func); - NNFW_STATUS set_default_backend(NNFW_BACKEND backend); - NNFW_STATUS set_op_backend(NNFW_OP op, NNFW_BACKEND backend); + NNFW_STATUS set_default_backend(std::string backend); + NNFW_STATUS set_op_backend(std::string op, std::string backend); private: std::shared_ptr _graph;