Skip to content

Commit fda3352

Browse files
committed
fixed for __riscv_v_intrinsic >= 12000
1 parent c17089e commit fda3352

File tree

5 files changed

+23
-14
lines changed

5 files changed

+23
-14
lines changed

cmake/deps.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ dlpack;https://github.com/dmlc/dlpack/archive/refs/tags/v0.6.zip;4d565dd2e5b3132
2222
# it contains changes on top of 3.4.0 which are required to fix build issues.
2323
# Until the 3.4.1 release this is the best option we have.
2424
# Issue link: https://gitlab.com/libeigen/eigen/-/issues/2744
25-
eigen;https://gitlab.com/libeigen/eigen/-/archive/e7248b26a1ed53fa030c5c459f7ea095dfd276ac/eigen-e7248b26a1ed53fa030c5c459f7ea095dfd276ac.zip;be8be39fdbc6e60e94fa7870b280707069b5b81a
25+
eigen;https://gitlab.com/libeigen/eigen/-/archive/e7248b26a1ed53fa030c5c459f7ea095dfd276ac/eigen-e7248b26a1ed53fa030c5c459f7ea095dfd276ac.zip;32b145f525a8308d7ab1c09388b2e288312d8eba
2626
flatbuffers;https://github.com/google/flatbuffers/archive/refs/tags/v23.5.26.zip;59422c3b5e573dd192fead2834d25951f1c1670c
2727
fp16;https://github.com/Maratyszcza/FP16/archive/0a92994d729ff76a58f692d3028ca1b64b145d91.zip;b985f6985a05a1c03ff1bb71190f66d8f98a1494
2828
fxdiv;https://github.com/Maratyszcza/FXdiv/archive/63058eff77e11aa15bf531df5dd34395ec3017c8.zip;a5658f4036402dbca7cebee32be57fb8149811e1

cmake/riscv64.spacemit.toolchain.cmake

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,12 @@ else()
1717
set(CMAKE_CROSSCOMPILING TRUE)
1818
endif()
1919

20-
if(NOT DEFINED CMAKE_CXX_FLAGS)
21-
set(CMAKE_CXX_FLAGS "-march=rv64gcv_zfh_zba")
22-
endif()
23-
24-
if(NOT DEFINED CMAKE_CXX_FLAGS)
25-
set(CMAKE_C_FLAGS "-march=rv64gcv_zfh_zba")
26-
endif()
27-
2820
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
2921
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
3022
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
3123
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
32-
33-
set(CMAKE_C_FLAGS "-march=rv64gcv_zfh_zba -latomic -mabi=lp64d ${CMAKE_C_FLAGS}")
34-
set(CMAKE_CXX_FLAGS "-march=rv64gcv_zfh_zba -latomic -mabi=lp64d ${CXX_FLAGS}")
24+
set(CMAKE_C_FLAGS "-march=rv64gcv_zfh_zba_zicbop -mabi=lp64d ${CMAKE_C_FLAGS}")
25+
set(CMAKE_CXX_FLAGS "-march=rv64gcv_zfh_zba_zicbop -mabi=lp64d ${CXX_FLAGS}")
26+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -latomic")
3527

3628
add_definitions(-D__fp16=_Float16)

