Skip to content
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

Handle NCCL.avg correctly #54

Merged
merged 2 commits into from
Feb 28, 2024
Merged
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 Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "NCCL"
uuid = "3fe64909-d7a1-4096-9b7d-7a0f12cf0f6b"
version = "0.1.0"
version = "0.1.1"

[deps]
CEnum = "fa961155-64e5-5f13-b03f-caf6b980ea82"
Expand Down
2 changes: 2 additions & 0 deletions src/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ ncclRedOp_t(::typeof(+)) = ncclSum
ncclRedOp_t(::typeof(*)) = ncclProd
ncclRedOp_t(::typeof(max)) = ncclMax
ncclRedOp_t(::typeof(min)) = ncclMin
# Handles the case where user directly passed in the ncclRedOp_t (eg. `NCCL.avg`)
ncclRedOp_t(x::ncclRedOp_t) = x
Comment on lines +36 to +37
Copy link
Member

Choose a reason for hiding this comment

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

This also shouldn't be required when the conversion happens implicitly using convert. But since this doesn't change the end-user API, we can change that later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

_op = ncclRedOp_t(op)
was causing trouble for me when I passed in NCCL.avg

Copy link
Member

Choose a reason for hiding this comment

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

Yeah I know, I'm just saying that there's a better fix than adding a no-op function, namely by relying on convert to do the conversion when necessary. It's fine adding this now, it was more of a mental note that we need to rework the conversion at some later point :-)


"""
NCCl.avg
Expand Down
57 changes: 41 additions & 16 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,49 @@ end
@testset "Allreduce!" begin
devs = CUDA.devices()
comms = NCCL.Communicators(devs)
recvbuf = Vector{CuVector{Float64}}(undef, length(devs))
sendbuf = Vector{CuVector{Float64}}(undef, length(devs))
N = 512
for (ii, dev) in enumerate(devs)
CUDA.device!(ii - 1)
sendbuf[ii] = CuArray(fill(Float64(ii), N))
recvbuf[ii] = CUDA.zeros(Float64, N)
end
NCCL.group() do
for ii in 1:length(devs)
NCCL.Allreduce!(sendbuf[ii], recvbuf[ii], +, comms[ii])

@testset "sum" begin
recvbuf = Vector{CuVector{Float64}}(undef, length(devs))
sendbuf = Vector{CuVector{Float64}}(undef, length(devs))
N = 512
for (ii, dev) in enumerate(devs)
CUDA.device!(ii - 1)
sendbuf[ii] = CuArray(fill(Float64(ii), N))
recvbuf[ii] = CUDA.zeros(Float64, N)
end
NCCL.group() do
for ii in 1:length(devs)
NCCL.Allreduce!(sendbuf[ii], recvbuf[ii], +, comms[ii])
end
end
answer = sum(1:length(devs))
for (ii, dev) in enumerate(devs)
device!(ii - 1)
crecv = collect(recvbuf[ii])
@test all(crecv .== answer)
end
end
answer = sum(1:length(devs))
for (ii, dev) in enumerate(devs)
device!(ii - 1)
crecv = collect(recvbuf[ii])
@test all(crecv .== answer)

@testset "NCCL.avg" begin
recvbuf = Vector{CuVector{Float64}}(undef, length(devs))
sendbuf = Vector{CuVector{Float64}}(undef, length(devs))
N = 512
for (ii, dev) in enumerate(devs)
CUDA.device!(ii - 1)
sendbuf[ii] = CuArray(fill(Float64(ii), N))
recvbuf[ii] = CUDA.zeros(Float64, N)
end
NCCL.group() do
for ii in 1:length(devs)
NCCL.Allreduce!(sendbuf[ii], recvbuf[ii], NCCL.avg, comms[ii])
end
end
answer = sum(1:length(devs)) / length(devs)
for (ii, dev) in enumerate(devs)
device!(ii - 1)
crecv = collect(recvbuf[ii])
@test all(crecv .≈ answer)
end
end
end

Expand Down
Loading