Skip to content

[CUDA] Implement Scan kernel - #2347

Merged
awni merged 5 commits into
ml-explore:mainfrom
zcbenz:cuda-scan
Jul 10, 2025
Merged

awni merged 5 commits into
ml-explore:mainfrom
zcbenz:cuda-scan

Conversation

@zcbenz

@zcbenz zcbenz commented Jul 10, 2025

Copy link
Copy Markdown
Member

This PR ports the Scan kernels from Metal to CUDA.

There are also a few changes to fix the LogAddExp op for complex numbers which caused the scan tests to fail:

  • A few C++ tests are added to show the failed case.
  • A cexpf.cuh file is added to port the complex number exp from thrust, we can not use thrust::exp directly unfortunately because it does not compile in JIT kernels when building with old CUDA versions (<= 12.2).
  • The complex number log1p is moved from utils.cuh to unary_ops.cuh so it is put together with other complex number functions.
  • The LogAddExp's implementation is updated to use PyTorch's algorithm.

@awni

awni commented Jul 10, 2025

Copy link
Copy Markdown
Member

Looks awesome! I'm wondering if those logaddexp tests will fail on Metal / CPU as well?

@zcbenz

zcbenz commented Jul 10, 2025

Copy link
Copy Markdown
Member Author

The exp test fails on Metal, should I port the cexpf?

@awni

awni commented Jul 10, 2025

Copy link
Copy Markdown
Member

The exp test fails on Metal, should I port the cexpf?

Yes that would be super useful.. it looks like a bug as is.

@zcbenz

zcbenz commented Jul 10, 2025

Copy link
Copy Markdown
Member Author

Updated to fix the exp on Metal.

@awni
awni merged commit 8347575 into ml-explore:main Jul 10, 2025
@zcbenz
zcbenz deleted the cuda-scan branch July 13, 2025 00:48
faisalmemon pushed a commit to faisalmemon/mlx that referenced this pull request Oct 30, 2025
* Contiguous scan

* Strided scan

* Enable tests

* Fix failing logaddexp test

* Use cexpf in Metal
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