[ml service] Refactor: Decompose ml_single_open_custom function for better maintainability - #651
[ml service] Refactor: Decompose ml_single_open_custom function for better maintainability#651songgot wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
This patch refactors a 200+ line function into five smaller functions,
improving readability and maintainability. 👍
Additional recommendations:
a. Avoid the '__' prefix—it’s reserved for system/compiler use.
b. Split _configure_nnfw_tensors by NNFW types to adhere to SRP.
…etter maintainability This commit refactors the monolithic ml_single_open_custom function (200+ lines) into smaller, focused helper functions to improve code readability and maintainability. The main function is now structured as a clear sequence of steps, each handled by a dedicated helper function. Signed-off-by: hyunil park <hyunil46.park@samsung.com>
94e9e4e to
9ed6579
Compare
|
From cursor. (both look legit)
_configure_nnfw_tensors()가 info->nnfw만 참조합니다. 그런데 직전에 호출한 _validate_and_determine_nnfw()는 검증 결과를 info->nnfw에 다시 써주지 않아서, 사용자가 ML_NNFW_TYPE_ANY(또는 잘못된 값)을 넘기면 여기 switch가 default로 빠집니다. TensorFlow/NNFW 등에서는 in/out 텐서 메타데이터 설정이 필수인데 이 단계가 생략돼 런타임 오류가 발생합니다. 검증된 nnfw를 info->nnfw에 저장하거나 이 함수가 nnfw 인자를 직접 받아 사용하도록 조정이 필요해 보입니다.
framework_name/framework 옵션을 통해 info->fw_name에 값을 넣을 수 있지만, _configure_filter_properties()에서는 항상 fw_name 인자(자동 감지 결과)만 사용합니다. 그래서 사용자가 명시적으로 프레임워크 문자열을 지정해도 더 이상 반영되지 않아 기존 기능이 회귀된 상태입니다. info->fw_name이 존재하면 이를 우선 사용하도록 복원해 주세요. |
Thank you for your review. |
myungjoo-bot
left a comment
There was a problem hiding this comment.
Automated review (transcribed from an AI review agent's report; please verify before acting).
Summary: The PR splits ml_single_open_custom() in c/src/ml-api-inference-single.c into eight static helpers, renames __setup_in_out_tensors -> _setup_in_out_tensors, and reformats type * var -> type *var across ~25 unrelated hunks. I traced every path of the original (validation order, goto error -> ml_single_close, list_models / hw_name / converted_models release, *single = NULL init, return codes, NNTR_INF block) against the decomposed version. Cleanup order and resource handling are preserved, but two data-flow changes alter behavior, and the PR conflicts with current main.
- [High] Resolved nnfw type not used for tensors setup —
_configure_nnfw_tensors(PR ~line 1154, called at ~1283) switches oninfo->nnfw(user value) instead of the localnnfwrewritten by_ml_validate_model_file()forML_NNFW_TYPE_ANY. WithML_NNFW_TYPE_ANYand a.pb/.ptmodel the switch hitsdefault, the mandatory in/out info push is skipped, and open fails withML_ERROR_STREAMS_PIPEeven when valid infos were supplied (previously: success, or a clearML_ERROR_INVALID_PARAMETER).ml_single_create_handle (nnfw)andfw_namedo use the resolved value, so handle and tensors config disagree. Fix: passnnfwas a parameter andswitch (nnfw)(do not write back into caller-ownedinfo). - [High]
framework_nameoption silently ignored —_configure_filter_properties(~1181): the original usedinfo->fw_namewhen set, else_ml_get_nnfw_subplugin_name (nnfw). The PR always passes the auto-derived name, so the explicitframework_namefromml_single_open_with_option()(still populated at ~1412-1414) is dead. Public-API regression. Fix:const char *framework = info->fw_name ? info->fw_name : fw_name;ing_object_set. - [High] Merge conflict with
main—git merge-treereports a content conflict in this file. Since the PR base,mainadded"latency", info->latency_modeto theg_object_setcall (507be1d; would be dropped by a naive rebase into_configure_filter_properties), rewrote__setup_in_out_tensors(d53de78), and changedml_single_close(472be75). Also, your own open #661 replaces exactly the_configure_general/armnn/nnfw_tensorsregion; the two PRs conflict with each other and should be rebased into one series. - [Medium] Existing tests cannot catch #1 or #2 — the
ML_NNFW_TYPE_ANYtests use tflite (falls intodefaultin both versions), and the onlyframework_nametest sets the name equal to the auto-detected one. Please add (a) underENABLE_TENSORFLOW,ml_single_openof the.pbmodel withML_NNFW_TYPE_ANY+ in/out infos expectingML_ERROR_NONE, and (b) anml_optiontest with aframework_namedifferent from the default subplugin name, asserting viaml_single_get_property (single, "framework", ...). - [Medium] Android CI failed on all four ABIs (logs expired).
_ml_convert_predefined_entityhas an__ANDROID__-only branch and is now called twice (see #7). Please re-run after rebase and confirm green. - [Low]
_configure_handle(~1045) is a single assignment that can only returnML_ERROR_NONE, yet the caller (~1277-1280) has a deadgoto error. Fold it into_configure_async_settings(asvoid) or inline both. - [Low]
_ml_convert_predefined_entity (info->models)is now called twice (~1010 and ~1178). Convert once inml_single_open_customand pass the result to both helpers. - [Low] Unrelated churn — 25 of 30 hunks are
type * var->type *varreformatting in untouched functions, contradicting the repo-wide gst-indent convention (.github/workflows/static.check.scripts/indent.sh) and being the main cause of the conflict. The__->_rename is also partial (__invoke,__process_output,__ml_validate_model_fileuntouched). Please drop the reformatting / rename from this PR. - [Low] Doxygen — remove the "Single Responsibility Principle" editorializing in
_configure_nnfw_tensors; document@param[out] determined_nnfw/@returnin_validate_and_determine_nnfw;char *hw_namein_configure_filter_propertiesshould beconst char *.
No back-door or suspicious behavior found.
This commit refactors the monolithic ml_single_open_custom function (200+ lines) into smaller, focused helper functions to improve code readability and maintainability. The main function is now structured as a clear sequence of steps, each handled by a dedicated helper function.