Skip to content

Commit

Permalink
z
Browse files Browse the repository at this point in the history
  • Loading branch information
nihui committed Aug 21, 2024
1 parent 46cd351 commit 270951e
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 14 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on:
- 'src/*'
- 'src/layer/*'
- 'src/layer/arm/**'
- 'src/layer/riscv/**'
- 'src/layer/x86/**'
- 'src/layer/vulkan/**'
pull_request:
Expand All @@ -20,6 +21,7 @@ on:
- 'src/*'
- 'src/layer/*'
- 'src/layer/arm/**'
- 'src/layer/riscv/**'
- 'src/layer/x86/**'
- 'src/layer/vulkan/**'
concurrency:
Expand Down Expand Up @@ -64,6 +66,11 @@ jobs:
mkdir build-x86_64 && cd build-x86_64
cmake ${{ env.NCNN_CMAKE_OPTIONS }} -DANDROID_ABI="x86_64" ..
cmake --build . -j $(nproc)
- name: riscv64
run: |
mkdir build-riscv64 && cd build-riscv64
cmake ${{ env.NCNN_CMAKE_OPTIONS }} -DANDROID_ABI="riscv64" ..
cmake --build . -j $(nproc)
- name: armeabi-v7a-shared
run: |
Expand All @@ -85,6 +92,11 @@ jobs:
mkdir build-x86_64-shared && cd build-x86_64-shared
cmake ${{ env.NCNN_CMAKE_OPTIONS }} -DANDROID_ABI="x86_64" -DNCNN_SHARED_LIB=ON ..
cmake --build . -j $(nproc)
- name: riscv64-shared
run: |
mkdir build-riscv64-shared && cd build-riscv64-shared
cmake ${{ env.NCNN_CMAKE_OPTIONS }} -DANDROID_ABI="riscv64" -DNCNN_SHARED_LIB=ON ..
cmake --build . -j $(nproc)
ndk-r16b:
runs-on: ubuntu-latest
Expand Down
14 changes: 11 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -416,10 +416,10 @@ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(riscv)")

if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(CMAKE_REQUIRED_FLAGS "-march=rv64gcv")
check_cxx_source_compiles("#include <riscv_vector.h>\nint main() { vfloat32m1_t _s, _w; float _v; size_t vl; _s = __riscv_vfmacc_vf_f32m1(_s, _v, _w, vl); return 0; }" NCNN_COMPILER_SUPPORT_RVV)
check_cxx_source_compiles("#include <riscv_vector.h>\nint main() { vfloat32m1_t _s, _w; float _v; size_t vl; _s = __riscv_vfmacc_vf_f32m1(_s, _v, _w, vl); return 0; }" NCNN_COMPILER_SUPPORT_RISCV_V)

set(CMAKE_REQUIRED_FLAGS "-march=rv64gcv_zvfh")
check_cxx_source_compiles("#include <riscv_vector.h>\nint main() { vfloat16m1_t _s, _w; __fp16 _v; size_t vl; _s = __riscv_vfmacc_vf_f16m1(_s, _v, _w, vl); return 0; }" NCNN_COMPILER_SUPPORT_RVV_ZVFH)
check_cxx_source_compiles("#include <riscv_vector.h>\nint main() { vfloat16m1_t _s, _w; __fp16 _v; size_t vl; _s = __riscv_vfmacc_vf_f16m1(_s, _v, _w, vl); return 0; }" NCNN_COMPILER_SUPPORT_RISCV_ZVFH)

# if(NOT NCNN_COMPILER_SUPPORT_RVV_ZFH)
# set(CMAKE_REQUIRED_FLAGS "-march=rv64gcv_zfh_zvfh0p1 -menable-experimental-extensions -D__fp16=_Float16")
Expand All @@ -428,8 +428,16 @@ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(riscv)")

unset(CMAKE_REQUIRED_FLAGS)

