Skip to content

Add OpenCL support to MLDataDevices#1590

Merged
avik-pal merged 15 commits intoLuxDL:mainfrom
VarLad:openclsupport
Dec 10, 2025
Merged

Add OpenCL support to MLDataDevices#1590
avik-pal merged 15 commits intoLuxDL:mainfrom
VarLad:openclsupport

Conversation

@VarLad
Copy link
Contributor

@VarLad VarLad commented Dec 8, 2025

This PR adds OpenCL support to MLDataDevices

@gemini-code-assist
Copy link

Summary of Changes

Hello @VarLad, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the MLDataDevices library by incorporating OpenCL as a new supported backend. This expansion allows users to leverage a broader range of GPU hardware for their machine learning computations, providing greater flexibility and accessibility. The changes involve adding necessary dependencies, implementing core OpenCL device functionalities, and updating the library's internal device management and testing infrastructure to seamlessly support OpenCL.

Highlights

  • OpenCL Integration: Added comprehensive support for OpenCL devices, allowing MLDataDevices to utilize OpenCL-compatible GPUs.
  • New Extension Module: Introduced MLDataDevicesOpenCLExt.jl to manage OpenCL-specific functionalities like device detection, data transfer, and FP64 support handling.
  • Core API Updates: Modified MLDataDevices.jl, internal.jl, and public.jl to export OpenCLDevice, integrate it into the device management system, and update relevant documentation.
  • Extensive Testing: Included new and updated test files (opencl_tests.jl, eltype_tests.jl, iterator_tests.jl, misc_tests.jl, runtests.jl) to ensure the correct functionality and integration of OpenCL support.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds OpenCL support to MLDataDevices, which is a great addition. The changes are mostly correct and follow the existing patterns for other GPU backends. I've found a few issues, mostly minor, including a copy-paste error in tests, a typo in a warning message, and a logic error in the test setup script. I've also pointed out a case of code duplication and a function that could be simplified for better maintainability. The most critical issues are in the test setup, which could lead to incorrect test execution or dependencies.

@VarLad
Copy link
Contributor Author

VarLad commented Dec 8, 2025

Not sure why but OpenCL tests are not working for me, as in, OpenCL doesn't get added by Pkg.
I might be missing something trivial. Could you take a look @avik-pal ?
(I am using this PR with Flux.jl without any issues)

@VarLad VarLad requested a review from avik-pal December 8, 2025 15:45
@VarLad VarLad requested a review from avik-pal December 9, 2025 15:18
@VarLad
Copy link
Contributor Author

VarLad commented Dec 9, 2025

I've bumped the minor version of the package, and formatted the file using Runic

@avik-pal
Copy link
Member

avik-pal commented Dec 9, 2025

I've bumped the minor version of the package, and formatted the file using Runic

format with JuliaFormatter v1

@avik-pal
Copy link
Member

avik-pal commented Dec 9, 2025

The other files also need formatting https://github.com/LuxDL/Lux.jl/actions/runs/20070192836/job/57571219544?pr=1590

Run set -euo pipefail
Saved working directory and index state WIP on (no branch): 2bb4672 Merge 3edde22ef5ad4283ebf4749fdc02503eba057f00 into 4a170a137a2e674f604836acb61dd448c4df1aab
lib/MLDataDevices/test/eltype_tests.jl:125:-        
lib/MLDataDevices/test/eltype_tests.jl:125:+
lib/MLDataDevices/test/iterator_tests.jl:30:-DEVICES = [CPUDevice, CUDADevice, AMDGPUDevice, MetalDevice, oneAPIDevice, OpenCLDevice, ReactantDevice]
lib/MLDataDevices/test/iterator_tests.jl:30:+DEVICES = [
lib/MLDataDevices/test/iterator_tests.jl:31:+    CPUDevice,
lib/MLDataDevices/test/iterator_tests.jl:32:+    CUDADevice,
lib/MLDataDevices/test/iterator_tests.jl:33:+    AMDGPUDevice,
lib/MLDataDevices/test/iterator_tests.jl:34:+    MetalDevice,
lib/MLDataDevices/test/iterator_tests.jl:35:+    oneAPIDevice,
lib/MLDataDevices/test/iterator_tests.jl:36:+    OpenCLDevice,
lib/MLDataDevices/test/iterator_tests.jl:37:+    ReactantDevice,
lib/MLDataDevices/test/iterator_tests.jl:38:+]
lib/MLDataDevices/test/misc_tests.jl:145:-        OpenCLDevice()
lib/MLDataDevices/test/misc_tests.jl:145:+        OpenCLDevice(),
lib/MLDataDevices/test/opencl_tests.jl:202:-
lib/MLDataDevices/test/runtests.jl:53:-        Base.Fix2(*, "_tests.jl"), ["reactant", "cuda", "amdgpu", "metal", "oneapi", "opencl"]
lib/MLDataDevices/test/runtests.jl:53:+        Base.Fix2(*, "_tests.jl"),
lib/MLDataDevices/test/runtests.jl:54:+        ["reactant", "cuda", "amdgpu", "metal", "oneapi", "opencl"],
time=2025-12-09T16:22:33.699Z level=INFO msg="reviewdog: failed to post a review comment: POST https://api.github.com/repos/LuxDL/Lux.jl/pulls/1590/reviews: 403 Resource not accessible by integration []"

Comment on lines 19 to 21
function MLDataDevices.functional(::Union{OpenCLDevice,Type{<:OpenCLDevice}})
return try
cl.device()
true
catch
false
end
end
Copy link
Member

Choose a reason for hiding this comment

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

Is there no nicer way than a try/catch?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was the most straightforward way to test for functionality, but the change in the latest commit should work good enough.

@avik-pal
Copy link
Member

@VarLad I dont think any of the opencl tests are actually running see https://github.com/LuxDL/Lux.jl/actions/runs/20078551609/job/57599487282?pr=1590#step:12:883

@VarLad
Copy link
Contributor Author

VarLad commented Dec 10, 2025

@avik-pal I think the issue was that loading pocl_jll (and OpenCL.jl) before MLDataDevices causes issues.
I've shifted the CPU fallback tests to a new file, while making sure that OpenCL is loaded before MLDataDevices.

@VarLad
Copy link
Contributor Author

VarLad commented Dec 10, 2025

@avik-pal tests seem to pass locally for me. Would you like any other changes to this?

@avik-pal avik-pal merged commit 719654d into LuxDL:main Dec 10, 2025
69 of 73 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