cpu-feats.cpp 749 B

1234567891011121314151617181920212223242526272829303132333435
  1. #include "ggml-backend-impl.h"
  2. #if defined(__riscv) && __riscv_xlen == 64
  3. #include <sys/auxv.h>
  4. //https://github.com/torvalds/linux/blob/master/arch/riscv/include/uapi/asm/hwcap.h#L24
  5. #ifndef COMPAT_HWCAP_ISA_V
  6. #define COMPAT_HWCAP_ISA_V (1 << ('V' - 'A'))
  7. #endif
  8. struct riscv64_features {
  9. bool has_rvv = false;
  10. riscv64_features() {
  11. uint32_t hwcap = getauxval(AT_HWCAP);
  12. has_rvv = !!(hwcap & COMPAT_HWCAP_ISA_V);
  13. }
  14. };
  15. static int ggml_backend_cpu_riscv64_score() {
  16. int score = 1;
  17. riscv64_features rf;
  18. #ifdef GGML_USE_RVV
  19. if (!rf.has_rvv) { return 0; }
  20. score += 1 << 1;
  21. #endif
  22. return score;
  23. }
  24. GGML_BACKEND_DL_SCORE_IMPL(ggml_backend_cpu_riscv64_score)
  25. #endif // __riscv && __riscv_xlen == 64