BLACK_F407VE: @micropython.native in frozen bytecode decorator build fails

Discussion and questions about boards that can run MicroPython but don't have a dedicated forum.
Target audience: Everyone interested in running MicroPython on other hardware.
Post Reply
ProudPagan
Posts: 35
Joined: Fri Apr 12, 2019 8:55 am

BLACK_F407VE: @micropython.native in frozen bytecode decorator build fails

Post by ProudPagan » Tue Jun 04, 2019 4:48 am

Hi,

This is for the BLACK_F407VE STM32F407VET6 board with MicroPython 1.11 (source at top of the tree).

I have used the @micropython.native decorator on the class methods that I have put in the ports/stm32/modules/
directory.

On trying a clean build, I encounter this error:

Code: Select all

GEN build-BLACK_F407VE/frozen_mpy.c
Traceback (most recent call last):
  File "../../tools/mpy-tool.py", line 864, in <module>
    main()
  File "../../tools/mpy-tool.py", line 852, in main
    raw_codes = [read_mpy(file) for file in args.files]
  File "../../tools/mpy-tool.py", line 852, in <listcomp>
    raw_codes = [read_mpy(file) for file in args.files]
  File "../../tools/mpy-tool.py", line 720, in read_mpy
    return read_raw_code(f, qstr_win)
  File "../../tools/mpy-tool.py", line 699, in read_raw_code
    raw_codes = [read_raw_code(f, qstr_win) for _ in range(n_raw_code)]
  File "../../tools/mpy-tool.py", line 699, in <listcomp>
    raw_codes = [read_raw_code(f, qstr_win) for _ in range(n_raw_code)]
  File "../../tools/mpy-tool.py", line 666, in read_raw_code
    off = read_uint(f, qstr_win)
  File "../../tools/mpy-tool.py", line 575, in read_uint
    b = read_byte(f, out)
  File "../../tools/mpy-tool.py", line 569, in read_byte
    out.append(b)
AttributeError: 'QStrWindow' object has no attribute 'append'
../../py/mkrules.mk:118: recipe for target 'build-BLACK_F407VE/frozen_mpy.c' failed
make: *** [build-BLACK_F407VE/frozen_mpy.c] Error 1
make: *** Deleting file 'build-BLACK_F407VE/frozen_mpy.c'
Without the decorator, build succeeds and I have a working .hex running fine on the board (but performance
sucks, hence the need for speed).

What am I doing wrong?

Thanks

PP

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: BLACK_F407VE: @micropython.native in frozen bytecode decorator build fails

Post by jimmo » Tue Jun 04, 2019 5:44 am

Looks like a bug. I've raised https://github.com/micropython/micropython/issues/4829 with more info.

Unfortunately I don't understand the new native .mpy encoding well enough to send a PR.

Sorry I don't have a good workaround for you right now.

ProudPagan
Posts: 35
Joined: Fri Apr 12, 2019 8:55 am

Re: BLACK_F407VE: @micropython.native in frozen bytecode decorator build fails

Post by ProudPagan » Tue Jun 04, 2019 1:19 pm

Thanks, jimmo.

Does anyone know how much speedup I can expect when using viper and native emitters w.r.t. pure Python for integer and string
operations?

PP

ProudPagan
Posts: 35
Joined: Fri Apr 12, 2019 8:55 am

Re: BLACK_F407VE: @micropython.native in frozen bytecode decorator build fails

Post by ProudPagan » Tue Jun 04, 2019 3:20 pm

I just picked up the fix to mpy-tool.py that Damien committed (https://github.com/micropython/micropython/issues/4829)
The build proceeds with warnings, but now my function (__truediv__) doesn't work -- I get this message:

Code: Select all

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: function missing required positional argument #31
I see these build warnings -- so I think there could be some other issue lurking somewhere:

Code: Select all

build-BLACK_F407VE/frozen_mpy.c:20728:47: note: (near initialization for 'fun_data_mpap__lt_module_gt__mpap___truediv__')
build-BLACK_F407VE/frozen_mpy.c:20729:5: warning: excess elements in array initializer
     MP_QSTR___truediv__ & 0xff, MP_QSTR___truediv__ >> 8,
     ^~~~~~~~~~~~~~~~~~~

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: BLACK_F407VE: @micropython.native in frozen bytecode decorator build fails

Post by jimmo » Tue Jun 04, 2019 10:20 pm

Can you post a follow-up to the bug?
That warning definitely sounds like it would be related to your problem.

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: BLACK_F407VE: @micropython.native in frozen bytecode decorator build fails

Post by jimmo » Tue Jun 04, 2019 10:30 pm

ProudPagan wrote:
Tue Jun 04, 2019 1:19 pm
Does anyone know how much speedup I can expect when using viper and native emitters w.r.t. pure Python for integer and string
operations?
It's hard to say because it depends so much on what the code is doing. So you've just got to measure it.

In one project where I used it quite a lot it made the difference between the project working and not working, but I got much bigger gains from restructuring the code (e.g. avoiding gc pressure, using memoryviews, algorithmic etc).

FYI I'm not sure how much native/viper affect string performance. (I've never looker, but perhaps mistakenly I've always assumed it was mostly about integer stuff).

ProudPagan
Posts: 35
Joined: Fri Apr 12, 2019 8:55 am

Re: BLACK_F407VE: @micropython.native in frozen bytecode decorator build fails

Post by ProudPagan » Wed Jun 05, 2019 5:28 am

Just did!
jimmo wrote:
Tue Jun 04, 2019 10:20 pm
Can you post a follow-up to the bug?
That warning definitely sounds like it would be related to your problem.

Post Reply