espressif / esp-dsp

DSP library for ESP-IDF
Apache License 2.0
482 stars 91 forks source link

dsps_dotprod_f32 is slow on first call (examples/dotprod) (DSP-121) #78

Open Bobobel opened 11 months ago

Bobobel commented 11 months ago

Environment

That example includes some bugs! I fixed them (producing a sum of squares) and checked for other input as well as repeated timings:

Results:

I (1422) main: Start Example. I (1422) main: The sum of N squares from 1 to N=256 = 5625216.000000 (reference=5625216) I (1432) main: Operation for N samples take 2639 cycles I (1432) main: End Example. I (1432) main: The sum of N squares from 1 to N=256 = 5625216.000000 (reference=5625216) I (1442) main: Operation for N samples take 429 cycles I (1452) main: End Example.

Then I increased N to get (only second reading): 1581 cycles for N=1024 , factor=3.68 3117 cycles for N=2048 , factor=7.39 6189 cycles for N=4096 , factor=14.43 Fine, it is scaling as expected.

Expected Behavior

Maybe you can decrease setup time for first call of that routine? I guess it will not pay because usually dotprod will be called repeatedly.

Actual Behavior

Steps to repropduce

just double the test in main

"It is not a fault its a feature" (:->

dmitry1945 commented 11 months ago

Hi @Bobobel

the timing for the first call is high because the dsps_dotprod_f32 is located in flash and should be copied to the cash after the first call. At second call it's already in cash, and the system don't spend time to copy it.

Regards, Dmitry