-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add HDF5 support through AbstractStorage
- Loading branch information
1 parent
a180e7c
commit 8804319
Showing
10 changed files
with
132 additions
and
27 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,16 +1,19 @@ | ||
name = "Checkpointing" | ||
uuid = "eb46d486-4f9c-4c3d-b445-a617f2a2f1ca" | ||
authors = ["Michel Schanen <[email protected]>", "Sri Hari Krishna Narayanan <[email protected]>"] | ||
version = "0.4.0" | ||
version = "0.5.0" | ||
|
||
[deps] | ||
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" | ||
Enzyme = "7da242da-08ed-463a-9acd-ee780be4f1d9" | ||
HDF5 = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f" | ||
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" | ||
Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b" | ||
|
||
[compat] | ||
ChainRulesCore = "1.0" | ||
Enzyme = "0.9" | ||
HDF5 = "0.16" | ||
julia = "1.7" | ||
|
||
[extras] | ||
|
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
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
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,17 @@ | ||
struct ArrayStorage{MT} <: AbstractStorage where {MT} | ||
_storage::Array{MT} | ||
end | ||
|
||
function ArrayStorage{MT}(acp::Int) where {MT} | ||
storage = Array{MT}(undef, acp) | ||
return ArrayStorage(storage) | ||
end | ||
|
||
Base.getindex(storage::ArrayStorage{MT}, i) where {MT} = storage._storage[i] | ||
|
||
function Base.setindex!(storage::ArrayStorage{MT}, v, i) where {MT} | ||
storage._storage[i] = v | ||
end | ||
|
||
Base.ndims(::Type{ArrayStorage{MT}}) where {MT} = 1 | ||
Base.size(storage::ArrayStorage{MT}) where {MT} = size(storage._storage) |
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,31 @@ | ||
mutable struct HDF5Storage{MT} <: AbstractStorage where {MT} | ||
fid::HDF5.File | ||
filename::String | ||
acp::Int64 | ||
end | ||
|
||
function HDF5Storage{MT}(acp::Int; filename=tempname()) where {MT} | ||
fid = h5open(filename, "w") | ||
storage = HDF5Storage{MT}(fid, filename, acp) | ||
function _finalizer(storage::HDF5Storage{MT}) | ||
close(storage.fid) | ||
return storage | ||
end | ||
finalizer(_finalizer, storage) | ||
return storage | ||
end | ||
|
||
function Base.getindex(storage::HDF5Storage{MT}, i)::MT where {MT} | ||
@assert i >= 1 && i <= storage.acp | ||
blob = read(storage.fid["$i"]) | ||
return deserialize(blob) | ||
end | ||
|
||
function Base.setindex!(storage::HDF5Storage{MT}, v::MT, i) where {MT} | ||
@assert i >= 1 && i <= storage.acp | ||
if haskey(storage.fid, "$i") | ||
delete_object(storage.fid, "$i") | ||
end | ||
blob = serialize(v) | ||
storage.fid["$i"] = blob | ||
end |
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