-
Notifications
You must be signed in to change notification settings - Fork 62
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
Do not allocate memory during WaveNet processing #49
Comments
Agreed. There should be some kind of |
Yes - typically this would be handled by allocating for the max size, but then only processing the number of samples you are given. Eigen has a way to specify the maximum matrix size, but unfortunately it is at compile time: https://eigen.tuxfamily.org/dox/classEigen_1_1Matrix.html It should be possible to create matrices/vectors at max size, and then just do block operations on them at the current given size. |
Sounds reasonable--I had started to move some things out in the iPlug2 plugin, but yeah, this reeks of me getting back into C++ for this project 😅
Did not know--great call! Let me know if either of you want to take this on--happy to assign it 👍🏻 |
I feel your pain...
I can probably look into sorting this out. |
I just ran NAM audiounit with Apple's auval real time safety checker and it pointed to a couple of things...
full transcript (from my NAM version...) |
if you set the EIGEN_RUNTIME_NO_MALLOC preprocessor macro and then ...
It shows that every single call to process is calling malloc/free. This is bad and fixing it might save quite a few CPU cycles, let alone preventing some potential glitches |
Maybe a clue here: |
I just pushed a pull-request that cleans up realtime memory allocations due to use of Eigen temporary Matrices. With the changes applied, NeuralAmpModelerCore no longer does memory allocations on any process call except the first. Net results: a 20% performance improvement (enormously valuable when running on Pi 4s'), a substantial reduction in CPU use jitter, and probably progressively worse performance as NAM, and other plugins that are unwisely doing memory allocations fragment the realtime thread's heap. Hosts can ensure that buffers for Eigen MatrixXfs are pre-allocated by processing one sample off the realtime thread before allowing the model to run on the realtime thread. Currently, MatrixXf memory is allocated during the first processing cycle. It might be useful to introduce an Activate() method on DSPs, the implementation of which would just run the model for one cycle. Or even do it as part of get_dsp(). |
Currently, the WaveNet model processing code re-sizes vectors and matrices based on the audio buffer size during processing. This is non-ideal for real-time operation. Instead, all sizing operations should be done out-of-band of the processing loop.
In most cases, the current behavior should not cause significant problems. If there is a fixed audio buffer size the resize operations should only happen once. A fixed buffer size is not guaranteed, however - DAWs will sometimes vary the block size.
The text was updated successfully, but these errors were encountered: