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.
Merge pull request #14 from chenfeiyue-cfy/base_1.18.0
Change develope base to 1.18.0
- Loading branch information
Showing
59 changed files
with
4,503 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
--- | ||
title: Verisilicon - VSINPU | ||
description: Instructions to execute ONNX Runtime with VsiNpu | ||
parent: Execution Providers | ||
# nav_order: 15 | ||
--- | ||
{::options toc_levels="2" /} | ||
|
||
# VSINPU Execution Provider | ||
VsiNpu constructed with TIM-VX as an onnxruntime Execution Provider. | ||
|
||
[TIM-VX](https://github.com/VeriSilicon/TIM-VX) is a software integration module provided by VeriSilicon to facilitate deployment of Neural-Networks on VeriSilicon ML accelerators. It serves as the backend binding for runtime frameworks such as Android NN, Tensorflow-Lite, MLIR, TVM and more. | ||
|
||
## Contents | ||
{: .no_toc } | ||
|
||
* TOC placeholder | ||
{:toc} | ||
|
||
## Prepare | ||
|
||
The VSINPU Execution Provider (EP) requires that tim-vx has already been built building EP. | ||
|
||
See [here](https://github.com/VeriSilicon/TIM-VX?tab=readme-ov-file#build-and-run) for building tim-vx-build. | ||
|
||
## Build | ||
### Linux | ||
|
||
1. export envs | ||
```bash | ||
export TIM_VX_INSTALL=<your-path-to-tim-vx-build>/install | ||
export VIVANTE_SDK_DIR=<your_path_of_tim-vx>/prebuilt-sdk/x86_64_linux | ||
export LD_LIBRARY_PATH=$VIVANTE_SDK_DIR/lib:$TIM_VX_INSTALL/lib | ||
``` | ||
|
||
2. build onnxruntime with "--use_vsinpu" | ||
|
||
```bash | ||
./build.sh --config Debug --build_shared_lib --use_vsinpu --skip_tests | ||
``` | ||
|
||
## Test | ||
VSINPU EP can run onnx models (unit-tests)with onnx binary onnx_test_runner (onnxruntime_test_all). | ||
1. export envs | ||
```bash | ||
export TIM_VX_INSTALL=<your-path-to-tim-vx-build>/install | ||
export VIVANTE_SDK_DIR=<your_path_of_tim-vx>/prebuilt-sdk/x86_64_linux | ||
export LD_LIBRARY_PATH=$VIVANTE_SDK_DIR/lib:$TIM_VX_INSTALL/lib | ||
``` | ||
2. run test | ||
```bash | ||
cd <your_path_to_onnxruntime_build>/Debug/ | ||
./onnx_test_runner -e vsinpu <yout_path_to_onnx_model> | ||
|
||
cd <your_path_to_onnxruntime_build>/Debug/ | ||
./onnxruntime_test_all --gtest_filter=ActivationOpTest.Sigmoid | ||
``` | ||
If detailed log information is required, please add the "-v" parameter. | ||
|
||
## Supported ops | ||
Following ops are supported by the VSINPU Execution Provider, it should be noted that all operators do not support dynamic shape input or output. | ||
|
||
|Operator|Note| | ||
|--------|------| | ||
|ai.onnx:Abs|| | ||
|ai.onnx:Add|| | ||
|ai.onnx:Conv|Only 1D/2D Conv is supported yet.| | ||
|ai.onnx:Div|| | ||
|ai.onnx:Exp|| | ||
|ai.onnx:Floor|| | ||
|ai.onnx:Gemm|| | ||
|ai.onnx:GlobalAveragePool|| | ||
|ai.onnx:HardSigmoid|| | ||
|ai.onnx:HardSwish|| | ||
|ai.onnx:LeakyRelu|| | ||
|ai.onnx:Log|| | ||
|ai.onnx:Mul|| | ||
|ai.onnx:Pow|| | ||
|ai.onnx:Relu|| | ||
|ai.onnx:Sigmoid|| | ||
|ai.onnx:Sin|| | ||
|ai.onnx:Sqrt|| | ||
|ai.onnx:Sub|| | ||
|ai.onnx:Tanh|| |
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
34 changes: 34 additions & 0 deletions
34
include/onnxruntime/core/providers/vsinpu/vsinpu_provider_factory.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,34 @@ | ||
/**************************************************************************** | ||
* | ||
* Copyright (c) 2023 Vivante Corporation | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a | ||
* copy of this software and associated documentation files (the "Software"), | ||
* to deal in the Software without restriction, including without limitation | ||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
* and/or sell copies of the Software, and to permit persons to whom the | ||
* Software is furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
* DEALINGS IN THE SOFTWARE. | ||
* | ||
*****************************************************************************/ | ||
#include "onnxruntime_c_api.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
ORT_API_STATUS(OrtSessionOptionsAppendExecutionProvider_VSINPU, _In_ OrtSessionOptions* options); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
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
127 changes: 127 additions & 0 deletions
127
onnxruntime/core/providers/vsinpu/builders/impl/activation_op_builder.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,127 @@ | ||
/**************************************************************************** | ||
* | ||
* Copyright (c) 2023 Vivante Corporation | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a | ||
* copy of this software and associated documentation files (the "Software"), | ||
* to deal in the Software without restriction, including without limitation | ||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
* and/or sell copies of the Software, and to permit persons to whom the | ||
* Software is furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
* DEALINGS IN THE SOFTWARE. | ||
* | ||
*****************************************************************************/ | ||
#include "core/providers/shared/utils/utils.h" | ||
#include "core/providers/vsinpu/builders/impl/base_op_builder.h" | ||
|
||
namespace onnxruntime { | ||
namespace vsi { | ||
namespace npu { | ||
class ReluOpBuilder : public BaseOpBuilder { | ||
public: | ||
bool HandleBuildOp(vsi::npu::GraphEP* graph_ep, | ||
std::vector<std::shared_ptr<tim::vx::Tensor>>& inputs, | ||
std::vector<std::shared_ptr<tim::vx::Tensor>>& outputs, | ||
const NodeUnit& node_unit) override { | ||
LOGS_DEFAULT(VERBOSE) << "Creating Relu Activation."; | ||
auto op = graph_ep->GetGraph()->CreateOperation<tim::vx::ops::Relu>(); | ||
(*op).BindInputs(inputs).BindOutputs(outputs); | ||
graph_ep->GetOps().push_back(std::move(op)); | ||
return true; | ||
} | ||
}; | ||
class SigmoidOpBuilder : public BaseOpBuilder { | ||
public: | ||
bool HandleBuildOp(vsi::npu::GraphEP* graph_ep, | ||
std::vector<std::shared_ptr<tim::vx::Tensor>>& inputs, | ||
std::vector<std::shared_ptr<tim::vx::Tensor>>& outputs, | ||
const NodeUnit& node_unit) override { | ||
LOGS_DEFAULT(VERBOSE) << "Creating Sigmoid Activation."; | ||
auto op = graph_ep->GetGraph()->CreateOperation<tim::vx::ops::Sigmoid>(); | ||
(*op).BindInputs(inputs).BindOutputs(outputs); | ||
graph_ep->GetOps().push_back(std::move(op)); | ||
return true; | ||
} | ||
}; | ||
class TanhOpBuilder : public BaseOpBuilder { | ||
public: | ||
bool HandleBuildOp(vsi::npu::GraphEP* graph_ep, | ||
std::vector<std::shared_ptr<tim::vx::Tensor>>& inputs, | ||
std::vector<std::shared_ptr<tim::vx::Tensor>>& outputs, | ||
const NodeUnit& node_unit) override { | ||
LOGS_DEFAULT(VERBOSE) << "Creating Tanh activation."; | ||
auto op = graph_ep->GetGraph()->CreateOperation<tim::vx::ops::Tanh>(); | ||
(*op).BindInputs(inputs).BindOutputs(outputs); | ||
graph_ep->GetOps().push_back(std::move(op)); | ||
return true; | ||
} | ||
}; | ||
|
||
class LeakyReluOpBuilder : public BaseOpBuilder { | ||
public: | ||
bool HandleBuildOp(vsi::npu::GraphEP* graph_ep, | ||
std::vector<std::shared_ptr<tim::vx::Tensor>>& inputs, | ||
std::vector<std::shared_ptr<tim::vx::Tensor>>& outputs, | ||
const NodeUnit& node_unit) override { | ||
LOGS_DEFAULT(VERBOSE) << "Creating LeakyRelu activation."; | ||
const auto& node = node_unit.GetNode(); | ||
NodeAttrHelper helper(node); | ||
auto alpha = helper.Get("alpha", 1.0f); | ||
auto op = | ||
graph_ep->GetGraph()->CreateOperation<tim::vx::ops::LeakyRelu>(alpha); | ||
(*op).BindInputs(inputs).BindOutputs(outputs); | ||
graph_ep->GetOps().push_back(std::move(op)); | ||
return true; | ||
} | ||
}; | ||
|
||
class EluOpBuilder : public BaseOpBuilder { | ||
public: | ||
bool HandleBuildOp(vsi::npu::GraphEP* graph_ep, | ||
std::vector<std::shared_ptr<tim::vx::Tensor>>& inputs, | ||
std::vector<std::shared_ptr<tim::vx::Tensor>>& outputs, | ||
const NodeUnit& node_unit) override { | ||
LOGS_DEFAULT(VERBOSE) << "Creating Elu activation."; | ||
const auto& node = node_unit.GetNode(); | ||
NodeAttrHelper helper(node); | ||
auto alpha = helper.Get("alpha", 1.0f); | ||
auto op = | ||
graph_ep->GetGraph()->CreateOperation<tim::vx::ops::LeakyRelu>(alpha); | ||
(*op).BindInputs(inputs).BindOutputs(outputs); | ||
graph_ep->GetOps().push_back(std::move(op)); | ||
return true; | ||
} | ||
}; | ||
|
||
class HardSigmoidOpBuilder : public BaseOpBuilder { | ||
public: | ||
bool HandleBuildOp(vsi::npu::GraphEP* graph_ep, | ||
std::vector<std::shared_ptr<tim::vx::Tensor>>& inputs, | ||
std::vector<std::shared_ptr<tim::vx::Tensor>>& outputs, | ||
const NodeUnit& node_unit) override { | ||
LOGS_DEFAULT(VERBOSE) << "Creating HardSigmoid activation."; | ||
const auto& node = node_unit.GetNode(); | ||
NodeAttrHelper helper(node); | ||
auto alpha = helper.Get("alpha", 1.0f); | ||
auto beta = helper.Get("beta", 1.0f); | ||
auto op = graph_ep->GetGraph()->CreateOperation<tim::vx::ops::HardSigmoid>( | ||
alpha, beta); | ||
(*op).BindInputs(inputs).BindOutputs(outputs); | ||
graph_ep->GetOps().push_back(std::move(op)); | ||
return true; | ||
} | ||
}; | ||
} // namespace npu | ||
|
||
} // namespace vsi | ||
} // namespace onnxruntime |
Oops, something went wrong.