onnxruntime/onnxruntime/test/providers/nnapi/nnapi_basic_test.cc

562 lines
25 KiB
C++
Raw Normal View History

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#if !defined(ORT_MINIMAL_BUILD) || defined(ORT_EXTENDED_MINIMAL_BUILD)
#include "core/common/logging/logging.h"
#include "core/providers/nnapi/nnapi_builtin/builders/op_builder.h"
#include "core/providers/nnapi/nnapi_builtin/builders/op_support_checker.h"
#include "core/providers/nnapi/nnapi_builtin/nnapi_execution_provider.h"
#include "core/providers/nnapi/nnapi_builtin/nnapi_lib/NeuralNetworksTypes.h"
#include "core/providers/nnapi/nnapi_builtin/nnapi_lib/nnapi_implementation.h"
Initial PR for NNAPI execution provider (#1220) * init * Update DNNLibrary * Update DNNLibrary, set compiler flags, it compiles now * Add more missing flags, add test * Update DNNLibrary * Update Compile method, fix allocator and some other bugs * Update DNNLibrary * Implement CopyTensor * Not delete state explicitly since it is managed by unique_ptr * Add the missing files when SingleUnitTestProjct is ON * misc changes * Fix wrong name in provider factory * Add my own test * Update the code of add node into graph, and add the missing initializer into graph * Fix the bug that re-build the graph produces extra output * Update DNNLibrary * Transpose nchw (ONNX) -> nhwc (NNAPI) * Add license * Add GetSupportedNodes method (implement it later) * Rename onnxruntime_nnapi_test->onnxruntime_nnapi_squeezenet_test * Update squeezenet_test.cpp after rebase master * Remove squeezenet_test.cpp since it is almost same with the c++ sample * Update DNNLibrary for GetSupportedNodes * Update GetSupportedNodes * Revert "Remove squeezenet_test.cpp since it is almost same with the c++ sample" This reverts commit a97575fd9ff49e50ba1dc8d8154790d8cd86c48d. * Update DNNLibrary * Fix multiple outputs bug * Remove GetKernelRegistry * Revert "Revert "Remove squeezenet_test.cpp since it is almost same with the c++ sample"" This reverts commit 2a0670e9cbf10ea654111ce39e198a4be0ddd838. * Set default memory type of NNAPI EP * Add CPUOutput allocator * Update DNNLibrary for multiple outputs * Fix bug of nhwc->nchw * Remove GetExecutionHandle()
2019-07-02 13:03:29 +00:00
#include "core/session/inference_session.h"
#include "core/framework/tensorprotoutils.h"
#include "test/common/tensor_op_test_utils.h"
Initial PR for NNAPI execution provider (#1220) * init * Update DNNLibrary * Update DNNLibrary, set compiler flags, it compiles now * Add more missing flags, add test * Update DNNLibrary * Update Compile method, fix allocator and some other bugs * Update DNNLibrary * Implement CopyTensor * Not delete state explicitly since it is managed by unique_ptr * Add the missing files when SingleUnitTestProjct is ON * misc changes * Fix wrong name in provider factory * Add my own test * Update the code of add node into graph, and add the missing initializer into graph * Fix the bug that re-build the graph produces extra output * Update DNNLibrary * Transpose nchw (ONNX) -> nhwc (NNAPI) * Add license * Add GetSupportedNodes method (implement it later) * Rename onnxruntime_nnapi_test->onnxruntime_nnapi_squeezenet_test * Update squeezenet_test.cpp after rebase master * Remove squeezenet_test.cpp since it is almost same with the c++ sample * Update DNNLibrary for GetSupportedNodes * Update GetSupportedNodes * Revert "Remove squeezenet_test.cpp since it is almost same with the c++ sample" This reverts commit a97575fd9ff49e50ba1dc8d8154790d8cd86c48d. * Update DNNLibrary * Fix multiple outputs bug * Remove GetKernelRegistry * Revert "Revert "Remove squeezenet_test.cpp since it is almost same with the c++ sample"" This reverts commit 2a0670e9cbf10ea654111ce39e198a4be0ddd838. * Set default memory type of NNAPI EP * Add CPUOutput allocator * Update DNNLibrary for multiple outputs * Fix bug of nhwc->nchw * Remove GetExecutionHandle()
2019-07-02 13:03:29 +00:00
#include "test/framework/test_utils.h"
#include "test/util/include/asserts.h"
#include "test/util/include/default_providers.h"
#include "test/util/include/inference_session_wrapper.h"
#include "test/util/include/test/test_environment.h"
#include "test/util/include/test_utils.h"
#if !defined(ORT_MINIMAL_BUILD)
// if this is a full build we need the provider test utils
#include "test/providers/provider_test_utils.h"
#include "test/optimizer/qdq_test_utils.h"
#endif
#include "gtest/gtest.h"
#include "gmock/gmock.h"
The initial PR for NNAPI EP (#4287) * Move nnapi dnnlib to subfolder * dnnlib compile settings * add nnapi buildin build.py * add onnxruntime_USE_NNAPI_BUILTIN * compile using onnxruntime_USE_NNAPI_BUILTIN * remove dnnlib from built in code * Group onnxruntime_USE_NNAPI_BUILTIN sources * add file stubs * java 32bit compile error * built in nnapi support 5-26 * init working version * initializer support * fix crash on free execution * add dynamic input support * bug fixes for dynamic input shape, add mul support, working on conv and batchnorm * Add batchnormalization, add overflow check for int64 attributes * add global average/max pool and reshape * minor changes * minor changes * add skip relu and options to use different type of memory * small bug fix for in operator relu * bug fix for nnapi * add transpose support, minor bug fix * Add transpose support * minor bug fixes, depthwise conv weight fix * fixed the bug where the onnx model input has mismatch order than the nnapi model input * add helper to add scalar operand * add separated opbuilder to handle single operator * add cast operator * fixed reshape, moved some logs to verbose * Add softmax and identity support, change shaper calling signature, and add support for int32 output * changed the way to execute the NNAPI * move NNMemory and InputOutputInfo into Model class * add limited support for input dynamic shape * add gemm support, fixed crash when allocating big array on stack * add abs/exp/floor/log/sigmoid/neg/sin/sqrt/tanh support * better dynamic input shape support; * add more check for IsOpSupportedImpl, refactored some code * some code style fix, switch to safeint * Move opbuilders to a map with single instance, minor bug fixes * add GetUniqueName for new temp tensors * change from throw std to ort_throw * build settings change and 3rd party notice update * add readme for nnapi_lib, move to ort log, add comments to public functions, clean the code * add android log sink and more logging changes, add new string for NnApiErrorDescription * add nnapi execution options/fp16 relax * fix a dnnlibrary build break * addressed review comments * address review comments, changed adding output for subgraph in NnapiExecutionProvider::GetCapability, minor issue fixes * formatting in build.py * more formatting fix in build.py, return fail status instead of throw in compute_func * moved android_log_sink to platform folder, minor coding style changes * addressed review comments
2020-06-26 07:02:39 +00:00
Initial PR for NNAPI execution provider (#1220) * init * Update DNNLibrary * Update DNNLibrary, set compiler flags, it compiles now * Add more missing flags, add test * Update DNNLibrary * Update Compile method, fix allocator and some other bugs * Update DNNLibrary * Implement CopyTensor * Not delete state explicitly since it is managed by unique_ptr * Add the missing files when SingleUnitTestProjct is ON * misc changes * Fix wrong name in provider factory * Add my own test * Update the code of add node into graph, and add the missing initializer into graph * Fix the bug that re-build the graph produces extra output * Update DNNLibrary * Transpose nchw (ONNX) -> nhwc (NNAPI) * Add license * Add GetSupportedNodes method (implement it later) * Rename onnxruntime_nnapi_test->onnxruntime_nnapi_squeezenet_test * Update squeezenet_test.cpp after rebase master * Remove squeezenet_test.cpp since it is almost same with the c++ sample * Update DNNLibrary for GetSupportedNodes * Update GetSupportedNodes * Revert "Remove squeezenet_test.cpp since it is almost same with the c++ sample" This reverts commit a97575fd9ff49e50ba1dc8d8154790d8cd86c48d. * Update DNNLibrary * Fix multiple outputs bug * Remove GetKernelRegistry * Revert "Revert "Remove squeezenet_test.cpp since it is almost same with the c++ sample"" This reverts commit 2a0670e9cbf10ea654111ce39e198a4be0ddd838. * Set default memory type of NNAPI EP * Add CPUOutput allocator * Update DNNLibrary for multiple outputs * Fix bug of nhwc->nchw * Remove GetExecutionHandle()
2019-07-02 13:03:29 +00:00
using namespace std;
using namespace ONNX_NAMESPACE;
using namespace ::onnxruntime::logging;
namespace onnxruntime {
namespace test {
Update kernel matching logic: decouple from op schemas and remove kernel def hashes (#12791) # Motivation Currently, ORT minimal builds use kernel def hashes to map from nodes to kernels to execute when loading the model. As the kernel def hashes must be known ahead of time, this works for statically registered kernels. This works well for the CPU EP. For this approach to work, the kernel def hashes must also be known at ORT format model conversion time, which means the EP with statically registered kernels must also be enabled then. This is not an issue for the always-available CPU EP. However, we do not want to require that any EP which statically registers kernels is always available too. Consequently, we explore another approach to match nodes to kernels that does not rely on kernel def hashes. An added benefit of this is the possibility of moving away from kernel def hashes completely, which would eliminate the maintenance burden of keeping the hashes stable. # Approach In a full build, ORT uses some information from the ONNX op schema to match a node to a kernel. We want to avoid including the ONNX op schema in a minimal build to reduce binary size. Essentially, we take the necessary information from the ONNX op schema and make it available in a minimal build. We decouple the ONNX op schema from the kernel matching logic. The kernel matching logic instead relies on per-op information which can either be obtained from the ONNX op schema or another source. This per-op information must be available in a minimal build when there are no ONNX op schemas. We put it in the ORT format model. Existing uses of kernel def hashes to look up kernels are replaced with the updated kernel matching logic. We no longer store kernel def hashes in the ORT format model’s session state and runtime optimization representations. We no longer keep the logic to generate and ensure stability of kernel def hashes.
2022-09-20 21:24:59 +00:00
#if !defined(ORT_MINIMAL_BUILD) || defined(ORT_EXTENDED_MINIMAL_BUILD)
namespace {
Update kernel matching logic: decouple from op schemas and remove kernel def hashes (#12791) # Motivation Currently, ORT minimal builds use kernel def hashes to map from nodes to kernels to execute when loading the model. As the kernel def hashes must be known ahead of time, this works for statically registered kernels. This works well for the CPU EP. For this approach to work, the kernel def hashes must also be known at ORT format model conversion time, which means the EP with statically registered kernels must also be enabled then. This is not an issue for the always-available CPU EP. However, we do not want to require that any EP which statically registers kernels is always available too. Consequently, we explore another approach to match nodes to kernels that does not rely on kernel def hashes. An added benefit of this is the possibility of moving away from kernel def hashes completely, which would eliminate the maintenance burden of keeping the hashes stable. # Approach In a full build, ORT uses some information from the ONNX op schema to match a node to a kernel. We want to avoid including the ONNX op schema in a minimal build to reduce binary size. Essentially, we take the necessary information from the ONNX op schema and make it available in a minimal build. We decouple the ONNX op schema from the kernel matching logic. The kernel matching logic instead relies on per-op information which can either be obtained from the ONNX op schema or another source. This per-op information must be available in a minimal build when there are no ONNX op schemas. We put it in the ORT format model. Existing uses of kernel def hashes to look up kernels are replaced with the updated kernel matching logic. We no longer store kernel def hashes in the ORT format model’s session state and runtime optimization representations. We no longer keep the logic to generate and ensure stability of kernel def hashes.
2022-09-20 21:24:59 +00:00
[[maybe_unused]]
void TestModelLoad(const ORTCHAR_T* model_file_name, const std::function<void(const Graph&)>& check_graph) {
SessionOptions so;
InferenceSessionWrapper session_object{so, GetEnvironment()};
ASSERT_STATUS_OK(session_object.RegisterExecutionProvider(std::make_unique<NnapiExecutionProvider>(0)));
ASSERT_STATUS_OK(session_object.Load(model_file_name));
ASSERT_STATUS_OK(session_object.Initialize());
check_graph(session_object.GetGraph());
}
} // namespace
Update kernel matching logic: decouple from op schemas and remove kernel def hashes (#12791) # Motivation Currently, ORT minimal builds use kernel def hashes to map from nodes to kernels to execute when loading the model. As the kernel def hashes must be known ahead of time, this works for statically registered kernels. This works well for the CPU EP. For this approach to work, the kernel def hashes must also be known at ORT format model conversion time, which means the EP with statically registered kernels must also be enabled then. This is not an issue for the always-available CPU EP. However, we do not want to require that any EP which statically registers kernels is always available too. Consequently, we explore another approach to match nodes to kernels that does not rely on kernel def hashes. An added benefit of this is the possibility of moving away from kernel def hashes completely, which would eliminate the maintenance burden of keeping the hashes stable. # Approach In a full build, ORT uses some information from the ONNX op schema to match a node to a kernel. We want to avoid including the ONNX op schema in a minimal build to reduce binary size. Essentially, we take the necessary information from the ONNX op schema and make it available in a minimal build. We decouple the ONNX op schema from the kernel matching logic. The kernel matching logic instead relies on per-op information which can either be obtained from the ONNX op schema or another source. This per-op information must be available in a minimal build when there are no ONNX op schemas. We put it in the ORT format model. Existing uses of kernel def hashes to look up kernels are replaced with the updated kernel matching logic. We no longer store kernel def hashes in the ORT format model’s session state and runtime optimization representations. We no longer keep the logic to generate and ensure stability of kernel def hashes.
2022-09-20 21:24:59 +00:00
#endif // !defined(ORT_MINIMAL_BUILD) || defined(ORT_EXTENDED_MINIMAL_BUILD)
#if !defined(ORT_MINIMAL_BUILD)
// Since NNAPI EP handles Reshape and Flatten differently,
// Please see ReshapeOpBuilder::CanSkipReshape in
// <repo_root>/onnxruntime/core/providers/nnapi/nnapi_builtin/builders/op_builder.cc
// We have a separated test for these skip reshape scenarios
TEST(NnapiExecutionProviderTest, ReshapeFlattenTest) {
const ORTCHAR_T* model_file_name = ORT_TSTR("testdata/nnapi_reshape_flatten_test.onnx");
#if defined(__ANDROID__)
std::vector<int64_t> dims_mul_x = {2, 1, 2};
std::vector<float> values_mul_x = {1.0f, 2.0f, 3.0f, 4.0f};
std::vector<int64_t> dims_mul_y = {3, 2, 2};
std::vector<float> values_mul_y = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f};
OrtValue ml_value_x;
CreateMLValue<float>(TestNnapiExecutionProvider()->GetAllocator(0, OrtMemTypeDefault), dims_mul_x, values_mul_x,
&ml_value_x);
OrtValue ml_value_y;
CreateMLValue<float>(TestNnapiExecutionProvider()->GetAllocator(0, OrtMemTypeDefault), dims_mul_y, values_mul_y,
&ml_value_y);
NameMLValMap feeds;
feeds.insert(std::make_pair("X", ml_value_x));
feeds.insert(std::make_pair("Y", ml_value_y));
RunAndVerifyOutputsWithEP(model_file_name, "NnapiExecutionProviderTest.ReshapeFlattenTest",
std::make_unique<NnapiExecutionProvider>(0),
feeds);
#else
// test load only
TestModelLoad(model_file_name,
[](const Graph& graph) { ASSERT_GT(CountAssignedNodes(graph, kNnapiExecutionProvider), 0)
<< "Some nodes should have been taken by the NNAPI EP"; });
#endif
}
TEST(NnapiExecutionProviderTest, SigmoidSupportedInputRankTest) {
const ORTCHAR_T* model_file_name = ORT_TSTR("testdata/nnapi_sigmoid_input_rank_test.onnx");
#if defined(__ANDROID__)
std::vector<int64_t> dims_mul_x = {2, 1, 2, 1, 2};
std::vector<float> values_mul_x = {1.0f, 2.0f, 3.0f, 4.0f, 1.0f, 2.0f, 3.0f, 4.0f};
OrtValue ml_value_x;
CreateMLValue<float>(TestNnapiExecutionProvider()->GetAllocator(0, OrtMemTypeDefault), dims_mul_x, values_mul_x,
&ml_value_x);
NameMLValMap feeds;
feeds.insert(std::make_pair("X", ml_value_x));
RunAndVerifyOutputsWithEP(model_file_name, "NnapiExecutionProviderTest.SigmoidSupportedInputRankTest",
std::make_unique<NnapiExecutionProvider>(0),
feeds, {ExpectedEPNodeAssignment::None} /* params */);
#else
// test load only
TestModelLoad(model_file_name,
[](const Graph& graph) { ASSERT_EQ(CountAssignedNodes(graph, kNnapiExecutionProvider), 0)
<< "No nodes should have been taken by the NNAPI EP"; });
#endif
}
// Since NNAPI EP does not support dynamic shape input and we now switch from the approach of immediately rejecting
// the whole graph in NNAPI EP if it has a dynamic input to check at individual operator support check level, we have a
// separated test here.
// Please see BaseOpBuilder::HasSupportedInputs in <repo_root>/onnxruntime/core/providers/nnapi/nnapi_builtin/builders/op_support_checker.cc
TEST(NnapiExecutionProviderTest, DynamicGraphInputTest) {
const ORTCHAR_T* model_file_name = ORT_TSTR("testdata/ep_dynamic_graph_input_test.onnx");
#if defined(__ANDROID__)
std::vector<int64_t> dims_mul_x = {1, 1, 4, 4};
std::vector<float> values_mul_x = {1.0f, 2.0f, 3.0f, 4.0f, 1.0f, 2.0f, 3.0f, 4.0f, 1.0f, 2.0f, 3.0f, 4.0f, 1.0f, 2.0f, 3.0f, 4.0f};
OrtValue ml_value_x;
CreateMLValue<float>(TestNnapiExecutionProvider()->GetAllocator(0, OrtMemTypeDefault), dims_mul_x, values_mul_x,
&ml_value_x);
NameMLValMap feeds;
feeds.insert(std::make_pair("X", ml_value_x));
RunAndVerifyOutputsWithEP(model_file_name, "NnapiExecutionProviderTest.DynamicGraphInputTest",
std::make_unique<NnapiExecutionProvider>(0),
feeds);
#else
TestModelLoad(model_file_name,
[](const Graph& graph) { ASSERT_EQ(CountAssignedNodes(graph, kNnapiExecutionProvider), 1)
<< "Exactly one node (Add) should have been taken by the NNAPI EP"; });
#endif
}
// This is to test the uint8 handling of operators without "QLinear" such as Concat and Transpose
// NNAPI will require scale and zero point for inputs of all quantized operations
// For these operators without "Qlinear", there is no information about the scale and zero point, we can
// only fetch these from the output of the previous node
// So uint8 support of these operators will only be enabled when they are internal to the graph
// by not consuming graph inputs
TEST(NnapiExecutionProviderTest, InternalUint8SupportTest) {
const ORTCHAR_T* model_file_name = ORT_TSTR("testdata/nnapi_internal_uint8_support.onnx");
#if defined(__ANDROID__)
std::vector<int64_t> dims_x = {1, 1, 1, 3};
std::vector<float> values_x = {0.0f, 256.0f, 512.0f};
OrtValue ml_value_x;
CreateMLValue<float>(TestNnapiExecutionProvider()->GetAllocator(0, OrtMemTypeDefault), dims_x, values_x,
&ml_value_x);
NameMLValMap feeds;
feeds.insert(std::make_pair("X", ml_value_x));
RunAndVerifyOutputsWithEP(model_file_name, "NnapiExecutionProviderTest.InternalUint8SupportTest",
std::make_unique<NnapiExecutionProvider>(0),
feeds);
#else
TestModelLoad(model_file_name,
[](const Graph& graph) { ASSERT_GT(CountAssignedNodes(graph, kNnapiExecutionProvider), 0)
<< "Some nodes should have been taken by the NNAPI EP"; });
#endif
}
#if defined(__ANDROID__)
// This is to verify the op_builders and op_support_checkers are consistent
TEST(NnapiExecutionProviderTest, CreateOpBuilderAndOpSupportCheckerTest) {
const auto& op_builders = nnapi::GetOpBuilders();
const auto& op_support_checkers = nnapi::GetOpSupportCheckers();
for (auto entry : op_builders) {
ASSERT_TRUE(op_support_checkers.find(entry.first) != op_support_checkers.cend());
}
for (auto entry : op_support_checkers) {
ASSERT_TRUE(op_builders.find(entry.first) != op_builders.cend());
}
}
#endif // #if defined(__ANDROID__)
Initial PR for NNAPI execution provider (#1220) * init * Update DNNLibrary * Update DNNLibrary, set compiler flags, it compiles now * Add more missing flags, add test * Update DNNLibrary * Update Compile method, fix allocator and some other bugs * Update DNNLibrary * Implement CopyTensor * Not delete state explicitly since it is managed by unique_ptr * Add the missing files when SingleUnitTestProjct is ON * misc changes * Fix wrong name in provider factory * Add my own test * Update the code of add node into graph, and add the missing initializer into graph * Fix the bug that re-build the graph produces extra output * Update DNNLibrary * Transpose nchw (ONNX) -> nhwc (NNAPI) * Add license * Add GetSupportedNodes method (implement it later) * Rename onnxruntime_nnapi_test->onnxruntime_nnapi_squeezenet_test * Update squeezenet_test.cpp after rebase master * Remove squeezenet_test.cpp since it is almost same with the c++ sample * Update DNNLibrary for GetSupportedNodes * Update GetSupportedNodes * Revert "Remove squeezenet_test.cpp since it is almost same with the c++ sample" This reverts commit a97575fd9ff49e50ba1dc8d8154790d8cd86c48d. * Update DNNLibrary * Fix multiple outputs bug * Remove GetKernelRegistry * Revert "Revert "Remove squeezenet_test.cpp since it is almost same with the c++ sample"" This reverts commit 2a0670e9cbf10ea654111ce39e198a4be0ddd838. * Set default memory type of NNAPI EP * Add CPUOutput allocator * Update DNNLibrary for multiple outputs * Fix bug of nhwc->nchw * Remove GetExecutionHandle()
2019-07-02 13:03:29 +00:00
TEST(NnapiExecutionProviderTest, FunctionTest) {
const ORTCHAR_T* model_file_name = ORT_TSTR("nnapi_execution_provider_test_graph.onnx");
{ // Create the model with 2 add nodes
onnxruntime::Model model("graph_1", false, DefaultLoggingManager().DefaultLogger());
auto& graph = model.MainGraph();
std::vector<onnxruntime::NodeArg*> inputs;
std::vector<onnxruntime::NodeArg*> outputs;
// FLOAT tensor.
ONNX_NAMESPACE::TypeProto float_tensor;
float_tensor.mutable_tensor_type()->set_elem_type(ONNX_NAMESPACE::TensorProto_DataType_FLOAT);
float_tensor.mutable_tensor_type()->mutable_shape()->add_dim()->set_dim_value(1);
float_tensor.mutable_tensor_type()->mutable_shape()->add_dim()->set_dim_value(1);
float_tensor.mutable_tensor_type()->mutable_shape()->add_dim()->set_dim_value(3);
float_tensor.mutable_tensor_type()->mutable_shape()->add_dim()->set_dim_value(2);
auto& input_arg_1 = graph.GetOrCreateNodeArg("X", &float_tensor);
auto& input_arg_2 = graph.GetOrCreateNodeArg("Y", &float_tensor);
inputs.push_back(&input_arg_1);
inputs.push_back(&input_arg_2);
auto& output_arg = graph.GetOrCreateNodeArg("node_1_out_1", &float_tensor);
outputs.push_back(&output_arg);
graph.AddNode("node_1", "Add", "node 1.", inputs, outputs);
auto& input_arg_3 = graph.GetOrCreateNodeArg("Z", &float_tensor);
inputs.clear();
inputs.push_back(&output_arg);
inputs.push_back(&input_arg_3);
auto& output_arg_2 = graph.GetOrCreateNodeArg("M", &float_tensor);
outputs.clear();
outputs.push_back(&output_arg_2);
graph.AddNode("node_2", "Add", "node 2.", inputs, outputs);
ASSERT_STATUS_OK(graph.Resolve());
ASSERT_STATUS_OK(onnxruntime::Model::Save(model, model_file_name));
}
Initial PR for NNAPI execution provider (#1220) * init * Update DNNLibrary * Update DNNLibrary, set compiler flags, it compiles now * Add more missing flags, add test * Update DNNLibrary * Update Compile method, fix allocator and some other bugs * Update DNNLibrary * Implement CopyTensor * Not delete state explicitly since it is managed by unique_ptr * Add the missing files when SingleUnitTestProjct is ON * misc changes * Fix wrong name in provider factory * Add my own test * Update the code of add node into graph, and add the missing initializer into graph * Fix the bug that re-build the graph produces extra output * Update DNNLibrary * Transpose nchw (ONNX) -> nhwc (NNAPI) * Add license * Add GetSupportedNodes method (implement it later) * Rename onnxruntime_nnapi_test->onnxruntime_nnapi_squeezenet_test * Update squeezenet_test.cpp after rebase master * Remove squeezenet_test.cpp since it is almost same with the c++ sample * Update DNNLibrary for GetSupportedNodes * Update GetSupportedNodes * Revert "Remove squeezenet_test.cpp since it is almost same with the c++ sample" This reverts commit a97575fd9ff49e50ba1dc8d8154790d8cd86c48d. * Update DNNLibrary * Fix multiple outputs bug * Remove GetKernelRegistry * Revert "Revert "Remove squeezenet_test.cpp since it is almost same with the c++ sample"" This reverts commit 2a0670e9cbf10ea654111ce39e198a4be0ddd838. * Set default memory type of NNAPI EP * Add CPUOutput allocator * Update DNNLibrary for multiple outputs * Fix bug of nhwc->nchw * Remove GetExecutionHandle()
2019-07-02 13:03:29 +00:00
#if defined(__ANDROID__)
Initial PR for NNAPI execution provider (#1220) * init * Update DNNLibrary * Update DNNLibrary, set compiler flags, it compiles now * Add more missing flags, add test * Update DNNLibrary * Update Compile method, fix allocator and some other bugs * Update DNNLibrary * Implement CopyTensor * Not delete state explicitly since it is managed by unique_ptr * Add the missing files when SingleUnitTestProjct is ON * misc changes * Fix wrong name in provider factory * Add my own test * Update the code of add node into graph, and add the missing initializer into graph * Fix the bug that re-build the graph produces extra output * Update DNNLibrary * Transpose nchw (ONNX) -> nhwc (NNAPI) * Add license * Add GetSupportedNodes method (implement it later) * Rename onnxruntime_nnapi_test->onnxruntime_nnapi_squeezenet_test * Update squeezenet_test.cpp after rebase master * Remove squeezenet_test.cpp since it is almost same with the c++ sample * Update DNNLibrary for GetSupportedNodes * Update GetSupportedNodes * Revert "Remove squeezenet_test.cpp since it is almost same with the c++ sample" This reverts commit a97575fd9ff49e50ba1dc8d8154790d8cd86c48d. * Update DNNLibrary * Fix multiple outputs bug * Remove GetKernelRegistry * Revert "Revert "Remove squeezenet_test.cpp since it is almost same with the c++ sample"" This reverts commit 2a0670e9cbf10ea654111ce39e198a4be0ddd838. * Set default memory type of NNAPI EP * Add CPUOutput allocator * Update DNNLibrary for multiple outputs * Fix bug of nhwc->nchw * Remove GetExecutionHandle()
2019-07-02 13:03:29 +00:00
std::vector<int64_t> dims_mul_x = {1, 1, 3, 2};
std::vector<float> values_mul_x = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f};
OrtValue ml_value_x;
CreateMLValue<float>(TestNnapiExecutionProvider()->GetAllocator(0, OrtMemTypeDefault), dims_mul_x, values_mul_x,
&ml_value_x);
Initial PR for NNAPI execution provider (#1220) * init * Update DNNLibrary * Update DNNLibrary, set compiler flags, it compiles now * Add more missing flags, add test * Update DNNLibrary * Update Compile method, fix allocator and some other bugs * Update DNNLibrary * Implement CopyTensor * Not delete state explicitly since it is managed by unique_ptr * Add the missing files when SingleUnitTestProjct is ON * misc changes * Fix wrong name in provider factory * Add my own test * Update the code of add node into graph, and add the missing initializer into graph * Fix the bug that re-build the graph produces extra output * Update DNNLibrary * Transpose nchw (ONNX) -> nhwc (NNAPI) * Add license * Add GetSupportedNodes method (implement it later) * Rename onnxruntime_nnapi_test->onnxruntime_nnapi_squeezenet_test * Update squeezenet_test.cpp after rebase master * Remove squeezenet_test.cpp since it is almost same with the c++ sample * Update DNNLibrary for GetSupportedNodes * Update GetSupportedNodes * Revert "Remove squeezenet_test.cpp since it is almost same with the c++ sample" This reverts commit a97575fd9ff49e50ba1dc8d8154790d8cd86c48d. * Update DNNLibrary * Fix multiple outputs bug * Remove GetKernelRegistry * Revert "Revert "Remove squeezenet_test.cpp since it is almost same with the c++ sample"" This reverts commit 2a0670e9cbf10ea654111ce39e198a4be0ddd838. * Set default memory type of NNAPI EP * Add CPUOutput allocator * Update DNNLibrary for multiple outputs * Fix bug of nhwc->nchw * Remove GetExecutionHandle()
2019-07-02 13:03:29 +00:00
OrtValue ml_value_y;
CreateMLValue<float>(TestNnapiExecutionProvider()->GetAllocator(0, OrtMemTypeDefault), dims_mul_x, values_mul_x,
&ml_value_y);
Initial PR for NNAPI execution provider (#1220) * init * Update DNNLibrary * Update DNNLibrary, set compiler flags, it compiles now * Add more missing flags, add test * Update DNNLibrary * Update Compile method, fix allocator and some other bugs * Update DNNLibrary * Implement CopyTensor * Not delete state explicitly since it is managed by unique_ptr * Add the missing files when SingleUnitTestProjct is ON * misc changes * Fix wrong name in provider factory * Add my own test * Update the code of add node into graph, and add the missing initializer into graph * Fix the bug that re-build the graph produces extra output * Update DNNLibrary * Transpose nchw (ONNX) -> nhwc (NNAPI) * Add license * Add GetSupportedNodes method (implement it later) * Rename onnxruntime_nnapi_test->onnxruntime_nnapi_squeezenet_test * Update squeezenet_test.cpp after rebase master * Remove squeezenet_test.cpp since it is almost same with the c++ sample * Update DNNLibrary for GetSupportedNodes * Update GetSupportedNodes * Revert "Remove squeezenet_test.cpp since it is almost same with the c++ sample" This reverts commit a97575fd9ff49e50ba1dc8d8154790d8cd86c48d. * Update DNNLibrary * Fix multiple outputs bug * Remove GetKernelRegistry * Revert "Revert "Remove squeezenet_test.cpp since it is almost same with the c++ sample"" This reverts commit 2a0670e9cbf10ea654111ce39e198a4be0ddd838. * Set default memory type of NNAPI EP * Add CPUOutput allocator * Update DNNLibrary for multiple outputs * Fix bug of nhwc->nchw * Remove GetExecutionHandle()
2019-07-02 13:03:29 +00:00
OrtValue ml_value_z;
CreateMLValue<float>(TestNnapiExecutionProvider()->GetAllocator(0, OrtMemTypeDefault), dims_mul_x, values_mul_x,
&ml_value_z);
Initial PR for NNAPI execution provider (#1220) * init * Update DNNLibrary * Update DNNLibrary, set compiler flags, it compiles now * Add more missing flags, add test * Update DNNLibrary * Update Compile method, fix allocator and some other bugs * Update DNNLibrary * Implement CopyTensor * Not delete state explicitly since it is managed by unique_ptr * Add the missing files when SingleUnitTestProjct is ON * misc changes * Fix wrong name in provider factory * Add my own test * Update the code of add node into graph, and add the missing initializer into graph * Fix the bug that re-build the graph produces extra output * Update DNNLibrary * Transpose nchw (ONNX) -> nhwc (NNAPI) * Add license * Add GetSupportedNodes method (implement it later) * Rename onnxruntime_nnapi_test->onnxruntime_nnapi_squeezenet_test * Update squeezenet_test.cpp after rebase master * Remove squeezenet_test.cpp since it is almost same with the c++ sample * Update DNNLibrary for GetSupportedNodes * Update GetSupportedNodes * Revert "Remove squeezenet_test.cpp since it is almost same with the c++ sample" This reverts commit a97575fd9ff49e50ba1dc8d8154790d8cd86c48d. * Update DNNLibrary * Fix multiple outputs bug * Remove GetKernelRegistry * Revert "Revert "Remove squeezenet_test.cpp since it is almost same with the c++ sample"" This reverts commit 2a0670e9cbf10ea654111ce39e198a4be0ddd838. * Set default memory type of NNAPI EP * Add CPUOutput allocator * Update DNNLibrary for multiple outputs * Fix bug of nhwc->nchw * Remove GetExecutionHandle()
2019-07-02 13:03:29 +00:00
NameMLValMap feeds;
feeds.insert(std::make_pair("X", ml_value_x));
feeds.insert(std::make_pair("Y", ml_value_y));
feeds.insert(std::make_pair("Z", ml_value_z));
RunAndVerifyOutputsWithEP(model_file_name, "NnapiExecutionProviderTest.FunctionTest",
std::make_unique<NnapiExecutionProvider>(0),
feeds);
#else
TestModelLoad(model_file_name,
[](const Graph& graph) { ASSERT_GT(CountAssignedNodes(graph, kNnapiExecutionProvider), 0)
<< "Some nodes should have been taken by the NNAPI EP"; });
#endif
Initial PR for NNAPI execution provider (#1220) * init * Update DNNLibrary * Update DNNLibrary, set compiler flags, it compiles now * Add more missing flags, add test * Update DNNLibrary * Update Compile method, fix allocator and some other bugs * Update DNNLibrary * Implement CopyTensor * Not delete state explicitly since it is managed by unique_ptr * Add the missing files when SingleUnitTestProjct is ON * misc changes * Fix wrong name in provider factory * Add my own test * Update the code of add node into graph, and add the missing initializer into graph * Fix the bug that re-build the graph produces extra output * Update DNNLibrary * Transpose nchw (ONNX) -> nhwc (NNAPI) * Add license * Add GetSupportedNodes method (implement it later) * Rename onnxruntime_nnapi_test->onnxruntime_nnapi_squeezenet_test * Update squeezenet_test.cpp after rebase master * Remove squeezenet_test.cpp since it is almost same with the c++ sample * Update DNNLibrary for GetSupportedNodes * Update GetSupportedNodes * Revert "Remove squeezenet_test.cpp since it is almost same with the c++ sample" This reverts commit a97575fd9ff49e50ba1dc8d8154790d8cd86c48d. * Update DNNLibrary * Fix multiple outputs bug * Remove GetKernelRegistry * Revert "Revert "Remove squeezenet_test.cpp since it is almost same with the c++ sample"" This reverts commit 2a0670e9cbf10ea654111ce39e198a4be0ddd838. * Set default memory type of NNAPI EP * Add CPUOutput allocator * Update DNNLibrary for multiple outputs * Fix bug of nhwc->nchw * Remove GetExecutionHandle()
2019-07-02 13:03:29 +00:00
}
TEST(NnapiExecutionProviderTest, TestNoShapeInputModel) {
const ORTCHAR_T* model_file_name = ORT_TSTR("input_with_no_shape_test_graph.onnx");
{ // Create the model with 2 add nodes, the graph has 2 inputs with no shape
onnxruntime::Model model("graph_1", false, DefaultLoggingManager().DefaultLogger());
auto& graph = model.MainGraph();
std::vector<onnxruntime::NodeArg*> inputs;
std::vector<onnxruntime::NodeArg*> outputs;
// FLOAT tensor without shape
ONNX_NAMESPACE::TypeProto float_tensor;
float_tensor.mutable_tensor_type()->set_elem_type(ONNX_NAMESPACE::TensorProto_DataType_FLOAT);
auto& input_arg_1 = graph.GetOrCreateNodeArg("X", &float_tensor);
auto& input_arg_2 = graph.GetOrCreateNodeArg("Y", &float_tensor);
inputs.push_back(&input_arg_1);
inputs.push_back(&input_arg_2);
auto& output_arg = graph.GetOrCreateNodeArg("node_1_out_1", &float_tensor);
outputs.push_back(&output_arg);
graph.AddNode("node_1", "Add", "node 1.", inputs, outputs);
auto& input_arg_3 = graph.GetOrCreateNodeArg("Z", &float_tensor);
inputs.clear();
inputs.push_back(&output_arg);
inputs.push_back(&input_arg_3);
auto& output_arg_2 = graph.GetOrCreateNodeArg("M", &float_tensor);
outputs.clear();
outputs.push_back(&output_arg_2);
graph.AddNode("node_2", "Add", "node 2.", inputs, outputs);
ASSERT_STATUS_OK(graph.Resolve());
ASSERT_STATUS_OK(onnxruntime::Model::Save(model, model_file_name));
}
// test load only
// since we know NNAPI supports Add op, but both Add ops in the graph has no input shape
// verify the entire graph will not be assigned to NNAPI EP
SessionOptions so;
InferenceSessionWrapper session_object{so, GetEnvironment()};
TestModelLoad(model_file_name,
[](const Graph& graph) { ASSERT_EQ(CountAssignedNodes(graph, kNnapiExecutionProvider), 0)
<< "No nodes should have been taken by the NNAPI EP"; });
}
static void RunQDQModelTest(
const GetQDQTestCaseFn& build_test_case,
const char* test_description,
const EPVerificationParams& params = EPVerificationParams()) {
onnxruntime::Model model(test_description, false, DefaultLoggingManager().DefaultLogger());
Graph& graph = model.MainGraph();
ModelTestBuilder helper(graph);
build_test_case(helper);
helper.SetGraphOutputs();
ASSERT_STATUS_OK(model.MainGraph().Resolve());
// Serialize the model to a string.
std::string model_data;
model.ToProto().SerializeToString(&model_data);
#if defined(__ANDROID__)
RunAndVerifyOutputsWithEP(model_data, "NnapiExecutionProviderTest.TestQDQModel",
std::make_unique<NnapiExecutionProvider>(0),
[NNAPI QDQ] AddQDQAdd/Mul, update to NNAPI QDQ handling, update some test settings (#10483) * Squashed commit of the following: commit 12380491a917493401a9bd65c6ed21122263a2df Author: Guoyu Wang <wanggy@outlook.com> Date: Mon Feb 7 12:59:04 2022 -0800 Add qdq mul support commit 9cadda7f2cad19ff9e67ee648c7f04d96dd98561 Merge: 7a32847761 0f5d0a091a Author: Guoyu Wang <wanggy@outlook.com> Date: Mon Feb 7 11:24:47 2022 -0800 Merge remote-tracking branch 'origin/master' into gwang-msft/qdq_mul commit 7a328477612cafe690a5479b1ce60ee9b87bd4c4 Author: Guoyu Wang <wanggy@outlook.com> Date: Mon Feb 7 00:41:30 2022 -0800 move test case to util commit c1a8f0d81e7e75e74dc7e9c45b27ccb77ca82282 Author: Guoyu Wang <wanggy@outlook.com> Date: Fri Feb 4 13:04:26 2022 -0800 update input/output check commit a6f0a0d50466f65d6b222ca7dfe31fe1a13c7113 Author: Guoyu Wang <wanggy@outlook.com> Date: Thu Feb 3 18:37:21 2022 -0800 update quantized io check functions commit 87f4d1dcfeafea1208b03e1ce06fb0b78a956964 Merge: 7849f07109 97b8f6f394 Author: Guoyu Wang <wanggy@outlook.com> Date: Wed Feb 2 17:22:58 2022 -0800 Merge remote-tracking branch 'origin/master' into gwang-msft/qdq_mul commit 7849f07109ddb5a5f82edf27431aded729dd3872 Author: Guoyu Wang <wanggy@outlook.com> Date: Wed Feb 2 17:22:55 2022 -0800 minor update commit 7196cdf4197d3275ba83d9a9bd6c6cbeb859b8a4 Author: Guoyu Wang <wanggy@outlook.com> Date: Wed Feb 2 10:50:10 2022 -0800 init change commit 84c00772a1eab9fb3a4002683e723152bb48c247 Merge: a8c7dce22f 7318361645 Author: Guoyu Wang <wanggy@outlook.com> Date: Tue Feb 1 18:21:17 2022 -0800 Merge remote-tracking branch 'origin/master' into gwang-msft/qdq_mul commit a8c7dce22f089def87be263d65357ca1d4293499 Merge: 55e536c182 ef7b4dc05c Author: Guoyu Wang <wanggy@outlook.com> Date: Tue Feb 1 13:51:04 2022 -0800 Merge remote-tracking branch 'origin/master' into gwang-msft/qdq_mul commit 55e536c182f151cbc360451164f78a548bd3ae71 Author: Guoyu Wang <wanggy@outlook.com> Date: Tue Feb 1 11:44:34 2022 -0800 address cr comments commit d460f5b776f53b2adc6c503fc7f0a120ea9c4775 Author: Guoyu Wang <wanggy@outlook.com> Date: Tue Feb 1 00:33:54 2022 -0800 fix android UT failure commit 52146cf06f5671299af27852fae6c31cf486f391 Author: Guoyu Wang <wanggy@outlook.com> Date: Mon Jan 31 16:01:13 2022 -0800 fix build break commit ec6d07df8bf59caf35d1b8e0d6b46d14b8676e49 Author: Guoyu Wang <wanggy@outlook.com> Date: Mon Jan 31 15:41:52 2022 -0800 minor update to UT commit 8ec8490b4fda73da91036935841792389b010ed8 Author: Guoyu Wang <wanggy@outlook.com> Date: Mon Jan 31 15:01:30 2022 -0800 Add NNAPI support of QDQ Resize * Update qdq add/mul test case, fix build break * Address CR comments * Add QLinearMul support * remove unused params * Address CR comments
2022-02-09 04:44:15 +00:00
helper.feeds_, params);
#else
// test load only
SessionOptions so;
InferenceSessionWrapper session_object{so, GetEnvironment()};
ASSERT_STATUS_OK(session_object.RegisterExecutionProvider(std::make_unique<NnapiExecutionProvider>(0)));
ASSERT_STATUS_OK(session_object.Load(model_data.data(), static_cast<int>(model_data.size())));
ASSERT_STATUS_OK(session_object.Initialize());
if (params.ep_node_assignment == ExpectedEPNodeAssignment::None) {
ASSERT_EQ(CountAssignedNodes(session_object.GetGraph(), kNnapiExecutionProvider), 0)
<< "No node should have been taken by the NNAPI EP";
} else if (params.ep_node_assignment == ExpectedEPNodeAssignment::All) {
ASSERT_EQ(CountAssignedNodes(session_object.GetGraph(), kNnapiExecutionProvider), session_object.GetGraph().NumberOfNodes())
<< "All nodes should have been taken by the NNAPI EP";
} else {
ASSERT_GT(CountAssignedNodes(session_object.GetGraph(), kNnapiExecutionProvider), 0)
<< "Some nodes should have been taken by the NNAPI EP";
}
#endif
}
TEST(NnapiExecutionProviderTest, TestQDQConv) {
RunQDQModelTest(BuildQDQConvTestCase<uint8_t /* InputType */,
uint8_t /* WeightType */,
int32_t /* BiasType */,
uint8_t /* OutputType */>(
{1, 1, 5, 5} /* input_shape */,
{1, 1, 3, 3} /* weights_shape */),
[NNAPI QDQ] AddQDQAdd/Mul, update to NNAPI QDQ handling, update some test settings (#10483) * Squashed commit of the following: commit 12380491a917493401a9bd65c6ed21122263a2df Author: Guoyu Wang <wanggy@outlook.com> Date: Mon Feb 7 12:59:04 2022 -0800 Add qdq mul support commit 9cadda7f2cad19ff9e67ee648c7f04d96dd98561 Merge: 7a32847761 0f5d0a091a Author: Guoyu Wang <wanggy@outlook.com> Date: Mon Feb 7 11:24:47 2022 -0800 Merge remote-tracking branch 'origin/master' into gwang-msft/qdq_mul commit 7a328477612cafe690a5479b1ce60ee9b87bd4c4 Author: Guoyu Wang <wanggy@outlook.com> Date: Mon Feb 7 00:41:30 2022 -0800 move test case to util commit c1a8f0d81e7e75e74dc7e9c45b27ccb77ca82282 Author: Guoyu Wang <wanggy@outlook.com> Date: Fri Feb 4 13:04:26 2022 -0800 update input/output check commit a6f0a0d50466f65d6b222ca7dfe31fe1a13c7113 Author: Guoyu Wang <wanggy@outlook.com> Date: Thu Feb 3 18:37:21 2022 -0800 update quantized io check functions commit 87f4d1dcfeafea1208b03e1ce06fb0b78a956964 Merge: 7849f07109 97b8f6f394 Author: Guoyu Wang <wanggy@outlook.com> Date: Wed Feb 2 17:22:58 2022 -0800 Merge remote-tracking branch 'origin/master' into gwang-msft/qdq_mul commit 7849f07109ddb5a5f82edf27431aded729dd3872 Author: Guoyu Wang <wanggy@outlook.com> Date: Wed Feb 2 17:22:55 2022 -0800 minor update commit 7196cdf4197d3275ba83d9a9bd6c6cbeb859b8a4 Author: Guoyu Wang <wanggy@outlook.com> Date: Wed Feb 2 10:50:10 2022 -0800 init change commit 84c00772a1eab9fb3a4002683e723152bb48c247 Merge: a8c7dce22f 7318361645 Author: Guoyu Wang <wanggy@outlook.com> Date: Tue Feb 1 18:21:17 2022 -0800 Merge remote-tracking branch 'origin/master' into gwang-msft/qdq_mul commit a8c7dce22f089def87be263d65357ca1d4293499 Merge: 55e536c182 ef7b4dc05c Author: Guoyu Wang <wanggy@outlook.com> Date: Tue Feb 1 13:51:04 2022 -0800 Merge remote-tracking branch 'origin/master' into gwang-msft/qdq_mul commit 55e536c182f151cbc360451164f78a548bd3ae71 Author: Guoyu Wang <wanggy@outlook.com> Date: Tue Feb 1 11:44:34 2022 -0800 address cr comments commit d460f5b776f53b2adc6c503fc7f0a120ea9c4775 Author: Guoyu Wang <wanggy@outlook.com> Date: Tue Feb 1 00:33:54 2022 -0800 fix android UT failure commit 52146cf06f5671299af27852fae6c31cf486f391 Author: Guoyu Wang <wanggy@outlook.com> Date: Mon Jan 31 16:01:13 2022 -0800 fix build break commit ec6d07df8bf59caf35d1b8e0d6b46d14b8676e49 Author: Guoyu Wang <wanggy@outlook.com> Date: Mon Jan 31 15:41:52 2022 -0800 minor update to UT commit 8ec8490b4fda73da91036935841792389b010ed8 Author: Guoyu Wang <wanggy@outlook.com> Date: Mon Jan 31 15:01:30 2022 -0800 Add NNAPI support of QDQ Resize * Update qdq add/mul test case, fix build break * Address CR comments * Add QLinearMul support * remove unused params * Address CR comments
2022-02-09 04:44:15 +00:00
"nnapi_qdq_test_graph_conv",
{ExpectedEPNodeAssignment::All});
}
TEST(NnapiExecutionProviderTest, TestQDQResize) {
// NNAPI EP does not support the default setting of Resize Op
// Use bi-linear and asymmetric for NNAPI EP only
// Setting verify_entire_graph_use_ep for this test as false. This is because layout transformation adds
// Transpose (NCHW -> NHWC) nodes. Post tranformation graph looks like this Transpose -> DQ -> Resize -> Q -> Transpose
// NNAPI does not pick the first Transpose as its input is graph/partition input
// See https://github.com/microsoft/onnxruntime/blob/main/onnxruntime/core/providers/nnapi/nnapi_builtin/builders/helper.cc#L305
// onnxruntime::nnapi::IsInternalQuantizationSupported
RunQDQModelTest(BuildQDQResizeTestCase({1, 3, 64, 64} /* input_shape */,
{1, 3, 32, 32} /* sizes_data */,
"linear" /* mode */,
"asymmetric" /* coordinate_transformation_mode */),
[NNAPI QDQ] AddQDQAdd/Mul, update to NNAPI QDQ handling, update some test settings (#10483) * Squashed commit of the following: commit 12380491a917493401a9bd65c6ed21122263a2df Author: Guoyu Wang <wanggy@outlook.com> Date: Mon Feb 7 12:59:04 2022 -0800 Add qdq mul support commit 9cadda7f2cad19ff9e67ee648c7f04d96dd98561 Merge: 7a32847761 0f5d0a091a Author: Guoyu Wang <wanggy@outlook.com> Date: Mon Feb 7 11:24:47 2022 -0800 Merge remote-tracking branch 'origin/master' into gwang-msft/qdq_mul commit 7a328477612cafe690a5479b1ce60ee9b87bd4c4 Author: Guoyu Wang <wanggy@outlook.com> Date: Mon Feb 7 00:41:30 2022 -0800 move test case to util commit c1a8f0d81e7e75e74dc7e9c45b27ccb77ca82282 Author: Guoyu Wang <wanggy@outlook.com> Date: Fri Feb 4 13:04:26 2022 -0800 update input/output check commit a6f0a0d50466f65d6b222ca7dfe31fe1a13c7113 Author: Guoyu Wang <wanggy@outlook.com> Date: Thu Feb 3 18:37:21 2022 -0800 update quantized io check functions commit 87f4d1dcfeafea1208b03e1ce06fb0b78a956964 Merge: 7849f07109 97b8f6f394 Author: Guoyu Wang <wanggy@outlook.com> Date: Wed Feb 2 17:22:58 2022 -0800 Merge remote-tracking branch 'origin/master' into gwang-msft/qdq_mul commit 7849f07109ddb5a5f82edf27431aded729dd3872 Author: Guoyu Wang <wanggy@outlook.com> Date: Wed Feb 2 17:22:55 2022 -0800 minor update commit 7196cdf4197d3275ba83d9a9bd6c6cbeb859b8a4 Author: Guoyu Wang <wanggy@outlook.com> Date: Wed Feb 2 10:50:10 2022 -0800 init change commit 84c00772a1eab9fb3a4002683e723152bb48c247 Merge: a8c7dce22f 7318361645 Author: Guoyu Wang <wanggy@outlook.com> Date: Tue Feb 1 18:21:17 2022 -0800 Merge remote-tracking branch 'origin/master' into gwang-msft/qdq_mul commit a8c7dce22f089def87be263d65357ca1d4293499 Merge: 55e536c182 ef7b4dc05c Author: Guoyu Wang <wanggy@outlook.com> Date: Tue Feb 1 13:51:04 2022 -0800 Merge remote-tracking branch 'origin/master' into gwang-msft/qdq_mul commit 55e536c182f151cbc360451164f78a548bd3ae71 Author: Guoyu Wang <wanggy@outlook.com> Date: Tue Feb 1 11:44:34 2022 -0800 address cr comments commit d460f5b776f53b2adc6c503fc7f0a120ea9c4775 Author: Guoyu Wang <wanggy@outlook.com> Date: Tue Feb 1 00:33:54 2022 -0800 fix android UT failure commit 52146cf06f5671299af27852fae6c31cf486f391 Author: Guoyu Wang <wanggy@outlook.com> Date: Mon Jan 31 16:01:13 2022 -0800 fix build break commit ec6d07df8bf59caf35d1b8e0d6b46d14b8676e49 Author: Guoyu Wang <wanggy@outlook.com> Date: Mon Jan 31 15:41:52 2022 -0800 minor update to UT commit 8ec8490b4fda73da91036935841792389b010ed8 Author: Guoyu Wang <wanggy@outlook.com> Date: Mon Jan 31 15:01:30 2022 -0800 Add NNAPI support of QDQ Resize * Update qdq add/mul test case, fix build break * Address CR comments * Add QLinearMul support * remove unused params * Address CR comments
2022-02-09 04:44:15 +00:00
"nnapi_qdq_test_graph_resize",
{ExpectedEPNodeAssignment::Some});
}
TEST(NnapiExecutionProviderTest, TestQDQResize_UnsupportedDefaultSetting) {
RunQDQModelTest(BuildQDQResizeTestCase({1, 3, 64, 64} /* input_shape */,
{1, 3, 32, 32} /* sizes_data */),
"nnapi_qdq_test_graph_resize_unsupported",
{ExpectedEPNodeAssignment::None});
}
TEST(NnapiExecutionProviderTest, TestQDQAveragePool) {
[NNAPI QDQ] AddQDQAdd/Mul, update to NNAPI QDQ handling, update some test settings (#10483) * Squashed commit of the following: commit 12380491a917493401a9bd65c6ed21122263a2df Author: Guoyu Wang <wanggy@outlook.com> Date: Mon Feb 7 12:59:04 2022 -0800 Add qdq mul support commit 9cadda7f2cad19ff9e67ee648c7f04d96dd98561 Merge: 7a32847761 0f5d0a091a Author: Guoyu Wang <wanggy@outlook.com> Date: Mon Feb 7 11:24:47 2022 -0800 Merge remote-tracking branch 'origin/master' into gwang-msft/qdq_mul commit 7a328477612cafe690a5479b1ce60ee9b87bd4c4 Author: Guoyu Wang <wanggy@outlook.com> Date: Mon Feb 7 00:41:30 2022 -0800 move test case to util commit c1a8f0d81e7e75e74dc7e9c45b27ccb77ca82282 Author: Guoyu Wang <wanggy@outlook.com> Date: Fri Feb 4 13:04:26 2022 -0800 update input/output check commit a6f0a0d50466f65d6b222ca7dfe31fe1a13c7113 Author: Guoyu Wang <wanggy@outlook.com> Date: Thu Feb 3 18:37:21 2022 -0800 update quantized io check functions commit 87f4d1dcfeafea1208b03e1ce06fb0b78a956964 Merge: 7849f07109 97b8f6f394 Author: Guoyu Wang <wanggy@outlook.com> Date: Wed Feb 2 17:22:58 2022 -0800 Merge remote-tracking branch 'origin/master' into gwang-msft/qdq_mul commit 7849f07109ddb5a5f82edf27431aded729dd3872 Author: Guoyu Wang <wanggy@outlook.com> Date: Wed Feb 2 17:22:55 2022 -0800 minor update commit 7196cdf4197d3275ba83d9a9bd6c6cbeb859b8a4 Author: Guoyu Wang <wanggy@outlook.com> Date: Wed Feb 2 10:50:10 2022 -0800 init change commit 84c00772a1eab9fb3a4002683e723152bb48c247 Merge: a8c7dce22f 7318361645 Author: Guoyu Wang <wanggy@outlook.com> Date: Tue Feb 1 18:21:17 2022 -0800 Merge remote-tracking branch 'origin/master' into gwang-msft/qdq_mul commit a8c7dce22f089def87be263d65357ca1d4293499 Merge: 55e536c182 ef7b4dc05c Author: Guoyu Wang <wanggy@outlook.com> Date: Tue Feb 1 13:51:04 2022 -0800 Merge remote-tracking branch 'origin/master' into gwang-msft/qdq_mul commit 55e536c182f151cbc360451164f78a548bd3ae71 Author: Guoyu Wang <wanggy@outlook.com> Date: Tue Feb 1 11:44:34 2022 -0800 address cr comments commit d460f5b776f53b2adc6c503fc7f0a120ea9c4775 Author: Guoyu Wang <wanggy@outlook.com> Date: Tue Feb 1 00:33:54 2022 -0800 fix android UT failure commit 52146cf06f5671299af27852fae6c31cf486f391 Author: Guoyu Wang <wanggy@outlook.com> Date: Mon Jan 31 16:01:13 2022 -0800 fix build break commit ec6d07df8bf59caf35d1b8e0d6b46d14b8676e49 Author: Guoyu Wang <wanggy@outlook.com> Date: Mon Jan 31 15:41:52 2022 -0800 minor update to UT commit 8ec8490b4fda73da91036935841792389b010ed8 Author: Guoyu Wang <wanggy@outlook.com> Date: Mon Jan 31 15:01:30 2022 -0800 Add NNAPI support of QDQ Resize * Update qdq add/mul test case, fix build break * Address CR comments * Add QLinearMul support * remove unused params * Address CR comments
2022-02-09 04:44:15 +00:00
// NNAPI use different rounding, which may cause ~1% difference in the result
RunQDQModelTest(BuildQDQAveragePoolTestCase<uint8_t /* InputType */,
uint8_t /* OutputType */>(
{1, 3, 32, 32} /* input_shape */),
[NNAPI QDQ] AddQDQAdd/Mul, update to NNAPI QDQ handling, update some test settings (#10483) * Squashed commit of the following: commit 12380491a917493401a9bd65c6ed21122263a2df Author: Guoyu Wang <wanggy@outlook.com> Date: Mon Feb 7 12:59:04 2022 -0800 Add qdq mul support commit 9cadda7f2cad19ff9e67ee648c7f04d96dd98561 Merge: 7a32847761 0f5d0a091a Author: Guoyu Wang <wanggy@outlook.com> Date: Mon Feb 7 11:24:47 2022 -0800 Merge remote-tracking branch 'origin/master' into gwang-msft/qdq_mul commit 7a328477612cafe690a5479b1ce60ee9b87bd4c4 Author: Guoyu Wang <wanggy@outlook.com> Date: Mon Feb 7 00:41:30 2022 -0800 move test case to util commit c1a8f0d81e7e75e74dc7e9c45b27ccb77ca82282 Author: Guoyu Wang <wanggy@outlook.com> Date: Fri Feb 4 13:04:26 2022 -0800 update input/output check commit a6f0a0d50466f65d6b222ca7dfe31fe1a13c7113 Author: Guoyu Wang <wanggy@outlook.com> Date: Thu Feb 3 18:37:21 2022 -0800 update quantized io check functions commit 87f4d1dcfeafea1208b03e1ce06fb0b78a956964 Merge: 7849f07109 97b8f6f394 Author: Guoyu Wang <wanggy@outlook.com> Date: Wed Feb 2 17:22:58 2022 -0800 Merge remote-tracking branch 'origin/master' into gwang-msft/qdq_mul commit 7849f07109ddb5a5f82edf27431aded729dd3872 Author: Guoyu Wang <wanggy@outlook.com> Date: Wed Feb 2 17:22:55 2022 -0800 minor update commit 7196cdf4197d3275ba83d9a9bd6c6cbeb859b8a4 Author: Guoyu Wang <wanggy@outlook.com> Date: Wed Feb 2 10:50:10 2022 -0800 init change commit 84c00772a1eab9fb3a4002683e723152bb48c247 Merge: a8c7dce22f 7318361645 Author: Guoyu Wang <wanggy@outlook.com> Date: Tue Feb 1 18:21:17 2022 -0800 Merge remote-tracking branch 'origin/master' into gwang-msft/qdq_mul commit a8c7dce22f089def87be263d65357ca1d4293499 Merge: 55e536c182 ef7b4dc05c Author: Guoyu Wang <wanggy@outlook.com> Date: Tue Feb 1 13:51:04 2022 -0800 Merge remote-tracking branch 'origin/master' into gwang-msft/qdq_mul commit 55e536c182f151cbc360451164f78a548bd3ae71 Author: Guoyu Wang <wanggy@outlook.com> Date: Tue Feb 1 11:44:34 2022 -0800 address cr comments commit d460f5b776f53b2adc6c503fc7f0a120ea9c4775 Author: Guoyu Wang <wanggy@outlook.com> Date: Tue Feb 1 00:33:54 2022 -0800 fix android UT failure commit 52146cf06f5671299af27852fae6c31cf486f391 Author: Guoyu Wang <wanggy@outlook.com> Date: Mon Jan 31 16:01:13 2022 -0800 fix build break commit ec6d07df8bf59caf35d1b8e0d6b46d14b8676e49 Author: Guoyu Wang <wanggy@outlook.com> Date: Mon Jan 31 15:41:52 2022 -0800 minor update to UT commit 8ec8490b4fda73da91036935841792389b010ed8 Author: Guoyu Wang <wanggy@outlook.com> Date: Mon Jan 31 15:01:30 2022 -0800 Add NNAPI support of QDQ Resize * Update qdq add/mul test case, fix build break * Address CR comments * Add QLinearMul support * remove unused params * Address CR comments
2022-02-09 04:44:15 +00:00
"nnapi_qdq_test_graph_averagepool",
{
ExpectedEPNodeAssignment::All,
[NNAPI QDQ] AddQDQAdd/Mul, update to NNAPI QDQ handling, update some test settings (#10483) * Squashed commit of the following: commit 12380491a917493401a9bd65c6ed21122263a2df Author: Guoyu Wang <wanggy@outlook.com> Date: Mon Feb 7 12:59:04 2022 -0800 Add qdq mul support commit 9cadda7f2cad19ff9e67ee648c7f04d96dd98561 Merge: 7a32847761 0f5d0a091a Author: Guoyu Wang <wanggy@outlook.com> Date: Mon Feb 7 11:24:47 2022 -0800 Merge remote-tracking branch 'origin/master' into gwang-msft/qdq_mul commit 7a328477612cafe690a5479b1ce60ee9b87bd4c4 Author: Guoyu Wang <wanggy@outlook.com> Date: Mon Feb 7 00:41:30 2022 -0800 move test case to util commit c1a8f0d81e7e75e74dc7e9c45b27ccb77ca82282 Author: Guoyu Wang <wanggy@outlook.com> Date: Fri Feb 4 13:04:26 2022 -0800 update input/output check commit a6f0a0d50466f65d6b222ca7dfe31fe1a13c7113 Author: Guoyu Wang <wanggy@outlook.com> Date: Thu Feb 3 18:37:21 2022 -0800 update quantized io check functions commit 87f4d1dcfeafea1208b03e1ce06fb0b78a956964 Merge: 7849f07109 97b8f6f394 Author: Guoyu Wang <wanggy@outlook.com> Date: Wed Feb 2 17:22:58 2022 -0800 Merge remote-tracking branch 'origin/master' into gwang-msft/qdq_mul commit 7849f07109ddb5a5f82edf27431aded729dd3872 Author: Guoyu Wang <wanggy@outlook.com> Date: Wed Feb 2 17:22:55 2022 -0800 minor update commit 7196cdf4197d3275ba83d9a9bd6c6cbeb859b8a4 Author: Guoyu Wang <wanggy@outlook.com> Date: Wed Feb 2 10:50:10 2022 -0800 init change commit 84c00772a1eab9fb3a4002683e723152bb48c247 Merge: a8c7dce22f 7318361645 Author: Guoyu Wang <wanggy@outlook.com> Date: Tue Feb 1 18:21:17 2022 -0800 Merge remote-tracking branch 'origin/master' into gwang-msft/qdq_mul commit a8c7dce22f089def87be263d65357ca1d4293499 Merge: 55e536c182 ef7b4dc05c Author: Guoyu Wang <wanggy@outlook.com> Date: Tue Feb 1 13:51:04 2022 -0800 Merge remote-tracking branch 'origin/master' into gwang-msft/qdq_mul commit 55e536c182f151cbc360451164f78a548bd3ae71 Author: Guoyu Wang <wanggy@outlook.com> Date: Tue Feb 1 11:44:34 2022 -0800 address cr comments commit d460f5b776f53b2adc6c503fc7f0a120ea9c4775 Author: Guoyu Wang <wanggy@outlook.com> Date: Tue Feb 1 00:33:54 2022 -0800 fix android UT failure commit 52146cf06f5671299af27852fae6c31cf486f391 Author: Guoyu Wang <wanggy@outlook.com> Date: Mon Jan 31 16:01:13 2022 -0800 fix build break commit ec6d07df8bf59caf35d1b8e0d6b46d14b8676e49 Author: Guoyu Wang <wanggy@outlook.com> Date: Mon Jan 31 15:41:52 2022 -0800 minor update to UT commit 8ec8490b4fda73da91036935841792389b010ed8 Author: Guoyu Wang <wanggy@outlook.com> Date: Mon Jan 31 15:01:30 2022 -0800 Add NNAPI support of QDQ Resize * Update qdq add/mul test case, fix build break * Address CR comments * Add QLinearMul support * remove unused params * Address CR comments
2022-02-09 04:44:15 +00:00
1e-2f /* fp32_abs_err */,
});
}
TEST(NnapiExecutionProviderTest, TestQDQAdd) {
RunQDQModelTest(BuildBinaryOpTestCase<uint8_t /* Input1Type */,
uint8_t /* Input2Type */,
uint8_t /* OutputType */>(
{1, 23, 13, 13} /* input_shape */,
"Add" /* op_type */),
"nnapi_qdq_test_graph_add",
{ExpectedEPNodeAssignment::All});
[NNAPI QDQ] AddQDQAdd/Mul, update to NNAPI QDQ handling, update some test settings (#10483) * Squashed commit of the following: commit 12380491a917493401a9bd65c6ed21122263a2df Author: Guoyu Wang <wanggy@outlook.com> Date: Mon Feb 7 12:59:04 2022 -0800 Add qdq mul support commit 9cadda7f2cad19ff9e67ee648c7f04d96dd98561 Merge: 7a32847761 0f5d0a091a Author: Guoyu Wang <wanggy@outlook.com> Date: Mon Feb 7 11:24:47 2022 -0800 Merge remote-tracking branch 'origin/master' into gwang-msft/qdq_mul commit 7a328477612cafe690a5479b1ce60ee9b87bd4c4 Author: Guoyu Wang <wanggy@outlook.com> Date: Mon Feb 7 00:41:30 2022 -0800 move test case to util commit c1a8f0d81e7e75e74dc7e9c45b27ccb77ca82282 Author: Guoyu Wang <wanggy@outlook.com> Date: Fri Feb 4 13:04:26 2022 -0800 update input/output check commit a6f0a0d50466f65d6b222ca7dfe31fe1a13c7113 Author: Guoyu Wang <wanggy@outlook.com> Date: Thu Feb 3 18:37:21 2022 -0800 update quantized io check functions commit 87f4d1dcfeafea1208b03e1ce06fb0b78a956964 Merge: 7849f07109 97b8f6f394 Author: Guoyu Wang <wanggy@outlook.com> Date: Wed Feb 2 17:22:58 2022 -0800 Merge remote-tracking branch 'origin/master' into gwang-msft/qdq_mul commit 7849f07109ddb5a5f82edf27431aded729dd3872 Author: Guoyu Wang <wanggy@outlook.com> Date: Wed Feb 2 17:22:55 2022 -0800 minor update commit 7196cdf4197d3275ba83d9a9bd6c6cbeb859b8a4 Author: Guoyu Wang <wanggy@outlook.com> Date: Wed Feb 2 10:50:10 2022 -0800 init change commit 84c00772a1eab9fb3a4002683e723152bb48c247 Merge: a8c7dce22f 7318361645 Author: Guoyu Wang <wanggy@outlook.com> Date: Tue Feb 1 18:21:17 2022 -0800 Merge remote-tracking branch 'origin/master' into gwang-msft/qdq_mul commit a8c7dce22f089def87be263d65357ca1d4293499 Merge: 55e536c182 ef7b4dc05c Author: Guoyu Wang <wanggy@outlook.com> Date: Tue Feb 1 13:51:04 2022 -0800 Merge remote-tracking branch 'origin/master' into gwang-msft/qdq_mul commit 55e536c182f151cbc360451164f78a548bd3ae71 Author: Guoyu Wang <wanggy@outlook.com> Date: Tue Feb 1 11:44:34 2022 -0800 address cr comments commit d460f5b776f53b2adc6c503fc7f0a120ea9c4775 Author: Guoyu Wang <wanggy@outlook.com> Date: Tue Feb 1 00:33:54 2022 -0800 fix android UT failure commit 52146cf06f5671299af27852fae6c31cf486f391 Author: Guoyu Wang <wanggy@outlook.com> Date: Mon Jan 31 16:01:13 2022 -0800 fix build break commit ec6d07df8bf59caf35d1b8e0d6b46d14b8676e49 Author: Guoyu Wang <wanggy@outlook.com> Date: Mon Jan 31 15:41:52 2022 -0800 minor update to UT commit 8ec8490b4fda73da91036935841792389b010ed8 Author: Guoyu Wang <wanggy@outlook.com> Date: Mon Jan 31 15:01:30 2022 -0800 Add NNAPI support of QDQ Resize * Update qdq add/mul test case, fix build break * Address CR comments * Add QLinearMul support * remove unused params * Address CR comments
2022-02-09 04:44:15 +00:00
}
TEST(NnapiExecutionProviderTest, TestQDQMul) {
// NNAPI use different rounding, which may cause ~1% difference in the result
RunQDQModelTest(BuildBinaryOpTestCase<uint8_t /* Input1Type */,
uint8_t /* Input2Type */,
uint8_t /* OutputType */>(
{1, 23, 13, 13} /* input_shape */,
"Mul" /* op_type */),
"nnapi_qdq_test_graph_mul",
{
ExpectedEPNodeAssignment::All,
1e-2f /* fp32_abs_err */
[NNAPI QDQ] AddQDQAdd/Mul, update to NNAPI QDQ handling, update some test settings (#10483) * Squashed commit of the following: commit 12380491a917493401a9bd65c6ed21122263a2df Author: Guoyu Wang <wanggy@outlook.com> Date: Mon Feb 7 12:59:04 2022 -0800 Add qdq mul support commit 9cadda7f2cad19ff9e67ee648c7f04d96dd98561 Merge: 7a32847761 0f5d0a091a Author: Guoyu Wang <wanggy@outlook.com> Date: Mon Feb 7 11:24:47 2022 -0800 Merge remote-tracking branch 'origin/master' into gwang-msft/qdq_mul commit 7a328477612cafe690a5479b1ce60ee9b87bd4c4 Author: Guoyu Wang <wanggy@outlook.com> Date: Mon Feb 7 00:41:30 2022 -0800 move test case to util commit c1a8f0d81e7e75e74dc7e9c45b27ccb77ca82282 Author: Guoyu Wang <wanggy@outlook.com> Date: Fri Feb 4 13:04:26 2022 -0800 update input/output check commit a6f0a0d50466f65d6b222ca7dfe31fe1a13c7113 Author: Guoyu Wang <wanggy@outlook.com> Date: Thu Feb 3 18:37:21 2022 -0800 update quantized io check functions commit 87f4d1dcfeafea1208b03e1ce06fb0b78a956964 Merge: 7849f07109 97b8f6f394 Author: Guoyu Wang <wanggy@outlook.com> Date: Wed Feb 2 17:22:58 2022 -0800 Merge remote-tracking branch 'origin/master' into gwang-msft/qdq_mul commit 7849f07109ddb5a5f82edf27431aded729dd3872 Author: Guoyu Wang <wanggy@outlook.com> Date: Wed Feb 2 17:22:55 2022 -0800 minor update commit 7196cdf4197d3275ba83d9a9bd6c6cbeb859b8a4 Author: Guoyu Wang <wanggy@outlook.com> Date: Wed Feb 2 10:50:10 2022 -0800 init change commit 84c00772a1eab9fb3a4002683e723152bb48c247 Merge: a8c7dce22f 7318361645 Author: Guoyu Wang <wanggy@outlook.com> Date: Tue Feb 1 18:21:17 2022 -0800 Merge remote-tracking branch 'origin/master' into gwang-msft/qdq_mul commit a8c7dce22f089def87be263d65357ca1d4293499 Merge: 55e536c182 ef7b4dc05c Author: Guoyu Wang <wanggy@outlook.com> Date: Tue Feb 1 13:51:04 2022 -0800 Merge remote-tracking branch 'origin/master' into gwang-msft/qdq_mul commit 55e536c182f151cbc360451164f78a548bd3ae71 Author: Guoyu Wang <wanggy@outlook.com> Date: Tue Feb 1 11:44:34 2022 -0800 address cr comments commit d460f5b776f53b2adc6c503fc7f0a120ea9c4775 Author: Guoyu Wang <wanggy@outlook.com> Date: Tue Feb 1 00:33:54 2022 -0800 fix android UT failure commit 52146cf06f5671299af27852fae6c31cf486f391 Author: Guoyu Wang <wanggy@outlook.com> Date: Mon Jan 31 16:01:13 2022 -0800 fix build break commit ec6d07df8bf59caf35d1b8e0d6b46d14b8676e49 Author: Guoyu Wang <wanggy@outlook.com> Date: Mon Jan 31 15:41:52 2022 -0800 minor update to UT commit 8ec8490b4fda73da91036935841792389b010ed8 Author: Guoyu Wang <wanggy@outlook.com> Date: Mon Jan 31 15:01:30 2022 -0800 Add NNAPI support of QDQ Resize * Update qdq add/mul test case, fix build break * Address CR comments * Add QLinearMul support * remove unused params * Address CR comments
2022-02-09 04:44:15 +00:00
});
}
[NNAPI QDQ] Add QDQTranspose op support (#10495) * Squashed commit of the following: commit 12380491a917493401a9bd65c6ed21122263a2df Author: Guoyu Wang <wanggy@outlook.com> Date: Mon Feb 7 12:59:04 2022 -0800 Add qdq mul support commit 9cadda7f2cad19ff9e67ee648c7f04d96dd98561 Merge: 7a32847761 0f5d0a091a Author: Guoyu Wang <wanggy@outlook.com> Date: Mon Feb 7 11:24:47 2022 -0800 Merge remote-tracking branch 'origin/master' into gwang-msft/qdq_mul commit 7a328477612cafe690a5479b1ce60ee9b87bd4c4 Author: Guoyu Wang <wanggy@outlook.com> Date: Mon Feb 7 00:41:30 2022 -0800 move test case to util commit c1a8f0d81e7e75e74dc7e9c45b27ccb77ca82282 Author: Guoyu Wang <wanggy@outlook.com> Date: Fri Feb 4 13:04:26 2022 -0800 update input/output check commit a6f0a0d50466f65d6b222ca7dfe31fe1a13c7113 Author: Guoyu Wang <wanggy@outlook.com> Date: Thu Feb 3 18:37:21 2022 -0800 update quantized io check functions commit 87f4d1dcfeafea1208b03e1ce06fb0b78a956964 Merge: 7849f07109 97b8f6f394 Author: Guoyu Wang <wanggy@outlook.com> Date: Wed Feb 2 17:22:58 2022 -0800 Merge remote-tracking branch 'origin/master' into gwang-msft/qdq_mul commit 7849f07109ddb5a5f82edf27431aded729dd3872 Author: Guoyu Wang <wanggy@outlook.com> Date: Wed Feb 2 17:22:55 2022 -0800 minor update commit 7196cdf4197d3275ba83d9a9bd6c6cbeb859b8a4 Author: Guoyu Wang <wanggy@outlook.com> Date: Wed Feb 2 10:50:10 2022 -0800 init change commit 84c00772a1eab9fb3a4002683e723152bb48c247 Merge: a8c7dce22f 7318361645 Author: Guoyu Wang <wanggy@outlook.com> Date: Tue Feb 1 18:21:17 2022 -0800 Merge remote-tracking branch 'origin/master' into gwang-msft/qdq_mul commit a8c7dce22f089def87be263d65357ca1d4293499 Merge: 55e536c182 ef7b4dc05c Author: Guoyu Wang <wanggy@outlook.com> Date: Tue Feb 1 13:51:04 2022 -0800 Merge remote-tracking branch 'origin/master' into gwang-msft/qdq_mul commit 55e536c182f151cbc360451164f78a548bd3ae71 Author: Guoyu Wang <wanggy@outlook.com> Date: Tue Feb 1 11:44:34 2022 -0800 address cr comments commit d460f5b776f53b2adc6c503fc7f0a120ea9c4775 Author: Guoyu Wang <wanggy@outlook.com> Date: Tue Feb 1 00:33:54 2022 -0800 fix android UT failure commit 52146cf06f5671299af27852fae6c31cf486f391 Author: Guoyu Wang <wanggy@outlook.com> Date: Mon Jan 31 16:01:13 2022 -0800 fix build break commit ec6d07df8bf59caf35d1b8e0d6b46d14b8676e49 Author: Guoyu Wang <wanggy@outlook.com> Date: Mon Jan 31 15:41:52 2022 -0800 minor update to UT commit 8ec8490b4fda73da91036935841792389b010ed8 Author: Guoyu Wang <wanggy@outlook.com> Date: Mon Jan 31 15:01:30 2022 -0800 Add NNAPI support of QDQ Resize * Update qdq add/mul test case, fix build break * Address CR comments * Add QLinearMul support * remove unused params * Address CR comments * wip * save * minor fix * fix * fix build * address pr comments * fix wrong ut tests * address comments * minor update * fix addinitializersskip Co-authored-by: Guoyu Wang <wanggy@outlook.com> Co-authored-by: rachguo <rachguo@rachguos-Mini.attlocal.net>
2022-02-11 18:42:08 +00:00
TEST(NnapiExecutionProviderTest, TestQDQTranspose) {
RunQDQModelTest(BuildQDQTransposeTestCase<uint8_t /* InputType */,
uint8_t /* OutputType */>(
{1, 3, 32, 32} /* input_shape */,
{0, 3, 1, 2} /* perms */),
"nnapi_qdq_test_graph_transpose",
{ExpectedEPNodeAssignment::All});
[NNAPI QDQ] Add QDQTranspose op support (#10495) * Squashed commit of the following: commit 12380491a917493401a9bd65c6ed21122263a2df Author: Guoyu Wang <wanggy@outlook.com> Date: Mon Feb 7 12:59:04 2022 -0800 Add qdq mul support commit 9cadda7f2cad19ff9e67ee648c7f04d96dd98561 Merge: 7a32847761 0f5d0a091a Author: Guoyu Wang <wanggy@outlook.com> Date: Mon Feb 7 11:24:47 2022 -0800 Merge remote-tracking branch 'origin/master' into gwang-msft/qdq_mul commit 7a328477612cafe690a5479b1ce60ee9b87bd4c4 Author: Guoyu Wang <wanggy@outlook.com> Date: Mon Feb 7 00:41:30 2022 -0800 move test case to util commit c1a8f0d81e7e75e74dc7e9c45b27ccb77ca82282 Author: Guoyu Wang <wanggy@outlook.com> Date: Fri Feb 4 13:04:26 2022 -0800 update input/output check commit a6f0a0d50466f65d6b222ca7dfe31fe1a13c7113 Author: Guoyu Wang <wanggy@outlook.com> Date: Thu Feb 3 18:37:21 2022 -0800 update quantized io check functions commit 87f4d1dcfeafea1208b03e1ce06fb0b78a956964 Merge: 7849f07109 97b8f6f394 Author: Guoyu Wang <wanggy@outlook.com> Date: Wed Feb 2 17:22:58 2022 -0800 Merge remote-tracking branch 'origin/master' into gwang-msft/qdq_mul commit 7849f07109ddb5a5f82edf27431aded729dd3872 Author: Guoyu Wang <wanggy@outlook.com> Date: Wed Feb 2 17:22:55 2022 -0800 minor update commit 7196cdf4197d3275ba83d9a9bd6c6cbeb859b8a4 Author: Guoyu Wang <wanggy@outlook.com> Date: Wed Feb 2 10:50:10 2022 -0800 init change commit 84c00772a1eab9fb3a4002683e723152bb48c247 Merge: a8c7dce22f 7318361645 Author: Guoyu Wang <wanggy@outlook.com> Date: Tue Feb 1 18:21:17 2022 -0800 Merge remote-tracking branch 'origin/master' into gwang-msft/qdq_mul commit a8c7dce22f089def87be263d65357ca1d4293499 Merge: 55e536c182 ef7b4dc05c Author: Guoyu Wang <wanggy@outlook.com> Date: Tue Feb 1 13:51:04 2022 -0800 Merge remote-tracking branch 'origin/master' into gwang-msft/qdq_mul commit 55e536c182f151cbc360451164f78a548bd3ae71 Author: Guoyu Wang <wanggy@outlook.com> Date: Tue Feb 1 11:44:34 2022 -0800 address cr comments commit d460f5b776f53b2adc6c503fc7f0a120ea9c4775 Author: Guoyu Wang <wanggy@outlook.com> Date: Tue Feb 1 00:33:54 2022 -0800 fix android UT failure commit 52146cf06f5671299af27852fae6c31cf486f391 Author: Guoyu Wang <wanggy@outlook.com> Date: Mon Jan 31 16:01:13 2022 -0800 fix build break commit ec6d07df8bf59caf35d1b8e0d6b46d14b8676e49 Author: Guoyu Wang <wanggy@outlook.com> Date: Mon Jan 31 15:41:52 2022 -0800 minor update to UT commit 8ec8490b4fda73da91036935841792389b010ed8 Author: Guoyu Wang <wanggy@outlook.com> Date: Mon Jan 31 15:01:30 2022 -0800 Add NNAPI support of QDQ Resize * Update qdq add/mul test case, fix build break * Address CR comments * Add QLinearMul support * remove unused params * Address CR comments * wip * save * minor fix * fix * fix build * address pr comments * fix wrong ut tests * address comments * minor update * fix addinitializersskip Co-authored-by: Guoyu Wang <wanggy@outlook.com> Co-authored-by: rachguo <rachguo@rachguos-Mini.attlocal.net>
2022-02-11 18:42:08 +00:00
}
TEST(NnapiExecutionProviderTest, TestQDQReshape) {
RunQDQModelTest(BuildQDQReshapeTestCase({1, 3, 64, 64} /* input_shape */,
{1, 64, 64, 3} /* reshape_shape */),
"nnapi_qdq_test_graph_reshape",
{ExpectedEPNodeAssignment::All});
}
TEST(NnapiExecutionProviderTest, TestQDQSoftMax) {
RunQDQModelTest(BuildQDQSoftMaxTestCase<uint8_t, uint8_t>(
{1, 32} /* input_shape */,
static_cast<int64_t>(1) /* axis */,
1.f / 256 /* output_scales */,
0 /* output_zp */),
"nnapi_qdq_test_graph_softmax",
{ExpectedEPNodeAssignment::All});
}
// This is to verify when Nnapi required scale and zero point are not satisfied
// the model can work as expected. (no nodes should be handled by Nnapi)
TEST(NnapiExecutionProviderTest, TestQDQSoftMax_UnsupportedOutputScaleAndZp) {
RunQDQModelTest(BuildQDQSoftMaxTestCase<uint8_t, uint8_t>(
{1, 32} /* input_shape */,
static_cast<int64_t>(1) /* axis */,
0.002f /* output_scales */,
1 /* output_zp */),
"nnapi_qdq_test_graph_softmax_unsupported",
{ExpectedEPNodeAssignment::None});
}
TEST(NnapiExecutionProviderTest, TestQDQConcat) {
RunQDQModelTest(BuildQDQConcatTestCase(
{
{1, 6, 36},
{1, 6, 8},
{1, 6, 2},
} /* input_shapes */,
2 /* axis */),
"nnapi_qdq_test_graph_concat",
{ExpectedEPNodeAssignment::All});
}
#if defined(__ANDROID__)
TEST(NnapiExecutionProviderTest, TestQDQConcat_UnsupportedInputScalesAndZp) {
// This is to verify all the inputs have the same scale and zp as input 0 for API 28-
// Currently, this test can only be run locally with a android emulator with API < 29
// See https://developer.android.com/studio/run/emulator-commandline for some info on
// starting a testing android emulator in command line. (Run an android build with emulator started)
// TODO: consider to configure this and enable it to run in Android CI.
const auto* nnapi = NnApiImplementation();
if (nnapi->nnapi_runtime_feature_level < ANEURALNETWORKS_FEATURE_LEVEL_3) {
RunQDQModelTest(BuildQDQConcatTestCaseUnsupportedInputScaleZp(),
"nnapi_qdq_test_graph_concat_unsupported",
{ExpectedEPNodeAssignment::None});
}
}
#endif
TEST(NnapiExecutionProviderTest, TestQDQGemm) {
RunQDQModelTest(BuildQDQGemmTestCase<uint8_t, uint8_t, uint8_t>(
{2, 2} /* input_shape1 */,
{2, 2} /* input_shape2 */,
true /* has_bias */,
1 /* transB */),
"nnapi_qdq_test_graph_gemm_1",
{ExpectedEPNodeAssignment::All});
}
TEST(NnapiExecutionProviderTest, TestQDQGemm_NoTransB) {
RunQDQModelTest(BuildQDQGemmTestCase<uint8_t, uint8_t, uint8_t>(
{2, 2} /* input_shape1 */,
{2, 2} /* input_shape2 */,
true /* has_bias */,
0 /* transB */),
"nnapi_qdq_test_graph_gemm_2",
{ExpectedEPNodeAssignment::All});
}
TEST(NnapiExecutionProviderTest, TestQDQGemm_NoBias) {
RunQDQModelTest(BuildQDQGemmTestCase<uint8_t, uint8_t, uint8_t>(
{2, 2} /* input_shape1 */,
{2, 2} /* input_shape2 */,
false /* has_bias */,
1 /* transB */),
"nnapi_qdq_test_graph_gemm_3",
{ExpectedEPNodeAssignment::All});
}
TEST(NnapiExecutionProviderTest, TestQDQMatMul) {
RunQDQModelTest(BuildQDQMatMulTestCase(
{2, 2} /* input_shape1 */,
{2, 2} /* input_shape2 */),
"nnapi_qdq_test_graph_matmul",
{ExpectedEPNodeAssignment::All});
}
#endif // !(ORT_MINIMAL_BUILD)
TEST(NnapiExecutionProviderTest, NNAPIFlagsTest) {
uint32_t nnapi_flags = NNAPI_FLAG_USE_NONE;
nnapi_flags |= NNAPI_FLAG_USE_FP16;
onnxruntime::NnapiExecutionProvider nnapi_ep(nnapi_flags);
const auto flags = nnapi_ep.GetNNAPIFlags();
ASSERT_TRUE(flags & NNAPI_FLAG_USE_FP16);
ASSERT_FALSE(flags & NNAPI_FLAG_USE_NCHW);
}
TEST(NnapiExecutionProviderTest, TestOrtFormatModel) {
// mnist model that has only had basic optimizations applied. nnapi should be able to take at least some of the nodes
Update kernel matching logic: decouple from op schemas and remove kernel def hashes (#12791) # Motivation Currently, ORT minimal builds use kernel def hashes to map from nodes to kernels to execute when loading the model. As the kernel def hashes must be known ahead of time, this works for statically registered kernels. This works well for the CPU EP. For this approach to work, the kernel def hashes must also be known at ORT format model conversion time, which means the EP with statically registered kernels must also be enabled then. This is not an issue for the always-available CPU EP. However, we do not want to require that any EP which statically registers kernels is always available too. Consequently, we explore another approach to match nodes to kernels that does not rely on kernel def hashes. An added benefit of this is the possibility of moving away from kernel def hashes completely, which would eliminate the maintenance burden of keeping the hashes stable. # Approach In a full build, ORT uses some information from the ONNX op schema to match a node to a kernel. We want to avoid including the ONNX op schema in a minimal build to reduce binary size. Essentially, we take the necessary information from the ONNX op schema and make it available in a minimal build. We decouple the ONNX op schema from the kernel matching logic. The kernel matching logic instead relies on per-op information which can either be obtained from the ONNX op schema or another source. This per-op information must be available in a minimal build when there are no ONNX op schemas. We put it in the ORT format model. Existing uses of kernel def hashes to look up kernels are replaced with the updated kernel matching logic. We no longer store kernel def hashes in the ORT format model’s session state and runtime optimization representations. We no longer keep the logic to generate and ensure stability of kernel def hashes.
2022-09-20 21:24:59 +00:00
const ORTCHAR_T* model_file_name = ORT_TSTR("testdata/mnist.basic.ort");
// The execution can only be performed on Android
#if defined(__ANDROID__)
RandomValueGenerator random{};
const std::vector<int64_t> dims = {1, 1, 28, 28};
std::vector<float> data = random.Gaussian<float>(dims, 0.0f, 1.f);
OrtValue ml_value;
CreateMLValue<float>(TestCPUExecutionProvider()->GetAllocator(0, OrtMemTypeDefault), dims, data,
&ml_value);
NameMLValMap feeds;
feeds.insert(std::make_pair("Input3", ml_value));
RunAndVerifyOutputsWithEP(model_file_name, "NnapiExecutionProviderTest.TestOrtFormatModel",
std::make_unique<NnapiExecutionProvider>(0),
feeds);
#else
// test load only
TestModelLoad(model_file_name,
[](const Graph& graph) { ASSERT_GT(CountAssignedNodes(graph, kNnapiExecutionProvider), 0)
<< "Some nodes should have been taken by the NNAPI EP"; });
#endif
}
// test that NNAPI EP can process an activation node that is outside of its partition
TEST(NnapiExecutionProviderTest, ActivationOutsideOfPartition) {
// model starts with Conv -> Relu
Update kernel matching logic: decouple from op schemas and remove kernel def hashes (#12791) # Motivation Currently, ORT minimal builds use kernel def hashes to map from nodes to kernels to execute when loading the model. As the kernel def hashes must be known ahead of time, this works for statically registered kernels. This works well for the CPU EP. For this approach to work, the kernel def hashes must also be known at ORT format model conversion time, which means the EP with statically registered kernels must also be enabled then. This is not an issue for the always-available CPU EP. However, we do not want to require that any EP which statically registers kernels is always available too. Consequently, we explore another approach to match nodes to kernels that does not rely on kernel def hashes. An added benefit of this is the possibility of moving away from kernel def hashes completely, which would eliminate the maintenance burden of keeping the hashes stable. # Approach In a full build, ORT uses some information from the ONNX op schema to match a node to a kernel. We want to avoid including the ONNX op schema in a minimal build to reduce binary size. Essentially, we take the necessary information from the ONNX op schema and make it available in a minimal build. We decouple the ONNX op schema from the kernel matching logic. The kernel matching logic instead relies on per-op information which can either be obtained from the ONNX op schema or another source. This per-op information must be available in a minimal build when there are no ONNX op schemas. We put it in the ORT format model. Existing uses of kernel def hashes to look up kernels are replaced with the updated kernel matching logic. We no longer store kernel def hashes in the ORT format model’s session state and runtime optimization representations. We no longer keep the logic to generate and ensure stability of kernel def hashes.
2022-09-20 21:24:59 +00:00
constexpr auto* model_file_name = ORT_TSTR("testdata/mnist.basic.ort");
// stop NNAPI partitioning at Relu so NNAPI EP only takes first Conv
const auto nnapi_partitioning_stop_ops = "Relu";
SessionOptions so;
InferenceSessionWrapper session_object{so, GetEnvironment()};
ASSERT_STATUS_OK(session_object.RegisterExecutionProvider(
std::make_unique<NnapiExecutionProvider>(0, nnapi_partitioning_stop_ops)));
ASSERT_STATUS_OK(session_object.Load(model_file_name));
ASSERT_STATUS_OK(session_object.Initialize());
// expect one NNAPI partition
ASSERT_EQ(CountAssignedNodes(session_object.GetGraph(), kNnapiExecutionProvider), 1);
}
Initial PR for NNAPI execution provider (#1220) * init * Update DNNLibrary * Update DNNLibrary, set compiler flags, it compiles now * Add more missing flags, add test * Update DNNLibrary * Update Compile method, fix allocator and some other bugs * Update DNNLibrary * Implement CopyTensor * Not delete state explicitly since it is managed by unique_ptr * Add the missing files when SingleUnitTestProjct is ON * misc changes * Fix wrong name in provider factory * Add my own test * Update the code of add node into graph, and add the missing initializer into graph * Fix the bug that re-build the graph produces extra output * Update DNNLibrary * Transpose nchw (ONNX) -> nhwc (NNAPI) * Add license * Add GetSupportedNodes method (implement it later) * Rename onnxruntime_nnapi_test->onnxruntime_nnapi_squeezenet_test * Update squeezenet_test.cpp after rebase master * Remove squeezenet_test.cpp since it is almost same with the c++ sample * Update DNNLibrary for GetSupportedNodes * Update GetSupportedNodes * Revert "Remove squeezenet_test.cpp since it is almost same with the c++ sample" This reverts commit a97575fd9ff49e50ba1dc8d8154790d8cd86c48d. * Update DNNLibrary * Fix multiple outputs bug * Remove GetKernelRegistry * Revert "Revert "Remove squeezenet_test.cpp since it is almost same with the c++ sample"" This reverts commit 2a0670e9cbf10ea654111ce39e198a4be0ddd838. * Set default memory type of NNAPI EP * Add CPUOutput allocator * Update DNNLibrary for multiple outputs * Fix bug of nhwc->nchw * Remove GetExecutionHandle()
2019-07-02 13:03:29 +00:00
} // namespace test
} // namespace onnxruntime
#endif // !defined(ORT_MINIMAL_BUILD) || defined(ORT_EXTENDED_MINIMAL_BUILD)