Skip to content

Allowing SPM to compile on Linux with CUDA#413

Merged
davidkoski merged 11 commits into
ml-explore:mainfrom
gmondada:gab/cuda1
Jun 17, 2026
Merged

Allowing SPM to compile on Linux with CUDA#413
davidkoski merged 11 commits into
ml-explore:mainfrom
gmondada:gab/cuda1

Conversation

@gmondada

@gmondada gmondada commented May 25, 2026

Copy link
Copy Markdown
Contributor

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
Contributor Author

@davidkoski @Joannis 👆

@gmondada

Copy link
Copy Markdown
Contributor 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

@davidkoski

Copy link
Copy Markdown
Collaborator

@gmondada FYI

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

We have the newer Xcode available in CI but it isn't the default, so we need this for it to run.

@davidkoski

Copy link
Copy Markdown
Collaborator
/Users/runner/actions-runner/_work/mlx-swift/mlx-swift/Source/MLX/GPU+CUDA.swift:14:13: error: invalid redeclaration of 'GPU'
public enum GPU {
            ^
/Users/runner/actions-runner/_work/mlx-swift/mlx-swift/Source/MLX/GPU+Metal.swift:15:13: note: 'GPU' previously declared here
public enum GPU {
            ^
/Users/runner/actions-runner/_work/mlx-swift/mlx-swift/Source/MLX/GPU+Metal.swift:15:13: note: 'GPU' previously declared here
public enum GPU {
            ^

looks like this might be a file exclusion issue on macOS (apple platforms probably).

@gmondada

gmondada commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

Oh, I didn't notice this compilation issue and wasn't aware of the Xcode project. Thanks for bringing this to my attention. Should work now.

@gmondada

Copy link
Copy Markdown
Contributor Author

... and didn't update the CMake build system. Now done.

@davidkoski

Copy link
Copy Markdown
Collaborator

Why have one build system when you could have 3?

@davidkoski davidkoski 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.

Build is clean in CI, thank you so much for your work on this!

@davidkoski davidkoski merged commit e23ae6b into ml-explore:main Jun 17, 2026
8 checks passed
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