-
Notifications
You must be signed in to change notification settings - Fork 13
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
Configure max_threads max value to 64 #41
Conversation
…coding does not crash on machines with high core counts
It looks like the line in codec_aom.c linked from #23 (comment) was added in libavif 1.0.2 and the most recent wheel builds are for libavif 1.0.1. It might be advantageous to have 64+ threads with some codecs—SVT-AV1 in particular—so I'm not sure it's a great idea to limit this for all codecs. However, it's tricky to know which encoder is being used by default, so it also wouldn't be straightforward to limit maxThreads for only libaom. How would you feel about wrapping this code in an |
It looks like this is an issue for both avm and aom: With that check, we will still have the issue when using newer libavif versions with aom or avm. Maybe it would be better to allow users to specify the maxThreads argument manually, but default to min(cpus, 64)? If users are using SVT and have more than 64 cores, then they can set it higher if they want. The library is currently not usable at all (with aom or avm) on large machines due to the current default behavior. |
Also I don't see any evidence that aom and avm didn't crash before that check was added. Maybe the check was added to protect against it because people were seeing crashes when setting it higher (like we are now). |
Alternatively: if the "codec" arg is provided and is "aom" or "avm", then limit maxThreads to 64. This arg here: |
The check was added at the same time that the Why don't you think the min maxThreads change in libavif 1.0.2 fixes this issue? When I run |
More to the point, if I hard-code maxThreads to 96, I see the same pytest failures as you. But when I recompile against the latest libavif, the tests pass. Hence my suggestion that we use preprocessor directives to target your change to versions of libavif that don't already cap the value passed to aom. |
I ran it again on a machine with way less than 64 cores and with libavif > 1.0.2 and I can still repro when setting maxThreads > 64. Check my libavif version:
Install clean from main:
Run the repro:
Make and check my changes:
Re-build and install:
Run it again:
|
Could you try pip installing this wheel and running your reproduction script? This is what the CI process creates for the latest libavif version. |
Sorry I'm not going to install a whl from dropbox... I hope you understand where I'm coming from. Can you try reproducing with conda? Install deps
Max sure libavif is > 1.0.2 Install pillow-avif-plugin and run
Then edit max_threads after the call to init_max_threads() to be = 96. Repeat the pip install and run again. |
I updated my PR to do the codec check since I confirmed (pending your repro) that this is still an issue on libavif 1.0.3. After this change I can not repro the crash no matter what I set max_threads to. |
I repeated the same repro with the same results with libavif 1.0.1. Also, to be super sure, I printed the libavif version string in there:
Rebuild and install:
Run it:
Note the 1.0.3 printed Check with conda:
I'm not sure how much more certainty we need. |
I see. I was compiling against the main branch from git source, which has the fix. But it looks like it never made it onto the v1.0.x release branch. I've flagged this to the maintainers of libavif. This had been the source of my hesitation: it's fine to fix it in this repository while we wait for it to make it into a release, but it really should be addressed in libavif. The change you made to check the codec is incomplete because libaom is the default encoder if available (i.e. |
Co-authored-by: Frankie Dintino <fdintino@gmail.com>
Makes sense to me. Thanks @fdintino! |
Add upper bound of 64 to max_threads in init_max_threads() so that encoding does not crash on machines with high core counts.
See the repro and discussion in issue #23
Before this change (on a machine with 96 cores):
Script:
Output:
After this change: program works as expected.