if(NCNN_COMPILER_SUPPORT_RVV)
if(NCNN_COMPILER_SUPPORT_RISCV_V)
option(NCNN_RVV "optimize risc-v platform with v extension" ON)
if(NCNN_COMPILER_SUPPORT_RISCV_ZVFH)
if(NCNN_RVV)
option(NCNN_ZVFH "optimize risc-v platform with zvfh extension" ON)
endif()
else()
message(WARNING "The compiler does not support zvfh extension. NCNN_ZVFH will be OFF.")
endif()

# option(NCNN_RVV_CHECK_VFREDSUM "check compilter about support rvv-intrinsic" ON)
# if(NCNN_RVV_CHECK_VFREDSUM)
# include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/ncnn_check_rvv_vfredusum.cmake)
Expand Down
13 changes: 8 additions & 5 deletions cmake/ncnn_add_layer.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -364,13 +364,16 @@ macro(ncnn_add_layer class)

if(NCNN_TARGET_ARCH STREQUAL "riscv" AND CMAKE_SIZEOF_VOID_P EQUAL 8)
if(NCNN_RUNTIME_CPU AND NCNN_RVV)
if(NCNN_COMPILER_SUPPORT_RVV_ZVFH)
ncnn_add_arch_opt_layer(${class} rvv "-march=rv64gcv_zvfh")
ncnn_add_arch_opt_layer(${class} rvv "-march=rv64gcv")

# if(NCNN_COMPILER_SUPPORT_RVV_ZVFH)
# ncnn_add_arch_opt_layer(${class} zvfh "-march=rv64gcv_zvfh")
# elseif(NCNN_COMPILER_SUPPORT_RVV_ZVFH)
# ncnn_add_arch_opt_layer(${class} rvv "-march=rv64gcv_zfh_zvfh0p1 -menable-experimental-extensions -D__fp16=_Float16")
elseif(NCNN_COMPILER_SUPPORT_RVV)
ncnn_add_arch_opt_layer(${class} rvv "-march=rv64gcv")
endif()
# endif()
endif()
if(NCNN_ZVFH)
ncnn_add_arch_opt_source(${class} zvfh "-march=rv64gcv_zvfh")
endif()
endif()

Expand Down
17 changes: 11 additions & 6 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -632,14 +632,19 @@ endif()

if(NCNN_TARGET_ARCH STREQUAL "riscv" AND NOT C906)
if(NOT NCNN_RUNTIME_CPU AND NCNN_RVV)
if(NCNN_COMPILER_SUPPORT_RVV_ZFH)
target_compile_options(ncnn PRIVATE -march=rv64gcv_zfh)
elseif(NCNN_COMPILER_SUPPORT_RVV_ZVFH)
target_compile_options(ncnn PRIVATE -march=rv64gcv_zfh_zvfh0p1 -menable-experimental-extensions -D__fp16=_Float16)
elseif(NCNN_COMPILER_SUPPORT_RVV)
target_compile_options(ncnn PRIVATE -march=rv64gcv)
set(RISCV_MARCH_FLAG "-march=rv64gcv")
if(NCNN_ZVFH)
set(RISCV_MARCH_FLAG "${RISCV_MARCH_FLAG}_zvfh")
endif()
# if(NCNN_COMPILER_SUPPORT_RVV_ZFH)
# target_compile_options(ncnn PRIVATE -march=rv64gcv_zfh)
# elseif(NCNN_COMPILER_SUPPORT_RVV_ZVFH)
# target_compile_options(ncnn PRIVATE -march=rv64gcv_zfh_zvfh0p1 -menable-experimental-extensions -D__fp16=_Float16)
# elseif(NCNN_COMPILER_SUPPORT_RVV)
# target_compile_options(ncnn PRIVATE -march=rv64gcv)
# endif()
endif()
target_compile_options(ncnn PRIVATE ${RISCV_MARCH_FLAG})
endif()

if(NCNN_PPC64LE_VSX)
Expand Down

0 comments on commit 270951e

Please sign in to comment.