Skip to content

RFC: Support Adapt.AbstractGPUDevice #1520

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/cudadrv/devices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export

Get a handle to a compute device.
"""
struct CuDevice
struct CuDevice <: AbstractGPUDevice
handle::CUdevice

function CuDevice(ordinal::Integer)
Expand Down
3 changes: 3 additions & 0 deletions lib/cudadrv/events.jl
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,6 @@ macro elapsed(ex)
elapsed(t0, t1)
end
end


Adapt.get_compute_unit_impl(@nospecialize(TypeHistory::Type), e::CuEvent) = device(e.ctx)
3 changes: 2 additions & 1 deletion lib/cusparse/CUSPARSE.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ using CEnum: @cenum
using LinearAlgebra
using LinearAlgebra: HermOrSym

using Adapt: Adapt, adapt
import Adapt
using Adapt: Adapt, adapt, AbstractGPUDevice

using SparseArrays

Expand Down
3 changes: 3 additions & 0 deletions lib/cusparse/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ const AbstractCuSparseMatrix{Tv, Ti} = AbstractCuSparseArray{Tv, Ti, 2}

Base.convert(T::Type{<:AbstractCuSparseArray}, m::AbstractArray) = m isa T ? m : T(m)

Adapt.get_compute_unit_impl(@nospecialize(TypeHistory::Type), A::AbstractCuSparseArray) = device(A.nzVal)


mutable struct CuSparseVector{Tv, Ti} <: AbstractCuSparseVector{Tv, Ti}
iPtr::CuVector{Ti}
nzVal::CuVector{Tv}
Expand Down
3 changes: 2 additions & 1 deletion src/CUDA.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ using LLVM
using LLVM.Interop
using Core: LLVMPtr

using Adapt: Adapt, adapt, WrappedArray
import Adapt
using Adapt: Adapt, adapt, WrappedArray, AbstractGPUDevice

using Requires: @require

Expand Down
7 changes: 7 additions & 0 deletions src/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,13 @@ function device(A::CuArray)
return device(A.storage.buffer.ctx)
end

Adapt.get_compute_unit_impl(@nospecialize(TypeHistory::Type), A::CuArray) = device(A)

Adapt.adapt_storage(dev::CuDevice, x) = device!(() -> Adapt.adapt_storage(CuArray, x), dev)

Sys.total_memory(dev::CuDevice) = CUDA.totalmem(dev)
Sys.free_memory(dev::CuDevice) = unsigned(CUDA.device!(CUDA.available_memory, dev))


## derived types

Expand Down