Skip to content

Commit

Permalink
more strict compiler rvv checks, drop rvv-071 support (#4094)
Browse files Browse the repository at this point in the history
  • Loading branch information
nihui authored Jul 28, 2022
1 parent 0666143 commit b4ba207
Show file tree
Hide file tree
Showing 41 changed files with 45 additions and 1,981 deletions.
11 changes: 9 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(mips)")
set(NCNN_TARGET_ARCH mips)

include(CheckCXXCompilerFlag)

check_cxx_compiler_flag("-mmsa" NCNN_COMPILER_SUPPORT_MIPS_MSA)

set(CMAKE_REQUIRED_FLAGS "-mloongson-mmi -I${CMAKE_CURRENT_SOURCE_DIR}/src/layer/mips")
Expand All @@ -293,8 +294,14 @@ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(riscv)")
set(NCNN_TARGET_ARCH riscv)

include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-march=rv64gcv" NCNN_COMPILER_SUPPORT_RVV)
check_cxx_compiler_flag("-march=rv64gcv_zfh" NCNN_COMPILER_SUPPORT_RVV_FP16)

set(CMAKE_REQUIRED_FLAGS "-march=rv64gcv")
check_cxx_source_compiles("#include <riscv_vector.h>\nint main() { vfloat32m1_t _s, _w; float _v; word_type vl; _s = vfmacc_vf_f32m1(_s, _v, _w, vl); return 0; }" NCNN_COMPILER_SUPPORT_RVV)

set(CMAKE_REQUIRED_FLAGS "-march=rv64gcv_zfh")
check_cxx_source_compiles("#include <riscv_vector.h>\nint main() { vfloat16m1_t _s, _w; __fp16 _v; word_type vl; _s = vfmacc_vf_f16m1(_s, _v, _w, vl); return 0; }" NCNN_COMPILER_SUPPORT_RVV_FP16)

unset(CMAKE_REQUIRED_FLAGS)

if(NCNN_COMPILER_SUPPORT_RVV)
option(NCNN_RVV "optimize risc-v platform with v extension" ON)
Expand Down
79 changes: 36 additions & 43 deletions cmake/ncnn_check_rvv_vfredusum.cmake
Original file line number Diff line number Diff line change
@@ -1,52 +1,45 @@
include(CheckCXXSourceCompiles)
include(CheckIncludeFile)

set(TEMP_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
set(CMAKE_REQUIRED_FLAGS "-march=rv64gcv")

if(NOT C906)
check_include_file(riscv_vector.h NCNN_RVV_COMPILER_SUPPORT_INTRINSIC)
endif()

if(NCNN_RVV_COMPILER_SUPPORT_INTRINSIC)
check_cxx_source_compiles("
#include <riscv_vector.h>
int main(void)
{
float in1[4] = {-1.f,0.f,+1.f,2.f};
float out1=0;
word_type vl = vsetvl_e32m8(4);
vfloat32m8_t _add = vle32_v_f32m8(in1,vl);
vfloat32m1_t _sum = vfmv_s_f_f32m1(vundefined_f32m1(),out1,vl);
_sum = vfredsum_vs_f32m8_f32m1(_sum, _add, _sum, vl);
out1 = vfmv_f_s_f32m1_f32(_sum);
return 0;
}
" NCNN_COMPILER_USE_VFREDSUM)
check_cxx_source_compiles("
#include <riscv_vector.h>
int main(void)
{
float in1[4] = {-1.f,0.f,+1.f,2.f};
float out1=0;
word_type vl = vsetvl_e32m8(4);
vfloat32m8_t _add = vle32_v_f32m8(in1,vl);
vfloat32m1_t _sum = vfmv_s_f_f32m1(vundefined_f32m1(),out1,vl);
_sum = vfredusum_vs_f32m8_f32m1(_sum, _add, _sum, vl);
out1 = vfmv_f_s_f32m1_f32(_sum);
return 0;
};
" NCNN_COMPILER_USE_VFREDUSUM)
check_cxx_source_compiles("
#include <riscv_vector.h>
int main(void)
{
float in1[4] = {-1.f,0.f,+1.f,2.f};
float out1=0;
word_type vl = vsetvl_e32m8(4);
vfloat32m8_t _add = vle32_v_f32m8(in1,vl);
vfloat32m1_t _sum = vfmv_s_f_f32m1(vundefined_f32m1(),out1,vl);
_sum = vfredsum_vs_f32m8_f32m1(_sum, _add, _sum, vl);
out1 = vfmv_f_s_f32m1_f32(_sum);
return 0;
}
" NCNN_COMPILER_USE_VFREDSUM)
check_cxx_source_compiles("
#include <riscv_vector.h>
int main(void)
{
float in1[4] = {-1.f,0.f,+1.f,2.f};
float out1=0;
word_type vl = vsetvl_e32m8(4);
vfloat32m8_t _add = vle32_v_f32m8(in1,vl);
vfloat32m1_t _sum = vfmv_s_f_f32m1(vundefined_f32m1(),out1,vl);
_sum = vfredusum_vs_f32m8_f32m1(_sum, _add, _sum, vl);
out1 = vfmv_f_s_f32m1_f32(_sum);
return 0;
};
" NCNN_COMPILER_USE_VFREDUSUM)

if(NCNN_COMPILER_USE_VFREDSUM AND NOT NCNN_COMPILER_USE_VFREDUSUM)
message(WARNING "The compiler uses vfredsum. Upgrading your toolchain is strongly recommended.")
foreach(LMUL 1 2 4 8)
add_definitions(-Dvfredusum_vs_f32m${LMUL}_f32m1=vfredsum_vs_f32m${LMUL}_f32m1)
if(NCNN_COMPILER_SUPPORT_RVV_FP16)
add_definitions(-Dvfredusum_vs_f16m${LMUL}_f16m1=vfredsum_vs_f16m${LMUL}_f16m1)
endif()
endforeach()
endif()
if(NCNN_COMPILER_USE_VFREDSUM AND NOT NCNN_COMPILER_USE_VFREDUSUM)
message(WARNING "The compiler uses vfredsum. Upgrading your toolchain is strongly recommended.")
foreach(LMUL 1 2 4 8)
add_definitions(-Dvfredusum_vs_f32m${LMUL}_f32m1=vfredsum_vs_f32m${LMUL}_f32m1)
if(NCNN_COMPILER_SUPPORT_RVV_FP16)
add_definitions(-Dvfredusum_vs_f16m${LMUL}_f16m1=vfredsum_vs_f16m${LMUL}_f16m1)
endif()
endforeach()
endif()

set(CMAKE_REQUIRED_FLAGS ${TEMP_CMAKE_REQUIRED_FLAGS})
Expand Down
4 changes: 0 additions & 4 deletions src/layer/riscv/absval_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@
#include "absval_riscv.h"

#if __riscv_vector
#ifdef RVV_SPEC_0_7
#include "riscv_v_071_fix.h"
#else
#include <riscv_vector.h>
#endif

static inline vfloat32m8_t vfabs_v_f32m8_absval(vfloat32m8_t op1, size_t vl)
{
Expand Down
4 changes: 0 additions & 4 deletions src/layer/riscv/binaryop_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@
#include <math.h>

#if __riscv_vector
#ifdef RVV_SPEC_0_7
#include "riscv_v_071_fix.h"
#else
#include <riscv_vector.h>
#endif
#include "rvv_mathfun.h"
#include "rvv_mathfun_fp16s.h"
#endif // __riscv_vector
Expand Down
4 changes: 0 additions & 4 deletions src/layer/riscv/cast_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@
#include "cast_riscv.h"

#if __riscv_vector
#ifdef RVV_SPEC_0_7
#include "riscv_v_071_fix.h"
#else
#include <riscv_vector.h>
#endif
#endif // __riscv_vector

namespace ncnn {
Expand Down
4 changes: 0 additions & 4 deletions src/layer/riscv/clip_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@
#include "clip_riscv.h"

#if __riscv_vector
#ifdef RVV_SPEC_0_7
#include "riscv_v_071_fix.h"
#else
#include <riscv_vector.h>
#endif
#include "rvv_mathfun.h"
#include "rvv_mathfun_fp16s.h"
#endif // __riscv_vector
Expand Down
4 changes: 0 additions & 4 deletions src/layer/riscv/concat_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@
#include "concat_riscv.h"

#if __riscv_vector
#ifdef RVV_SPEC_0_7
#include "riscv_v_071_fix.h"
#else
#include <riscv_vector.h>
#endif
#endif // __riscv_vector

#include "riscv_usability.h"
Expand Down
4 changes: 0 additions & 4 deletions src/layer/riscv/convolution1d_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@
#include "convolution1d_riscv.h"

#if __riscv_vector
#ifdef RVV_SPEC_0_7
#include "riscv_v_071_fix.h"
#else
#include <riscv_vector.h>
#endif
#endif // __riscv_vector

#include "riscv_activation.h"
Expand Down
4 changes: 0 additions & 4 deletions src/layer/riscv/convolution_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@
#include "layer_type.h"

#if __riscv_vector
#ifdef RVV_SPEC_0_7
#include "riscv_v_071_fix.h"
#else
#include <riscv_vector.h>
#endif
#endif // __riscv_vector

#include "riscv_activation.h"
Expand Down
4 changes: 0 additions & 4 deletions src/layer/riscv/convolutiondepthwise_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@
#include "layer_type.h"

#if __riscv_vector
#ifdef RVV_SPEC_0_7
#include "riscv_v_071_fix.h"
#else
#include <riscv_vector.h>
#endif
#endif // __riscv_vector

#include "riscv_activation.h"
Expand Down
4 changes: 0 additions & 4 deletions src/layer/riscv/crop_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@
#include "crop_riscv.h"

#if __riscv_vector
#ifdef RVV_SPEC_0_7
#include "riscv_v_071_fix.h"
#else
#include <riscv_vector.h>
#endif
#endif // __riscv_vector

#include "riscv_usability.h"
Expand Down
4 changes: 0 additions & 4 deletions src/layer/riscv/deconvolution_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@
#include "layer_type.h"

#if __riscv_vector
#ifdef RVV_SPEC_0_7
#include "riscv_v_071_fix.h"
#else
#include <riscv_vector.h>
#endif
#endif // __riscv_vector

#include "riscv_activation.h"
Expand Down
4 changes: 0 additions & 4 deletions src/layer/riscv/deconvolutiondepthwise_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@
#include "layer_type.h"

#if __riscv_vector
#ifdef RVV_SPEC_0_7
#include "riscv_v_071_fix.h"
#else
#include <riscv_vector.h>
#endif
#endif // __riscv_vector

#include "riscv_activation.h"
Expand Down
4 changes: 0 additions & 4 deletions src/layer/riscv/dropout_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@
#include "dropout_riscv.h"

#if __riscv_vector
#ifdef RVV_SPEC_0_7
#include "riscv_v_071_fix.h"
#else
#include <riscv_vector.h>
#endif
#endif // __riscv_vector

namespace ncnn {
Expand Down
4 changes: 0 additions & 4 deletions src/layer/riscv/flatten_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@
#include "flatten_riscv.h"

#if __riscv_vector
#ifdef RVV_SPEC_0_7
#include "riscv_v_071_fix.h"
#else
#include <riscv_vector.h>
#endif
#endif // __riscv_vector

#include "riscv_usability.h"
Expand Down
4 changes: 0 additions & 4 deletions src/layer/riscv/gelu_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@
#include "gelu_riscv.h"

#if __riscv_vector
#ifdef RVV_SPEC_0_7
#include "riscv_v_071_fix.h"
#else
#include <riscv_vector.h>
#endif
#include "rvv_mathfun.h"
#endif // __riscv_vector

Expand Down
4 changes: 0 additions & 4 deletions src/layer/riscv/gru_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@
#include "gru_riscv.h"

#if __riscv_vector
#ifdef RVV_SPEC_0_7
#include "riscv_v_071_fix.h"
#else
#include <riscv_vector.h>
#endif
#endif // __riscv_vector

namespace ncnn {
Expand Down
4 changes: 0 additions & 4 deletions src/layer/riscv/hardsigmoid_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@
#include "hardsigmoid_riscv.h"

#if __riscv_vector
#ifdef RVV_SPEC_0_7
#include "riscv_v_071_fix.h"
#else
#include <riscv_vector.h>
#endif
#endif // __riscv_vector

namespace ncnn {
Expand Down
4 changes: 0 additions & 4 deletions src/layer/riscv/hardswish_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@
#include "hardswish_riscv.h"

#if __riscv_vector
#ifdef RVV_SPEC_0_7
#include "riscv_v_071_fix.h"
#else
#include <riscv_vector.h>
#endif
#endif // __riscv_vector

namespace ncnn {
Expand Down
4 changes: 0 additions & 4 deletions src/layer/riscv/innerproduct_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@
#include "layer_type.h"

#if __riscv_vector
#ifdef RVV_SPEC_0_7
#include "riscv_v_071_fix.h"
#else
#include <riscv_vector.h>
#endif
#endif // __riscv_vector

#include "riscv_activation.h"
Expand Down
4 changes: 0 additions & 4 deletions src/layer/riscv/interp_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@
#include <math.h>

#if __riscv_vector
#ifdef RVV_SPEC_0_7
#include "riscv_v_071_fix.h"
#else
#include <riscv_vector.h>
#endif
#include "riscv_usability.h"
#endif // __riscv_vector

Expand Down
4 changes: 0 additions & 4 deletions src/layer/riscv/mish_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@
#include "mish_riscv.h"

#if __riscv_vector
#ifdef RVV_SPEC_0_7
#include "riscv_v_071_fix.h"
#else
#include <riscv_vector.h>
#endif
#include "rvv_mathfun.h"
#include "rvv_mathfun_fp16s.h"
#endif // __riscv_vector
Expand Down
4 changes: 0 additions & 4 deletions src/layer/riscv/packing_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@
#include "packing_riscv.h"

#if __riscv_vector
#ifdef RVV_SPEC_0_7
#include "riscv_v_071_fix.h"
#else
#include <riscv_vector.h>
#endif
#endif // __riscv_vector

namespace ncnn {
Expand Down
4 changes: 0 additions & 4 deletions src/layer/riscv/padding_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@
#include "padding_riscv.h"

#if __riscv_vector
#ifdef RVV_SPEC_0_7
#include "riscv_v_071_fix.h"
#else
#include <riscv_vector.h>
#endif
#endif // __riscv_vector

#include "riscv_usability.h"
Expand Down
4 changes: 0 additions & 4 deletions src/layer/riscv/pooling_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@
#include <float.h>

#if __riscv_vector
#ifdef RVV_SPEC_0_7
#include "riscv_v_071_fix.h"
#else
#include <riscv_vector.h>
#endif
#endif // __riscv_vector

#include "riscv_usability.h"
Expand Down
Loading

3 comments on commit b4ba207

@baibeta
Copy link

@baibeta baibeta commented on b4ba207 Jan 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May I ask why rvv0.7.1 support is removed? Thanks

@nihui
Copy link
Member Author

@nihui nihui commented on b4ba207 Jan 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May I ask why rvv0.7.1 support is removed? Thanks

because the new c906 toolchain dropped rvv0.7.1 intrinsics support and gained rvv1.0 intrinsics.

@baibeta
Copy link

@baibeta baibeta commented on b4ba207 Jan 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May I ask why rvv0.7.1 support is removed? Thanks

because the new c906 toolchain dropped rvv0.7.1 intrinsics support and gained rvv1.0 intrinsics.

Thanks

Please sign in to comment.