Skip to content

Commit f43ff32

Browse files
rainyflyheliqi
andauthored
[C# api] add c sharp api for fastdeploy (PaddlePaddle#1246)
* add c sharp api for fastdeploy * update accroding to c apis * add cmakelist for c sharp api * add cmakelists for c sharp * fix cmakelists * fix cmakelists * add c sharp api for fastdeploy * add ppyoloe demo * add ppyoloe demo * modify demo namespace code * add readme * fix format * format code * fix doc --------- Co-authored-by: heliqi <[email protected]>
1 parent e12091f commit f43ff32

File tree

15 files changed

+1600
-1
lines changed

15 files changed

+1600
-1
lines changed

CMakeLists.txt

+9-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ option(WITH_TIMVX "Whether to compile for TIMVX deploy." OFF)
7474
option(WITH_KUNLUNXIN "Whether to compile for KunlunXin XPU deploy." OFF)
7575
option(WITH_TESTING "Whether to compile with unittest." OFF)
7676
option(WITH_CAPI "Whether to compile with c api." OFF)
77-
77+
option(WITH_CSHARPAPI "Whether to compile with c# api" OFF)
7878
############################# Options for Android cross compiling #########################
7979
if(ANDROID)
8080
option(WITH_OPENCV_STATIC "Whether to use OpenCV static lib for Android." OFF)
@@ -424,8 +424,15 @@ if(WITH_CAPI)
424424
endif()
425425
endif()
426426

427+
if(WITH_CSHARPAPI)
428+
if(MSVC)
429+
add_subdirectory(${PROJECT_SOURCE_DIR}/csharp)
430+
endif()
431+
endif()
432+
427433

428434
configure_file(${PROJECT_SOURCE_DIR}/FastDeploy.cmake.in ${PROJECT_SOURCE_DIR}/FastDeploy.cmake @ONLY)
435+
configure_file(${PROJECT_SOURCE_DIR}/FastDeployCSharp.cmake.in ${PROJECT_SOURCE_DIR}/FastDeployCSharp.cmake @ONLY)
429436
configure_file(${PROJECT_SOURCE_DIR}/python/fastdeploy/c_lib_wrap.py.in ${PROJECT_SOURCE_DIR}/python/fastdeploy/c_lib_wrap.py)
430437
configure_file(${PROJECT_SOURCE_DIR}/python/scripts/process_libraries.py.in ${PROJECT_SOURCE_DIR}/python/scripts/process_libraries.py)
431438

@@ -678,6 +685,7 @@ install(
678685
${PROJECT_SOURCE_DIR}/ThirdPartyNotices.txt
679686
${PROJECT_SOURCE_DIR}/VERSION_NUMBER
680687
${PROJECT_SOURCE_DIR}/FastDeploy.cmake
688+
${PROJECT_SOURCE_DIR}/FastDeployCSharp.cmake
681689
${PROJECT_SOURCE_DIR}/cmake/FastDeployConfig.cmake
682690
${PROJECT_SOURCE_DIR}/cmake/utils.cmake
683691
${PROJECT_SOURCE_DIR}/cmake/openmp.cmake

FastDeployCSharp.cmake

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
list(APPEND FASTDEPLOY_DOTNET_REFERENCES
2+
"Microsoft.CSharp"
3+
"System"
4+
"System.Core"
5+
"System.Data"
6+
"System.Deployment"
7+
"System.Drawing"
8+
"System.Net.Http"
9+
"System.Xml"
10+
"System.Reflection"
11+
"${CMAKE_CURRENT_LIST_DIR}/csharp_lib/fastdeploy_csharp.dll")
12+
13+
set(FASTDEPLOY_PACKAGE_REFERENCES "OpenCvSharp4_4.7.0.20230115;OpenCvSharp4.runtime.win_4.7.0.20230115")
14+

FastDeployCSharp.cmake.in

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
list(APPEND FASTDEPLOY_DOTNET_REFERENCES
2+
"Microsoft.CSharp"
3+
"System"
4+
"System.Core"
5+
"System.Data"
6+
"System.Deployment"
7+
"System.Drawing"
8+
"System.Net.Http"
9+
"System.Xml"
10+
"System.Reflection"
11+
"${CMAKE_CURRENT_LIST_DIR}/csharp_lib/fastdeploy_csharp.dll")
12+
13+
set(FASTDEPLOY_PACKAGE_REFERENCES "OpenCvSharp4_4.7.0.20230115;OpenCvSharp4.runtime.win_4.7.0.20230115")

csharp/CMakeLists.txt

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
##################################### Building: FastDeploy C# API #######################################
16+
PROJECT(fastdeploy_csharp CSharp)
17+
18+
CMAKE_MINIMUM_REQUIRED (VERSION 3.10)
19+
20+
option(ENABLE_VISION "Whether to enable vision models usage." OFF)
21+
22+
message("fastdeploy_csharp_SOURCE_DIR: ${fastdeploy_csharp_SOURCE_DIR}")
23+
file(GLOB_RECURSE DEPLOY_CSHARPAPI_SRCS ${fastdeploy_csharp_SOURCE_DIR}/fastdeploy/*.cs)
24+
if(NOT ENABLE_VISION)
25+
file(GLOB_RECURSE DEPLOY_VISION_CSHARPAPI_SRCS ${fastdeploy_csharp_SOURCE_DIR}/fastdeploy/vision/*.cs)
26+
list(REMOVE_ITEM DEPLOY_CSHARPAPI_SRCS ${DEPLOY_VISION_CSHARPAPI_SRCS})
27+
endif()
28+
29+
# Define the DLL target, including all relevant project files.
30+
add_library(${PROJECT_NAME} SHARED ${DEPLOY_CSHARPAPI_SRCS})
31+
32+
# Set the C# language version (defaults to 3.0 if not set).
33+
set(CMAKE_CSharp_FLAGS "/langversion:10")
34+
# Add in some .NET reference libraries.
35+
set_property(TARGET ${PROJECT_NAME} PROPERTY VS_DOTNET_REFERENCES
36+
"Microsoft.CSharp"
37+
"System"
38+
"System.Core"
39+
"System.Data"
40+
"System.Deployment"
41+
"System.Drawing"
42+
"System.Net.Http"
43+
"System.Xml"
44+
)
45+
46+
47+
set_property(TARGET ${PROJECT_NAME}
48+
PROPERTY VS_PACKAGE_REFERENCES "OpenCvSharp4_4.7.0.20230115"
49+
)
50+
51+
##################################### Installing: FastDeploy C# API #######################################
52+
53+
install(
54+
TARGETS ${PROJECT_NAME}
55+
LIBRARY DESTINATION csharp_lib
56+
ARCHIVE DESTINATION csharp_lib
57+
RUNTIME DESTINATION csharp_lib
58+
)

csharp/fastdeploy/enum_varaibles.cs

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
namespace fastdeploy {
16+
17+
public enum ModelFormat {
18+
AUTOREC, ///< Auto recognize the model format by model file name
19+
PADDLE, ///< Model with paddlepaddle format
20+
ONNX, ///< Model with ONNX format
21+
RKNN, ///< Model with RKNN format
22+
TORCHSCRIPT, ///< Model with TorchScript format
23+
SOPHGO, ///< Model with SOPHGO format
24+
}
25+
26+
public enum rknpu2_CpuName {
27+
RK356X = 0, /* run on RK356X. */
28+
RK3588 = 1, /* default,run on RK3588. */
29+
UNDEFINED,
30+
}
31+
32+
public enum rknpu2_CoreMask {
33+
RKNN_NPU_CORE_AUTO = 0, //< default, run on NPU core randomly.
34+
RKNN_NPU_CORE_0 = 1, //< run on NPU core 0.
35+
RKNN_NPU_CORE_1 = 2, //< run on NPU core 1.
36+
RKNN_NPU_CORE_2 = 4, //< run on NPU core 2.
37+
RKNN_NPU_CORE_0_1 =
38+
RKNN_NPU_CORE_0 | RKNN_NPU_CORE_1, //< run on NPU core 1 and core 2.
39+
RKNN_NPU_CORE_0_1_2 =
40+
RKNN_NPU_CORE_0_1 | RKNN_NPU_CORE_2, //< run on NPU core 1 and core 2.
41+
RKNN_NPU_CORE_UNDEFINED,
42+
}
43+
44+
public enum LitePowerMode {
45+
LITE_POWER_HIGH = 0, ///< Use Lite Backend with high power mode
46+
LITE_POWER_LOW = 1, ///< Use Lite Backend with low power mode
47+
LITE_POWER_FULL = 2, ///< Use Lite Backend with full power mode
48+
LITE_POWER_NO_BIND = 3, ///< Use Lite Backend with no bind power mode
49+
LITE_POWER_RAND_HIGH = 4, ///< Use Lite Backend with rand high mode
50+
LITE_POWER_RAND_LOW = 5 ///< Use Lite Backend with rand low power mode
51+
}
52+
53+
}

0 commit comments

Comments
 (0)