HLS 三角函数报错:undefined reference to ‘cordic_apfixed::circ_table_arctan_128‘
最近在通过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
这个变量在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)
};
这样重新编译,hls就不会报错了。