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

Missing broadcast capability in optimized kernels. #8051

Open
cptspacemanspiff opened this issue Jan 30, 2025 · 1 comment
Open

Missing broadcast capability in optimized kernels. #8051

cptspacemanspiff opened this issue Jan 30, 2025 · 1 comment
Assignees
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

@cptspacemanspiff
Copy link
Contributor

cptspacemanspiff commented Jan 30, 2025

Missing broadcast causes abort.

So, I ran into a bug where the optimized kernel library, op_add, op_sub, and op_div are missing broadcast support. I specifically ran into it when trying to add a 2x8x12x12 tensor with a 2x1x12x12 tensor. (I only ran into it when I was doing batch size of greater than 1, which is my assumption why this has not been an issue?)

The cause of this seems to be an update a while back that presumably added new optimization paths for use with op_mul:

enum class ElementwiseOptimizedPath {
  kNone,
  kTreatAs1d,
  kBroadcast2dBy1d,
  kBroadcast2dBy1dReverseArguments,
  kBroadcastNdByNd,
  kBroadcastNdByNdReverseArguments,
  kBroadcastLastDim,
  kBroadcastLastDimReverseArguments,
};

However, the first 4 are the only ones known in op_add, op_sub, and op_div, and the logic falls to an error if it encounters an unexpected optimization path.

Playing with it, a quick and dirty fix is to add a check for if we are using one of the un-implemented broadcasts, then fallback to kNone

  auto selected_optimized_path = select_optimized_path(a, b, out);
  if (selected_optimized_path == ElementwiseOptimizedPath::kBroadcastNdByNd ||
      selected_optimized_path == ElementwiseOptimizedPath::kBroadcastNdByNdReverseArguments ||
      selected_optimized_path == ElementwiseOptimizedPath::kBroadcastLastDim || 
      selected_optimized_path == ElementwiseOptimizedPath::kBroadcastLastDimReverseArguments) {
      selected_optimized_path = ElementwiseOptimizedPath::kNone;
  }

That is obviously non-ideal, but was my temp fix for myself.

Versions

Executorch main branch.

cc @larryliu0820 @manuelcandales

@manuelcandales manuelcandales added the module: kernels Issues related to kernel libraries and utilities, and code under kernels/ label Jan 30, 2025
@manuelcandales
Copy link
Contributor

cc @swolchok

@manuelcandales manuelcandales added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Jan 30, 2025
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

3 participants