Skip to content
Open

Hdf5 #83

Show file tree
Hide file tree
Changes from 6 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
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "Legate"
uuid = "1238f2cf-6593-4d60-9aca-2f5364e49909"
version = "0.1.2"
version = "0.1.3"

[deps]
CxxWrap = "1f15a43c-97ca-5a2a-ae31-89f07a497df4"
Expand All @@ -27,6 +27,6 @@ FunctionWrappers = "1.1.3"
JuliaFormatter = "2.2.0"
LegatePreferences = "0.1.6"
julia = "1.10"
legate_jl_wrapper_jll = "25.10.4"
legate_jl_wrapper_jll = "25.10.5"
legate_jll = "25.10.2"
Preferences = "1"
Preferences = "1"
2 changes: 1 addition & 1 deletion lib/legate_jl_wrapper/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
25.10.3
25.10.5
15 changes: 15 additions & 0 deletions lib/legate_jl_wrapper/include/wrapper.inl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "legate/mapping/machine.h"
#include "legate/runtime/runtime.h"
#include "legate/timing/timing.h"
#include "legate/io/hdf5/interface.h"
#include "legion.h"
#include "legion/legion_config.h"

Expand Down Expand Up @@ -330,4 +331,18 @@ inline uint64_t time_nanoseconds() {
return legate::timing::measure_nanoseconds().value();
}
} // namespace time


namespace hdf5 {
inline LogicalArray read_h5(const std::string& file_path, const std::string& dataset_name) {
Comment thread
krasow marked this conversation as resolved.
Outdated
return legate::io::hdf5::from_file(std::filesystem::path(file_path), dataset_name);
}

inline void write_h5(const LogicalArray& array, const std::string& file_path, const std::string& dataset_name) {
Comment thread
krasow marked this conversation as resolved.
Outdated
legate::io::hdf5::to_file(array, std::filesystem::path(file_path), dataset_name);
}
} // namespace hdf5

} // namespace legate_wrapper


12 changes: 11 additions & 1 deletion lib/legate_jl_wrapper/src/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,13 @@ JLCXX_MODULE define_julia_module(jlcxx::Module& mod) {
.method("data", &LogicalArray::data) // returns LogicalStore
.method("get_physical_array",
&LogicalArray::get_physical_array) // return PhysicalArray
.method("unbound", &LogicalArray::unbound);
.method("unbound", &LogicalArray::unbound)
.method("shape", [](const LogicalArray& arr) {
auto s = arr.data().shape();
std::vector<uint64_t> result;
for (int i = 0; i < arr.dim(); i++) result.push_back(s[i]);
return result;
});

mod.add_type<AutoTask>("AutoTask")
.method("add_input", static_cast<Variable (AutoTask::*)(LogicalArray)>(
Expand Down Expand Up @@ -234,5 +240,9 @@ JLCXX_MODULE define_julia_module(jlcxx::Module& mod) {
mod.method("time_microseconds", &legate_wrapper::time::time_microseconds);
mod.method("time_nanoseconds", &legate_wrapper::time::time_nanoseconds);

/* hdf5 */
mod.method("read_h5", &legate_wrapper::hdf5::read_h5);
mod.method("write_h5", &legate_wrapper::hdf5::write_h5);
Comment thread
krasow marked this conversation as resolved.
Outdated

wrap_ufi(mod);
}
32 changes: 32 additions & 0 deletions src/api/data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -284,3 +284,35 @@ function get_ptr(arr::PhysicalStore)
# PhysicalStore -> Ptr
return _get_ptr(CxxWrap.CxxPtr(arr)) # cxxwrap call
end

"""
read_h5(path::String, dataset::String) -> LogicalArray

Read a dataset from an HDF5 file into a LogicalArray.

# Arguments
- `path`: Path to the HDF5 file.
- `dataset`: Name of the dataset to read.
"""
function read_hdf5(path::String, dataset::String)
Comment thread
krasow marked this conversation as resolved.
Outdated
impl = read_h5(path, dataset) # cxxwrap call
ndim = Int(dim(impl))
shp = Tuple(Int.(shape(impl)))
T = code_type_map[Int(code(type(impl)))]
return LogicalArray{T, ndim}(impl, shp)
end


"""
write_h5(array::LogicalArray, path::String, dataset::String)

Write a LogicalArray to a dataset in an HDF5 file.

# Arguments
- `array`: The array to write.
- `path`: Path to the HDF5 file.
- `dataset`: Name of the dataset to write.
"""
function write_hdf5(array::LogicalArray, path::String, dataset::String)
Comment thread
krasow marked this conversation as resolved.
Outdated
write_h5(array.handle, path, dataset)
end
Loading