forked from microsoft/onnxruntime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The initial PR for NNAPI EP (microsoft#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
- Loading branch information
1 parent
37cbe85
commit 9e0f5fc
Showing
36 changed files
with
5,727 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
onnxruntime/core/platform/android/logging/android_log_sink.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
#ifdef __ANDROID__ | ||
#include <android/log.h> | ||
|
||
#include "core/common/logging/capture.h" | ||
#include "core/common/logging/isink.h" | ||
#include "core/platform/android/logging/android_log_sink.h" | ||
|
||
namespace onnxruntime { | ||
namespace logging { | ||
|
||
void AndroidLogSink::SendImpl(const Timestamp& /* timestamp */, const std::string& logger_id, const Capture& message) { | ||
std::ostringstream msg; | ||
|
||
int severity = ANDROID_LOG_INFO; | ||
switch (message.Severity()) { | ||
case Severity::kVERBOSE: | ||
severity = ANDROID_LOG_VERBOSE; | ||
break; | ||
case Severity::kINFO: | ||
severity = ANDROID_LOG_INFO; | ||
break; | ||
case Severity::kWARNING: | ||
severity = ANDROID_LOG_WARN; | ||
break; | ||
case Severity::kERROR: | ||
severity = ANDROID_LOG_ERROR; | ||
break; | ||
case Severity::kFATAL: | ||
severity = ANDROID_LOG_FATAL; | ||
break; | ||
} | ||
|
||
msg << " [" << message.SeverityPrefix() << ":" << message.Category() << ":" << logger_id << ", " | ||
<< message.Location().ToString() << "] " << message.Message() << std::endl; | ||
|
||
__android_log_print(severity, message.Category(), "%s", msg.str().c_str()); | ||
} | ||
|
||
} // namespace logging | ||
} // namespace onnxruntime | ||
#endif |
20 changes: 20 additions & 0 deletions
20
onnxruntime/core/platform/android/logging/android_log_sink.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
#pragma once | ||
|
||
#ifdef __ANDROID__ | ||
namespace onnxruntime { | ||
namespace logging { | ||
/// <summary> | ||
/// A __android_log_print based ISink | ||
/// </summary> | ||
/// <seealso cref="ISink" /> | ||
class AndroidLogSink : public ISink { | ||
public: | ||
AndroidLogSink() = default; | ||
void SendImpl(const Timestamp& timestamp, const std::string& logger_id, const Capture& message) override; | ||
}; | ||
} // namespace logging | ||
} // namespace onnxruntime | ||
#endif |
63 changes: 63 additions & 0 deletions
63
onnxruntime/core/providers/nnapi/nnapi_builtin/builders/helper.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// | ||
// Created by daquexian on 5/21/18. | ||
// | ||
#pragma once | ||
|
||
#include <core/common/common.h> | ||
#include <string> | ||
|
||
#include "core/providers/nnapi/nnapi_builtin/nnapi_lib/NeuralNetworksTypes.h" | ||
|
||
#define THROW_ON_ERROR(val) \ | ||
{ \ | ||
const auto ret = (val); \ | ||
ORT_ENFORCE( \ | ||
ret == ANEURALNETWORKS_NO_ERROR, \ | ||
std::string("Error in ") + __FILE__ + std::string(":") + \ | ||
std::to_string(__LINE__) + std::string(", function name: ") + \ | ||
std::string(__func__) + "error, ret: " + GetErrorCause(ret)); \ | ||
} | ||
|
||
#define THROW_ON_ERROR_WITH_NOTE(val, note) \ | ||
{ \ | ||
const auto ret = (val); \ | ||
ORT_ENFORCE( \ | ||
ret == ANEURALNETWORKS_NO_ERROR, \ | ||
std::string("Error in ") + __FILE__ + std::string(":") + \ | ||
std::to_string(__LINE__) + std::string(", function name: ") + \ | ||
std::string(__func__) + "error, ret: " + GetErrorCause(ret) + \ | ||
std::string(", ") + (note)); \ | ||
} | ||
|
||
template <class Map, class Key> | ||
inline bool Contains(const Map& map, const Key& key) { | ||
return map.find(key) != map.end(); | ||
} | ||
|
||
inline std::string GetErrorCause(int error_code) { | ||
switch (error_code) { | ||
case ANEURALNETWORKS_NO_ERROR: | ||
return "ANEURALNETWORKS_NO_ERROR"; | ||
case ANEURALNETWORKS_OUT_OF_MEMORY: | ||
return "ANEURALNETWORKS_OUT_OF_MEMORY"; | ||
case ANEURALNETWORKS_INCOMPLETE: | ||
return "ANEURALNETWORKS_INCOMPLETE"; | ||
case ANEURALNETWORKS_UNEXPECTED_NULL: | ||
return "ANEURALNETWORKS_UNEXPECTED_NULL"; | ||
case ANEURALNETWORKS_BAD_DATA: | ||
return "ANEURALNETWORKS_BAD_DATA"; | ||
case ANEURALNETWORKS_OP_FAILED: | ||
return "ANEURALNETWORKS_OP_FAILED"; | ||
case ANEURALNETWORKS_BAD_STATE: | ||
return "ANEURALNETWORKS_BAD_STATE"; | ||
case ANEURALNETWORKS_UNMAPPABLE: | ||
return "ANEURALNETWORKS_UNMAPPABLE"; | ||
case ANEURALNETWORKS_OUTPUT_INSUFFICIENT_SIZE: | ||
return "ANEURALNETWORKS_OUTPUT_INSUFFICIENT_SIZE"; | ||
case ANEURALNETWORKS_UNAVAILABLE_DEVICE: | ||
return "ANEURALNETWORKS_UNAVAILABLE_DEVICE"; | ||
|
||
default: | ||
return "Unknown error code: " + std::to_string(error_code); | ||
} | ||
} |
Oops, something went wrong.