diff --git a/.github/workflows/linux-riscv64.yml b/.github/workflows/linux-riscv64.yml index 82741908e55..d4e4c56edcc 100644 --- a/.github/workflows/linux-riscv64.yml +++ b/.github/workflows/linux-riscv64.yml @@ -92,7 +92,7 @@ jobs: run: | export RISCV_ROOT_PATH=/data/action/osd/Xuantie-900-gcc-linux-6.6.0-glibc-x86_64-V3.0.1 mkdir build && cd build - cmake -DCMAKE_TOOLCHAIN_FILE=../toolchains/c906-v301.toolchain.cmake -DCMAKE_BUILD_TYPE=release -DNCNN_OPENMP=OFF -DNCNN_THREADS=OFF -DNCNN_RUNTIME_CPU=OFF -DNCNN_XTHEADVECTOR=ON -DNCNN_RVV=OFF -DNCNN_ZFH=OFF -DNCNN_SIMPLEOCV=ON -DNCNN_BUILD_EXAMPLES=ON -DNCNN_BUILD_TESTS=ON .. + cmake -DCMAKE_TOOLCHAIN_FILE=../toolchains/c906-v301.toolchain.cmake -DCMAKE_BUILD_TYPE=release -DNCNN_OPENMP=OFF -DNCNN_THREADS=OFF -DNCNN_RUNTIME_CPU=OFF -DNCNN_RVV=OFF -DNCNN_XTHEADVECTOR=ON -DNCNN_ZFH=ON -DNCNN_SIMPLEOCV=ON -DNCNN_BUILD_EXAMPLES=ON -DNCNN_BUILD_TESTS=ON .. - name: build continue-on-error: true run: cmake --build build -j 8 @@ -114,7 +114,7 @@ jobs: run: | export RISCV_ROOT_PATH=/data/action/osd/Xuantie-900-gcc-linux-6.6.0-glibc-x86_64-V3.0.1 mkdir build && cd build - cmake -DCMAKE_TOOLCHAIN_FILE=../toolchains/c910-v301.toolchain.cmake -DCMAKE_BUILD_TYPE=release -DNCNN_OPENMP=ON -DNCNN_RUNTIME_CPU=OFF -DNCNN_XTHEADVECTOR=ON -DNCNN_RVV=OFF -DNCNN_ZFH=OFF -DNCNN_SIMPLEOCV=ON -DNCNN_BUILD_EXAMPLES=ON -DNCNN_BUILD_TESTS=ON .. + cmake -DCMAKE_TOOLCHAIN_FILE=../toolchains/c910-v301.toolchain.cmake -DCMAKE_BUILD_TYPE=release -DNCNN_OPENMP=ON -DNCNN_RUNTIME_CPU=OFF -DNCNN_RVV=OFF -DNCNN_XTHEADVECTOR=ON -DNCNN_ZFH=ON -DNCNN_SIMPLEOCV=ON -DNCNN_BUILD_EXAMPLES=ON -DNCNN_BUILD_TESTS=ON .. - name: build continue-on-error: true run: cmake --build build -j 8 diff --git a/CMakeLists.txt b/CMakeLists.txt index c0cddcf325c..6372b28b73b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -420,9 +420,9 @@ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(riscv)") if(CMAKE_SIZEOF_VOID_P EQUAL 8) check_cxx_source_compiles("#if __riscv_v == 7000\nint main() { return 0; }\n#endif\n" NCNN_COMPILER_IS_XUANTIE_GCC) - # if(NCNN_COMPILER_IS_XUANTIE_GCC) - # message(FATAL_ERROR "Since XuanTie GCC Toolchain is not yet ready for RVV1.0, the risc-v optimized code of ncnn has been migrated to the RVV1.0 standard. Please use the old version of ncnn, which can be found at https://github.com/Tencent/ncnn/releases/download/20240820/ncnn-20240820-full-source.zip") - # endif() + if(NCNN_COMPILER_IS_XUANTIE_GCC) + message(WARNING "Since XuanTie GCC Toolchain is not yet ready for RVV1.0, the risc-v optimized code of ncnn has been migrated to the RVV1.0 standard. Please use the old version of ncnn, which can be found at https://github.com/Tencent/ncnn/releases/download/20240820/ncnn-20240820-full-source.zip") + endif() set(CMAKE_REQUIRED_FLAGS "-march=rv64gcv") check_cxx_source_compiles("#include \nint main() { vfloat32m8_t _s, _w; float _v; size_t vl; _s = __riscv_vfmacc_vf_f32m8(_s, _v, _w, vl); vfloat32m1_t _x; vfloat32m1x2_t _xx = __riscv_vcreate_v_f32m1x2(_x, _x); return 0; }" NCNN_COMPILER_SUPPORT_RISCV_V) diff --git a/cmake/ncnn_add_layer.cmake b/cmake/ncnn_add_layer.cmake index 2561edb530a..cbc1b09e0b1 100644 --- a/cmake/ncnn_add_layer.cmake +++ b/cmake/ncnn_add_layer.cmake @@ -420,7 +420,7 @@ macro(ncnn_add_layer class) if(NOT NCNN_RUNTIME_CPU AND NCNN_ZVFH) ncnn_add_arch_opt_source(${class} zfh "-march=rv64gcv_zfh_zvfh -D__fp16=_Float16") elseif(NOT NCNN_RUNTIME_CPU AND NCNN_XTHEADVECTOR) - ncnn_add_arch_opt_source(${class} zfh "-march=rv64gc_zfh_xtheadvector -D__fp16=_Float16") + ncnn_add_arch_opt_source(${class} zfh "-march=rv64gc_zfh_xtheadvector -D__riscv_zvfh=1 -D__fp16=_Float16") else() ncnn_add_arch_opt_source(${class} zfh "-march=rv64gc_zfh -D__fp16=_Float16") endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c4301944055..cd5f9b6728d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -680,7 +680,7 @@ if(NCNN_TARGET_ARCH STREQUAL "riscv" AND CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT C90 set(RISCV_MARCH_FLAG "-march=rv64gc_xtheadvector") if(NCNN_ZFH) set(RISCV_MARCH_FLAG "${RISCV_MARCH_FLAG}_zfh") - target_compile_options(ncnn PRIVATE -D__fp16=_Float16) + target_compile_options(ncnn PRIVATE -D__riscv_zvfh=1 -D__fp16=_Float16) endif() endif() target_compile_options(ncnn PRIVATE ${RISCV_MARCH_FLAG}) diff --git a/src/layer/riscv/instancenorm_riscv_zfh.cpp b/src/layer/riscv/instancenorm_riscv_zfh.cpp index 9751bdbc797..d3ad2cf15d5 100644 --- a/src/layer/riscv/instancenorm_riscv_zfh.cpp +++ b/src/layer/riscv/instancenorm_riscv_zfh.cpp @@ -45,7 +45,7 @@ int InstanceNorm_riscv::forward_inplace_fp16s(Mat& bottom_top_blob, const Option // mean and var float sum = 0.f; float sqsum = 0.f; -#if __riscv_zvfh +#if __riscv_zvfh && !defined(C906) vfloat32m1_t _sum = __riscv_vfmv_s_f_f32m1(0.f, __riscv_vsetvlmax_e32m1()); vfloat32m1_t _sqsum = __riscv_vfmv_s_f_f32m1(0.f, __riscv_vsetvlmax_e32m1()); { @@ -70,7 +70,7 @@ int InstanceNorm_riscv::forward_inplace_fp16s(Mat& bottom_top_blob, const Option } #endif // __riscv_zvfh float mean = sum / size; -#if __riscv_zvfh +#if __riscv_zvfh && !defined(C906) { int n = size; __fp16* ptr_sqsum = ptr; @@ -215,7 +215,7 @@ int InstanceNorm_riscv::forward_inplace_fp16sa(Mat& bottom_top_blob, const Optio // mean and var __fp16 sum = 0.f; __fp16 sqsum = 0.f; -#if __riscv_zvfh +#if __riscv_zvfh && !defined(C906) vfloat16m1_t _sum = __riscv_vfmv_s_f_f16m1(0.f, __riscv_vsetvlmax_e32m1()); vfloat16m1_t _sqsum = __riscv_vfmv_s_f_f16m1(0.f, __riscv_vsetvlmax_e32m1()); { @@ -240,7 +240,7 @@ int InstanceNorm_riscv::forward_inplace_fp16sa(Mat& bottom_top_blob, const Optio } #endif // __riscv_zvfh __fp16 mean = sum / size; -#if __riscv_zvfh +#if __riscv_zvfh && !defined(C906) { int n = size; __fp16* ptr_sqsum = ptr; diff --git a/toolchains/c906-v301.toolchain.cmake b/toolchains/c906-v301.toolchain.cmake index e67e0b0c14a..3ef3c0f655e 100644 --- a/toolchains/c906-v301.toolchain.cmake +++ b/toolchains/c906-v301.toolchain.cmake @@ -30,12 +30,12 @@ if(NOT CMAKE_FIND_ROOT_PATH_MODE_PACKAGE) set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) endif() -set(CMAKE_C_FLAGS "-march=rv64gc_zfh_xtheadvector_xtheadc -mabi=lp64d -mtune=c906 -DC906=1 -static") -set(CMAKE_CXX_FLAGS "-march=rv64gc_zfh_xtheadvector_xtheadc -mabi=lp64d -mtune=c906 -DC906=1 -static") +set(CMAKE_C_FLAGS "-march=rv64gc_zfh_xtheadvector_xtheadc -mabi=lp64d -mtune=c906 -DC906=1 -D__riscv_zvfh=1 -static") +set(CMAKE_CXX_FLAGS "-march=rv64gc_zfh_xtheadvector_xtheadc -mabi=lp64d -mtune=c906 -DC906=1 -D__riscv_zvfh=1 -static") # cache flags set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "c flags") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "c++ flags") # export RISCV_ROOT_PATH=/home/nihui/osd/Xuantie-900-gcc-linux-6.6.0-glibc-x86_64-V3.0.1 -# cmake -DCMAKE_TOOLCHAIN_FILE=../toolchains/c906-v301.toolchain.cmake -DCMAKE_BUILD_TYPE=release -DNCNN_BUILD_TESTS=ON -DNCNN_OPENMP=OFF -DNCNN_THREADS=OFF -DNCNN_RUNTIME_CPU=OFF -DNCNN_ZFH=ON -DNCNN_XTHEADVECTOR=ON -DNCNN_SIMPLEOCV=ON -DNCNN_BUILD_EXAMPLES=ON .. +# cmake -DCMAKE_TOOLCHAIN_FILE=../toolchains/c906-v301.toolchain.cmake -DCMAKE_BUILD_TYPE=release -DNCNN_BUILD_TESTS=ON -DNCNN_OPENMP=OFF -DNCNN_THREADS=OFF -DNCNN_RUNTIME_CPU=OFF -DNCNN_RVV=OFF -DNCNN_XTHEADVECTOR=ON -DNCNN_ZFH=ON -DNCNN_SIMPLEOCV=ON -DNCNN_BUILD_EXAMPLES=ON .. diff --git a/toolchains/c910-v301.toolchain.cmake b/toolchains/c910-v301.toolchain.cmake index 145a4415bde..503d0c73f50 100644 --- a/toolchains/c910-v301.toolchain.cmake +++ b/toolchains/c910-v301.toolchain.cmake @@ -30,12 +30,12 @@ if(NOT CMAKE_FIND_ROOT_PATH_MODE_PACKAGE) set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) endif() -set(CMAKE_C_FLAGS "-march=rv64gc_zfh_xtheadvector_xtheadc -mabi=lp64d -mtune=c910 -DC906=1 -static") -set(CMAKE_CXX_FLAGS "-march=rv64gc_zfh_xtheadvector_xtheadc -mabi=lp64d -mtune=c910 -DC906=1 -static") +set(CMAKE_C_FLAGS "-march=rv64gc_zfh_xtheadvector_xtheadc -mabi=lp64d -mtune=c910 -DC906=1 -D__riscv_zvfh=1 -static") +set(CMAKE_CXX_FLAGS "-march=rv64gc_zfh_xtheadvector_xtheadc -mabi=lp64d -mtune=c910 -DC906=1 -D__riscv_zvfh=1 -static") # cache flags set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "c flags") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "c++ flags") # export RISCV_ROOT_PATH=/home/nihui/osd/Xuantie-900-gcc-linux-6.6.0-glibc-x86_64-V3.0.1 -# cmake -DCMAKE_TOOLCHAIN_FILE=../toolchains/c910-v301.toolchain.cmake -DCMAKE_BUILD_TYPE=release -DNCNN_BUILD_TESTS=ON -DNCNN_OPENMP=ON -DNCNN_RUNTIME_CPU=OFF -DNCNN_ZFH=ON -DNCNN_XTHEADVECTOR=ON -DNCNN_SIMPLEOCV=ON -DNCNN_BUILD_EXAMPLES=ON .. +# cmake -DCMAKE_TOOLCHAIN_FILE=../toolchains/c910-v301.toolchain.cmake -DCMAKE_BUILD_TYPE=release -DNCNN_BUILD_TESTS=ON -DNCNN_OPENMP=ON -DNCNN_RUNTIME_CPU=OFF -DNCNN_RVV=OFF -DNCNN_XTHEADVECTOR=ON -DNCNN_ZFH=ON -DNCNN_SIMPLEOCV=ON -DNCNN_BUILD_EXAMPLES=ON ..