Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mcid.py: optimize FFT and A-weighting calculations #33057

Merged
merged 6 commits into from
Jul 25, 2024

Conversation

deanlee
Copy link
Contributor

@deanlee deanlee commented Jul 24, 2024

Precompute A-weighting filter coefficients for reuse in each callback to enhance performance and reduce computational overhead.

Copy link
Contributor

github-actions bot commented Jul 24, 2024

Thanks for contributing to openpilot! In order for us to review your PR as quickly as possible, check the following:

  • Convert your PR to a draft unless it's ready to review
  • Read the contributing docs
  • Before marking as "ready for review", ensure:
    • the goal is clearly stated in the description
    • all the tests are passing
    • the change is something we merge
    • include a route or your device' dongle ID if relevant

@adeebshihadeh
Copy link
Contributor

Do you have before/after on some benchmark? We need that for any optimization PR.

@deanlee
Copy link
Contributor Author

deanlee commented Jul 24, 2024

I have not tested the reduced CPU usage of this PR on the device separately. I only measured the reduced time, and it saves approximately 1.5 ms on every update on the device.

As for CPU usage, I tested it along with another PR (not yet submitted) that replaces np.concatenate with a circular buffer to efficiently manage incoming audio samples, avoiding costly array resizing operations. Together, these two PRs can reduce CPU usage by half (about reduce 4% cpu usage)

@adeebshihadeh
Copy link
Contributor

test_onroad.py is a good benchmark for this

"system.micd": 6.0,

@adeebshihadeh
Copy link
Contributor

trigger-jenkins

@adeebshihadeh
Copy link
Contributor

test_onroad says the CPU went to 3.9% from 5%, so definitely an improvement! But the memory usage check failed:
image

@deanlee
Copy link
Contributor Author

deanlee commented Jul 24, 2024

Not sure what the issue is. The cached calculation result A_WEIGHTING in the global variable is only about 4KB.

update: The memory size of the array A_WEIGHTING is 32KB. Is this causing the issue?

system/micd.py Outdated Show resolved Hide resolved
@sshane
Copy link
Contributor

sshane commented Jul 24, 2024

jenkins passed on a subsequent run w/ no changes, flaky test? @adeebshihadeh

@adeebshihadeh
Copy link
Contributor

I haven't seen that test fail randomly before. We can run a few more times to confirm though

@sshane
Copy link
Contributor

sshane commented Jul 25, 2024

Passed 5 subsequent runs across the day. @deanlee can you make it use cache?

@deanlee deanlee force-pushed the micd_precomputing_weighting branch from d47e4e1 to b7516a4 Compare July 25, 2024 06:54
@deanlee
Copy link
Contributor Author

deanlee commented Jul 25, 2024

Completed. The function now uses cache.

spacing
@sshane sshane force-pushed the micd_precomputing_weighting branch from 0104073 to 487328f Compare July 25, 2024 20:17
@sshane
Copy link
Contributor

sshane commented Jul 25, 2024

trigger-jenkins

@sshane sshane merged commit 313a282 into commaai:master Jul 25, 2024
5 checks passed
@deanlee deanlee deleted the micd_precomputing_weighting branch July 25, 2024 21:00
Edison-CBS pushed a commit to Edison-CBS/openpilot that referenced this pull request Sep 15, 2024
* Precomputing weighting

* add comments back

* use cache

* spacing

spacing

* clean up

* lower by diff

---------

Co-authored-by: Shane Smiskol <[email protected]>
old-commit-hash: 313a282
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants