foss-xtensa / ndsplib-hifi4

NatureDSP Library for HiFi4 DSP cores
Other
3 stars 2 forks source link

Compile errors on NatureDSP for HiFi4 on i.MX8MP #3

Open iuliana-prodan opened 2 months ago

iuliana-prodan commented 2 months ago

When compiling the NatureDSP Lib from this github repo, for the HiFi4 DSP from i.MX8MP, I get the following error:

ndsplib-hifi4/NDSP_HiFi4/NDSP_HiFi4_v430/build/project/xtclang/library$ make -e XTENSA_SYSTEM= XTENSA_CORE=hifi4_mscale_v2_0_2_prod
xt-clang -pipe    -DDATA_CACHE=0  -I ../../../../library/include  -I ../../../../library/include_private  -O3   -mlongcalls -fno-builtin  -Wall -Wno-return-type -std=c99 -Werror -D__RENAMING__    -c ../../../../library/fir/conv2d/conv2d_5x5f_hifi4.c -o _llvm-Xtensa-release/conv2d_5x5f_hifi4.o 
xt-clang -pipe    -DDATA_CACHE=0  -I ../../../../library/include  -I ../../../../library/include_private  -O3   -mlongcalls -fno-builtin  -Wall -Wno-return-type -std=c99 -Werror -D__RENAMING__    -c ../../../../library/fir/firblk/stereo_bkfir16x16_hifi4.c -o _llvm-Xtensa-release/stereo_bkfir16x16_hifi4.o 
...
xt-clang -pipe    -DDATA_CACHE=0  -I ../../../../library/include  -I ../../../../library/include_private  -O3   -mlongcalls -fno-builtin  -Wall -Wno-return-type -std=c99 -Werror -D__RENAMING__    -c ../../../../library/fir/firblkf/bkfiraf_process_hifi4.c -o _llvm-Xtensa-release/bkfiraf_process_hifi4.o 
../../../../library/fir/firblkf/bkfiraf_process_hifi4.c:171:13: error: implicit declaration of function 'XT_LSX2XC1' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
            XT_LSX2XC1(h01, pH0, 4*sizeof(float32_t));
            ^
../../../../library/fir/firblkf/bkfiraf_process_hifi4.c:225:13: error: implicit declaration of function 'XT_LSX2XC1' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
            XT_LSX2XC1(h01, pH0, 4*sizeof(float32_t));
            ^
../../../../library/fir/firblkf/bkfiraf_process_hifi4.c:287:13: error: implicit declaration of function 'XT_LSX2XC1' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
            XT_LSX2XC1(h01, pH0, 4*sizeof(float32_t));
            ^
../../../../library/fir/firblkf/bkfiraf_process_hifi4.c:171:24: error: variable 'h01' is uninitialized when used here [-Werror,-Wuninitialized]
            XT_LSX2XC1(h01, pH0, 4*sizeof(float32_t));
                       ^~~
../../../../library/fir/firblkf/bkfiraf_process_hifi4.c:99:18: note: initialize the variable 'h01' to silence this warning
    xtfloatx2 h01, h23;
                 ^
                  = 0
../../../../library/fir/firblkf/bkfiraf_process_hifi4.c:172:24: error: variable 'h23' is uninitialized when used here [-Werror,-Wuninitialized]
            XT_LSX2XC1(h23, pH1, 4*sizeof(float32_t));
                       ^~~
../../../../library/fir/firblkf/bkfiraf_process_hifi4.c:99:23: note: initialize the variable 'h23' to silence this warning
    xtfloatx2 h01, h23;
                      ^
                       = 0
5 errors generated.
make: *** [makefile:1658: _llvm-Xtensa-release/bkfiraf_process_hifi4.o] Error 1
iuliana-prodan commented 2 months ago

I believe the problem is that, for bkfiraf_process_hifi4 at line 77 is defined XT_LSX2XC1 only for __LESSTHANLX8__:

#if __LESSTHANLX8__
/* Circular load with using CBEGIN1/CEND1 */
#define XT_LSX2XC1(reg, addr, offs)\
{\
    ae_int32x2 t;\
    AE_L32X2_XC1(t, addr, offs);\
    reg = XT_AE_MOVXTFLOATX2_FROMINT32X2(t);\
}
#endif 

but later is used for both cases (w/ or w/o __LESSTHANLX8__defined - see line 168)

#if __LESSTHANLX8__
            XT_LSX2XC1(h01, castxcc(ae_int32x2,pH0), 4*sizeof(float32_t));
            XT_LSX2XC1(h23, castxcc(ae_int32x2,pH1), 4*sizeof(float32_t));
#else           
            XT_LSX2XC1(h01, pH0, 4*sizeof(float32_t));
            XT_LSX2XC1(h23, pH1, 4*sizeof(float32_t));
#endif 

or at line 221

#if __LESSTHANLX8__
            XT_LSX2XC1(h01, castxcc(ae_int32x2,pH0), 4*sizeof(float32_t));
            XT_LSX2XC1(h23, castxcc(ae_int32x2,pH1), 4*sizeof(float32_t));
#else
            XT_LSX2XC1(h01, pH0, 4*sizeof(float32_t));
            XT_LSX2XC1(h23, pH1, 4*sizeof(float32_t));
#endif

or line 283:

#if __LESSTHANLX8__
            XT_LSX2XC1(h01, castxcc(ae_int32x2,pH0), 4*sizeof(float32_t));
            XT_LSX2XC1(h23, castxcc(ae_int32x2,pH1), 4*sizeof(float32_t));
#else
            XT_LSX2XC1(h01, pH0, 4*sizeof(float32_t));
            XT_LSX2XC1(h23, pH1, 4*sizeof(float32_t));
#endif

@cad-audio @cad-audioNDSP can you please let me know how can I overcome this? Thanks.

cad-audioNDSP commented 2 months ago

Hi Iulia Prodan,

Which toolchain are you using and what is the LX version of the core used? If you are using a toolchain earlier than RJ2024.3 (i.e the core is pre LX8), then you need to enable the flag LESSTHANLX8 In /hifi4_library/include_private/common.h Set #define LESSTHANLX8 1
This should solve the build issue.

iuliana-prodan commented 1 month ago

Hi @cad-audioNDSP,

I'm using Xtensa Toolchain version RI-2023.11-linux, Xtensa Core = hifi4_mscale_v2_0_2_prod. The core is a HiFi4 core which is LX6.

When setting LESSTHANLX8=1 the compilation is ok, I get the library. But I would like to be able to compile the library without modifying the code - just take the code, unzip and compile.

Can we make LESSTHANLX8 a different variable that can be changed from command line, as argument to make command?

Thanks, Iulia

iuliana-prodan commented 1 month ago

@cad-audioNDSP can you please make the following changes: in common.h (from /NDSP_HiFi4_v430/library/include_private/common.h):

diff /ndsplib-hifi4/NDSP_HiFi4/NDSP_HiFi4_v430/library/include_private/common.h ndsplib-hifi4/NDSP_HiFi4/original/NDSP_HiFi4_v430/library/include_private/common.h
35d34
< #ifndef __LESSTHANLX8__
37d35
< #endif

in makefile (from NDSP_HiFi4_v430/build/project/xtclang/library/):

diff makefile ../../../../../original/NDSP_HiFi4_v430/build/project/xtclang/library/
126,130d125
< __LESSTHANLX8__ ?= ""
<  ifneq ($(__LESSTHANLX8__), "")
<     CFLAGS  += -D__LESSTHANLX8__=$(__LESSTHANLX8__)
< endif
< 

With these 2 changes any user can take the code and compile the library for an LX8 or less than LX8 core with a make argument, no need to change the code.

With the above modifications, for an LX6 core I'm compiling the library with: make -e XTENSA_SYSTEM= XTENSA_CORE=hifi4_mscale_v2_0_2_prod __LESSTHANLX8__=1

I can create a pull request for this, but I have access only to the archive. So, is it possible to make these changes?

Thank you!