micropython-ulab icon indicating copy to clipboard operation
micropython-ulab copied to clipboard

[BUG] Build for 1 dimensional arrays fails

Open saraverbeecke opened this issue 1 year ago • 5 comments

Describe the bug Error when building ulab for 1 dimension.

Configuration used

#define ULAB_MAX_DIMS (1) // Limit array dimensions to 1D

Output

../../../ulab/code/numpy/compare.c: In function 'compare_nonzero':
../../../ulab/code/numpy/compare.c:511:58: error: 'arrays$' may be used uninitialized [-Werror=maybe-uninitialized]
  511 |                             arrays[ULAB_MAX_DIMS - 1 - d][count] = indices[d];
      |                                                          ^
../../../ulab/code/numpy/compare.c:484:15: note: 'arrays$' was declared here
  484 |     uint16_t *arrays[ULAB_MAX_DIMS];
      |               ^~~~~~
cc1: all warnings being treated as errors
-e See https://github.com/micropython/micropython/wiki/Build-Troubleshooting
make: *** [build-STM32F405RG/code/numpy/compare.o] Error 1
./build.sh: line 82: |: syntax error: operand expected (error token is "|")

saraverbeecke avatar Oct 24 '24 14:10 saraverbeecke

Can you tell a bit more about your platform? I've just compiled the 1D unix port with gcc, and got no errors.

v923z avatar Oct 24 '24 17:10 v923z

I am building Micropython with ulab for a custom stm32f405 board based on PyBoard (PYBV11) on macOS.

Building micropython for a genuine Pyboard (checkout release 1.23) with ulab (checkout release 6.5.5) works with: make BOARD=PYBV11 USER_C_MODULES=../../../ulab all As followed from the ulab README.md

Building with a custom ulab config.h file also works now with: make BOARD=PYBV11 USER_C_MODULES=../../../ulab DULAB_CONFIG_FILE=my_custom_config.h all

I previously used CFLAGS_EXTRA="-DULAB_CONFIG_FILE=my_custom_config.h" as make argument, but placing DULAB_CONFIG_FILE outside the CFLAGS_EXTRA did the trick.

Now building for my custom board failed because I had MICROPY_PY_BUILTINS_COMPLEX set to 0 in my mpconfigboard.h file to save space. It seems that ulab needs this to build. Even when I disable ULAB_SUPPORTS_COMPLEX. I have a working build now, but I would like to save space and get rid of the complex support...

saraverbeecke avatar Oct 25 '24 09:10 saraverbeecke

OK, this is useful information, I can try to get to the bottom of this. Thanks for bringing it up!

v923z avatar Oct 25 '24 19:10 v923z

Now building for my custom board failed because I had MICROPY_PY_BUILTINS_COMPLEX set to 0 in my mpconfigboard.h file to save space. It seems that ulab needs this to build. Even when I disable ULAB_SUPPORTS_COMPLEX. I have a working build now, but I would like to save space and get rid of the complex support...

Wait! If you unset ULAB_SUPPORTS_COMPLEX, then you can no longer need MICROPY_PY_BUILTINS_COMPLEX. In fact, you shouldn't need that, even if you set ULAB_SUPPORTS_COMPLEX. Complexes are treated as pairs of floats, and we don't use any functions that explicitly works with complex numbers. Can you post the offending lines in the compilation output?

v923z avatar Oct 25 '24 19:10 v923z

Now using make BOARD=STM32F405RG USER_C_MODULES=../../../ulab DULAB_CONFIG_FILE=my_custom_config.h all (with the correct usage of the DULAB_CONFIG_FILE argument for make), the compilation is successful but the linker fails. Here is the output where the linker stopped:

