highway icon indicating copy to clipboard operation
highway copied to clipboard

Failure to compile with clang++ 20 on riscv64

Open andreas-schwab opened this issue 8 months ago • 12 comments

$ clang++ -c -stdlib=libc++ -I. hwy/per_target.cc In file included from hwy/per_target.cc:28: In file included from ./hwy/highway.h:629: ./hwy/ops/rvv-inl.h:644:17: error: use of undeclared identifier '__riscv_vsetvlmax_e8mf8' 644 | HWY_RVV_FOREACH(HWY_RVV_LANES, Lanes, setvlmax_e, _ALL) | ^ ./hwy/ops/rvv-inl.h:644:17: error: use of undeclared identifier '__riscv_vsetvl_e8mf8' ./hwy/ops/rvv-inl.h:644:17: error: use of undeclared identifier '__riscv_vsetvl_e8mf8' ./hwy/ops/rvv-inl.h:644:17: error: use of undeclared identifier '__riscv_vsetvlmax_e16mf4' ./hwy/ops/rvv-inl.h:644:17: error: use of undeclared identifier '__riscv_vsetvl_e16mf4' ./hwy/ops/rvv-inl.h:644:17: error: use of undeclared identifier '__riscv_vsetvl_e16mf4' ./hwy/ops/rvv-inl.h:644:17: error: use of undeclared identifier '__riscv_vsetvlmax_e32mf2' ./hwy/ops/rvv-inl.h:644:17: error: use of undeclared identifier '__riscv_vsetvl_e32mf2' ./hwy/ops/rvv-inl.h:644:17: error: use of undeclared identifier '__riscv_vsetvl_e32mf2' ./hwy/ops/rvv-inl.h:644:17: error: use of undeclared identifier '__riscv_vsetvlmax_e64m1' ./hwy/ops/rvv-inl.h:644:17: error: use of undeclared identifier '__riscv_vsetvl_e64m1' ./hwy/ops/rvv-inl.h:644:17: error: use of undeclared identifier '__riscv_vsetvl_e64m1' ./hwy/ops/rvv-inl.h:644:17: error: use of undeclared identifier '__riscv_vsetvlmax_e64m2' ./hwy/ops/rvv-inl.h:644:17: error: use of undeclared identifier '__riscv_vsetvl_e64m2' ./hwy/ops/rvv-inl.h:644:17: error: use of undeclared identifier '__riscv_vsetvl_e64m2' ./hwy/ops/rvv-inl.h:644:17: error: use of undeclared identifier '__riscv_vsetvlmax_e64m4' ./hwy/ops/rvv-inl.h:644:17: error: use of undeclared identifier '__riscv_vsetvl_e64m4' ./hwy/ops/rvv-inl.h:644:17: error: use of undeclared identifier '__riscv_vsetvl_e64m4' ./hwy/ops/rvv-inl.h:644:17: error: use of undeclared identifier '__riscv_vsetvlmax_e64m8' fatal error: too many errors emitted, stopping now [-ferror-limit=] 20 errors generated.

andreas-schwab avatar Apr 07 '25 21:04 andreas-schwab

Hi, due to https://github.com/llvm/llvm-project/issues/56592 clang currently still requires a flag like -march=rv64gcv1p0. HTH?

jan-wassenberg avatar Apr 08 '25 05:04 jan-wassenberg

Why does it work with clang++ 19 then?

andreas-schwab avatar Apr 08 '25 08:04 andreas-schwab

The difference is that clang 20 started advertising support for __riscv_v_intrinsic, without which we do not attempt to use RVV.

jan-wassenberg avatar Apr 08 '25 08:04 jan-wassenberg

Thanks for checking. 11000 used to be correct (0.11), but we can update to 1.0.

jan-wassenberg avatar Apr 30 '25 12:04 jan-wassenberg

For reference, commit 6bd4bdded4fe666dc90872fd4472b967b6e5cd55 implies that Clang 20.1.x is now required when compiling for RISC-V, see: https://github.com/llvm/llvm-project/commit/05b3d26181ade32f5988d2be4939f605a5225782

kleisauke avatar May 06 '25 11:05 kleisauke

Right. Unfortunately Clang had a breaking change with VXRM for which there was no feature test. Requiring 1.0 'fails safe' in that regard. You can override this by defining HWY_BASELINE_TARGETS directly.

jan-wassenberg avatar May 06 '25 11:05 jan-wassenberg

@andreas-schwab and @jan-wassenberg, the issue was that Clang 20 and later on RISC-V define __riscv_v_intrinsic, even when the "V" extension is not enabled. I have implemented a fix in pull request #2586 that fixes this issue that checks that __riscv_v is also defined.

johnplatts avatar Jun 05 '25 13:06 johnplatts

That's how it is supposed to be, see the RISC-V Vector C Intrinsic Specification:

Chapter 2. Test macro The __riscv_v_intrinsic macro is the C macro to test the compiler’s support for the RISC-V "V" extension intrinsics. This macro should be defined even if the vector extension is not enabled.

andreas-schwab avatar Jun 05 '25 13:06 andreas-schwab

That's how it is supposed to be, see the RISC-V Vector C Intrinsic Specification:

Chapter 2. Test macro The __riscv_v_intrinsic macro is the C macro to test the compiler’s support for the RISC-V "V" extension intrinsics. This macro should be defined even if the vector extension is not enabled.

@andreas-schwab Thanks for pointing this out.

I have also made some additional changes to rvv_ops-inl.h and set_macros-inl.h in pull request #2587 that along with the changes in pull request #2586 allow Google Highway to be compiled for RISC-V with dynamic dispatch enabled with Clang 20 or later.

johnplatts avatar Jun 05 '25 17:06 johnplatts

Thanks @johnplatts ! I believe this is now fixed, closing.

jan-wassenberg avatar Jul 04 '25 09:07 jan-wassenberg

I have also made some additional changes to rvv_ops-inl.h and set_macros-inl.h in pull request #2587 that along with the changes in pull request #2586 allow Google Highway to be compiled for RISC-V with dynamic dispatch enabled with Clang 20 or later.

Could the RVV runtime dispatch check be fixed then? It is currently still disabled by && 0: https://github.com/google/highway/blob/master/hwy/detect_targets.h#L752

kxxt avatar Jul 04 '25 13:07 kxxt

hm, if it's just a matter of removing the && 0 sure, but when I also remove gcv from the build flags, there are build failures with float16 sseg2 when building interleaved_test.

jan-wassenberg avatar Jul 04 '25 17:07 jan-wassenberg