onnxruntime/core/mlas/lib/q4gemm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ MlasQ4GemmOperation(
126126

127127
size_t RowsRemaining = RangeCountM;
128128
while (RowsRemaining > 0) {
129-
#if defined(MLAS_TARGET_AMD64_IX86) || defined(MLAS_TARGET_POWER) || defined(MLAS_TARGET_LARCH64) || defined(MLAS_TARGET_RISCV64)
129+
#if defined(MLAS_TARGET_AMD64_IX86) || defined(MLAS_TARGET_POWER) || defined(MLAS_TARGET_LARCH64)
130130
auto RowsHandled = GetMlasPlatform().GemmFloatKernel(
131131
a_row, dequant_b, c_blk, K, RowsRemaining, CountN, lda, ldc, 1.f, true);
132132
#else

onnxruntime/core/mlas/lib/quantize.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,11 @@ MlasQuantizeLinear<int8_t>(
923923
vfloat32m4_t vec_f32 = __riscv_vle32_v_f32m4(input_ptr, vl);
924924
vec_f32 = __riscv_vfmul_vf_f32m4(vec_f32, div_scale, vl);
925925
vec_f32 = __riscv_vfadd_vf_f32m4(vec_f32, ZeroPoint, vl);
926+
#if __riscv_v_intrinsic <= 11000
926927
vint8m1_t vec_out = __riscv_vnclip_wx_i8m1(__riscv_vfncvt_x_f_w_i16m2(vec_f32, vl), 0, vl);
928+
#else
929+
vint8m1_t vec_out = __riscv_vnclip_wx_i8m1(__riscv_vfncvt_x_f_w_i16m2(vec_f32, vl), 0, 0, vl);
930+
#endif
927931
__riscv_vse8_v_i8m1(output_ptr, vec_out, vl);
928932
}
929933
}
@@ -950,7 +954,11 @@ MlasQuantizeLinear<uint8_t>(
950954
vec_f32 = __riscv_vfadd_vf_f32m4(vec_f32, ZeroPoint, vl);
951955
vint16m2_t vec_i16 = __riscv_vfncvt_x_f_w_i16m2(vec_f32, vl);
952956
vec_i16 = __riscv_vmax_vx_i16m2(vec_i16, 0, vl);
957+
#if __riscv_v_intrinsic <= 11000
953958
vuint8m1_t vec_out = __riscv_vnclipu_wx_u8m1(__riscv_vreinterpret_v_i16m2_u16m2(vec_i16), 0, vl);
959+
#else
960+
vuint8m1_t vec_out = __riscv_vnclipu_wx_u8m1(__riscv_vreinterpret_v_i16m2_u16m2(vec_i16), 0, 0, vl);
961+
#endif
954962
__riscv_vse8_v_u8m1(output_ptr, vec_out, vl);
955963
}
956964
}
@@ -2078,11 +2086,19 @@ MlasRequantizeOutputImpl(
20782086

20792087
if constexpr (std::is_signed<OutputType>::value) {
20802088
vint16m2_t I16Vector = __riscv_vfncvt_x_f_w_i16m2(FloatVector, vl);
2089+
#if __riscv_v_intrinsic <= 11000
20812090
vint8m1_t OutVector = __riscv_vnclip_wx_i8m1(I16Vector, 0, vl);
2091+
#else
2092+
vint8m1_t OutVector = __riscv_vnclip_wx_i8m1(I16Vector, 0, 0, vl);
2093+
#endif
20822094
__riscv_vse8_v_i8m1(RowOutput, OutVector, vl);
20832095
} else {
20842096
vuint16m2_t U16Vector = __riscv_vfncvt_xu_f_w_u16m2(FloatVector, vl);
2097+
#if __riscv_v_intrinsic <= 11000
20852098
vuint8m1_t OutVector = __riscv_vnclipu_wx_u8m1(U16Vector, 0, vl);
2099+
#else
2100+
vuint8m1_t OutVector = __riscv_vnclipu_wx_u8m1(U16Vector, 0, 0, vl);
2101+
#endif
20862102
__riscv_vse8_v_u8m1(RowOutput, OutVector, vl);
20872103
}
20882104
}

tools/scripts/build_riscv64.spacemit.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#!/bin/bash
22
# Copyright (c) 2023 SpacemiT. All rights reserved.
3-
# bash build_riscv64.spacemit.sh <onnxruntime_src_dir> <arch> <config>,
3+
# bash build_riscv64.spacemit.sh <onnxruntime_src_dir> <arch> <config>,
44
# arch is x86 or rv64, config is Release or RelWithDebInfo or Debug
55
# before run this script, please ensure that RISCV_ROOT_PATH is set to the path of riscv toolchain
6+
# https://archive.spacemit.com/toolchain/spacemit-toolchain-linux-glibc-x86_64-v1.1.2.tar.xz
67

78
ARCH=$(uname -m)
89
MATCH_ARCH=""

0 commit comments

Comments
 (0)