Skip to content

Allowing SPM to compile on Linux with CUDA#413

Open
gmondada wants to merge 7 commits into
ml-explore:mainfrom
gmondada:gab/cuda1
Open

Allowing SPM to compile on Linux with CUDA#413
gmondada wants to merge 7 commits into
ml-explore:mainfrom
gmondada:gab/cuda1

Conversation

@gmondada
Copy link
Copy Markdown

@gmondada gmondada commented May 25, 2026

Proposed changes

This PR introduces an SPM plug-in allowing CUDA to be compiled by SPM on Linux.

Example1 can be compiled on Linux with command:

swift build --product Example1

SPM invokes nvcc, therefore you need the CUDA toolkit to be installed.

A few notes:

  • You need at least CUDA 13.2. Version 12 has a very limited support for clang.
  • This solution rely on “CGen” SPM experimental feature, which is only available in Swift 6.3.
  • Code generated at compile time is managed by tools/update-mlx.sh.
  • On my computer I need to compile with --jobs=2 for limiting the memory required during compilation. Solutions to mitigate this will be proposed in further PRs.

Checklist

  • I have read the CONTRIBUTING document
  • I have run pre-commit run --all-files to format my code / installed pre-commit prior to committing changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the necessary documentation (if needed)

@gmondada gmondada marked this pull request as ready for review May 25, 2026 11:52
@gmondada
Copy link
Copy Markdown
Author

@davidkoski @Joannis 👆

@gmondada
Copy link
Copy Markdown
Author

To compile with CUDA on Mac, just create a docker with https://github.com/gmondada/cuda-toolkit-docker/blob/main/Dockerfile.ubuntu24

@davidkoski
Copy link
Copy Markdown
Collaborator

Xcode 26.3
...
package 'mlx-swift' is using Swift tools version 6.3.0 but the installed version is 6.2.4

Let me see if we have Xcode 26.4 available in CI.

@davidkoski davidkoski mentioned this pull request May 26, 2026
4 tasks
@davidkoski
Copy link
Copy Markdown
Collaborator

See #414 -- it looks like we can use the latest or a particular version of Xcode:

        env:
          DEVELOPER_DIR: /Applications/Xcode-latest.app

this should be done for all the steps that do xcodebuild or xcrun

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