This repository has been archived by the owner on Nov 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for OpenCL devices
- Loading branch information
Showing
6 changed files
with
57 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
name = "MLDataDevices" | ||
uuid = "7e8f7934-dd98-4c1a-8fe8-92b47a384d40" | ||
authors = ["Avik Pal <[email protected]> and contributors"] | ||
version = "1.1.1" | ||
version = "1.2.0" | ||
|
||
[deps] | ||
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" | ||
|
@@ -17,6 +17,7 @@ FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b" | |
GPUArrays = "0c68f7d7-f131-5f86-a1c3-88cf8149b2d7" | ||
MLUtils = "f1d291b0-491e-4a28-83b9-f70985020b54" | ||
Metal = "dde4c033-4e86-420c-a63e-0dd931031962" | ||
OpenCL = "08131aa3-fb12-5dee-8b74-c09406e224a2" | ||
RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd" | ||
ReverseDiff = "37e2e3b7-166d-5795-8a7a-e32c996b4267" | ||
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" | ||
|
@@ -33,6 +34,7 @@ MLDataDevicesFillArraysExt = "FillArrays" | |
MLDataDevicesGPUArraysExt = "GPUArrays" | ||
MLDataDevicesMLUtilsExt = "MLUtils" | ||
MLDataDevicesMetalExt = ["GPUArrays", "Metal"] | ||
MLDataDevicesOpenCLExt = ["GPUArrays", "OpenCL"] | ||
MLDataDevicesRecursiveArrayToolsExt = "RecursiveArrayTools" | ||
MLDataDevicesReverseDiffExt = "ReverseDiff" | ||
MLDataDevicesSparseArraysExt = "SparseArrays" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
module MLDataDevicesOpenCLExt | ||
|
||
using Adapt: Adapt | ||
using MLDataDevices: MLDataDevices, Internal, OpenCLDevice, reset_gpu_device! | ||
using GPUArrays: GPUArrays | ||
using OpenCL: OpenCL, CLArray | ||
|
||
__init__() = reset_gpu_device!() | ||
|
||
MLDataDevices.loaded(::Union{OpenCLDevice, Type{<:OpenCLDevice}}) = true | ||
# TODO: Check if OpenCL can provide a `functional` function. | ||
MLDataDevices.functional(::Union{OpenCLDevice, Type{<:OpenCLDevice}}) = true | ||
|
||
# Default RNG | ||
MLDataDevices.default_device_rng(::OpenCLDevice) = GPUArrays.default_rng(CLArray) | ||
|
||
# Query Device from Array | ||
Internal.get_device(::CLArray) = OpenCLDevice() | ||
|
||
Internal.get_device_type(::CLArray) = OpenCLDevice | ||
|
||
# unsafe_free! | ||
function Internal.unsafe_free_internal!(::Type{OpenCLDevice}, ::AbstractArray) | ||
# TODO: Implement this | ||
@warn "Support for `unsafe_free!` for OpenCL is not implemented yet. This is a no-op." maxlog=1 | ||
return | ||
end | ||
|
||
# Device Transfer | ||
Adapt.adapt_storage(::OpenCLDevice, x::AbstractArray) = CLArray(x) | ||
|
||
# TODO: Eventually we want to do robust device management, since it is possible users | ||
# change the device after creating the OpenCLDevice and that might cuase unwanted | ||
# behavior. | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters