tum-ei-eda / mlonmcu-sw

Target software library (MLIF, Machine Learning Interface) used by the MLonMCU python package
1 stars 3 forks source link

gcc and llvm support work, but with some problem. Todo: llvm spike su… #9

Closed zhouxinyu0723 closed 1 year ago

zhouxinyu0723 commented 1 year ago

About my current progress:

I tried to add the ara target in mlonmcu-sw. The gcc target works fine now.

But the llvm target has some issues during linking.

There are a list of errors like the following

ld.lld: error: /mnt/d/time_5_semester_TUM/hiwi/ara/install/riscv-gcc/riscv64-unknown-elf/lib/libc.a(lib_a-vfprintf.o):(function _vfprintf_r: .text+0x129e): relocation R_RISCV_HI20 out of range: 524301 is not in [-524288, 524287]; references .LC1

The problem appears in the situation where printf from gcc/lib is used.

It does not appear when llvm lib is used, but then mlonmcu-sw will complain about some missing libraries.

The reason is that lib.a which contains the printf function is located at a very lower address and the program is loaded in a very high address, the address relocation in jmp failed.

This issue can be solved by using the customized printf provided in the ara repo. But then the main.c function is different in that #include"printf.h" is used instead of "#include <stdio.h>".

The issue also appears in the origin example when I add the -lstdc++ and --gcc-toolchain= and --sysroot= flags in the makefile and use "#include <stdio.h>" in the main.

PhilippvK commented 1 year ago

Let me add another requirement here: I want to be able the Number of Cycles and Instructions executed. AFAIK Ara supports the default RISC-V performance counter CSRs, so you can probably just reuse lib/target/generic_riscv.c

PhilippvK commented 1 year ago

I tried using rdinstret() with ara, but it seems to crash in verilator. Let's focus on the Cycle count only which seems to be already working.

PhilippvK commented 1 year ago

BTW, the verilator simulation can be run as wollows from the ara/hardware subdirectory:

build/verilator/Vara_tb_verilator  -l ram,/path/to/mlonmcu/workspace/temp/sessions/latest/runs/0/mlif/bin/generic_mlif,elf
PhilippvK commented 1 year ago

Can you fix the merge conflict?

PhilippvK commented 1 year ago

If ready for merge, please remove draft status

PhilippvK commented 1 year ago

Thank you for your contribution @zhouxinyu0723