Halide icon indicating copy to clipboard operation
Halide copied to clipboard

How to set HL_TARGET to get risc-v elf which Flags is 0x3, RVC, single-float ABI

Open chentaowu opened this issue 3 years ago • 5 comments

hello guys, when i build generator.a with riscv-32-linux-xx,i always get the elf format which Flags is 0x4, double-float ABI, how can i get the elf which Flags with 0x3, RVC, single-float ABI . here i met another question, how to build a none os riscv version halide generator.

chentaowu avatar Jun 27 '22 03:06 chentaowu

Tagging @zvookin, who is most familiar with the RISC-V backend.

steven-johnson avatar Jun 27 '22 15:06 steven-johnson

bumping this @zvookin

I am trying to compile a generator for noOS target with riscv-unknown-linux-gnu-g++ to compile and run a bare metal binary. I am getting errors referring to halide_error, halide_malloc, halide_free, and halide_print:

$ ./gen -r riscv-vector-runtime -e object,c_header -o ././build/sconv-/ target=riscv-noos-64-rvv-vector_bits_512
riscv64-unknown-linux-gnu-ar: creating ./build/sconv-/riscv-vector-gen.a
$ riscv64-unknown-linux-gnu-g++ ./build/sconv-/src/run-riscv.cpp -static ./build/sconv-/riscv-vector-gen.a -o ./build/sconv-/riscv-vector-run -I ./build/sconv- -I /scratch/miles.rusch/llvm17/Halide/build/include -std=c++17 -ldl -lpthread
/nscratch/miles.rusch/riscv-tools-install/bin/../lib/gcc/riscv64-unknown-linux-gnu/12.2.0/../../../../riscv64-unknown-linux-gnu/bin/ld: ./build/sconv-/riscv-vector-gen.a(riscv-vector-runtime.o): in function `Halide::Runtime::Internal::(anonymous namespace)::HeapPrinter<(Halide::Runtime::Internal::PrinterType)1, 1024ull>::~HeapPrinter()':
force_include_types.cpp:(.text._ZN6Halide7Runtime8Internal12_GLOBAL__N_111HeapPrinterILNS1_11PrinterTypeE1ELy1024EED2Ev+0x1e): undefined reference to `halide_error'
/nscratch/miles.rusch/riscv-tools-install/bin/../lib/gcc/riscv64-unknown-linux-gnu/12.2.0/../../../../riscv64-unknown-linux-gnu/bin/ld: ./build/sconv-/riscv-vector-gen.a(riscv-vector-runtime.o): in function `.Lpcrel_hi2':
force_include_types.cpp:(.text._ZNK6Halide7Runtime8Internal11PrinterBase16allocation_errorEv[_ZNK6Halide7Runtime8Internal11PrinterBase16allocation_errorEv]+0x1c): undefined reference to `halide_error'
/nscratch/miles.rusch/riscv-tools-install/bin/../lib/gcc/riscv64-unknown-linux-gnu/12.2.0/../../../../riscv64-unknown-linux-gnu/bin/ld: ./build/sconv-/riscv-vector-gen.a(riscv-vector-runtime.o): in function `.Lpcrel_hi3':
force_include_types.cpp:(.text.halide_default_semaphore_init+0x12): undefined reference to `halide_error'
/nscratch/miles.rusch/riscv-tools-install/bin/../lib/gcc/riscv64-unknown-linux-gnu/12.2.0/../../../../riscv64-unknown-linux-gnu/bin/ld: ./build/sconv-/riscv-vector-gen.a(riscv-vector-runtime.o): in function `.Lpcrel_hi4':
force_include_types.cpp:(.text.halide_default_semaphore_try_acquire+0x12): undefined reference to `halide_error'

miles-rusch-berkeley avatar Feb 14 '24 01:02 miles-rusch-berkeley

Another possible solution to generate baremetal code could be to use riscv-unkown-elf-g++. But right now this doesn't work because it doesn't have -ldl or -lpthread libraries. I am not using parallelism and I am not using dynamic linking, is there a way to compile without these libraries using the riscv elf toolchain?

miles-rusch-berkeley avatar Feb 14 '24 01:02 miles-rusch-berkeley

If the target OS is NoOs, we put very little in the runtime, because we can't reasonably provide an implementation of halide_print that uses posixy functions like printf. I suggest just providing your own implementation of any missing symbols. E.g. for halide_error:

extern "C" void halide_error(void *ucon, const char *message) {
  ... do something with message here...
}

You can see the signature for these functions in HalideRuntime.h

abadams avatar Feb 14 '24 01:02 abadams

AOT compiled code shouldn't need libpthread if it's not using threads and it shouldn't need libdl unless a GPU backend is using it. Sure libHalide needs these things always, but compiled code shouldn't require them if they're not used. Like unless something changed to force stuff to be used somehow.

zvookin avatar Feb 14 '24 07:02 zvookin