Skip to content

Conversation

@junchao-loongson
Copy link
Contributor

@junchao-loongson junchao-loongson commented Oct 29, 2025

  1. Add safeint header file application path to MLAS
  2. Fix syntax errors in sqnbitgem and lasx

@lixing-star

Description

  1. Prior to [LARCH64 CPU]Provide inference acceleration optimization for Loongson CPU with 4-bit quantized models #26280, SafeInt was not utilized in MLAS. The CMake script did not include the SafeInt header file path, resulting in a compilation error reporting that SafeInt.hpp could not be found. In the patch, I added this path (if there are other better methods, please let me know).
    在 #26280 之前MLAS中没有使用到SafeInt,cmake脚本没有包含SafeInt头文件路径,编译会提示找不到SafeInt.hpp头文件,补丁中我添加了该路径(如果有其他更好方法请告诉我)
[ 11%] Building CXX object CMakeFiles/onnxruntime_mlas.dir/home/zjc/work/ai/onnxruntime/onnxruntime/core/mlas/lib/sqnbitgemm_kernel_lasx.cpp.o
In file included from /home/zjc/work/ai/onnxruntime/onnxruntime/core/mlas/lib/sqnbitgemm_kernel_lasx_common.h:9,
                 from /home/zjc/work/ai/onnxruntime/onnxruntime/core/mlas/lib/sqnbitgemm_kernel_lasx.cpp:25:
/home/zjc/work/ai/onnxruntime/onnxruntime/core/common/safeint.h:35:10: fatal error: SafeInt.hpp: No such file or directory
   35 | #include "SafeInt.hpp"

  1. In commit [LARCH64 CPU]Provide inference acceleration optimization for Loongson CPU with 4-bit quantized models #26280 (4cae30a), there is a syntax error in the code. The Value() member does not exist in SafeInt 3.0.28, and the compiler will report the following compilation error:
    在 #26280 中4cae30acd43efa4209fd4f8681932d7d3c3e9263 commit代码存在语法错误,SafeInt 3.0.28中并不存在Value()成员,编译器会报以下编译错误
In file included from /home/zjc/work/ai/onnxruntime/onnxruntime/core/mlas/lib/sqnbitgemm_kernel_lasx.cpp:25:
/home/zjc/work/ai/onnxruntime/onnxruntime/core/mlas/lib/sqnbitgemm_kernel_lasx_common.h: In function ‘size_t GetContinueLayoutOffsetSubBlk(size_t, size_t, size_t, size_t)’:
/home/zjc/work/ai/onnxruntime/onnxruntime/core/mlas/lib/sqnbitgemm_kernel_lasx_common.h:71:29: error: ‘class SafeInt<long unsigned int>’ has no member named ‘Value’
   71 |     return scale_dst_offset.Value();
      |                             ^~~~~
/home/zjc/work/ai/onnxruntime/onnxruntime/core/mlas/lib/sqnbitgemm_kernel_lasx_common.h: In function ‘size_t GetContinueLayoutOffsetBlkInSubBlk(size_t, size_t, size_t, size_t, int)’:
/home/zjc/work/ai/onnxruntime/onnxruntime/core/mlas/lib/sqnbitgemm_kernel_lasx_common.h:90:29: error: ‘class SafeInt<long unsigned int>’ has no member named ‘Value’
   90 |     return scale_dst_offset.Value();
      |                             ^~~~~
/home/zjc/work/ai/onnxruntime/onnxruntime/core/mlas/lib/sqnbitgemm_kernel_lasx_common.h: In lambda function:
/home/zjc/work/ai/onnxruntime/onnxruntime/core/mlas/lib/sqnbitgemm_kernel_lasx_common.h:110:61: error: ‘const class SafeInt<long unsigned int>’ has no member named ‘Value’
  110 |         float QuantBScale = QuantBScaleBegin[src_blk_offset.Value()];
      |                                                             ^~~~~
/home/zjc/work/ai/onnxruntime/onnxruntime/core/mlas/lib/sqnbitgemm_kernel_lasx_common.h:117:71: error: ‘class SafeInt<long unsigned int>’ has no member named ‘Value’
  117 |             const std::byte* QuantBZP = QuantBZPBegin + src_zp_offset.Value();
      |                                                                       ^~~~~

This patch has passed unit testing. Details are in LastTest.log.
该补丁通过了单元测试,详细信息在LastTest.log
test env:

  • system: Anolis OS
  • CPU: Loongson-3C6000/S
100% tests passed, 0 tests failed out of 9

Total Test time (real) =  83.73 sec
2025-10-29 16:31:23,614 build [INFO] - Build complete

LastTest.zip

Feel free to @ me for any future PRs related to loongarch—I'd be happy to assist with the review.
以后有loongarch相关PR欢迎@我,我很乐意协助审查

1. Add safeint header file application path to MLAS
2. Fix syntax errors in sqnbitgem and lasx

Co-authored-by: lixing [email protected]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant