Add a conservative RISC-V build path for TensorFlow Lite dependencies#869
Conversation
|
Thank you for contributing! If I understand correctly, a The XNNPACK readme (https://github.com/google/XNNPACK) lists support for 'RISC-V (RV32GC and RV64GC)'. Perhaps I'm misunderstanding something here, so let me know if what I said is not correct. |
|
Thanks, that is a fair concern. My previous change was too broad and would have disabled the accelerated path for all |
|
Thanks for the detailed feedback. I pushed an update in The condition is now narrower:
If I also re-checked both branches of the condition locally:
|
Tombana
left a comment
There was a problem hiding this comment.
Two suggestions to simplify things, and can you revert the changes to README.md ?
|
Thanks for the suggestions. I pushed a follow-up in Please take another look when you have time. |
Why
Larq Compute Engine already has portable bitpacking, BGEMM, and indirect-BGEMM paths for non-AArch64 targets, but its bundled TensorFlow Lite dependency chain is not conservative enough for a
riscv64Linux target that lackssys/hwprobe.h.In a fresh
dockcross/linux-riscv64cross-build, third-partycpuinfostill tried to compile its RISC-V Linuxhwprobesource and failed before the portable kernels could be used. The goal of this patch is not to disable acceleration for all RISC-V systems, but to provide a conservative fallback only when that target header is unavailable while preserving the upstream accelerated path on RISC-V systems that do provide it.What changed
CMakeLists.txtsoriscv*Linux targets first probe forsys/hwprobe.h.TFLITE_ENABLE_XNNPACKand expose a smallcmake/riscv_cpuinfo_shim/library ascpuinfo::cpuinfo.cpuinfo_initialize() == false, which lets TensorFlow Lite's bundledruyfall back to its existing fixed-cache conservative path instead of depending on Linuxhwprobeheaders.sys/hwprobe.his available, the upstreamcpuinfo/ XNNPACK path is left unchanged.Verification
riscv64cross-build completed successfully indockcross/linux-riscv64with:cmake -S /work -B /tmp/build -G Ninja -DCOMPILE_BENCHMARK=OFFcmake --build /tmp/build --parallel 4CMakeCache.txtfrom that real build records:TFLITE_ENABLE_XNNPACK:BOOL=OFFRUY_FIND_CPUINFO:BOOL=OFFbuild.ninjashows:cmake/riscv_cpuinfo_shim/cpuinfo.ccompiled intolibcpuinfo.asrc/riscv/linux/riscv-hw.c-DTFLITE_WITHOUT_XNNPACKfileandreadelf -hconfirm the producedexamplebinary is a real RISC-V ELF executable.qemu-riscv64 -L ... -E LD_LIBRARY_PATH=/lib:/usr/lib ./examplestarts successfully and prints:lce_minimal <tflite model>sys/hwprobe.h, the RISC-V fallback path is selected;sys/hwprobe.h, the fallback path is not selected.Notes
hwprobesupport.cpuinfoshim is only used onriscv*Linux targets that do not providesys/hwprobe.h, and its behavior is deliberately minimal: fail feature detection cleanly so bundledruycan use its already-existing fallback path.