当前位置:   article > 正文

HLS 三角函数报错:undefined reference to ‘cordic_apfixed::circ_table_arctan_128‘

HLS 三角函数报错:undefined reference to ‘cordic_apfixed::circ_table_arctan_128‘

下面这是很笨的方法,只能解决cos函数不能用的问题。后面我在使用hls::log对ap_fixed类型数据进行计算的时候又出现了新的问题,下面这种方法就不适用了。但是这种方法可以帮我们发现问题出在哪,所以请大家简单浏览一下。最全面的方法我放在本文后面。


最近在通过HLS实现一些算法,其中用到了hls::cos函数,写完代码编译报错:

../Vitis_HLS/hls_cordic_apfixed.h:229: undefined reference to `cordic_apfixed::circ_table_arctan_128'
build/xf_computePhaseMap_accel.o: In function `void cordic_apfixed::cordic_circ_apfixed<39, 3, 1>(ap_fixed<39, 3, (ap_q_mode)5, (ap_o_mode)3, 0>&, ap_fixed<39, 3, (ap_q_mode)5, (ap_o_mode)3, 0>&, ap_fixed<39, 3, (ap_q_mode)5, (ap_o_mode)3, 0>&)':
../Vitis_HLS/hls_cordic_apfixed.h:229: undefined reference to `cordic_apfixed::circ_table_arctan_128'
collect2: error: ld returned 1 exit status
  • 1
  • 2
  • 3
  • 4

这个变量在Vitis_HLS/hls_cordic_apfixed.h中,对应的代码是:extern const ap_ufixed<128,2> circ_table_arctan_128[128];,可见该变量是个外部变量。
网上搜了很久,没有相应的解决方案。于是自己研究为什么会这样,个人感觉这个circ_table_arctan_128变量的定义应该是在某个动态链接库中,但是找了一下没找到相应的库,因此只能用最笨的方法了。
circ_table_arctan_128是hls中用在CORDIC算法里面的一些提前计算好的数据,CORDIC算法我就不介绍了,自己百度一下网上很多,一般用在FPGA中简化三角函数的计算。那我们其实可以自己算出来这个数组然后直接修改这个头文件代码。通过GPT大法,我最终算出了可靠的值,大家直接将extern const ap_ufixed<128,2> circ_table_arctan_128[128];这行代码替换为:


  const ap_ufixed<128,2> circ_table_arctan_128[128] = {
  0.7853981633974483,  // atan(2^-0)
  0.4636476090008061,  // atan(2^-1)
  0.24497866312686414, // atan(2^-2)
  0.12435499454676144, // atan(2^-3)
  0.06241880999595735, // atan(2^-4)
  0.031239833430268277, // atan(2^-5)
  0.015623728620476831, // atan(2^-6)
  0.007812341060101111, // atan(2^-7)
  0.0039062301319669718, // atan(2^-8)
  0.0019531225164788188, // atan(2^-9)
  0.0009765621895593195, // atan(2^-10)
  0.0004882812111948983, // atan(2^-11)
  0.00024414062014936177, // atan(2^-12)
  0.00012207031189367021, // atan(2^-13)
  0.00006103515617420877, // atan(2^-14)
  0.000030517578115526396, // atan(2^-15)
  0.000015258789061315762, // atan(2^-16)
  0.00000762939453110197, // atan(2^-17)
  0.000003814697265606496, // atan(2^-18)
  0.000001907348632810187, // atan(2^-19)
  0.0000009536743164059602, // atan(2^-20)
  0.0000004768371582030884, // atan(2^-21)
  0.0000002384185791015576, // atan(2^-22)
  0.00000011920928955078125, // atan(2^-23)
  0.00000005960464477539063, // atan(2^-24)
  0.00000002980232238769531, // atan(2^-25)
  0.000000014901161193847656, // atan(2^-26)
  0.000000007450580596923828, // atan(2^-27)
  0.000000003725290298461914, // atan(2^-28)
  0.000000001862645149230957, // atan(2^-29)
  0.0000000009313225746154785, // atan(2^-30)
  0.0000000004656612873077393, // atan(2^-31)
  0.0000000002328306436538696, // atan(2^-32)
  0.0000000001164153218269348, // atan(2^-33)
  0.00000000005820766091346741, // atan(2^-34)
  0.0000000000291038304567337, // atan(2^-35)
  0.00000000001455191522836685, // atan(2^-36)
  0.000000000007275957614183426, // atan(2^-37)
  0.000000000003637978807091713, // atan(2^-38)
  0.000000000001818989403545856, // atan(2^-39)
  0.0000000000009094947017729282, // atan(2^-40)
  0.0000000000004547473508864641, // atan(2^-41)
  0.0000000000002273736754432321, // atan(2^-42)
  0.000000000000113686837721616, // atan(2^-43)
  0.00000000000005684341886080801, // atan(2^-44)
  0.00000000000002842170943040401, // atan(2^-45)
  0.000000000000014210854715202, // atan(2^-46)
  0.000000000000007105427357601002, // atan(2^-47)
  0.000000000000003552713678800501, // atan(2^-48)
  0.00000000000000177635683940025, // atan(2^-49)
  0.0000000000000008881784197001251, // atan(2^-50)
  0.0000000000000004440892098500626, // atan(2^-51)
  0.0000000000000002220446049250313, // atan(2^-52)
  0.0000000000000001110223024625156, // atan(2^-53)
  0.00000000000000005551115123125783, // atan(2^-54)
  0.00000000000000002775557561562892, // atan(2^-55)
  0.00000000000000001387778780781446, // atan(2^-56)
  0.000000000000000006938893903907228, // atan(2^-57)
  0.000000000000000003469446951953614, // atan(2^-58)
  0.000000000000000001734723475976807, // atan(2^-59)
  0.0000000000000000008673617379884035, // atan(2^-60)
  0.0000000000000000004336808689942018, // atan(2^-61)
  0.0000000000000000002168404344971009, // atan(2^-62)
  0.0000000000000000001084202172485504, // atan(2^-63)
  0.00000000000000000005421010862427521, // atan(2^-64)
  0.00000000000000000002710505431213761, // atan(2^-65)
  0.0000000000000000000135525271560688, // atan(2^-66)
  0.000000000000000000006776263578034402, // atan(2^-67)
  0.000000000000000000003388131789017201, // atan(2^-68)
  0.000000000000000000001694065894508601, // atan(2^-69)
  0.0000000000000000000008470329472543004, // atan(2^-70)
  0.0000000000000000000004235164736271502, // atan(2^-71)
  0.0000000000000000000002117582368135751, // atan(2^-72)
  0.0000000000000000000001058791184067876, // atan(2^-73)
  0.00000000000000000000005293955920339378, // atan(2^-74)
  0.00000000000000000000002646977960169689, // atan(2^-75)
  0.00000000000000000000001323488980084845, // atan(2^-76)
  0.000000000000000000000006617444900424225, // atan(2^-77)
  0.000000000000000000000003308722450212113, // atan(2^-78)
  0.000000000000000000000001654361225106056, // atan(2^-79)
  0.000000000000000000000000827180612553028, // atan(2^-80)
  0.000000000000000000000000413590306276514, // atan(2^-81)
  0.000000000000000000000000206795153138257, // atan(2^-82)
  0.0000000000000000000000001033975765691285, // atan(2^-83)
  0.00000000000000000000000005169878828456426, // atan(2^-84)
  0.00000000000000000000000002584939414228213, // atan(2^-85)
  0.00000000000000000000000001292469707114106, // atan(2^-86)
  0.000000000000000000000000006462348535570531, // atan(2^-87)
  0.000000000000000000000000003231174267785265, // atan(2^-88)
  0.000000000000000000000000001615587133892633, // atan(2^-89)
  0.0000000000000000000000000008075935474463164, // atan(2^-90)
  0.0000000000000000000000000004037967737231582, // atan(2^-91)
  0.0000000000000000000000000002018983868615791, // atan(2^-92)
  0.0000000000000000000000000001009491934307896, // atan(2^-93)
  0.00000000000000000000000000005047459671539478, // atan(2^-94)
  0.00000000000000000000000000002523729835769739, // atan(2^-95)
  0.0000000000000000000000000000126186491788487, // atan(2^-96)
  0.000000000000000000000000000006309324589424349, // atan(2^-97)
  0.000000000000000000000000000003154662294712175, // atan(2^-98)
  0.000000000000000000000000000001577331147356087, // atan(2^-99)
  0.0000000000000000000000000000007886655736780435, // atan(2^-100)
  0.0000000000000000000000000000003943327868390218, // atan(2^-101)
  0.0000000000000000000000000000001971663934195109, // atan(2^-102)
  0.00000000000000000000000000000009858319670975544, // atan(2^-103)
  0.00000000000000000000000000000004929159835487772, // atan(2^-104)
  0.00000000000000000000000000000002464579917743886, // atan(2^-105)
  0.00000000000000000000000000000001232289958871943, // atan(2^-106)
  0.000000000000000000000000000000006161449794359716, // atan(2^-107)
  0.000000000000000000000000000000003080724897179858, // atan(2^-108)
  0.000000000000000000000000000000001540362448589929, // atan(2^-109)
  0.0000000000000000000000000000000007701812242949645, // atan(2^-110)
  0.0000000000000000000000000000000003850906121474823, // atan(2^-111)
  0.0000000000000000000000000000000001925453060737411, // atan(2^-112)
  0.00000000000000000000000000000000009627265303687056, // atan(2^-113)
  0.00000000000000000000000000000000004813632651843528, // atan(2^-114)
  0.00000000000000000000000000000000002406816325921764, // atan(2^-115)
  0.00000000000000000000000000000000001203408162960882, // atan(2^-116)
  0.00000000000000000000000000000000000601704081480441, // atan(2^-117)
  0.000000000000000000000000000000000003008520407402205, // atan(2^-118)
  0.000000000000000000000000000000000001504260203701103, // atan(2^-119)
  0.0000000000000000000000000000000000007521301018505515, // atan(2^-120)
  0.0000000000000000000000000000000000003760650509252758, // atan(2^-121)
  0.0000000000000000000000000000000000001880325254626379, // atan(2^-122)
  0.00000000000000000000000000000000000009401626273131894, // atan(2^-123)
  0.00000000000000000000000000000000000004700813136565947, // atan(2^-124)
  0.00000000000000000000000000000000000002350406568282974, // atan(2^-125)
  0.00000000000000000000000000000000000001175203284141487, // atan(2^-126)
  0.000000000000000000000000000000000000005876016420707434 // atan(2^-127)
  };
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131

这样重新编译,hls就不会报错了。


分割线


后面使用hls::log<32,12>(ap_fixed<32,12>(1.1f))的时候,又报错:

build/xf_computePhaseMap_accel.o: In function `ap_fixed<32, 16, (ap_q_mode)5, (ap_o_mode)3, 0> log_apfixed_reduce::log<32, 16>(ap_fixed<32, 16, (ap_q_mode)5, (ap_o_mode)3, 0>)':
/root/dong/prj/structured_light_dzh/prj_linux//../Vitis_HLS/hls_log_apfixed.h:756: undefined reference to `log_apfixed_reduce::log_inverse_lut_table::array'
/root/dong/prj/structured_light_dzh/prj_linux//../Vitis_HLS/hls_log_apfixed.h:759: undefined reference to `log_apfixed_reduce::log0_lut_table<ap_fixed<29, 7, (ap_q_mode)5, (ap_o_mode)3, 0>, 0, 5, 64>::array'
build/xf_computePhaseMap_accel.o: In function `void cordic_apfixed::cordic_circ_apfixed<34, 3, 0>(ap_fixed<34, 3, (ap_q_mode)5, (ap_o_mode)3, 0>&, ap_fixed<34, 3, (ap_q_mode)5, (ap_o_mode)3, 0>&, ap_fixed<34, 3, (ap_q_mode)5, (ap_o_mode)3, 0>&)':
  • 1
  • 2
  • 3
  • 4

TMD,我快崩溃了。百度和Google都无果。奶奶的,改成ap_int就能用,改成ap_fixed就不行了。看了一下报错的头文件发现log_apfixed_reduce::log_inverse_lut_table::array里面的array只有定义,但是没有赋值就直接使用了。说白了还是找不到源文件的问题,也找不到源文件编译出来的动态链接库。

没办法,只能去Vitis_hls的安装目录下面找相似的内容,还真让我找到了。

/tools/Xilinx/Vitis_HLS/2021.1/src
  • 1

这个文件夹中有两个压缩包:hls_math.zip, hlsgraph.zip,我们需要的就在hls_math.zip里面,通过unzip hls_math.zip将该压缩包进行解压,cd hls_math进入到该文件夹中,通过ls查看内容:

root@fc31f9cc99b9:/tools/Xilinx/Vitis_HLS/2021.1/src/hls_math# ls
Makefile  include  lib  obj  src
  • 1
  • 2

通过vim打开Makefile:

vim Makefile
  • 1

HLS_DIR := $(shell vivado_hls -root_dir)直接修改为HLS的根路径,我这里是:HLS_DIR := /tools/Xilinx/Vitis_HLS/2021.1/,然后将CXX := $(HLS_DIR)/lnx64/tools/gcc/bin/g++改为你自己的C++编译器路径,我这里是:CXX := /usr/bin/g++,然后保存退出::wq
返回terminal,直接执行:make,等待文件编译完成,由于源文件太多,编译需要花费较长时间。编译完成后会在lib/文件夹中生成两个动态链接库:

libhlsm.so  libhlsmc++.so
  • 1

这两个链接库可以不完美的解决我们的问题。为什么说是不完美的解决呢?因为当我把这两个链接库添加到Makefile之后(添加方法请看:使用HLS FFT报错: undefined reference to‘xilinx_ip_xfft_v9_1_*‘问题解决方法),又报错(吐了家人们):
makefile:

LIBVITIS_LIB := /tools/Xilinx/Vitis_HLS/2021.1/src/hls_math/lib
CFLAGS += -L$(LIBVITIS_LIB)  -lhlsmc++ -lhlsm 
run: $(OBJ)
	$(ECHO_OFF) $(CC) $(CFLAGS) -I$(INCDIR) $^ -o $@ -lhlsmc++ -lhlsm 
  • 1
  • 2
  • 3
  • 4

报错:

/tools/Xilinx/Vitis_HLS/2021.1/src/hls_math/lib/libhlsmc++.so: undefined reference to `xip_fpo_rec_flt'
/tools/Xilinx/Vitis_HLS/2021.1/src/hls_math/lib/libhlsmc++.so: undefined reference to `xip_fpo_greater_d'
/tools/Xilinx/Vitis_HLS/2021.1/src/hls_math/lib/libhlsmc++.so: undefined reference to `xip_fpo_equal'
/tools/Xilinx/Vitis_HLS/2021.1/src/hls_math/lib/libhlsmc++.so: undefined reference to `xip_fpo_rec_d'
/tools/Xilinx/Vitis_HLS/2021.1/src/hls_math/lib/libhlsmc++.so: undefined reference to `xip_fpo_less'
/tools/Xilinx/Vitis_HLS/2021.1/src/hls_math/lib/libhlsmc++.so: undefined reference to `xip_fpo_set_nan'
/tools/Xilinx/Vitis_HLS/2021.1/src/hls_math/lib/libhlsmc++.so: undefined reference to `xip_fpo_get_flt'
/tools/Xilinx/Vitis_HLS/2021.1/src/hls_math/lib/libhlsmc++.so: undefined reference to `xip_fpo_set_inf'
/tools/Xilinx/Vitis_HLS/2021.1/src/hls_math/lib/libhlsmc++.so: undefined reference to `xip_fpo_init2'
/tools/Xilinx/Vitis_HLS/2021.1/src/hls_math/lib/libhlsmc++.so: undefined reference to `xip_fpo_equal_flt'
/tools/Xilinx/Vitis_HLS/2021.1/src/hls_math/lib/libhlsmc++.so: undefined reference to `xip_fpo_sub_flt'
/tools/Xilinx/Vitis_HLS/2021.1/src/hls_math/lib/libhlsmc++.so: undefined reference to `xip_fpo_greaterequal_flt'
/tools/Xilinx/Vitis_HLS/2021.1/src/hls_math/lib/libhlsmc++.so: undefined reference to `xip_fpo_set_flt'
/tools/Xilinx/Vitis_HLS/2021.1/src/hls_math/lib/libhlsmc++.so: undefined reference to `xip_fpo_add_flt'
/tools/Xilinx/Vitis_HLS/2021.1/src/hls_math/lib/libhlsmc++.so: undefined reference to `xip_fpo_clear'
/tools/Xilinx/Vitis_HLS/2021.1/src/hls_math/lib/libhlsmc++.so: undefined reference to `xip_fpo_sqrt_flt'
/tools/Xilinx/Vitis_HLS/2021.1/src/hls_math/lib/libhlsmc++.so: undefined reference to `xip_fpo_greater'
/tools/Xilinx/Vitis_HLS/2021.1/src/hls_math/lib/libhlsmc++.so: undefined reference to `xip_fpo_exp_d'
/tools/Xilinx/Vitis_HLS/2021.1/src/hls_math/lib/libhlsmc++.so: undefined reference to `xip_fpo_greaterequal_d'
/tools/Xilinx/Vitis_HLS/2021.1/src/hls_math/lib/libhlsmc++.so: undefined reference to `xip_fpo_inits2'
/tools/Xilinx/Vitis_HLS/2021.1/src/hls_math/lib/libhlsmc++.so: undefined reference to `xip_fpo_recsqrt_d'
/tools/Xilinx/Vitis_HLS/2021.1/src/hls_math/lib/libhlsmc++.so: undefined reference to `xip_fpo_greater_flt'
/tools/Xilinx/Vitis_HLS/2021.1/src/hls_math/lib/libhlsmc++.so: undefined reference to `xip_fpo_log_flt'
/tools/Xilinx/Vitis_HLS/2021.1/src/hls_math/lib/libhlsmc++.so: undefined reference to `xip_fpo_notequal_flt'
/tools/Xilinx/Vitis_HLS/2021.1/src/hls_math/lib/libhlsmc++.so: undefined reference to `xip_fpo_set_zero'
/tools/Xilinx/Vitis_HLS/2021.1/src/hls_math/lib/libhlsmc++.so: undefined reference to `xip_fpo_less_flt'
/tools/Xilinx/Vitis_HLS/2021.1/src/hls_math/lib/libhlsmc++.so: undefined reference to `xip_fpo_mul'
/tools/Xilinx/Vitis_HLS/2021.1/src/hls_math/lib/libhlsmc++.so: undefined reference to `xip_fpo_div_flt'
/tools/Xilinx/Vitis_HLS/2021.1/src/hls_math/lib/libhlsmc++.so: undefined reference to `xip_fpo_mul_flt'
/tools/Xilinx/Vitis_HLS/2021.1/src/hls_math/lib/libhlsmc++.so: undefined reference to `xip_fpo_exp_flt'
/tools/Xilinx/Vitis_HLS/2021.1/src/hls_math/lib/libhlsmc++.so: undefined reference to `xip_fpo_equal_d'
/tools/Xilinx/Vitis_HLS/2021.1/src/hls_math/lib/libhlsmc++.so: undefined reference to `xip_fpo_clears'
/tools/Xilinx/Vitis_HLS/2021.1/src/hls_math/lib/libhlsmc++.so: undefined reference to `xip_fpo_less_d'
/tools/Xilinx/Vitis_HLS/2021.1/src/hls_math/lib/libhlsmc++.so: undefined reference to `xip_fpo_div'
/tools/Xilinx/Vitis_HLS/2021.1/src/hls_math/lib/libhlsmc++.so: undefined reference to `xip_fpo_div_d'
/tools/Xilinx/Vitis_HLS/2021.1/src/hls_math/lib/libhlsmc++.so: undefined reference to `xip_fpo_lessequal_d'
/tools/Xilinx/Vitis_HLS/2021.1/src/hls_math/lib/libhlsmc++.so: undefined reference to `xip_fpo_lessequal_flt'
/tools/Xilinx/Vitis_HLS/2021.1/src/hls_math/lib/libhlsmc++.so: undefined reference to `xip_fpo_recsqrt_flt'
/tools/Xilinx/Vitis_HLS/2021.1/src/hls_math/lib/libhlsmc++.so: undefined reference to `xip_fpo_notequal_d'
/tools/Xilinx/Vitis_HLS/2021.1/src/hls_math/lib/libhlsmc++.so: undefined reference to `xip_fpo_log_d'
/tools/Xilinx/Vitis_HLS/2021.1/src/hls_math/lib/libhlsmc++.so: undefined reference to `xip_fpo_add'
/tools/Xilinx/Vitis_HLS/2021.1/src/hls_math/lib/libhlsmc++.so: undefined reference to `xip_fpo_lessequal'
/tools/Xilinx/Vitis_HLS/2021.1/src/hls_math/lib/libhlsmc++.so: undefined reference to `xip_fpo_greaterequal'
/tools/Xilinx/Vitis_HLS/2021.1/src/hls_math/lib/libhlsmc++.so: undefined reference to `xip_fpo_sqrt_d'
/tools/Xilinx/Vitis_HLS/2021.1/src/hls_math/lib/libhlsmc++.so: undefined reference to `xip_fpo_notequal'
/tools/Xilinx/Vitis_HLS/2021.1/src/hls_math/lib/libhlsmc++.so: undefined reference to `xip_fpo_sub'
/tools/Xilinx/Vitis_HLS/2021.1/src/hls_math/lib/libhlsmc++.so: undefined reference to `xip_fpo_mul_d'
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47

尼玛,服了。google了一下,有篇文章提到了相关的:Support for arbitrary precision floating point types in SDSOC,但是里面提到的方法不管用。好好好,这么玩是吧。

然后我又发现这里报错都和fpo相关,想到之前在:/tools/Xilinx/Vitis_HLS/2021.1/lnx64/tools/fpo_v7_0中看到过这个东西。然后将下列代码加入makefile中:

LIBVITIS_LIB := /tools/Xilinx/Vitis_HLS/2021.1/lnx64/tools/fpo_v7_0
CFLAGS += -L$(LIBVITIS_LIB)  -lIp_floating_point_v7_0_bitacc_cmodel -lmpfr
run: $(OBJ)
	$(ECHO_OFF) $(CC) $(CFLAGS) -I$(INCDIR) $^ -o $@  -lIp_floating_point_v7_0_bitacc_cmodel -lmpfr
  • 1
  • 2
  • 3
  • 4

至此,完美解决。记录下来,希望能帮到和我遇到一样问题的朋友。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/94090
推荐阅读
相关标签
  

闽ICP备14008679号