Skip to content

[Routines] Introduce HostExecutor backend#329

Merged
shivasankarka merged 469 commits into
Mojo-Numerics-and-Algorithms-group:pre-0.9from
shivasankarka:operations
Mar 4, 2026
Merged

[Routines] Introduce HostExecutor backend#329
shivasankarka merged 469 commits into
Mojo-Numerics-and-Algorithms-group:pre-0.9from
shivasankarka:operations

Conversation

@shivasankarka

@shivasankarka shivasankarka commented Mar 3, 2026

Copy link
Copy Markdown
Collaborator

This PR adds support for HostExecutor (name subject to change) implemented in routines/operations/backend.mojo following #328 . This struct contains the following methods,

  • apply_unary - takes one argument as input (SIMD, NDArray)
  • apply_binary - takes two arguments as input (any combination of SIMD, NDArray)
  • apply_unary_predicate - takes one argument (SIMD, NDArray) and returns some boolean value (SIMD[DType.boo], NDArray[DType.bool])
  • apply_binary_predicate - takes two arguments and returns some boolean value (SIMD[DType.bool], NDArray[DType.bool])

All the operations are vectorized.

@shivasankarka
shivasankarka requested a review from forfudan March 3, 2026 15:00

@forfudan forfudan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shivasankarka, thanks! I did some fixes:

  1. Add treatment of 0d array in apply_unary()
  2. The shape check is before 0d check in apply_binary(), which may cause mismatches. It is re-ordered.
  3. apply_binary_predicate(array, scalar) uses simd_width_of[DType.bool](), seemingly mismatches with the dtype. It is changed to simd_width_of[dtype]().
  4. Iport operations

@shivasankarka

Copy link
Copy Markdown
Collaborator Author

@forfudan Thanks. Regarding 3) shouldn't it be The width of bool type. Because if not, we are writing onto a Boolean pointer with int/float wide SIMD vectors which may be incorrect/inefficient. I'm not sure how it works under the hood.

@forfudan

forfudan commented Mar 3, 2026

Copy link
Copy Markdown
Collaborator

@forfudan Thanks. Regarding 3) shouldn't it be The width of bool type. Because if not, we are writing onto a Boolean pointer with int/float wide SIMD vectors which may be incorrect/inefficient. I'm not sure how it works under the hood.

@shivasankarka you are absolutely right! I got it wrong. Please revert this change.

@shivasankarka
shivasankarka merged commit c6715aa into Mojo-Numerics-and-Algorithms-group:pre-0.9 Mar 4, 2026
2 checks passed
forfudan added a commit that referenced this pull request Mar 31, 2026
This PR adds support for `HostExecutor` (name subject to change)
implemented in `routines/operations/backend.mojo` following #328 . This
struct contains the following methods,

- `apply_unary` - takes one argument as input (SIMD, NDArray)
- `apply_binary` - takes two arguments as input (any combination of
SIMD, NDArray)
- `apply_unary_predicate` - takes one argument (SIMD, NDArray) and
returns some boolean value (SIMD[DType.boo], NDArray[DType.bool])
- `apply_binary_predicate` - takes two arguments and returns some
boolean value (SIMD[DType.bool], NDArray[DType.bool])

All the operations are vectorized.

---------

Co-authored-by: ZHU Yuhao <dr.yuhao.zhu@outlook.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants