Skip to content

Commit a1e3ebf

Browse files
authored
implement simplemath (#4905)
* complete abs, fmod and sin function in simplemath.h * remove some unused variables in simplemath.cpp * modify test-coverage.yml and add some functions to simplemath.cpp * modify erf.cpp which included math.h * include platform.h for NCNN_SIMPLEMATH definition * move utility constants and functions in simplemath.h to simplemath.cpp * guard simplemath functions with extern "C" * add NCNN_EXPORT macro in simplemath.h * include plateform.h and guard all declarations with NCNN_SIMPLEMATH * clean unused code in test_unaryop.cpp * guard #include <vector> with NCNN_SIMPLEMATH in benchncnn.cpp * add 'static' to guard functions that not declarated in header file * modify sin and cos with better implementation --------- Co-authored-by: HonestDeng <[email protected]>
1 parent a6decad commit a1e3ebf

File tree

146 files changed

+818
-245
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

146 files changed

+818
-245
lines changed

.ci/linux-x64-cpu-gcc.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,11 @@ jobs:
117117
cmake --build . -j $(nproc)
118118
- name: test-simplestl-simpleomp
119119
run: cd build-simplestl-simpleomp && ctest --output-on-failure -j $(nproc)
120+
- name: build-simplestl-simplemath
121+
run: |
122+
mkdir build-simplestl-simplemath && cd build-simplestl-simplemath
123+
cmake -DCMAKE_TOOLCHAIN_FILE=../toolchains/host-c.gcc.toolchain.cmake -DNCNN_STDIO=ON -DNCNN_STRING=ON -DNCNN_SIMPLESTL=ON -DNCNN_SIMPLEMATH=ON -DNCNN_BUILD_TESTS=ON -DNCNN_BUILD_BENCHMARK=OFF -DNCNN_BUILD_TOOLS=OFF -DNCNN_BUILD_EXAMPLES=OFF ..
124+
cmake --build . -j $(nproc)
125+
- name: test-simplestl-simplemath
126+
run: cd build-simplestl-simplemath && ctest --output-on-failure -j $(nproc)
127+

.ci/test-coverage.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,3 +908,47 @@ jobs:
908908
lcov --list lcov.info
909909
- name: codecov
910910
run: ./codecov -t ${{settings.CODECOV_TOKEN.access_token}} -C ${{ ci.sha }} -B ${{ ci.head_ref }} -f build/lcov.info
911+
912+
linux-gcc-x64-simplemath:
913+
name: linux-gcc-x64-simplemath
914+
915+
runs-on:
916+
pool-name: docker
917+
container:
918+
image: bkci/ci:ubuntu
919+
steps:
920+
- name: checkout
921+
checkout: self
922+
with:
923+
strategy: FRESH_CHECKOUT
924+
enableSubmodule: false
925+
enableGitLfs: false
926+
927+
- name: install-deps
928+
run: |
929+
apt-get update
930+
apt-get install -y lcov
931+
curl https://uploader.codecov.io/verification.gpg | gpg --no-default-keyring --keyring trustedkeys.gpg --import
932+
curl -Os https://uploader.codecov.io/latest/linux/codecov
933+
curl -Os https://uploader.codecov.io/latest/linux/codecov.SHA256SUM
934+
curl -Os https://uploader.codecov.io/latest/linux/codecov.SHA256SUM.sig
935+
gpgv codecov.SHA256SUM.sig codecov.SHA256SUM
936+
shasum -a 256 -c codecov.SHA256SUM
937+
chmod +x codecov
938+
939+
- name: build
940+
run: |
941+
mkdir build && cd build
942+
cmake -DCMAKE_TOOLCHAIN_FILE=../toolchains/host-c.gcc.toolchain.cmake -DCMAKE_BUILD_TYPE=debug -DNCNN_COVERAGE=ON -DNCNN_STDIO=ON -DNCNN_STRING=ON -DNCNN_SIMPLESTL=ON -DNCNN_SIMPLEMATH=ON -DNCNN_BUILD_TESTS=ON -DNCNN_BUILD_BENCHMARK=OFF -DNCNN_BUILD_TOOLS=OFF -DNCNN_BUILD_EXAMPLES=OFF ..
943+
cmake --build . -j $(nproc)
944+
- name: test
945+
run: cd build && ctest --output-on-failure -j $(nproc)
946+
- name: lcov-collect
947+
run: |
948+
cd build
949+
lcov -d ./src -c -o lcov.info
950+
lcov -r lcov.info '/usr/*' -o lcov.info
951+
lcov -r lcov.info '*/build/*' -o lcov.info
952+
lcov --list lcov.info
953+
- name: codecov
954+
run: ./codecov -t ${{settings.CODECOV_TOKEN.access_token}} -C ${{ ci.sha }} -B ${{ ci.head_ref }} -f build/lcov.info

.github/workflows/linux-aarch64-cpu-gcc.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,17 @@ jobs:
8686
export PATH=$GITHUB_WORKSPACE/qemu-install/bin:$PATH
8787
cd build-noint8
8888
TESTS_EXECUTABLE_LOADER=qemu-aarch64 TESTS_EXECUTABLE_LOADER_ARGUMENTS="-L;/usr/aarch64-linux-gnu" ctest --output-on-failure -j 2
89+
90+
- name: build-simplestl-simplemath
91+
run: |
92+
mkdir build-simplestl-simplemath && cd build-simplestl-simplemath
93+
cmake -DCMAKE_TOOLCHAIN_FILE=../toolchains/aarch64-linux-gnu-c.toolchain.cmake -DNCNN_STDIO=ON -DNCNN_STRING=ON -DNCNN_SIMPLESTL=ON -DNCNN_SIMPLEMATH=ON -DNCNN_BUILD_TESTS=ON -DNCNN_BUILD_BENCHMARK=OFF -DNCNN_BUILD_TOOLS=OFF -DNCNN_BUILD_EXAMPLES=OFF ..
94+
cmake --build . -j 2
95+
- name: test-simplestl-simplemath
96+
run: |
97+
export PATH=$GITHUB_WORKSPACE/qemu-install/bin:$PATH
98+
cd build-simplestl-simplemath
99+
TESTS_EXECUTABLE_LOADER=qemu-aarch64 TESTS_EXECUTABLE_LOADER_ARGUMENTS="-L;/usr/aarch64-linux-gnu" ctest --output-on-failure -j 2
89100
90101
linux-gcc-arm82:
91102
runs-on: ubuntu-20.04

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ option(NCNN_INSTALL_SDK "install ncnn library and headers" ON)
5656
option(NCNN_SIMPLEOCV "minimal opencv structure emulation" OFF)
5757
option(NCNN_SIMPLEOMP "minimal openmp runtime emulation" OFF)
5858
option(NCNN_SIMPLESTL "minimal cpp stl structure emulation" OFF)
59+
option(NCNN_SIMPLEMATH "minimal cmath" OFF)
5960
option(NCNN_THREADS "build with threads" ON)
6061
option(NCNN_BENCHMARK "print benchmark information for every layer" OFF)
6162
option(NCNN_C_API "build with C api" ON)

benchmark/benchncnn.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@
2525
#include "datareader.h"
2626
#include "net.h"
2727
#include "gpu.h"
28+
29+
#ifndef NCNN_SIMPLESTL
2830
#include <vector>
31+
#endif
2932

3033
class DataReaderFromEmpty : public ncnn::DataReader
3134
{

src/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ set(ncnn_SRCS
3939
simpleocv.cpp
4040
simpleomp.cpp
4141
simplestl.cpp
42+
simplemath.cpp
4243
)
4344

4445
if(ANDROID)
@@ -207,7 +208,7 @@ if(NOT NCNN_SHARED_LIB)
207208
set_target_properties(ncnn PROPERTIES COMPILE_FLAGS -DNCNN_STATIC_DEFINE)
208209
endif()
209210

210-
if(NCNN_SIMPLESTL)
211+
if(NCNN_SIMPLESTL AND NOT NCNN_SIMPLEMATH)
211212
# link math lib explicitly
212213
target_link_libraries(ncnn PUBLIC m)
213214
endif()
@@ -260,7 +261,6 @@ if(NCNN_THREADS)
260261
if(TARGET Threads::Threads)
261262
target_link_libraries(ncnn PUBLIC Threads::Threads)
262263
endif()
263-
264264
if(NCNN_SIMPLEOMP OR NCNN_SIMPLESTL)
265265
target_link_libraries(ncnn PUBLIC pthread)
266266
endif()
@@ -580,6 +580,7 @@ if(NCNN_INSTALL_SDK)
580580
simpleocv.h
581581
simpleomp.h
582582
simplestl.h
583+
simplemath.h
583584
vulkan_header_fix.h
584585
${CMAKE_CURRENT_BINARY_DIR}/ncnn_export.h
585586
${CMAKE_CURRENT_BINARY_DIR}/layer_shader_type_enum.h
@@ -598,5 +599,4 @@ endif()
598599
# add ncnn and generate-spirv to a virtual project group
599600
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
600601
set_property(TARGET ncnn PROPERTY FOLDER "libncnn")
601-
set_property(TARGET ncnn-generate-spirv PROPERTY FOLDER "libncnn")
602-
602+
set_property(TARGET ncnn-generate-spirv PROPERTY FOLDER "libncnn")

src/gpu.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
#if NCNN_VULKAN
1818

19-
#include <math.h>
2019
#include <string.h>
2120
#include <vulkan/vulkan.h>
2221

src/layer.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
#include "cpu.h"
1818

19-
#include <math.h>
2019
#include <string.h>
2120

2221
#ifdef _MSC_VER

src/layer.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
#include "paramdict.h"
2222
#include "platform.h"
2323

24-
#include <math.h>
25-
2624
#if NCNN_VULKAN
2725
#include "command.h"
2826
#include "pipeline.h"

src/layer/arm/binaryop_arm.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
#include "binaryop_arm.h"
1616

17-
#include <math.h>
18-
1917
#if __ARM_NEON
2018
#include <arm_neon.h>
2119
#include "neon_mathfun.h"

0 commit comments

Comments
 (0)