Skip to content

Commit fffd430

Browse files
[VSINPU]Code improvement && Slice/Dropout OP support (microsoft#21217)
### Description - Refactor codes to meet line length limit and guard missing warning - Add slice/dropout op support - Move vsinpu ep's cmake settings from onnxruntime_providers.cmake to a separate file - Modify apis with param onnxruntime::Path because this kind is replaced by std:filesystem::path by microsoft#20920
1 parent cc0de0d commit fffd430

39 files changed

+365
-59
lines changed

cmake/onnxruntime_providers.cmake

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -192,32 +192,7 @@ if (onnxruntime_USE_TVM)
192192
endif()
193193

194194
if (onnxruntime_USE_VSINPU)
195-
add_definitions(-DUSE_VSINPU=1)
196-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter")
197-
file(GLOB_RECURSE onnxruntime_providers_vsinpu_srcs
198-
"${ONNXRUNTIME_ROOT}/core/providers/vsinpu/builders/*.h"
199-
"${ONNXRUNTIME_ROOT}/core/providers/vsinpu/builders/*.cc"
200-
"${ONNXRUNTIME_ROOT}/core/providers/vsinpu/*.h"
201-
"${ONNXRUNTIME_ROOT}/core/providers/vsinpu/*.cc"
202-
"${ONNXRUNTIME_ROOT}/core/providers/shared/utils/utils.h"
203-
"${ONNXRUNTIME_ROOT}/core/providers/shared/utils/utils.cc"
204-
)
205-
source_group(TREE ${ONNXRUNTIME_ROOT}/core FILES ${onnxruntime_providers_vsinpu_srcs})
206-
add_library(onnxruntime_providers_vsinpu ${onnxruntime_providers_vsinpu_srcs})
207-
onnxruntime_add_include_to_target(onnxruntime_providers_vsinpu
208-
onnxruntime_common onnxruntime_framework onnx onnx_proto protobuf::libprotobuf-lite flatbuffers Boost::mp11
209-
safeint_interface nsync::nsync_cpp)
210-
add_dependencies(onnxruntime_providers_vsinpu ${onnxruntime_EXTERNAL_DEPENDENCIES})
211-
set_target_properties(onnxruntime_providers_vsinpu PROPERTIES FOLDER "ONNXRuntime" LINKER_LANGUAGE CXX)
212-
target_include_directories(onnxruntime_providers_vsinpu PRIVATE ${ONNXRUNTIME_ROOT} $ENV{TIM_VX_INSTALL}/include)
213-
214-
find_library(TIMVX_LIBRARY NAMES tim-vx PATHS $ENV{TIM_VX_INSTALL}/lib NO_DEFAULT_PATH)
215-
if(TIMVX_LIBRARY)
216-
target_link_libraries(onnxruntime_providers_vsinpu PRIVATE ${TIMVX_LIBRARY})
217-
else()
218-
message(FATAL_ERROR "Cannot find TIM-VX library!")
219-
endif()
220-
195+
include(onnxruntime_providers_vsinpu.cmake)
221196
endif()
222197

223198
if (onnxruntime_USE_XNNPACK)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
add_definitions(-DUSE_VSINPU=1)
2+
file(GLOB_RECURSE onnxruntime_providers_vsinpu_srcs
3+
"${ONNXRUNTIME_ROOT}/core/providers/vsinpu/builders/*.h"
4+
"${ONNXRUNTIME_ROOT}/core/providers/vsinpu/builders/*.cc"
5+
"${ONNXRUNTIME_ROOT}/core/providers/vsinpu/*.h"
6+
"${ONNXRUNTIME_ROOT}/core/providers/vsinpu/*.cc"
7+
"${ONNXRUNTIME_ROOT}/core/providers/shared/utils/utils.h"
8+
"${ONNXRUNTIME_ROOT}/core/providers/shared/utils/utils.cc"
9+
)
10+
source_group(TREE ${ONNXRUNTIME_ROOT}/core FILES ${onnxruntime_providers_vsinpu_srcs})
11+
add_library(onnxruntime_providers_vsinpu ${onnxruntime_providers_vsinpu_srcs})
12+
onnxruntime_add_include_to_target(onnxruntime_providers_vsinpu
13+
onnxruntime_common onnxruntime_framework onnx onnx_proto protobuf::libprotobuf-lite flatbuffers Boost::mp11
14+
safeint_interface nsync::nsync_cpp)
15+
add_dependencies(onnxruntime_providers_vsinpu ${onnxruntime_EXTERNAL_DEPENDENCIES})
16+
set_target_properties(onnxruntime_providers_vsinpu PROPERTIES FOLDER "ONNXRuntime" LINKER_LANGUAGE CXX)
17+
target_include_directories(onnxruntime_providers_vsinpu PRIVATE ${ONNXRUNTIME_ROOT} $ENV{TIM_VX_INSTALL}/include)
18+
19+
find_library(TIMVX_LIBRARY NAMES tim-vx PATHS $ENV{TIM_VX_INSTALL}/lib NO_DEFAULT_PATH)
20+
if(NOT TIMVX_LIBRARY)
21+
message(FATAL_ERROR "TIM-VX library is not found!")
22+
endif()
23+
24+
if(CMAKE_CROSSCOMPILING)
25+
message(STATUS "VSINPU ep will be cross compiled.")
26+
if(EXISTS "$ENV{VIVANTE_SDK_DIR}/drivers")
27+
set(DRIVER_DIR "$ENV{VIVANTE_SDK_DIR}/drivers")
28+
elseif(EXISTS "$ENV{VIVANTE_SDK_DIR}/lib")
29+
set(DRIVER_DIR "$ENV{VIVANTE_SDK_DIR}/lib")
30+
else()
31+
message(FATAL_ERROR "Neither drivers nor lib directory exists in this VIVANTE_SDK_DIR.")
32+
endif()
33+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter -Wl,-rpath-link ${DRIVER_DIR} ${TIMVX_LIBRARY}")
34+
else()
35+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter")
36+
target_link_libraries(onnxruntime_providers_vsinpu PRIVATE ${TIMVX_LIBRARY})
37+
endif()

onnxruntime/core/providers/vsinpu/builders/impl/activation_op_builder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* DEALINGS IN THE SOFTWARE.
2222
*
2323
*****************************************************************************/
24+
#pragma once
2425
#include <memory>
2526
#include <vector>
2627
#include <utility>

onnxruntime/core/providers/vsinpu/builders/impl/base_op_builder.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,16 @@ bool BaseOpBuilder::HasSupportedInputOutputs(const InitializedTensorSet& initial
100100
}
101101
}
102102
for (const auto& output : node_unit.Outputs()) {
103+
for (const auto& dim : output.node_arg.Shape()->dim()) {
104+
if (!dim.has_dim_value()) {
105+
LOGS_DEFAULT(WARNING) << "Dynamic shape is not supported for now, for output:" << output.node_arg.Name();
106+
return false;
107+
}
108+
if (dim.dim_value() == 0 && output.node_arg.Shape()->dim_size() > 1) {
109+
LOGS_DEFAULT(WARNING) << "Zero in shape is not supported for now, for output:" << output.node_arg.Name();
110+
return false;
111+
}
112+
}
103113
if (output.quant_param.has_value()) {
104114
if (!has_supported_shape(output.quant_param->scale, node_unit.Name(), node_unit.OpType()))
105115
return false;

onnxruntime/core/providers/vsinpu/builders/impl/base_op_builder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class BaseOpBuilder : public IOpBuilder {
4040
bool IsSupported(const onnxruntime::GraphViewer& graph_viewer,
4141
const NodeUnit& node_unit) const override;
4242
bool BuildOp(vsi::npu::GraphEP* graph_ep,
43-
const onnxruntime::GraphViewer& graph_viewer, const NodeUnit& node_unit);
43+
const onnxruntime::GraphViewer& graph_viewer, const NodeUnit& node_unit) override;
4444
virtual bool IsOpSupported(const onnxruntime::GraphViewer& graph_viewer,
4545
const Node* node) const {
4646
return true;

onnxruntime/core/providers/vsinpu/builders/impl/cast_op_builder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* DEALINGS IN THE SOFTWARE.
2222
*
2323
*****************************************************************************/
24+
#pragma once
2425
#include <memory>
2526
#include <vector>
2627
#include <utility>

onnxruntime/core/providers/vsinpu/builders/impl/clip_op_builder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* DEALINGS IN THE SOFTWARE.
2222
*
2323
*****************************************************************************/
24+
#pragma once
2425
#include <memory>
2526
#include <vector>
2627
#include "core/providers/vsinpu/builders/impl/base_op_builder.h"

onnxruntime/core/providers/vsinpu/builders/impl/concat_op_builder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* DEALINGS IN THE SOFTWARE.
2222
*
2323
*****************************************************************************/
24+
#pragma once
2425
#include <memory>
2526
#include <vector>
2627
#include <utility>

onnxruntime/core/providers/vsinpu/builders/impl/conv_op_builder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* DEALINGS IN THE SOFTWARE.
2222
*
2323
*****************************************************************************/
24+
#pragma once
2425
#include <string>
2526
#include <memory>
2627
#include <vector>

onnxruntime/core/providers/vsinpu/builders/impl/dequantize_op_builder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* DEALINGS IN THE SOFTWARE.
2222
*
2323
*****************************************************************************/
24+
#pragma once
2425
#include <memory>
2526
#include <vector>
2627
#include <utility>

0 commit comments

Comments
 (0)