Skip to content

Commit

Permalink
Fix and test the legacy memory pool. (#2402)
Browse files Browse the repository at this point in the history
[skip julia]
[skip cuda]
[skip downstream]
[skip subpackages]
  • Loading branch information
maleadt committed May 29, 2024
1 parent 5bbd9a7 commit 7e6a57a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
19 changes: 19 additions & 0 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,25 @@ steps:
if: build.message !~ /\[skip tests\]/ && build.message !~ /\[skip special\]/ && !build.pull_request.draft
timeout_in_minutes: 30

- label: "Legacy memory allocator"
plugins:
- JuliaCI/julia#v1:
version: "1.10"
- JuliaCI/julia-test#v1:
test_args: "--quickfail core base"
- JuliaCI/julia-coverage#v1:
dirs:
- src
- lib
- examples
agents:
queue: "juliagpu"
cuda: "*"
env:
JULIA_CUDA_MEMORY_POOL: 'none'
if: build.message !~ /\[skip tests\]/ && build.message !~ /\[skip special\]/ && !build.pull_request.draft
timeout_in_minutes: 30

- label: "CuArray with {{matrix.memory}} memory"
plugins:
- JuliaCI/julia#v1:
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "CUDA"
uuid = "052768ef-5323-5732-b1bb-66c8b64840ba"
version = "5.4.1"
version = "5.4.2"

[deps]
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"
Expand Down
24 changes: 16 additions & 8 deletions src/memory.jl
Original file line number Diff line number Diff line change
Expand Up @@ -627,28 +627,36 @@ end
@inline function _pool_alloc(::Type{DeviceMemory}, sz)
state = active_state()

if stream_ordered(state.device)
mem = if stream_ordered(state.device)
pool_mark!(state.device, true)
pool = pool_create(state.device)
end

mem = let pool = pool # closure capture bug
retry_reclaim(isnothing) do
memory_limit_exceeded(sz) && return nothing

# try the actual allocation
try
if stream_ordered(state.device)
alloc(DeviceMemory, sz; async=true, state.stream, pool)
else
alloc(DeviceMemory, sz; async=false)
end
alloc(DeviceMemory, sz; async=true, state.stream, pool)
catch err
isa(err, OutOfGPUMemoryError) || rethrow()
return nothing
end
end
else
retry_reclaim(isnothing) do
memory_limit_exceeded(sz) && return nothing

# try the actual allocation
try
alloc(DeviceMemory, sz; async=false)
catch err
isa(err, OutOfGPUMemoryError) || rethrow()
return nothing
end
end
end
# NOTE: the `retry_reclaim` body is duplicated to work around
# closure capture issues with the `pool` variable
mem === nothing && throw(OutOfGPUMemoryError(sz))

account!(memory_stats(state.device), sz)
Expand Down

2 comments on commit 7e6a57a

@maleadt
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/107858

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 v5.4.2 -m "<description of version>" 7e6a57af3867a58993380dfc8485529a0f62467e
git push origin v5.4.2

Please sign in to comment.