Skip to content

[CUDA] Bundle CCCL for JIT compilation - #2357

Merged
awni merged 2 commits into
ml-explore:mainfrom
zcbenz:distribute-cccl
Jul 12, 2025
Merged

awni merged 2 commits into
ml-explore:mainfrom
zcbenz:distribute-cccl

Conversation

@zcbenz

@zcbenz zcbenz commented Jul 11, 2025

Copy link
Copy Markdown
Member

Close #2348.

Bundle CCCL as part of python distribution (installed in the include directory along with MLX headers), and make JIT compiler search headers from it. This ensure the JIT compilation gets the same result with host compilation.

Currently only libcudacxx (i.e. cuda/std/xxx headers) are shipped since the JIT code (under backend/cuda/device) only uses it. It would be very easy to also ship CUB headers if needed. However thrust currently is not compatible with JIT (NVIDIA/cccl#4305) and we should avoid using it in JIT code.

This PR also removes code that was used to work around old CCCL versions.

return op_t.str();
}

std::filesystem::path current_binary_dir() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There was a comment about this needing to stay inline. I think the purpose of that is to make sure upstream dependencies of MLX get the right binary path. Could you make it inline in the header?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe a better change would be to have a wrapper around the inline version which sets the static variable so it gets properly cached. But the one used by register_library in metal device.h should be inline in a header.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The inline version of register_library got removed in #2055 (not sure if it is intentional), so I think there is no longer needs making this inline? The only place using it is device.cpp so it only returns the dir containing libmlx.so.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hmm.. good point. get_library can be called by third-party extensions. If it is called without a path then it will attempt to look for a metal library where the current binary is located. Presumably that will be the libmlx now.. which I would have thought is a bug 🤔

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Either way this PR doesn't change that behavior so let's move forward with it.

@awni awni left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks great!! I left one comment, please address then we can merge.

@awni
awni merged commit 6325f60 into ml-explore:main Jul 12, 2025
@zcbenz
zcbenz deleted the distribute-cccl branch July 13, 2025 00:48
faisalmemon pushed a commit to faisalmemon/mlx that referenced this pull request Oct 30, 2025
* Ship CCCL for JIT compilation

* Remove cexpf
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.

[CUDA] Ship CCCL in python distribution

2 participants