Skip to content

Commit

Permalink
Merge pull request #35 from LuxDL/ap/range
Browse files Browse the repository at this point in the history
Handle Abstract Range for GPU
  • Loading branch information
avik-pal authored Mar 11, 2024
2 parents ce8b898 + e3025b1 commit de25a7a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "LuxDeviceUtils"
uuid = "34f89e08-e1d5-43b4-8944-0b49ac560553"
authors = ["Avik Pal <[email protected]> and contributors"]
version = "0.1.16"
version = "0.1.17"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down
12 changes: 9 additions & 3 deletions src/LuxDeviceUtils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -322,20 +322,26 @@ get_device(::AbstractArray) = LuxCPUDevice()

# Adapt Interface
abstract type AbstractLuxDeviceAdaptor end
abstract type AbstractLuxGPUDeviceAdaptor <: AbstractLuxDeviceAdaptor end

struct LuxCPUAdaptor <: AbstractLuxDeviceAdaptor end
struct LuxCUDAAdaptor{D} <: AbstractLuxDeviceAdaptor
struct LuxCUDAAdaptor{D} <: AbstractLuxGPUDeviceAdaptor
device::D
end
struct LuxAMDGPUAdaptor{D} <: AbstractLuxDeviceAdaptor
struct LuxAMDGPUAdaptor{D} <: AbstractLuxGPUDeviceAdaptor
device::D
end
struct LuxMetalAdaptor <: AbstractLuxDeviceAdaptor end
struct LuxMetalAdaptor <: AbstractLuxGPUDeviceAdaptor end

adapt_storage(::LuxCPUAdaptor, x::AbstractRange) = x
adapt_storage(::LuxCPUAdaptor, x::AbstractArray) = adapt(Array, x)
adapt_storage(::LuxCPUAdaptor, rng::AbstractRNG) = rng

# Prevent Ambiguity
for T in (LuxAMDGPUAdaptor, LuxCUDAAdaptor, LuxMetalAdaptor)
@eval adapt_storage(to::$(T), x::AbstractRange) = adapt(to, collect(x))
end

_isbitsarray(::AbstractArray{<:Number}) = true
_isbitsarray(::AbstractArray{T}) where {T} = isbitstype(T)
_isbitsarray(x) = false
Expand Down

2 comments on commit de25a7a

@avik-pal
Copy link
Member Author

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/102678

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.17 -m "<description of version>" de25a7a655a84ab7764bd2aa48c5296e7732a743
git push origin v0.1.17

Please sign in to comment.