Skip to content

Commit ed060ad

Browse files
committed
Compare CUDA devices by UUIDs
1 parent 774168c commit ed060ad

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
1010
KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c"
1111
MemPool = "f9f48841-c794-520a-933b-121f7ba6ed94"
1212
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
13+
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
1314

1415
[compat]
1516
Adapt = "1, 2, 3"

src/cu.jl

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
using .CUDA
22
import .CUDA: CuDevice, CuContext, devices, attribute
33

4+
using UUIDs
5+
46
export CuArrayDeviceProc
57

68
"Represents a single CUDA GPU device."
79
struct CuArrayDeviceProc <: Dagger.Processor
810
owner::Int
9-
#ctx::CuContext
1011
device::Int
12+
device_uuid::UUID
1113
end
1214
@gpuproc(CuArrayDeviceProc, CuArray)
1315
Dagger.get_parent(proc::CuArrayDeviceProc) = Dagger.OSProc(proc.owner)
@@ -49,7 +51,15 @@ function Dagger.move(from::CuArrayDeviceProc, to::CuArrayDeviceProc, x::Dagger.C
4951
finalizer(arr) do arr
5052
CUDA.cuIpcCloseMemHandle(pointer(arr))
5153
end
52-
# FIXME: Deal with to_proc being a different GPU
54+
if from.device_uuid != to.device_uuid
55+
CUDA.device!(to.device) do
56+
to_arr = similar(arr)
57+
copyto!(to_arr, arr)
58+
to_arr
59+
end
60+
else
61+
arr
62+
end
5363
else
5464
# Different node, use DtoH, serialization, HtoD
5565
# TODO UCX
@@ -68,7 +78,7 @@ function Dagger.execute!(proc::CuArrayDeviceProc, func, args...)
6878
end)
6979
end
7080
Base.show(io::IO, proc::CuArrayDeviceProc) =
71-
print(io, "CuArrayDeviceProc on worker $(proc.owner), device $(proc.device)")
81+
print(io, "CuArrayDeviceProc on worker $(proc.owner), device $(proc.device), uuid $(proc.device_uuid)")
7282

7383
processor(::Val{:CUDA}) = CuArrayDeviceProc
7484
cancompute(::Val{:CUDA}) = CUDA.has_cuda()
@@ -77,7 +87,7 @@ kernel_backend(::CuArrayDeviceProc) = CUDADevice()
7787
if CUDA.has_cuda()
7888
for dev in devices()
7989
Dagger.add_callback!(() -> begin
80-
return CuArrayDeviceProc(Distributed.myid(), #=CuContext(dev),=# dev.handle)
90+
return CuArrayDeviceProc(Distributed.myid(), dev.handle, CUDA.uuid(dev))
8191
end)
8292
end
8393
end

0 commit comments

Comments
 (0)