LINK build-STM32F405RG/firmware.elf
/Applications/ArmGNUToolchain/13.2.Rel1/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: build-STM32F405RG/code/ulab_tools.o: in function `ulab_tools_mp_obj_is_scalar':
/Users/sarahv/Projects/custom_pyboard/micropython/ports/stm32/../../../ulab/code/ulab_tools.c:276:(.text.ulab_tools_mp_obj_is_scalar+0x30): undefined reference to `mp_type_complex'
/Applications/ArmGNUToolchain/13.2.Rel1/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: build-STM32F405RG/code/ndarray.o: in function `ndarray_set_complex_value':
/Users/sarahv/Projects/custom_pyboard/micropython/ports/stm32/../../../ulab/code/ndarray.c:54:(.text.ndarray_set_complex_value+0x1e): undefined reference to `mp_obj_get_complex'
/Applications/ArmGNUToolchain/13.2.Rel1/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: /Users/sarahv/Projects/custom_pyboard/micropython/ports/stm32/../../../ulab/code/ndarray.c:60:(.text.ndarray_set_complex_value+0x3c): undefined reference to `mp_type_complex'
/Applications/ArmGNUToolchain/13.2.Rel1/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: build-STM32F405RG/code/ndarray.o: in function `ndarray_get_item':
/Users/sarahv/Projects/custom_pyboard/micropython/ports/stm32/../../../ulab/code/ndarray.c:302:(.text.ndarray_get_item+0x12): undefined reference to `mp_obj_new_complex'
/Applications/ArmGNUToolchain/13.2.Rel1/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: build-STM32F405RG/code/ndarray.o: in function `ndarray_assign_elements':
/Users/sarahv/Projects/custom_pyboard/micropython/ports/stm32/../../../ulab/code/ndarray.c:481:(.text.ndarray_assign_elements+0x42): undefined reference to `mp_obj_get_complex'
/Applications/ArmGNUToolchain/13.2.Rel1/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: build-STM32F405RG/code/ndarray.o: in function `ndarray_from_mp_obj':
/Users/sarahv/Projects/custom_pyboard/micropython/ports/stm32/../../../ulab/code/ndarray.c:1662:(.text.ndarray_from_mp_obj+0xe8): undefined reference to `mp_obj_get_complex'
/Applications/ArmGNUToolchain/13.2.Rel1/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: /Users/sarahv/Projects/custom_pyboard/micropython/ports/stm32/../../../ulab/code/ndarray.c:1667:(.text.ndarray_from_mp_obj+0x108): undefined reference to `mp_type_complex'
/Applications/ArmGNUToolchain/13.2.Rel1/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: build-STM32F405RG/code/numpy/carray/carray.o: in function `carray_conjugate':
/Users/sarahv/Projects/custom_pyboard/micropython/ports/stm32/../../../ulab/code/numpy/carray/carray.c:112:(.text.carray_conjugate+0x62): undefined reference to `mp_obj_get_complex'
/Applications/ArmGNUToolchain/13.2.Rel1/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: /Users/sarahv/Projects/custom_pyboard/micropython/ports/stm32/../../../ulab/code/numpy/carray/carray.c:114:(.text.carray_conjugate+0x76): undefined reference to `mp_obj_new_complex'
/Applications/ArmGNUToolchain/13.2.Rel1/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: /Users/sarahv/Projects/custom_pyboard/micropython/ports/stm32/../../../ulab/code/numpy/carray/carray.c:118:(.text.carray_conjugate+0x9c): undefined reference to `mp_type_complex'
/Applications/ArmGNUToolchain/13.2.Rel1/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: build-STM32F405RG/code/numpy/create.o: in function `create_linspace':
/Users/sarahv/Projects/custom_pyboard/micropython/ports/stm32/../../../ulab/code/numpy/create.c:606:(.text.create_linspace+0x50): undefined reference to `mp_obj_get_complex'
/Applications/ArmGNUToolchain/13.2.Rel1/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: /Users/sarahv/Projects/custom_pyboard/micropython/ports/stm32/../../../ulab/code/numpy/create.c:607:(.text.create_linspace+0x5a): undefined reference to `mp_obj_get_complex'
/Applications/ArmGNUToolchain/13.2.Rel1/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: /Users/sarahv/Projects/custom_pyboard/micropython/ports/stm32/../../../ulab/code/numpy/create.c:648:(.text.create_linspace+0xe4): undefined reference to `mp_obj_new_complex'
/Applications/ArmGNUToolchain/13.2.Rel1/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: /Users/sarahv/Projects/custom_pyboard/micropython/ports/stm32/../../../ulab/code/numpy/create.c:650:(.text.create_linspace+0x170): undefined reference to `mp_type_complex'
/Applications/ArmGNUToolchain/13.2.Rel1/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: build-STM32F405RG/code/numpy/vector.o: in function `vector_exp':
/Users/sarahv/Projects/custom_pyboard/micropython/ports/stm32/../../../ulab/code/numpy/vector.c:616:(.text.vector_exp+0x36): undefined reference to `mp_obj_get_complex'
/Applications/ArmGNUToolchain/13.2.Rel1/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: /Users/sarahv/Projects/custom_pyboard/micropython/ports/stm32/../../../ulab/code/numpy/vector.c:618:(.text.vector_exp+0x66): undefined reference to `mp_obj_new_complex'
/Applications/ArmGNUToolchain/13.2.Rel1/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: /Users/sarahv/Projects/custom_pyboard/micropython/ports/stm32/../../../ulab/code/numpy/vector.c:679:(.text.vector_exp+0x114): undefined reference to `mp_type_complex'
/Applications/ArmGNUToolchain/13.2.Rel1/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: build-STM32F405RG/code/numpy/vector.o: in function `vector_sqrt':
/Users/sarahv/Projects/custom_pyboard/micropython/ports/stm32/../../../ulab/code/numpy/vector.c:900:(.text.vector_sqrt+0x4a): undefined reference to `mp_obj_get_complex'
/Applications/ArmGNUToolchain/13.2.Rel1/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: /Users/sarahv/Projects/custom_pyboard/micropython/ports/stm32/../../../ulab/code/numpy/vector.c:904:(.text.vector_sqrt+0x9a): undefined reference to `mp_obj_new_complex'
/Applications/ArmGNUToolchain/13.2.Rel1/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: /Users/sarahv/Projects/custom_pyboard/micropython/ports/stm32/../../../ulab/code/numpy/vector.c:1022:(.text.vector_sqrt+0x1ec): undefined reference to `mp_type_complex'
collect2: error: ld returned 1 exit status
make: *** [build-STM32F405RG/firmware.elf] Error 1

Disabling MICROPY_PY_BUILTINS_COMPLEX in the mpconfigboard.h of micropython resolves this issue... (for the rest all other configs remain the same...) Hope this output helps a bit to pinpoint the underlying issue?

saraverbeecke avatar Oct 26 '24 19:10 saraverbeecke