Skip to content
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

Draft: [onert] NNAPI for test only #13817

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .ahub/sam/exclude.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ runtime/libs/circle-schema/include/circle_traininfo_generated.h
runtime/onert/core/src/loader/tflite_schema_generated.h

# External code: Android NN API
runtime/nnapi-header/include/NeuralNetworks.h
runtime/nnapi-header/include/NeuralNetworksExtensions.h
runtime/onert/api/nnapi/include/NeuralNetworks.h
runtime/onert/api/nnapi/include/NeuralNetworksExtensions.h

# External code: Tensorflow lite
runtime/libs/profiling/
Expand Down
43 changes: 2 additions & 41 deletions docs/howto/how-to-introduce-a-new-operation-into-runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ onert support the operation.
- [How To Introduce a New Operation Into Runtime](#how-to-introduce-a-new-operation-into-runtime)
- [Index](#index)
- [Core](#core)
- [Frontend](#frontend)
- [Loaders](#loaders)
- [Base Loader](#base-loader)
- [TFLite Loader](#tflite-loader)
- [Circle Loader](#circle-loader)
- [NNAPI](#nnapi)
- [Backend](#backend)
- [ShapeFixer](#shapefixer)
- [acl_cl](#acl_cl)
Expand Down Expand Up @@ -232,12 +230,10 @@ void DynamicShapeInferer::visit(const ir::operation::Select &op)
}
```

## Frontend

This module generates IR from a model. There are two kinds of frontend: Loader and NNAPI. First, Loader loads a model file and generates IR from it. Second, NNAPI generates IR from a model set via [Neural Networks API of android](https://developer.android.com/ndk/guides/neuralnetworks)

### Loaders

This module generates IR from a model.

#### Base Loader

This is where the common parts of loaders are implemented.
Expand Down Expand Up @@ -275,41 +271,6 @@ If you want new operation to be loaded on only TFLite Loader, you only need to i
This loads a circle file generated by the compiler.
If you want new operation to be loaded on only Circle Loader, you only need to implement loading the operation here.

### NNAPI

1. Add to the OperationFactory to generate IR of new operation
- [OperationFactory](/runtime/onert/api/nnapi/wrapper/OperationFactory.cc)

```cpp
_map[ANEURALNETWORKS_SELECT] = [](const OperationFactory::Param &init_param, Operands &) {
assert(init_param.input_count == 3 && init_param.output_count == 1);

OperandIndexSequence outputs{init_param.outputs[0]};

// Each input should be interpreted as follows:
//
// 0 -> Cond Tensor Index
// 1 -> Input1 Tensor Index
// 2 -> Input2 Tensor Index
OperandIndexSequence inputs;
for (uint32_t n = 0; n < init_param.input_count; ++n)
{
inputs.append(OperandIndex{init_param.inputs[n]});
}

return new operation::Select{inputs, outputs};
};
```

2. If you want that NNAPI supports new operation of TFLite's model, you need to update the things related to the operation in [nnapi_delegate](/runtime/libs/tflite/port/1.13.1/src/nnapi_delegate.cpp) like below

```cpp
case tflite::BuiltinOperator_SELECT:
nnapi_version = 12; // require NNAPI 1.2
nn_op_type = ANEURALNETWORKS_SELECT;
break;
```

## Backend

This module generates kernels and tensors of backend such as [ComputeLibrary](https://github.com/ARM-software/ComputeLibrary/) from generated graph-based IR. For this, the runtime fairly works on it internally. But this is not enough because of dependence on backend. So, there are several components that require additional implementation on each backend.
Expand Down
5 changes: 0 additions & 5 deletions docs/howto/how-to-use-nnapi-binding.md

This file was deleted.

1 change: 0 additions & 1 deletion docs/howto/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ How To
./how-to-run-package.md
./how-to-make-an-application-with-runtime.md
./how-to-use-api.md
./how-to-use-nnapi-binding.md
./how-to-use-nnfw-api.md
./how-to-use-specific-backend.md
./how-to-contribute.md
Expand Down
8 changes: 1 addition & 7 deletions docs/runtime/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,7 @@ There are three parts - Frontend, Core and Backend. Core works with Frontend and

Frontend API is about from creation/loading the model and

Runtime supports two (frontend) APIs - NN API and NNFW API.

### NN API

NN API stands for Android Neural Networks API. It is part of Android Open Source Project and we provide a binding between NN API and One Runtime.

For usage, refer to [Howto : NN API](../howto/how-to-use-nnapi-binding.md).
Runtime supports NNFW API.

### NNFW API

Expand Down
8 changes: 0 additions & 8 deletions runtime/nnapi-header/CMakeLists.txt

This file was deleted.

28 changes: 15 additions & 13 deletions runtime/onert/api/nnapi/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
# NNAPI Frontend is only for test purpose.
# So, it's not built by default.
if(NOT ENABLE_TEST OR NOT BUILD_RUNTIME_NNAPI_TEST)
return()
endif(NOT ENABLE_TEST OR NOT BUILD_RUNTIME_NNAPI_TEST)

file(GLOB_RECURSE SOURCES_FRONTEND "*.cc")
file(GLOB_RECURSE TESTS_FRONTEND "*.test.cc")
list(REMOVE_ITEM SOURCES_FRONTEND ${TESTS_FRONTEND})

set(LIB_ONERT onert)
set(LIB_ONERT_NNAPI onert-nnapi)

add_library(${LIB_ONERT} SHARED ${SOURCES_FRONTEND})
target_link_libraries(${LIB_ONERT} PUBLIC nnfw-nnapi-header)
target_link_libraries(${LIB_ONERT} PUBLIC onert_core) # TODO Link PRIVATE onert_core
target_link_libraries(${LIB_ONERT} PRIVATE nnfw_common)
target_link_libraries(${LIB_ONERT} PRIVATE nnfw_coverage)
add_library(${LIB_ONERT_NNAPI} SHARED ${SOURCES_FRONTEND})
target_include_directories(${LIB_ONERT_NNAPI} PUBLIC include)
target_link_libraries(${LIB_ONERT_NNAPI} PUBLIC onert_core) # TODO Link PRIVATE onert_core
target_link_libraries(${LIB_ONERT_NNAPI} PRIVATE nnfw_common)
target_link_libraries(${LIB_ONERT_NNAPI} PRIVATE nnfw_coverage)

set_target_properties(${LIB_ONERT} PROPERTIES OUTPUT_NAME neuralnetworks)
set_target_properties(${LIB_ONERT_NNAPI} PROPERTIES OUTPUT_NAME neuralnetworks)

install(TARGETS ${LIB_ONERT} DESTINATION lib)

if(NOT ENABLE_TEST)
return()
endif(NOT ENABLE_TEST)
install(TARGETS ${LIB_ONERT_NNAPI} DESTINATION lib)

add_executable(test_onert_frontend_nnapi ${TESTS_FRONTEND})

target_link_libraries(test_onert_frontend_nnapi PRIVATE ${LIB_ONERT} dl)
target_link_libraries(test_onert_frontend_nnapi PRIVATE ${LIB_ONERT_NNAPI} dl)
target_link_libraries(test_onert_frontend_nnapi PRIVATE gtest)
target_link_libraries(test_onert_frontend_nnapi PRIVATE gtest_main)

Expand Down
1 change: 0 additions & 1 deletion runtime/onert/api/nnfw/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ add_library(${ONERT_DEV} SHARED ${API_SRC})
# But runtime developer can use nnfw_internal.h by linking nnfw-dev
set(NNFW_API_HEADERS include/nnfw.h include/nnfw_experimental.h)

target_link_libraries(${ONERT_DEV} PUBLIC nnfw-nnapi-header)
target_link_libraries(${ONERT_DEV} PRIVATE onert_core)
target_link_libraries(${ONERT_DEV} PRIVATE nnfw_lib_misc)
target_link_libraries(${ONERT_DEV} PRIVATE jsoncpp ${LIB_PTHREAD})
Expand Down
4 changes: 2 additions & 2 deletions tests/custom_op/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function(add_nnfw_custom_op_app NAME)
list(APPEND LIBNAMELIST "${KERNEL}${SUFFIX}")
endforeach()
target_link_libraries(${NAME} PRIVATE ${LIBNAMELIST})
target_link_libraries(${NAME} PRIVATE nnfw-nnapi-header nnfw-dev)
target_link_libraries(${NAME} PRIVATE nnfw-dev)
target_link_libraries(${NAME} PRIVATE dl ${LIB_PTHREAD})
endfunction()

Expand All @@ -57,7 +57,7 @@ function(add_nnfw_custom_op_kernel NAME STATIC)
# message(FATAL_ERROR SHARED)
add_library(${LIBNAME} SHARED ${ARGN})
endif()
target_link_libraries(${LIBNAME} PRIVATE nnfw-nnapi-header nnfw-dev)
target_link_libraries(${LIBNAME} PRIVATE nnfw-dev)
target_link_libraries(${LIBNAME} PRIVATE flatbuffers::flatbuffers-23.5.26)
endfunction()

Expand Down
4 changes: 0 additions & 4 deletions tests/libs/nnapi/CMakeLists.txt

This file was deleted.

2 changes: 1 addition & 1 deletion tests/nnapi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ target_include_directories(${RUNTIME_NNAPI_TEST} PRIVATE ${RUNTIME_NNAPI_TEST_SR
# Define NNTEST_ONLY_PUBLIC_API to avoid android dependency
target_compile_definitions(${RUNTIME_NNAPI_TEST} PRIVATE NNTEST_ONLY_PUBLIC_API)

target_link_libraries(${RUNTIME_NNAPI_TEST} nnfw_lib_nnapi)
target_link_libraries(${RUNTIME_NNAPI_TEST} onert-nnapi)
target_link_libraries(${RUNTIME_NNAPI_TEST} gtest gmock)
target_link_libraries(${RUNTIME_NNAPI_TEST} ${LIB_PTHREAD} dl)

Expand Down