From fe6bc1ed4d1df0e41299c79fbfb2e13e59e5acc0 Mon Sep 17 00:00:00 2001 From: nihui Date: Tue, 14 Jul 2020 22:55:19 +0800 Subject: [PATCH] Ci rv64gcv and rv64gc (#1936) --- .github/workflows/elf-riscv64-cpu-gcc.yml | 196 ++++++++++++++++++ .github/workflows/linux-x64-cpu-clang.yml | 24 --- .github/workflows/linux-x64-cpu-gcc.yml | 18 -- .github/workflows/windows-x64-cpu-vs2019.yml | 4 +- .github/workflows/windows-x64-gpu-vs2019.yml | 2 +- .travis.yml | 2 +- CMakeLists.txt | 1 + README.md | 1 + benchmark/benchncnn.cpp | 9 +- cmake/run_test.cmake | 5 + src/CMakeLists.txt | 2 + src/allocator.h | 4 +- src/layer/riscv/clip_riscv.cpp | 75 +++++++ src/layer/riscv/clip_riscv.h | 32 +++ src/platform.h.in | 32 +++ tests/CMakeLists.txt | 3 +- tests/test_binaryop.cpp | 46 ++-- .../riscv64-unknown-elf.toolchain.cmake | 19 ++ 18 files changed, 402 insertions(+), 73 deletions(-) create mode 100644 .github/workflows/elf-riscv64-cpu-gcc.yml create mode 100644 cmake/run_test.cmake create mode 100644 src/layer/riscv/clip_riscv.cpp create mode 100644 src/layer/riscv/clip_riscv.h create mode 100644 toolchains/riscv64-unknown-elf.toolchain.cmake diff --git a/.github/workflows/elf-riscv64-cpu-gcc.yml b/.github/workflows/elf-riscv64-cpu-gcc.yml new file mode 100644 index 000000000..7551ad862 --- /dev/null +++ b/.github/workflows/elf-riscv64-cpu-gcc.yml @@ -0,0 +1,196 @@ +name: elf-riscv64-cpu-gcc +on: [push, pull_request] +jobs: + newlib-rv64gcv-gcc: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v2 + with: + submodules: true + + - name: cache-riscv + id: cache-riscv + uses: actions/cache@v1 + with: + path: rv64gcv-install + key: rv64gcv-newlib-install + + - name: install-riscv-build-deps + if: steps.cache-riscv.outputs.cache-hit != 'true' + run: | + sudo apt-get update + sudo apt-get install autoconf automake autotools-dev curl python3 libmpc-dev libmpfr-dev libgmp-dev gawk build-essential bison flex texinfo gperf libtool patchutils bc zlib1g-dev libexpat-dev device-tree-compiler + + - name: checkout-riscv-gnu-toolchain + if: steps.cache-riscv.outputs.cache-hit != 'true' + uses: actions/checkout@v2 + with: + repository: riscv/riscv-gnu-toolchain + path: riscv-gnu-toolchain + ref: 5842fde8ee5bb3371643b60ed34906eff7a5fa31 + - name: checkout-riscv-gnu-toolchain-submodules + if: steps.cache-riscv.outputs.cache-hit != 'true' + run: | + cd riscv-gnu-toolchain + git submodule update --init --recursive --depth 1 riscv-binutils + git submodule update --init --recursive --depth 1 riscv-gcc + git submodule update --init --recursive --depth 1 riscv-glibc + git submodule update --init --recursive --depth 1 riscv-dejagnu + git submodule update --init --recursive --depth 1 riscv-newlib + git submodule update --init --recursive --depth 1 riscv-gdb + - name: riscv-gnu-toolchain + if: steps.cache-riscv.outputs.cache-hit != 'true' + run: | + cd riscv-gnu-toolchain + sed -i '/__OBSOLETE_MATH/d' riscv-newlib/newlib/libm/common/math_errf.c + ./configure --prefix=$GITHUB_WORKSPACE/rv64gcv-install --with-arch=rv64gcv + make -j2 + + - name: checkout-riscv-pk + if: steps.cache-riscv.outputs.cache-hit != 'true' + uses: actions/checkout@v2 + with: + repository: riscv/riscv-pk + path: riscv-pk + ref: 5d9ed238e1cabfbca3c47f50d32894ce94bfc304 + - name: riscv-pk + if: steps.cache-riscv.outputs.cache-hit != 'true' + run: | + cd riscv-pk + mkdir build + cd build + export PATH=$GITHUB_WORKSPACE/rv64gcv-install/bin:$PATH + ../configure --prefix=$GITHUB_WORKSPACE/rv64gcv-install --with-arch=rv64gcv --host=riscv64-unknown-elf + make -j2 + make install + + - name: checkout-riscv-isa-sim + if: steps.cache-riscv.outputs.cache-hit != 'true' + uses: actions/checkout@v2 + with: + repository: riscv/riscv-isa-sim + path: riscv-isa-sim + ref: ecc039ef5726315b7e37e8a9c7b682bbe09c9cf5 + - name: riscv-isa-sim + if: steps.cache-riscv.outputs.cache-hit != 'true' + run: | + cd riscv-isa-sim + mkdir build + cd build + export PATH=$GITHUB_WORKSPACE/rv64gcv-install/bin:$PATH + ../configure --prefix=$GITHUB_WORKSPACE/rv64gcv-install --with-isa=rv64gcv + make -j2 + make install + + - name: riscv-strip-install + if: steps.cache-riscv.outputs.cache-hit != 'true' + run: find $GITHUB_WORKSPACE/rv64gcv-install -type f | xargs -i strip -g {} || true + + - name: configure + run: export RISCV_ROOT_PATH=$GITHUB_WORKSPACE/rv64gcv-install && mkdir build && cd build && cmake -DCMAKE_TOOLCHAIN_FILE=../toolchains/riscv64-unknown-elf.toolchain.cmake -DNCNN_THREADS=OFF -DNCNN_OPENMP=OFF -DNCNN_BUILD_TOOLS=OFF -DNCNN_BUILD_EXAMPLES=OFF .. + - name: build + run: cmake --build build -j 2 + - name: test + run: | + sudo apt-get update + sudo apt-get install device-tree-compiler + export PATH=$GITHUB_WORKSPACE/rv64gcv-install/bin:$PATH + cd build + TESTS_EXECUTABLE_LOADER=spike TESTS_EXECUTABLE_LOADER_ARGUMENTS=$GITHUB_WORKSPACE/rv64gcv-install/riscv64-unknown-elf/bin/pk ctest --output-on-failure -j 2 + + newlib-rv64gc-gcc: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v2 + with: + submodules: true + + - name: cache-riscv + id: cache-riscv + uses: actions/cache@v1 + with: + path: rv64gc-install + key: rv64gc-newlib-install + + - name: install-riscv-build-deps + if: steps.cache-riscv.outputs.cache-hit != 'true' + run: | + sudo apt-get update + sudo apt-get install autoconf automake autotools-dev curl python3 libmpc-dev libmpfr-dev libgmp-dev gawk build-essential bison flex texinfo gperf libtool patchutils bc zlib1g-dev libexpat-dev device-tree-compiler + + - name: checkout-riscv-gnu-toolchain + if: steps.cache-riscv.outputs.cache-hit != 'true' + uses: actions/checkout@v2 + with: + repository: riscv/riscv-gnu-toolchain + path: riscv-gnu-toolchain + ref: 256a4108922f76403a63d6567501c479971d5575 + - name: checkout-riscv-gnu-toolchain-submodules + if: steps.cache-riscv.outputs.cache-hit != 'true' + run: | + cd riscv-gnu-toolchain + git submodule update --init --recursive --depth 1 riscv-binutils + git submodule update --init --recursive --depth 1 riscv-gcc + git submodule update --init --recursive --depth 1 riscv-glibc + git submodule update --init --recursive --depth 1 riscv-dejagnu + git submodule update --init --recursive --depth 1 riscv-newlib + git submodule update --init --recursive --depth 1 riscv-gdb + - name: riscv-gnu-toolchain + if: steps.cache-riscv.outputs.cache-hit != 'true' + run: | + cd riscv-gnu-toolchain + sed -i '/__OBSOLETE_MATH/d' riscv-newlib/newlib/libm/common/math_errf.c + ./configure --prefix=$GITHUB_WORKSPACE/rv64gc-install --with-arch=rv64gc + make -j2 + + - name: checkout-riscv-pk + if: steps.cache-riscv.outputs.cache-hit != 'true' + uses: actions/checkout@v2 + with: + repository: riscv/riscv-pk + path: riscv-pk + ref: 5d9ed238e1cabfbca3c47f50d32894ce94bfc304 + - name: riscv-pk + if: steps.cache-riscv.outputs.cache-hit != 'true' + run: | + cd riscv-pk + mkdir build + cd build + export PATH=$GITHUB_WORKSPACE/rv64gc-install/bin:$PATH + ../configure --prefix=$GITHUB_WORKSPACE/rv64gc-install --with-arch=rv64gc --host=riscv64-unknown-elf + make -j2 + make install + + - name: checkout-riscv-isa-sim + if: steps.cache-riscv.outputs.cache-hit != 'true' + uses: actions/checkout@v2 + with: + repository: riscv/riscv-isa-sim + path: riscv-isa-sim + ref: ecc039ef5726315b7e37e8a9c7b682bbe09c9cf5 + - name: riscv-isa-sim + if: steps.cache-riscv.outputs.cache-hit != 'true' + run: | + cd riscv-isa-sim + mkdir build + cd build + export PATH=$GITHUB_WORKSPACE/rv64gc-install/bin:$PATH + ../configure --prefix=$GITHUB_WORKSPACE/rv64gc-install --with-isa=rv64gc + make -j2 + make install + + - name: riscv-strip-install + if: steps.cache-riscv.outputs.cache-hit != 'true' + run: find $GITHUB_WORKSPACE/rv64gc-install -type f | xargs -i strip -g {} || true + + - name: configure + run: export RISCV_ROOT_PATH=$GITHUB_WORKSPACE/rv64gc-install && mkdir build && cd build && cmake -DCMAKE_TOOLCHAIN_FILE=../toolchains/riscv64-unknown-elf.toolchain.cmake -DNCNN_THREADS=OFF -DNCNN_OPENMP=OFF -DNCNN_BUILD_TOOLS=OFF -DNCNN_BUILD_EXAMPLES=OFF .. + - name: build + run: cmake --build build -j 2 + - name: test + run: | + sudo apt-get update + sudo apt-get install device-tree-compiler + export PATH=$GITHUB_WORKSPACE/rv64gc-install/bin:$PATH + cd build + TESTS_EXECUTABLE_LOADER=spike TESTS_EXECUTABLE_LOADER_ARGUMENTS=$GITHUB_WORKSPACE/rv64gc-install/riscv64-unknown-elf/bin/pk ctest --output-on-failure -j 2 diff --git a/.github/workflows/linux-x64-cpu-clang.yml b/.github/workflows/linux-x64-cpu-clang.yml index 9c5844000..faded322c 100644 --- a/.github/workflows/linux-x64-cpu-clang.yml +++ b/.github/workflows/linux-x64-cpu-clang.yml @@ -87,30 +87,6 @@ jobs: - 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: diff --git a/.github/workflows/linux-x64-cpu-gcc.yml b/.github/workflows/linux-x64-cpu-gcc.yml index 4e675e847..7bdac6111 100644 --- a/.github/workflows/linux-x64-cpu-gcc.yml +++ b/.github/workflows/linux-x64-cpu-gcc.yml @@ -69,24 +69,6 @@ jobs: - 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: diff --git a/.github/workflows/windows-x64-cpu-vs2019.yml b/.github/workflows/windows-x64-cpu-vs2019.yml index 8b0fb204b..3db491293 100644 --- a/.github/workflows/windows-x64-cpu-vs2019.yml +++ b/.github/workflows/windows-x64-cpu-vs2019.yml @@ -27,7 +27,7 @@ jobs: - name: build run: cmake --build build --config Release -j 2 - name: test - run: cd build; ctest --output-on-failure -j 2 + run: cd build; ctest -C Release --output-on-failure -j 2 windows-vs2019-avx2: runs-on: windows-latest @@ -55,7 +55,7 @@ jobs: - name: build run: cmake --build build --config Release -j 2 - name: test - run: cd build; ctest --output-on-failure -j 2 + run: cd build; ctest -C Release --output-on-failure -j 2 windows-vs2019-nostdio-nostring: runs-on: windows-latest diff --git a/.github/workflows/windows-x64-gpu-vs2019.yml b/.github/workflows/windows-x64-gpu-vs2019.yml index 0019b9299..0a54abc80 100644 --- a/.github/workflows/windows-x64-gpu-vs2019.yml +++ b/.github/workflows/windows-x64-gpu-vs2019.yml @@ -72,4 +72,4 @@ jobs: run: | Copy-Item -Path '.\VulkanSDK\RunTimeInstaller\x64\vulkan-1.dll' -Destination 'build\tests' $env:VK_ICD_FILENAMES="$env:GITHUB_WORKSPACE\swiftshader-install\vk_swiftshader_icd.json" - cd build; ctest --output-on-failure -j 2 + cd build; ctest -C Release --output-on-failure -j 2 diff --git a/.travis.yml b/.travis.yml index 50b7490f5..20a88bed5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -54,7 +54,7 @@ matrix: dist: 1803-containers env: - NAME=windows-vs2017 - - BUILD="mkdir build && cd build && cmake .. && cmake --build . && ctest --output-on-failure -j 2" + - BUILD="mkdir build && cd build && cmake .. && cmake --build . --config Release && ctest -C Release --output-on-failure -j 2" - name: "test-coverage-arm64" os: linux diff --git a/CMakeLists.txt b/CMakeLists.txt index 7185d9426..4bc59e388 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,7 @@ 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_THREADS "build with threads" ON) 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) diff --git a/README.md b/README.md index c5598869b..32782791f 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ ncnn 是一个为手机端极致优化的高性能神经网络前向计算框架 | iOS | [![Build Status](https://img.shields.io/github/workflow/status/Tencent/ncnn/ios-cpu)](https://github.com/Tencent/ncnn/actions?query=workflow%3Aios-cpu) | [![Build Status](https://img.shields.io/github/workflow/status/Tencent/ncnn/ios-cpu)](https://github.com/Tencent/ncnn/actions?query=workflow%3Aios-cpu) | — | [![Build Status](https://img.shields.io/github/workflow/status/Tencent/ncnn/ios-64bit-gpu)](https://github.com/Tencent/ncnn/actions?query=workflow%3Aios-64bit-gpu) | | iOS Simulator | [![Build Status](https://img.shields.io/github/workflow/status/Tencent/ncnn/ios-simulator)](https://github.com/Tencent/ncnn/actions?query=workflow%3Aios-simulator) | [![Build Status](https://img.shields.io/github/workflow/status/Tencent/ncnn/ios-simulator)](https://github.com/Tencent/ncnn/actions?query=workflow%3Aios-simulator) | — | — | | WebAssembly | — | [![Build Status](https://img.shields.io/github/workflow/status/Tencent/ncnn/web-assembly)](https://github.com/Tencent/ncnn/actions?query=workflow%3Aweb-assembly) | — | — | +| RISC-V GCC/Newlib | — | [![Build Status](https://img.shields.io/github/workflow/status/Tencent/ncnn/elf-riscv64-cpu-gcc)](https://github.com/Tencent/ncnn/actions?query=workflow%3Aelf-riscv64-cpu-gcc) | — | — | --- diff --git a/benchmark/benchncnn.cpp b/benchmark/benchncnn.cpp index 6cd2b8761..771df0608 100644 --- a/benchmark/benchncnn.cpp +++ b/benchmark/benchncnn.cpp @@ -95,8 +95,15 @@ void benchmark(const char* comment, const ncnn::Mat& _in, const ncnn::Option& op // sleep 10 seconds for cooling down SOC :( #ifdef _WIN32 Sleep(10 * 1000); -#else +#elif defined(__unix__) || defined(__APPLE__) sleep(10); +#elif _POSIX_TIMERS + struct timespec ts; + ts.tv_sec = 10; + ts.tv_nsec = 0; + nanosleep(&ts, &ts); +#else + // TODO How to handle it ? #endif } diff --git a/cmake/run_test.cmake b/cmake/run_test.cmake new file mode 100644 index 000000000..c49fb14f7 --- /dev/null +++ b/cmake/run_test.cmake @@ -0,0 +1,5 @@ + +execute_process(COMMAND $ENV{TESTS_EXECUTABLE_LOADER} $ENV{TESTS_EXECUTABLE_LOADER_ARGUMENTS} ${TEST_EXECUTABLE} $ENV{TESTS_ARGUMENTS} RESULT_VARIABLE result) +if(NOT "${result}" STREQUAL "0") + message(FATAL_ERROR "Test failed with return value '${result}'") +endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 30de1670b..9e3df9900 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -145,6 +145,8 @@ macro(ncnn_add_layer class) set(arch arm) elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(mips)") set(arch mips) + elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(riscv)") + set(arch riscv) else() set(arch x86) endif() diff --git a/src/allocator.h b/src/allocator.h index a82b82931..dfbabf691 100644 --- a/src/allocator.h +++ b/src/allocator.h @@ -67,7 +67,7 @@ static inline void* fastMalloc(size_t size) { #if _MSC_VER return _aligned_malloc(size, MALLOC_ALIGN); -#elif _POSIX_C_SOURCE >= 200112L || (__ANDROID__ && __ANDROID_API__ >= 17) +#elif (defined(__unix__) || defined(__APPLE__)) && _POSIX_C_SOURCE >= 200112L || (__ANDROID__ && __ANDROID_API__ >= 17) void* ptr = 0; if (posix_memalign(&ptr, MALLOC_ALIGN, size)) ptr = 0; @@ -90,7 +90,7 @@ static inline void fastFree(void* ptr) { #if _MSC_VER _aligned_free(ptr); -#elif _POSIX_C_SOURCE >= 200112L || (__ANDROID__ && __ANDROID_API__ >= 17) +#elif (defined(__unix__) || defined(__APPLE__)) && _POSIX_C_SOURCE >= 200112L || (__ANDROID__ && __ANDROID_API__ >= 17) free(ptr); #elif __ANDROID__ && __ANDROID_API__ < 17 free(ptr); diff --git a/src/layer/riscv/clip_riscv.cpp b/src/layer/riscv/clip_riscv.cpp new file mode 100644 index 000000000..b7f488876 --- /dev/null +++ b/src/layer/riscv/clip_riscv.cpp @@ -0,0 +1,75 @@ +// 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. + +#include "clip_riscv.h" + +#include "riscv-pk/encoding.h" + +namespace ncnn { + +Clip_riscv::Clip_riscv() +{ +} + +int Clip_riscv::forward_inplace(Mat& bottom_top_blob, const Option& opt) const +{ + int w = bottom_top_blob.w; + int h = bottom_top_blob.h; + int channels = bottom_top_blob.c; + int size = w * h; + + #pragma omp parallel for num_threads(opt.num_threads) + for (int q = 0; q < channels; q++) + { + float* ptr = bottom_top_blob.channel(q); + + int remain = size; + +#if __riscv_vector + asm volatile( + "L0: \n" + "vsetvli t0, %1, e32, m8 \n" + "vle32.v v0, (%0) \n" + "vfmax.vf v0, v0, %4 \n" + "vfmin.vf v0, v0, %5 \n" + "vse32.v v0, (%0) \n" + "slli t1, t0, 2 \n" + "add %0, %0, t1 \n" + "sub %1, %1, t0 \n" + "bnez %1, L0 \n" + : "=r"(ptr), // %0 + "=r"(remain) // %1 + : "0"(ptr), + "1"(remain), + "f"(min), // %4 + "f"(max) // %5 + : "cc", "memory", "t0", "t1"); +#else // __riscv_vector + for (; remain > 0; remain--) + { + if (*ptr < min) + *ptr = min; + + if (*ptr > max) + *ptr = max; + + ptr++; + } +#endif // __riscv_vector + } + + return 0; +} + +} //namespace ncnn diff --git a/src/layer/riscv/clip_riscv.h b/src/layer/riscv/clip_riscv.h new file mode 100644 index 000000000..0c346b3fe --- /dev/null +++ b/src/layer/riscv/clip_riscv.h @@ -0,0 +1,32 @@ +// 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 LAYER_CLIP_RISCV_H +#define LAYER_CLIP_RISCV_H + +#include "clip.h" + +namespace ncnn { + +class Clip_riscv : virtual public Clip +{ +public: + Clip_riscv(); + + virtual int forward_inplace(Mat& bottom_top_blob, const Option& opt) const; +}; + +} // namespace ncnn + +#endif // LAYER_CLIP_RISCV_H diff --git a/src/platform.h.in b/src/platform.h.in index ca647c423..39532d070 100644 --- a/src/platform.h.in +++ b/src/platform.h.in @@ -19,6 +19,7 @@ #cmakedefine01 NCNN_STRING #cmakedefine01 NCNN_OPENCV #cmakedefine01 NCNN_SIMPLESTL +#cmakedefine01 NCNN_THREADS #cmakedefine01 NCNN_BENCHMARK #cmakedefine01 NCNN_PIXEL #cmakedefine01 NCNN_PIXEL_ROTATE @@ -27,6 +28,7 @@ #cmakedefine01 NCNN_REQUANT #cmakedefine01 NCNN_AVX2 +#if NCNN_THREADS #if (defined _WIN32 && !(defined __MINGW32__)) #define WIN32_LEAN_AND_MEAN #include @@ -34,6 +36,7 @@ #else #include #endif +#endif // NCNN_THREADS #if __ANDROID_API__ >= 26 #define VK_USE_PLATFORM_ANDROID_KHR @@ -41,6 +44,7 @@ namespace ncnn { +#if NCNN_THREADS #if (defined _WIN32 && !(defined __MINGW32__)) class Mutex { @@ -134,6 +138,34 @@ private: pthread_t t; }; #endif // _WIN32 +#else // NCNN_THREADS +class Mutex +{ +public: + Mutex() {} + ~Mutex() {} + void lock() {} + void unlock() {} +}; + +class ConditionVariable +{ +public: + ConditionVariable() {} + ~ConditionVariable() {} + void wait(Mutex& /*mutex*/) {} + void broadcast() {} + void signal() {} +}; + +class Thread +{ +public: + Thread(void* (*/*start*/)(void*), void* /*args*/ = 0) {} + ~Thread() {} + void join() {} +}; +#endif // NCNN_THREADS } // namespace ncnn diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 57b202b96..e1939d219 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -2,7 +2,8 @@ macro(ncnn_add_test name) add_executable(test_${name} test_${name}.cpp) target_link_libraries(test_${name} PRIVATE ncnn) - add_test(test_${name} test_${name}) + + add_test(NAME test_${name} COMMAND ${CMAKE_COMMAND} -DTEST_EXECUTABLE=$ -P ${CMAKE_CURRENT_SOURCE_DIR}/../cmake/run_test.cmake) # add test to a virtual project group set_property(TARGET test_${name} PROPERTY FOLDER "tests") diff --git a/tests/test_binaryop.cpp b/tests/test_binaryop.cpp index 7e9f20ce7..c6e824ada 100644 --- a/tests/test_binaryop.cpp +++ b/tests/test_binaryop.cpp @@ -282,29 +282,29 @@ int main() for (op_type = 0; op_type < OP_TYPE_MAX; op_type++) { int ret = 0 - || test_binaryop_1() - || test_binaryop_2() - || test_binaryop_3() - || test_binaryop_4() - || test_binaryop_5() - || test_binaryop_6() - || test_binaryop_7() - || test_binaryop_8() - || test_binaryop_9() - || test_binaryop_10() - || test_binaryop_11() - || test_binaryop_12() - || test_binaryop_13() - || test_binaryop_14() - || test_binaryop_15() - || test_binaryop_16() - || test_binaryop_17() - || test_binaryop_18() - || test_binaryop_19() - || test_binaryop_s1() - || test_binaryop_s2() - || test_binaryop_s3() - || test_binaryop_s4(); + || test_binaryop_1() + || test_binaryop_2() + || test_binaryop_3() + || test_binaryop_4() + || test_binaryop_5() + || test_binaryop_6() + || test_binaryop_7() + || test_binaryop_8() + || test_binaryop_9() + || test_binaryop_10() + || test_binaryop_11() + || test_binaryop_12() + || test_binaryop_13() + || test_binaryop_14() + || test_binaryop_15() + || test_binaryop_16() + || test_binaryop_17() + || test_binaryop_18() + || test_binaryop_19() + || test_binaryop_s1() + || test_binaryop_s2() + || test_binaryop_s3() + || test_binaryop_s4(); if (ret != 0) return ret; diff --git a/toolchains/riscv64-unknown-elf.toolchain.cmake b/toolchains/riscv64-unknown-elf.toolchain.cmake new file mode 100644 index 000000000..f2bebbaf1 --- /dev/null +++ b/toolchains/riscv64-unknown-elf.toolchain.cmake @@ -0,0 +1,19 @@ +set(CMAKE_SYSTEM_NAME Generic) +set(CMAKE_SYSTEM_PROCESSOR riscv64) + +if(DEFINED ENV{RISCV_ROOT_PATH}) + file(TO_CMAKE_PATH $ENV{RISCV_ROOT_PATH} RISCV_ROOT_PATH) +else() + message(FATAL_ERROR "RISCV_ROOT_PATH env must be defined") +endif() + +set(RISCV_ROOT_PATH ${RISCV_ROOT_PATH} CACHE STRING "root path to riscv toolchain") + +set(CMAKE_C_COMPILER "${RISCV_ROOT_PATH}/bin/riscv64-unknown-elf-gcc") +set(CMAKE_CXX_COMPILER "${RISCV_ROOT_PATH}/bin/riscv64-unknown-elf-g++") + +set(CMAKE_FIND_ROOT_PATH "${RISCV_ROOT_PATH}/riscv64-unknown-elf") + +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)