* 去掉对stl的依赖 * 头文件名,push_back改正 * 去掉构造托管 * 好像是折腾 * data 的返回改为指针,非指针引用 * resize一处写错 * stdint * 加入c_str * 改文件名为小写 * NCNN_SIMPLESTL option * simplestl default to OFF * Update linux-x64-cpu-gcc.yml * Update linux-x64-cpu-gcc.yml * Update linux-x64-cpu-clang.yml * drop functional header * arm32 arm64 simplestl ci * 修改一处内存泄漏, 去掉编译器警告 * resize时默认量的bug Co-authored-by: nihuini <nihuini@tencent.com> Co-authored-by: nihui <shuizhuyuanluo@126.com>tags/20200616
| @@ -72,3 +72,53 @@ jobs: | |||
| run: mkdir build && cd build && cmake -DNCNN_STDIO=OFF -DNCNN_STRING=OFF -DNCNN_BUILD_TESTS=OFF -DNCNN_BUILD_BENCHMARK=OFF -DNCNN_BUILD_TOOLS=OFF -DNCNN_BUILD_EXAMPLES=OFF .. | |||
| - name: build | |||
| run: cmake --build build -j 2 | |||
| linux-clang-simplestl: | |||
| runs-on: ubuntu-latest | |||
| steps: | |||
| - uses: actions/checkout@v2 | |||
| - name: configure | |||
| env: | |||
| CC: clang | |||
| CXX: clang++ | |||
| run: mkdir build && cd build && cmake -DNCNN_STDIO=ON -DNCNN_STRING=ON -DNCNN_SIMPLESTL=ON -DNCNN_BUILD_TESTS=ON -DNCNN_BUILD_BENCHMARK=OFF -DNCNN_BUILD_TOOLS=OFF -DNCNN_BUILD_EXAMPLES=OFF .. | |||
| - name: build | |||
| run: cmake --build build -j 2 | |||
| - name: test | |||
| run: cd build && ctest --output-on-failure -j 2 | |||
| linux-clang-nostdio-simplestl: | |||
| runs-on: ubuntu-latest | |||
| steps: | |||
| - uses: actions/checkout@v2 | |||
| - name: configure | |||
| env: | |||
| CC: clang | |||
| CXX: clang++ | |||
| run: mkdir build && cd build && cmake -DNCNN_STDIO=OFF -DNCNN_STRING=ON -DNCNN_SIMPLESTL=ON -DNCNN_BUILD_TESTS=OFF -DNCNN_BUILD_BENCHMARK=OFF -DNCNN_BUILD_TOOLS=OFF -DNCNN_BUILD_EXAMPLES=OFF .. | |||
| - name: build | |||
| run: cmake --build build -j 2 | |||
| linux-clang-nostring-simplestl: | |||
| runs-on: ubuntu-latest | |||
| steps: | |||
| - uses: actions/checkout@v2 | |||
| - name: configure | |||
| env: | |||
| CC: clang | |||
| CXX: clang++ | |||
| run: mkdir build && cd build && cmake -DNCNN_STDIO=ON -DNCNN_STRING=OFF -DNCNN_SIMPLESTL=ON -DNCNN_BUILD_TESTS=OFF -DNCNN_BUILD_BENCHMARK=OFF -DNCNN_BUILD_TOOLS=OFF -DNCNN_BUILD_EXAMPLES=OFF .. | |||
| - name: build | |||
| run: cmake --build build -j 2 | |||
| linux-clang-nostdio-nostring-simplestl: | |||
| runs-on: ubuntu-latest | |||
| steps: | |||
| - uses: actions/checkout@v2 | |||
| - name: configure | |||
| env: | |||
| CC: clang | |||
| CXX: clang++ | |||
| run: mkdir build && cd build && cmake -DNCNN_STDIO=OFF -DNCNN_STRING=OFF -DNCNN_SIMPLESTL=ON -DNCNN_BUILD_TESTS=OFF -DNCNN_BUILD_BENCHMARK=OFF -DNCNN_BUILD_TOOLS=OFF -DNCNN_BUILD_EXAMPLES=OFF .. | |||
| - name: build | |||
| run: cmake --build build -j 2 | |||
| @@ -57,3 +57,41 @@ jobs: | |||
| run: mkdir build && cd build && cmake -DNCNN_STDIO=OFF -DNCNN_STRING=OFF -DNCNN_BUILD_TESTS=OFF -DNCNN_BUILD_BENCHMARK=OFF -DNCNN_BUILD_TOOLS=OFF -DNCNN_BUILD_EXAMPLES=OFF .. | |||
| - name: build | |||
| run: cmake --build build -j 2 | |||
| linux-gcc-simplestl: | |||
| runs-on: ubuntu-latest | |||
| steps: | |||
| - uses: actions/checkout@v2 | |||
| - name: configure | |||
| run: mkdir build && cd build && cmake -DNCNN_STDIO=ON -DNCNN_STRING=ON -DNCNN_SIMPLESTL=ON -DNCNN_BUILD_TESTS=ON -DNCNN_BUILD_BENCHMARK=OFF -DNCNN_BUILD_TOOLS=OFF -DNCNN_BUILD_EXAMPLES=OFF .. | |||
| - name: build | |||
| run: cmake --build build -j 2 | |||
| - name: test | |||
| run: cd build && ctest --output-on-failure -j 2 | |||
| linux-gcc-nostdio-simplestl: | |||
| runs-on: ubuntu-latest | |||
| steps: | |||
| - uses: actions/checkout@v2 | |||
| - name: configure | |||
| run: mkdir build && cd build && cmake -DNCNN_STDIO=OFF -DNCNN_STRING=ON -DNCNN_SIMPLESTL=ON -DNCNN_BUILD_TESTS=OFF -DNCNN_BUILD_BENCHMARK=OFF -DNCNN_BUILD_TOOLS=OFF -DNCNN_BUILD_EXAMPLES=OFF .. | |||
| - name: build | |||
| run: cmake --build build -j 2 | |||
| linux-gcc-nostring-simplestl: | |||
| runs-on: ubuntu-latest | |||
| steps: | |||
| - uses: actions/checkout@v2 | |||
| - name: configure | |||
| run: mkdir build && cd build && cmake -DNCNN_STDIO=ON -DNCNN_STRING=OFF -DNCNN_SIMPLESTL=ON -DNCNN_BUILD_TESTS=OFF -DNCNN_BUILD_BENCHMARK=OFF -DNCNN_BUILD_TOOLS=OFF -DNCNN_BUILD_EXAMPLES=OFF .. | |||
| - name: build | |||
| run: cmake --build build -j 2 | |||
| linux-gcc-nostdio-nostring-simplestl: | |||
| runs-on: ubuntu-latest | |||
| steps: | |||
| - uses: actions/checkout@v2 | |||
| - name: configure | |||
| run: mkdir build && cd build && cmake -DNCNN_STDIO=OFF -DNCNN_STRING=OFF -DNCNN_SIMPLESTL=ON -DNCNN_BUILD_TESTS=OFF -DNCNN_BUILD_BENCHMARK=OFF -DNCNN_BUILD_TOOLS=OFF -DNCNN_BUILD_EXAMPLES=OFF .. | |||
| - name: build | |||
| run: cmake --build build -j 2 | |||
| @@ -31,6 +31,24 @@ matrix: | |||
| - NAME=linux-clang | |||
| - BUILD="mkdir build && cd build && cmake .. && make -j2 && ctest --output-on-failure -j 2" | |||
| - name: "linux-gcc-arm64-simplestl" | |||
| os: linux | |||
| arch: arm64 | |||
| dist: bionic | |||
| compiler: gcc | |||
| env: | |||
| - NAME=linux-gcc-simplestl | |||
| - BUILD="mkdir build && cd build && cmake -DNCNN_SIMPLESTL=ON -DNCNN_BUILD_TOOLS=OFF -DNCNN_BUILD_EXAMPLES=OFF .. && make -j2 && ctest --output-on-failure -j 2" | |||
| - name: "linux-clang-arm64-simplestl" | |||
| os: linux | |||
| arch: arm64 | |||
| dist: bionic | |||
| compiler: clang | |||
| env: | |||
| - NAME=linux-clang-simplestl | |||
| - BUILD="mkdir build && cd build && cmake -DNCNN_SIMPLESTL=ON -DNCNN_BUILD_TOOLS=OFF -DNCNN_BUILD_EXAMPLES=OFF .. && make -j2 && ctest --output-on-failure -j 2" | |||
| - name: "windows-vs2017" | |||
| os: windows | |||
| dist: 1803-containers | |||
| @@ -56,6 +74,15 @@ matrix: | |||
| - BEFORE_BUILD="sudo dpkg --add-architecture armhf && sudo apt-get update && sudo apt-get -y install crossbuild-essential-armhf libc6:armhf libstdc++-5-dev:armhf linux-libc-dev:armhf" | |||
| - BUILD="mkdir build && cd build && cmake -DCMAKE_TOOLCHAIN_FILE=../toolchains/arm-linux-gnueabihf.toolchain.cmake -DNCNN_BUILD_TOOLS=OFF -DNCNN_BUILD_EXAMPLES=OFF - .. && make -j2 VERBOSE=1 && ctest --output-on-failure -j 2" | |||
| - name: "linux-gcc-arm32-simplestl" | |||
| os: linux | |||
| arch: arm64 | |||
| dist: bionic | |||
| env: | |||
| - NAME=linux-gcc-arm32-simplestl | |||
| - BEFORE_BUILD="sudo dpkg --add-architecture armhf && sudo apt-get update && sudo apt-get -y install crossbuild-essential-armhf libc6:armhf libstdc++-5-dev:armhf linux-libc-dev:armhf" | |||
| - BUILD="mkdir build && cd build && cmake -DCMAKE_TOOLCHAIN_FILE=../toolchains/arm-linux-gnueabihf.toolchain.cmake -DNCNN_SIMPLESTL=ON -DNCNN_BUILD_TOOLS=OFF -DNCNN_BUILD_EXAMPLES=OFF - .. && make -j2 VERBOSE=1 && ctest --output-on-failure -j 2" | |||
| - name: "test-coverage-arm32" | |||
| os: linux | |||
| arch: arm64 | |||
| @@ -24,6 +24,7 @@ option(NCNN_STDIO "load model from external file" ON) | |||
| option(NCNN_STRING "plain and verbose string" ON) | |||
| option(NCNN_INSTALL_SDK "install ncnn library and headers" ON) | |||
| option(NCNN_OPENCV "minimal opencv structure emulation" OFF) | |||
| option(NCNN_SIMPLESTL "minimal cpp stl structure emulation" OFF) | |||
| option(NCNN_BENCHMARK "print benchmark information for every layer" OFF) | |||
| option(NCNN_PIXEL "convert and resize from/to image pixel" ON) | |||
| option(NCNN_PIXEL_ROTATE "rotate image pixel orientation" ON) | |||
| @@ -24,7 +24,6 @@ | |||
| #include <stdlib.h> | |||
| #include <list> | |||
| #include <vector> | |||
| #include "platform.h" | |||
| #if NCNN_VULKAN | |||
| @@ -15,8 +15,6 @@ | |||
| #ifndef NCNN_BLOB_H | |||
| #define NCNN_BLOB_H | |||
| #include <string> | |||
| #include <vector> | |||
| #include "platform.h" | |||
| #include "mat.h" | |||
| @@ -19,7 +19,6 @@ | |||
| #if NCNN_VULKAN | |||
| #include <vector> | |||
| #include <vulkan/vulkan.h> | |||
| #include "mat.h" | |||
| @@ -17,7 +17,6 @@ | |||
| #include <limits.h> | |||
| #include <string.h> | |||
| #include <vector> | |||
| #ifdef _OPENMP | |||
| #include <omp.h> | |||
| @@ -22,8 +22,6 @@ | |||
| #include <string.h> | |||
| #include <algorithm> | |||
| #include <string> | |||
| #include <vector> | |||
| #include "mat.h" | |||
| #include "command.h" | |||
| @@ -20,7 +20,6 @@ | |||
| #if NCNN_VULKAN | |||
| #include <vulkan/vulkan.h> | |||
| #include <vector> | |||
| #include "mat.h" | |||
| namespace ncnn { | |||
| @@ -15,8 +15,6 @@ | |||
| #ifndef NCNN_LAYER_H | |||
| #define NCNN_LAYER_H | |||
| #include <string> | |||
| #include <vector> | |||
| #include <math.h> | |||
| #include "platform.h" | |||
| #include "mat.h" | |||
| @@ -15,7 +15,6 @@ | |||
| #include "binaryop_arm.h" | |||
| #include <math.h> | |||
| #include <algorithm> | |||
| #include <functional> | |||
| #if __ARM_NEON | |||
| #include <arm_neon.h> | |||
| @@ -1734,6 +1733,22 @@ static int binary_op_scalar_inplace_bf16s(Mat& a, float b, const Option& opt) | |||
| return 0; | |||
| } | |||
| struct binary_op_add { | |||
| float operator() (const float& x, const float& y) const { return x + y; } | |||
| }; | |||
| struct binary_op_sub { | |||
| float operator() (const float& x, const float& y) const { return x - y; } | |||
| }; | |||
| struct binary_op_mul { | |||
| float operator() (const float& x, const float& y) const { return x * y; } | |||
| }; | |||
| struct binary_op_div { | |||
| float operator() (const float& x, const float& y) const { return x / y; } | |||
| }; | |||
| struct binary_op_max { | |||
| float operator() (const float& x, const float& y) const { return std::max(x, y); } | |||
| }; | |||
| @@ -1799,16 +1814,16 @@ int BinaryOp_arm::forward_bf16s(const std::vector<Mat>& bottom_blobs, std::vecto | |||
| if (elempack == 1 && elempack1 == 1) | |||
| { | |||
| if (op_type == Operation_ADD) | |||
| return binary_op_bf16s< std::plus<float> >(bottom_blob, bottom_blob1, top_blob, opt); | |||
| return binary_op_bf16s<binary_op_add>(bottom_blob, bottom_blob1, top_blob, opt); | |||
| if (op_type == Operation_SUB) | |||
| return binary_op_bf16s< std::minus<float> >(bottom_blob, bottom_blob1, top_blob, opt); | |||
| return binary_op_bf16s<binary_op_sub>(bottom_blob, bottom_blob1, top_blob, opt); | |||
| if (op_type == Operation_MUL) | |||
| return binary_op_bf16s< std::multiplies<float> >(bottom_blob, bottom_blob1, top_blob, opt); | |||
| return binary_op_bf16s<binary_op_mul>(bottom_blob, bottom_blob1, top_blob, opt); | |||
| if (op_type == Operation_DIV) | |||
| return binary_op_bf16s< std::divides<float> >(bottom_blob, bottom_blob1, top_blob, opt); | |||
| return binary_op_bf16s<binary_op_div>(bottom_blob, bottom_blob1, top_blob, opt); | |||
| if (op_type == Operation_MAX) | |||
| return binary_op_bf16s<binary_op_max>(bottom_blob, bottom_blob1, top_blob, opt); | |||
| @@ -1868,16 +1883,16 @@ int BinaryOp_arm::forward_inplace_bf16s(Mat& bottom_top_blob, const Option& opt) | |||
| if (elempack == 1) | |||
| { | |||
| if (op_type == Operation_ADD) | |||
| return binary_op_scalar_inplace_bf16s< std::plus<float> >(bottom_top_blob, b, opt); | |||
| return binary_op_scalar_inplace_bf16s<binary_op_add>(bottom_top_blob, b, opt); | |||
| if (op_type == Operation_SUB) | |||
| return binary_op_scalar_inplace_bf16s< std::minus<float> >(bottom_top_blob, b, opt); | |||
| return binary_op_scalar_inplace_bf16s<binary_op_sub>(bottom_top_blob, b, opt); | |||
| if (op_type == Operation_MUL) | |||
| return binary_op_scalar_inplace_bf16s< std::multiplies<float> >(bottom_top_blob, b, opt); | |||
| return binary_op_scalar_inplace_bf16s<binary_op_mul>(bottom_top_blob, b, opt); | |||
| if (op_type == Operation_DIV) | |||
| return binary_op_scalar_inplace_bf16s< std::divides<float> >(bottom_top_blob, b, opt); | |||
| return binary_op_scalar_inplace_bf16s<binary_op_div>(bottom_top_blob, b, opt); | |||
| if (op_type == Operation_MAX) | |||
| return binary_op_scalar_inplace_bf16s<binary_op_max>(bottom_top_blob, b, opt); | |||
| @@ -14,7 +14,6 @@ | |||
| #include "unaryop_arm.h" | |||
| #include <math.h> | |||
| #include <functional> | |||
| #if __ARM_NEON | |||
| #include <arm_neon.h> | |||
| @@ -15,7 +15,6 @@ | |||
| #include "binaryop.h" | |||
| #include <math.h> | |||
| #include <algorithm> | |||
| #include <functional> | |||
| namespace ncnn { | |||
| @@ -487,6 +486,26 @@ static int binary_op_scalar_inplace(Mat& a, float b, const Option& opt) | |||
| return 0; | |||
| } | |||
| template<typename T> | |||
| struct binary_op_add { | |||
| T operator() (const T& x, const T& y) const { return x + y; } | |||
| }; | |||
| template<typename T> | |||
| struct binary_op_sub { | |||
| T operator() (const T& x, const T& y) const { return x - y; } | |||
| }; | |||
| template<typename T> | |||
| struct binary_op_mul { | |||
| T operator() (const T& x, const T& y) const { return x * y; } | |||
| }; | |||
| template<typename T> | |||
| struct binary_op_div { | |||
| T operator() (const T& x, const T& y) const { return x / y; } | |||
| }; | |||
| template<typename T> | |||
| struct binary_op_max { | |||
| T operator() (const T& x, const T& y) const { return std::max(x, y); } | |||
| @@ -520,16 +539,16 @@ int BinaryOp::forward(const std::vector<Mat>& bottom_blobs, std::vector<Mat>& to | |||
| Mat& top_blob = top_blobs[0]; | |||
| if (op_type == Operation_ADD) | |||
| return binary_op< std::plus<float> >(bottom_blob, bottom_blob1, top_blob, opt); | |||
| return binary_op< binary_op_add<float> >(bottom_blob, bottom_blob1, top_blob, opt); | |||
| if (op_type == Operation_SUB) | |||
| return binary_op< std::minus<float> >(bottom_blob, bottom_blob1, top_blob, opt); | |||
| return binary_op< binary_op_sub<float> >(bottom_blob, bottom_blob1, top_blob, opt); | |||
| if (op_type == Operation_MUL) | |||
| return binary_op< std::multiplies<float> >(bottom_blob, bottom_blob1, top_blob, opt); | |||
| return binary_op< binary_op_mul<float> >(bottom_blob, bottom_blob1, top_blob, opt); | |||
| if (op_type == Operation_DIV) | |||
| return binary_op< std::divides<float> >(bottom_blob, bottom_blob1, top_blob, opt); | |||
| return binary_op< binary_op_div<float> >(bottom_blob, bottom_blob1, top_blob, opt); | |||
| if (op_type == Operation_MAX) | |||
| return binary_op< binary_op_max<float> >(bottom_blob, bottom_blob1, top_blob, opt); | |||
| @@ -552,16 +571,16 @@ int BinaryOp::forward(const std::vector<Mat>& bottom_blobs, std::vector<Mat>& to | |||
| int BinaryOp::forward_inplace(Mat& bottom_top_blob, const Option& opt) const | |||
| { | |||
| if (op_type == Operation_ADD) | |||
| return binary_op_scalar_inplace< std::plus<float> >(bottom_top_blob, b, opt); | |||
| return binary_op_scalar_inplace< binary_op_add<float> >(bottom_top_blob, b, opt); | |||
| if (op_type == Operation_SUB) | |||
| return binary_op_scalar_inplace< std::minus<float> >(bottom_top_blob, b, opt); | |||
| return binary_op_scalar_inplace< binary_op_sub<float> >(bottom_top_blob, b, opt); | |||
| if (op_type == Operation_MUL) | |||
| return binary_op_scalar_inplace< std::multiplies<float> >(bottom_top_blob, b, opt); | |||
| return binary_op_scalar_inplace< binary_op_mul<float> >(bottom_top_blob, b, opt); | |||
| if (op_type == Operation_DIV) | |||
| return binary_op_scalar_inplace< std::divides<float> >(bottom_top_blob, b, opt); | |||
| return binary_op_scalar_inplace< binary_op_div<float> >(bottom_top_blob, b, opt); | |||
| if (op_type == Operation_MAX) | |||
| return binary_op_scalar_inplace< binary_op_max<float> >(bottom_top_blob, b, opt); | |||
| @@ -15,7 +15,6 @@ | |||
| #include "proposal.h" | |||
| #include <math.h> | |||
| #include <algorithm> | |||
| #include <vector> | |||
| namespace ncnn { | |||
| @@ -17,7 +17,6 @@ | |||
| #include <limits.h> | |||
| #include <math.h> | |||
| #include <algorithm> | |||
| #include <functional> | |||
| namespace ncnn { | |||
| @@ -761,6 +760,16 @@ struct post_process_log { | |||
| T operator() (const T& x) const { return static_cast<T>(log(x)); } | |||
| }; | |||
| template<typename T> | |||
| struct reduction_op_add { | |||
| T operator() (const T& x, const T& y) const { return x + y; } | |||
| }; | |||
| template<typename T> | |||
| struct reduction_op_mul { | |||
| T operator() (const T& x, const T& y) const { return x * y; } | |||
| }; | |||
| template<typename T> | |||
| struct reduction_op_asum { | |||
| T operator() (const T& x, const T& y) const { return static_cast<T>(x + fabs(y)); } | |||
| @@ -833,13 +842,13 @@ int Reduction::forward(const Mat& bottom_blob, Mat& top_blob, const Option& opt) | |||
| } | |||
| if (operation == ReductionOp_SUM) | |||
| return reduction< std::plus<float>, std::plus<float>, post_process_identity<float> >(bottom_blob, top_blob, 0.f, reduce_w, reduce_h, reduce_c, false, coeff, keepdims, opt); | |||
| return reduction< reduction_op_add<float>, reduction_op_add<float>, post_process_identity<float> >(bottom_blob, top_blob, 0.f, reduce_w, reduce_h, reduce_c, false, coeff, keepdims, opt); | |||
| if (operation == ReductionOp_ASUM) | |||
| return reduction< reduction_op_asum<float>, std::plus<float>, post_process_identity<float> >(bottom_blob, top_blob, 0.f, reduce_w, reduce_h, reduce_c, false, coeff, keepdims, opt); | |||
| return reduction< reduction_op_asum<float>, reduction_op_add<float>, post_process_identity<float> >(bottom_blob, top_blob, 0.f, reduce_w, reduce_h, reduce_c, false, coeff, keepdims, opt); | |||
| if (operation == ReductionOp_SUMSQ) | |||
| return reduction< reduction_op_sumsq<float>, std::plus<float>, post_process_identity<float> >(bottom_blob, top_blob, 0.f, reduce_w, reduce_h, reduce_c, false, coeff, keepdims, opt); | |||
| return reduction< reduction_op_sumsq<float>, reduction_op_add<float>, post_process_identity<float> >(bottom_blob, top_blob, 0.f, reduce_w, reduce_h, reduce_c, false, coeff, keepdims, opt); | |||
| if (operation == ReductionOp_MEAN) | |||
| { | |||
| @@ -862,7 +871,7 @@ int Reduction::forward(const Mat& bottom_blob, Mat& top_blob, const Option& opt) | |||
| } | |||
| float coeff_mean = coeff / scale; | |||
| return reduction< std::plus<float>, std::plus<float>, post_process_identity<float> >(bottom_blob, top_blob, 0.f, reduce_w, reduce_h, reduce_c, true, coeff_mean, keepdims, opt); | |||
| return reduction< reduction_op_add<float>, reduction_op_add<float>, post_process_identity<float> >(bottom_blob, top_blob, 0.f, reduce_w, reduce_h, reduce_c, true, coeff_mean, keepdims, opt); | |||
| } | |||
| if (operation == ReductionOp_MAX) | |||
| @@ -872,19 +881,19 @@ int Reduction::forward(const Mat& bottom_blob, Mat& top_blob, const Option& opt) | |||
| return reduction< reduction_op_min<float>, reduction_op_min<float>, post_process_identity<float> >(bottom_blob, top_blob, FLT_MAX, reduce_w, reduce_h, reduce_c, false, coeff, keepdims, opt); | |||
| if (operation == ReductionOp_PROD) | |||
| return reduction< std::multiplies<float>, std::multiplies<float>, post_process_identity<float> >(bottom_blob, top_blob, 1.f, reduce_w, reduce_h, reduce_c, false, coeff, keepdims, opt); | |||
| return reduction< reduction_op_mul<float>, reduction_op_mul<float>, post_process_identity<float> >(bottom_blob, top_blob, 1.f, reduce_w, reduce_h, reduce_c, false, coeff, keepdims, opt); | |||
| if (operation == ReductionOp_L1) | |||
| return reduction< reduction_op_asum<float>, std::plus<float>, post_process_identity<float> >(bottom_blob, top_blob, 0.f, reduce_w, reduce_h, reduce_c, false, 1.f, keepdims, opt); | |||
| return reduction< reduction_op_asum<float>, reduction_op_add<float>, post_process_identity<float> >(bottom_blob, top_blob, 0.f, reduce_w, reduce_h, reduce_c, false, 1.f, keepdims, opt); | |||
| if (operation == ReductionOp_L2) | |||
| return reduction< reduction_op_sumsq<float>, std::plus<float>, post_process_sqrt<float> >(bottom_blob, top_blob, 0.f, reduce_w, reduce_h, reduce_c, true, 1.f, keepdims, opt); | |||
| return reduction< reduction_op_sumsq<float>, reduction_op_add<float>, post_process_sqrt<float> >(bottom_blob, top_blob, 0.f, reduce_w, reduce_h, reduce_c, true, 1.f, keepdims, opt); | |||
| if (operation == ReductionOp_LogSum) | |||
| return reduction< std::plus<float>, std::plus<float>, post_process_log<float> >(bottom_blob, top_blob, 0.f, reduce_w, reduce_h, reduce_c, true, 1.f, keepdims, opt); | |||
| return reduction< reduction_op_add<float>, reduction_op_add<float>, post_process_log<float> >(bottom_blob, top_blob, 0.f, reduce_w, reduce_h, reduce_c, true, 1.f, keepdims, opt); | |||
| if (operation == ReductionOp_LogSumExp) | |||
| return reduction< reduction_op_sumsexp<float>, std::plus<float>, post_process_log<float> >(bottom_blob, top_blob, 0.f, reduce_w, reduce_h, reduce_c, true, 1.f, keepdims, opt); | |||
| return reduction< reduction_op_sumsexp<float>, reduction_op_add<float>, post_process_log<float> >(bottom_blob, top_blob, 0.f, reduce_w, reduce_h, reduce_c, true, 1.f, keepdims, opt); | |||
| return 0; | |||
| } | |||
| @@ -14,7 +14,6 @@ | |||
| #include "unaryop.h" | |||
| #include <math.h> | |||
| #include <functional> | |||
| namespace ncnn { | |||
| @@ -15,7 +15,6 @@ | |||
| #include "binaryop_vulkan.h" | |||
| #include <math.h> | |||
| #include <algorithm> | |||
| #include <functional> | |||
| #include "layer_shader_type.h" | |||
| namespace ncnn { | |||
| @@ -15,7 +15,6 @@ | |||
| #include "modelbin.h" | |||
| #include <string.h> | |||
| #include <vector> | |||
| #include "datareader.h" | |||
| namespace ncnn { | |||
| @@ -15,7 +15,6 @@ | |||
| #ifndef NCNN_NET_H | |||
| #define NCNN_NET_H | |||
| #include <vector> | |||
| #include "platform.h" | |||
| #include "blob.h" | |||
| #include "layer.h" | |||
| @@ -20,7 +20,6 @@ | |||
| #if NCNN_OPENCV | |||
| #include <algorithm> | |||
| #include <string> | |||
| #include "mat.h" | |||
| #if defined(_MSC_VER) || defined(__GNUC__) | |||
| @@ -15,7 +15,6 @@ | |||
| #include "pipeline.h" | |||
| #include <math.h> | |||
| #include <algorithm> | |||
| #include <string> | |||
| #include "mat.h" | |||
| #include "option.h" | |||
| #include "layer_shader_type.h" | |||
| @@ -18,6 +18,7 @@ | |||
| #cmakedefine01 NCNN_STDIO | |||
| #cmakedefine01 NCNN_STRING | |||
| #cmakedefine01 NCNN_OPENCV | |||
| #cmakedefine01 NCNN_SIMPLESTL | |||
| #cmakedefine01 NCNN_BENCHMARK | |||
| #cmakedefine01 NCNN_PIXEL | |||
| #cmakedefine01 NCNN_PIXEL_ROTATE | |||
| @@ -135,6 +136,13 @@ private: | |||
| } // namespace ncnn | |||
| #if NCNN_SIMPLESTL | |||
| #include "simplestl.h" | |||
| #else | |||
| #include <vector> | |||
| #include <string> | |||
| #endif | |||
| #if NCNN_STDIO | |||
| #include <stdio.h> | |||
| #define NCNN_LOGE(...) do { fprintf(stderr, ##__VA_ARGS__); fprintf(stderr, "\n"); } while(0) | |||
| @@ -0,0 +1,182 @@ | |||
| // Tencent is pleased to support the open source community by making ncnn available. | |||
| // | |||
| // Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. | |||
| // | |||
| // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except | |||
| // in compliance with the License. You may obtain a copy of the License at | |||
| // | |||
| // https://opensource.org/licenses/BSD-3-Clause | |||
| // | |||
| // Unless required by applicable law or agreed to in writing, software distributed | |||
| // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | |||
| // CONDITIONS OF ANY KIND, either express or implied. See the License for the | |||
| // specific language governing permissions and limitations under the License. | |||
| #ifndef NCNN_SIMPLESTL_H | |||
| #define NCNN_SIMPLESTL_H | |||
| #include <new> | |||
| #include <stddef.h> | |||
| #include <stdint.h> | |||
| #include <string.h> | |||
| // minimal stl data structure implementation | |||
| namespace std { | |||
| template <typename T> | |||
| struct vector | |||
| { | |||
| vector() {} | |||
| vector(const size_t new_size, const T& value = T()) { resize(new_size, value); } | |||
| ~vector() { clear(); } | |||
| vector(const vector& v) | |||
| { | |||
| resize(v.size()); | |||
| for (size_t i = 0; i < size_; i++) { data_[i] = v.data_[i]; } | |||
| } | |||
| vector& operator=(const vector& v) | |||
| { | |||
| if (this == &v) | |||
| { | |||
| return *this; | |||
| } | |||
| resize(0); | |||
| resize(v.size()); | |||
| for (size_t i = 0; i < size_; i++) | |||
| { | |||
| data_[i] = v.data_[i]; | |||
| } | |||
| return *this; | |||
| } | |||
| void resize(const size_t new_size, const T& value = T()) | |||
| { | |||
| try_alloc(new_size); | |||
| if (new_size > size_) | |||
| { | |||
| for (size_t i = size_; i < new_size; i++) | |||
| { | |||
| new (&data_[i]) T(value); | |||
| } | |||
| } | |||
| else if (new_size < size_) | |||
| { | |||
| for (size_t i = new_size; i < size_; i++) | |||
| { | |||
| data_[i].~T(); | |||
| } | |||
| } | |||
| size_ = new_size; | |||
| } | |||
| void clear() | |||
| { | |||
| for (size_t i = 0; i < size_; i++) | |||
| { | |||
| data_[i].~T(); | |||
| } | |||
| delete[](char*) data_; | |||
| data_ = nullptr; | |||
| size_ = 0; | |||
| capacity_ = 0; | |||
| } | |||
| T* data() const { return data_; } | |||
| size_t size() const { return size_; } | |||
| T& operator[](size_t i) const { return data_[i]; } | |||
| T* begin() const { return &data_[0]; } | |||
| T* end() const { return &data_[size_]; } | |||
| bool empty() const { return size_ == 0; } | |||
| void push_back(const T& t) | |||
| { | |||
| try_alloc(size_ + 1); | |||
| new (&data_[size_]) T(t); | |||
| size_++; | |||
| } | |||
| void insert(T* pos, T* b, T* e) | |||
| { | |||
| vector* v = nullptr; | |||
| if (b >= begin() && b < end()) | |||
| { | |||
| //the same vector | |||
| v = new vector(*this); | |||
| b = v->begin() + (b - begin()); | |||
| e = v->begin() + (e - begin()); | |||
| } | |||
| size_t diff = pos - begin(); | |||
| try_alloc(size_ + (e - b)); | |||
| pos = begin() + diff; | |||
| memmove(pos + (e - b), pos, (end() - pos) * sizeof(T)); | |||
| size_t len = e - b; | |||
| size_ += len; | |||
| for (size_t i = 0; i < len; i++) | |||
| { | |||
| *pos = *b; | |||
| pos++; | |||
| b++; | |||
| } | |||
| delete v; | |||
| } | |||
| T* erase(T* pos) | |||
| { | |||
| pos->~T(); | |||
| memmove(pos, pos + 1, (end() - pos - 1) * sizeof(T)); | |||
| size_--; | |||
| return pos; | |||
| } | |||
| protected: | |||
| T* data_ = nullptr; | |||
| size_t size_ = 0; | |||
| size_t capacity_ = 0; | |||
| void try_alloc(size_t new_size) | |||
| { | |||
| if (new_size * 3 / 2 > capacity_ / 2) | |||
| { | |||
| capacity_ = new_size * 2; | |||
| T* new_data = (T*)new char[capacity_ * sizeof(T)]; | |||
| memset(new_data, 0, capacity_ * sizeof(T)); | |||
| if (data_) | |||
| { | |||
| memmove(new_data, data_, sizeof(T) * size_); | |||
| delete[](char*) data_; | |||
| } | |||
| data_ = new_data; | |||
| } | |||
| } | |||
| }; | |||
| struct string : public vector<char> | |||
| { | |||
| string() {} | |||
| string(const char* str) | |||
| { | |||
| size_t len = strlen(str); | |||
| resize(len); | |||
| memcpy(data_, str, len); | |||
| } | |||
| const char* c_str() const { return (const char*)data_; } | |||
| bool operator==(const string& str2) const { return strcmp(data_, str2.data_) == 0; } | |||
| bool operator==(const char* str2) const { return strcmp(data_, str2) == 0; } | |||
| bool operator!=(const char* str2) const { return strcmp(data_, str2) != 0; } | |||
| string& operator+=(const string& str1) | |||
| { | |||
| insert(end(), str1.begin(), str1.end()); | |||
| return *this; | |||
| } | |||
| }; | |||
| inline string operator+(const string& str1, const string& str2) | |||
| { | |||
| string str(str1); | |||
| str.insert(str.end(), str2.begin(), str2.end()); | |||
| return str; | |||
| } | |||
| } // namespace std | |||
| #endif // NCNN_SIMPLESTL_H | |||