Skip to content

Commit 927aff6

Browse files
Enable AscendC kernel operator
AscendC is an extended syntax for the C/C++ language that can be used to write operators that run on Ascend NPU. This commit introduce an operator(threshold) written in AscendC. Others can refer to this to implement other operators. AscendC can implement efficient fusion operators according to needs, in this case, threshold execution speed increased by nearly 4 times. Co-authored-by: CaoMengqing <cmq0113@163.com>
1 parent c7602a8 commit 927aff6

15 files changed

+704
-92
lines changed

modules/cannops/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,9 @@ ocv_include_directories(${CMAKE_SOURCE_DIR}/modules/ts/include)
1515
ocv_add_accuracy_tests(DEPENDS_ON opencv_cannops)
1616
ocv_add_perf_tests(DEPENDS_ON opencv_cannops)
1717
ocv_add_samples(opencv_cannops)
18+
19+
# compile ascnedc kernels.
20+
add_subdirectory(ascendc_kernels)
21+
ocv_include_directories(${CMAKE_BINARY_DIR}/include/ascendc_kernels)
22+
ocv_target_link_libraries(opencv_cannops PRIVATE ascendc_kernels)
23+
ocv_target_link_libraries(opencv_test_cannops PRIVATE ascendc_kernels)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
set(SOC_VERSION "ascend310p3" CACHE STRING "system on chip type")
2+
set(ASCEND_CANN_PACKAGE_PATH "/usr/local/Ascend/ascend-toolkit/latest" CACHE PATH "ASCEND CANN package installation directory")
3+
set(RUN_MODE "npu" CACHE STRING "run mode: npu/sim/cpu")
4+
5+
if(EXISTS ${ASCEND_CANN_PACKAGE_PATH}/compiler/tikcpp/ascendc_kernel_cmake)
6+
set(ASCENDC_CMAKE_DIR ${ASCEND_CANN_PACKAGE_PATH}/compiler/tikcpp/ascendc_kernel_cmake)
7+
elseif(EXISTS ${ASCEND_CANN_PACKAGE_PATH}/ascendc_devkit/tikcpp/samples/cmake)
8+
set(ASCENDC_CMAKE_DIR ${ASCEND_CANN_PACKAGE_PATH}/ascendc_devkit/tikcpp/samples/cmake)
9+
else()
10+
message(FATAL_ERROR "ascendc_kernel_cmake does not exist, please check whether the compiler package is installed.")
11+
endif()
12+
13+
include(${ASCENDC_CMAKE_DIR}/ascendc.cmake)
14+
15+
ascendc_library(ascendc_kernels STATIC
16+
threshold_opencv_kernel.cpp
17+
)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#ifndef KERNEL_TILING_H
2+
#define KERNEL_TILING_H
3+
4+
/*
5+
* threshType:
6+
* THRESH_BINARY = 0,
7+
* THRESH_BINARY_INV = 1,
8+
* THRESH_TRUNC = 2,
9+
* THRESH_TOZERO = 3,
10+
* THRESH_TOZERO_INV = 4,
11+
*/
12+
#pragma pack(push, 8)
13+
struct ThresholdOpencvTilingData
14+
{
15+
float maxVal;
16+
float thresh;
17+
uint32_t totalLength;
18+
uint8_t threshType;
19+
uint8_t dtype;
20+
};
21+
#pragma pack(pop)
22+
#endif // KERNEL_TILING_H

0 commit comments

Comments
 (0)