2025년 3월 27일부터 AOSP를 빌드하고 기여하려면 aosp-main
대신 android-latest-release
를 사용하는 것이 좋습니다. 자세한 내용은 AOSP 변경사항을 참고하세요.
NNAPI 드라이버 구현 권장사항
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
이 페이지에서는 앱 개발자가 Neural Networks API(NNAPI)를 광범위하게 채택할 수 있도록 NNAPI 드라이버를 구현하는 방법에 관한 권장사항을 설명합니다.
시작 시간을 짧게 유지하기
처음 사용 시 드라이버가 모델의 가중치를 변환하는 경우 드라이버가 컴파일 캐싱을 지원하는지 확인합니다. 이를 지원하면 앱이 시작할 때 컴파일에 사용되는 시간이 줄어듭니다. 이 사항이 중요한 이유는 시작 시간이 너무 긴 경우 앱에서 하드웨어 가속을 사용하지 않을 수 있기 때문입니다. 예를 들어 일부 앱의 가중치가 100MB를 초과하는 경우 앱이 실행될 때마다 가중치를 변환하는 것은 낭비입니다.
최소 지연 시간 줄이기
모델에서 하드웨어 가속을 사용하도록 하려면 드라이버의 최소 지연 시간을 줄이는 것이 중요합니다. 대다수 앱이 여러 번 실행되는 소형 모델을 사용합니다. 워크로드 실행에 필요한 최소 지연 시간이 너무 길다면(예: 수 밀리초) 모델은 하드웨어 가속을 사용하는 대신 CPU에서 워크로드를 실행할 수 있습니다. 이 경우 소요 시간이 1밀리초 또는 2밀리초에 불과합니다. 비용이 많이 드는 스레드 동기화에 주의하세요.
NN HAL SchedTune 그룹 사용하기
Android 11 이상부터 AOSP에는 프로세스 간 NN HAL 프로세스에 빅 코어를 사용할 수 있는 전용 NN HAL SchedTune 그룹(사전 정의된 top-app
cgroup 내의 동일 프로세스 구현과 유사함)이 포함됩니다. 이 SchedTune 그룹을 사용하면 특히 소형 모델의 드라이버 오버헤드가 줄어듭니다.
SchedTune 그룹을 사용하려면 NN HAL 프로세스의 init.rc
파일에 다음 행을 추가하세요.
writepid /dev/stune/nnapi-hal/tasks
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-07-27(UTC)
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["필요한 정보가 없음","missingTheInformationINeed","thumb-down"],["너무 복잡함/단계 수가 너무 많음","tooComplicatedTooManySteps","thumb-down"],["오래됨","outOfDate","thumb-down"],["번역 문제","translationIssue","thumb-down"],["샘플/코드 문제","samplesCodeIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-07-27(UTC)"],[],[],null,["# NNAPI driver implementation best practices\n\n| **Deprecated:** Starting in Android 15, the\n| [NNAPI (NDK API)](https://developer.android.com/ndk/guides/neuralnetworks) is deprecated. The Neural Networks HAL interface\n| continues to be supported.\n|\n| For more information, see the\n| [NNAPI Migration Guide](https://developer.android.com/ndk/guides/neuralnetworks/migration-guide).\n\nThis page describes best practices for implementing Neural Networks API (NNAPI)\ndrivers to allow for broad adoption of the NNAPI by app developers.\n\nKeep startup times short\n------------------------\n\nIf your driver transforms the weights of a model on first use, make sure the\ndriver supports compilation caching, which reduces the time used for compilation\nwhen an app starts. This is important as apps might avoid using hardware\nacceleration if start-up times are too long. For example, some apps have\nmore than 100 MB of weights and transforming these each time the app\nlaunches is wasteful.\n\nReduce minimal latency\n----------------------\n\nTo ensure that models use hardware acceleration, it's important to reduce the\nminimal latency in drivers. Many apps use small models that are executed\nmultiple times and if the minimal latency to execute a workload is too high,\nsuch as a few milliseconds, models might run the workload on the CPU, which only\ntakes one or two milliseconds, instead of\nusing hardware accelerations. Be careful of costly thread synchronization.\n\nUse the NN HAL SchedTune group\n------------------------------\n\nFrom Android 11 or higher, AOSP includes a dedicated\nNN HAL\n[SchedTune](https://android.googlesource.com/kernel/msm/+/android-msm-marlin-3.18-nougat-dr1/Documentation/scheduler/sched-tune.txt)\ngroup that allows interprocess NN HAL processes to use big\ncores, similar to same-process implementation within the predefined\n`top-app` [cgroup](/docs/core/perf/cgroups). Using this\nSchedTune group reduces driver overhead, especially for small models.\n\nTo use the SchedTune group, add the following line to the `init.rc` file of\nthe NN HAL process: \n\n writepid /dev/stune/nnapi-hal/tasks"]]