-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Experimental] Add memory recording which can then be bulk-freed (#698)
- Loading branch information
Showing
4 changed files
with
54 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
name = "AMDGPU" | ||
uuid = "21141c5a-9bdb-4563-92ae-f87d6854732e" | ||
authors = ["Julian P Samaroo <[email protected]>", "Valentin Churavy <[email protected]>", "Anton Smirnov <[email protected]>"] | ||
version = "1.1.0" | ||
version = "1.1.1" | ||
|
||
[deps] | ||
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# NOTE: EXPERIMENTAL API. | ||
|
||
const MemoryRecords = LockedObject(Dict{UInt64, ROCArray}()) | ||
|
||
const RECORD_MEMORY::Ref{Bool} = Ref(false) | ||
|
||
function record_memory!(rec::Bool; free::Bool = true, sync::Bool = false) | ||
RECORD_MEMORY[] = rec | ||
if !rec | ||
free && free_records!(; sync) | ||
end | ||
return | ||
end | ||
|
||
record_memory() = RECORD_MEMORY[] | ||
|
||
function record!(x) | ||
Base.lock(records -> records[_hash(x)] = x, MemoryRecords) | ||
return | ||
end | ||
|
||
function free_records!(; sync::Bool = false) | ||
Base.lock(MemoryRecords) do records | ||
for (k, x) in records | ||
unsafe_free!(x) | ||
end | ||
empty!(records) | ||
end | ||
sync && AMDGPU.synchronize() | ||
return | ||
end | ||
|
||
function remove_record!(x) | ||
record_memory() || return | ||
|
||
k = _hash(x) | ||
Base.lock(MemoryRecords) do records | ||
if k in records.keys | ||
pop!(records, k) | ||
end | ||
end | ||
return | ||
end | ||
|
||
_hash(x::ROCArray) = | ||
Base.hash(x.buf.rc.obj.mem.ptr, | ||
Base.hash(x.offset, | ||
Base.hash(x.dims))) |
98e7084
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
98e7084
There was a problem hiding this comment.
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/119674
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.
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: