Skip to content

Commit

Permalink
Handle NCCL.avg correctly (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
avik-pal authored Feb 28, 2024
1 parent 3a49978 commit 0ee0774
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 17 deletions.
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

"""
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

3 comments on commit 0ee0774

@avik-pal
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@maleadt can we release this patch?

@maleadt
Copy link
Member

@maleadt maleadt commented on 0ee0774 Mar 2, 2024

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/102133

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.1 -m "<description of version>" 0ee07746656b879504736829435935cf5df031af
git push origin v0.1.1

Please sign in to comment.