Skip to content

Replace remaining uses of linearize_access_indexes for broadcasting with BroadcastIndexesRange #8965

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

Open
swolchok opened this issue Mar 5, 2025 · 1 comment
Labels
module: kernels Issues related to kernel libraries and utilities, and code under kernels/ triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Comments

@swolchok
Copy link
Contributor

swolchok commented Mar 5, 2025

BroadcastIndexesRange is more efficient than linearize_access_indexes-based loops. We have several remaining places that use linearize_access_indexes, and what they have in common is that they're not looping over an existing Tensor's .sizes() and .strides(). To make these work nicely, we need a way for BroadcastIndexesRange to play nicely with .sizes() and .strides() ArrayRefs that aren't attached to a Tensor.

Specific usage sites that can be improved:

x1_base_ix = linearize_access_indexes(out_base_coord, out.dim(), x1);

https://github.com/pytorch/executorch/blob/95f779ae2120d94e20bb95ae6af45da76ce3ff52/kernels/portable/cpu/op_index_put.cpp#L145.(I think?)

size_t in_linear_index = linearize_access_indexes(

linearize_access_indexes(broadcast_indexes, broadcast_ndim, in);
(might be straightforwardly fixable right away with no extra work)

cc @larryliu0820 @manuelcandales

@swolchok swolchok added the module: kernels Issues related to kernel libraries and utilities, and code under kernels/ label Mar 5, 2025
@swolchok
Copy link
Contributor Author

swolchok commented Mar 5, 2025

filed an issue because I don't necessarily intend to get to this one right away.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module: kernels Issues related to kernel libraries and utilities, and code under kernels/ triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

No branches or pull requests

2 participants