fix: const filtering strat is size dependent #891
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently constant filtering uses parallelism like a hammer but for
einsum
operations wheredot
andconstant
filtering may be called repeatedly for MANY small arrays (eg.einsum ijk,ijk->ij
where input dims are[1024,1024,2]
we call it 1024*1024 times for arrays of size 2 which, induces terrible overhead from spinning up threads.Instead we should use sequential search methods for smaller arrays, lest we want to avoid this overhead.
Here we also leverage benchmarks to get a rough threshold where we should switch from sequential to a parallel search for constants. On a M3 Max the results are below, giving us a rough crossover point of 1mil elements.