Realm
A distributed, event-based tasking library
Loading...
Searching...
No Matches
hdf5_internal.h
Go to the documentation of this file.
1/*
2 * Copyright 2025 Stanford University, NVIDIA Corporation
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef REALM_HDF5_INTERNAL_H
19#define REALM_HDF5_INTERNAL_H
20
21#include "realm/mem_impl.h"
22
25
26#include <hdf5.h>
27
28#define CHECK_HDF5(cmd) \
29 do { \
30 herr_t res = (cmd); \
31 if(res < 0) { \
32 fprintf(stderr, "HDF5 error on %s:\n", #cmd); \
33 H5Eprint2(H5E_DEFAULT, stderr); \
34 assert(0); \
35 } \
36 } while(0)
37
38namespace Realm {
39
40 namespace HDF5 {
41
43 public:
44 static HDF5Dataset *open(const char *filename, const char *dsetname,
45 bool read_only);
46 void flush();
47 void close();
48
49 protected:
52
53 public:
55 int ndims;
56 static const int MAX_DIM = 16;
59 };
60
61 class HDF5Memory : public MemoryImpl {
62 public:
63 static const size_t ALIGNMENT = 256;
64
65 HDF5Memory(RuntimeImpl *_runtime_impl, Memory _me);
66
67 virtual ~HDF5Memory(void);
68
69 virtual void get_bytes(off_t offset, void *dst, size_t size);
70
71 virtual void put_bytes(off_t offset, const void *src, size_t size);
72
73 virtual void *get_direct_ptr(off_t offset, size_t size);
74
76 bool need_alloc_result,
77 bool poisoned,
78 TimeLimit work_until);
79
80 virtual void release_storage_immediate(RegionInstanceImpl *inst, bool poisoned,
81 TimeLimit work_until);
82
83 // HDF5Memory supports ExternalHDF5Resource
85 size_t &inst_offset);
87 };
88
89 class HDF5Request : public Request {
90 public:
91 void *mem_base; // could be source or dest
94 };
95 class HDF5Channel;
96
98 public:
99 virtual int set_rect(const RegionInstanceImpl *inst,
100 const InstanceLayoutPieceBase *piece, size_t field_size,
101 size_t field_offset, int ndims, const int64_t lo[/*ndims*/],
102 const int64_t hi[/*ndims*/], const int order[/*ndims*/]);
103
104 // hid_t dset_id;
105 // hid_t dtype_id;
106 // FieldID field_id; // used to cache open datasets
107 const std::string *filename;
108 const std::string *dsetname;
109 // std::vector<hsize_t> dset_bounds;
110 std::vector<hsize_t> offset; // start location in dataset
111 std::vector<hsize_t> extent; // xfer dimensions in memory and dataset
112 };
113
114 class HDF5XferDes : public XferDes {
115 public:
116 HDF5XferDes(uintptr_t _dma_op, Channel *_channel, NodeID _launch_node,
117 XferDesID _guid, const std::vector<XferDesPortInfo> &inputs_info,
118 const std::vector<XferDesPortInfo> &outputs_info, int _priority,
119 const void *_fill_data, size_t _fill_size);
120
121 long get_requests(Request **requests, long nr);
124 void flush();
125
126 virtual bool request_available();
128 virtual void enqueue_request(Request *req);
129
131
132 private:
133 bool req_in_use;
134 HDF5Request hdf5_req;
135 typedef std::pair<const std::string *, const std::string *> DatasetMapKey;
136 typedef std::map<DatasetMapKey, HDF5Dataset *> DatasetMap;
137 DatasetMap datasets;
138 static const size_t MAX_FILL_SIZE_IN_BYTES = 65536;
139 };
140
141 // single channel handles both HDF5 reads and writes
142 class HDF5Channel : public SingleXDQChannel<HDF5Channel, HDF5XferDes> {
143 public:
146
147 // handle HDF5 requests in order - no concurrency
148 static const bool is_ordered = true;
149
150 virtual XferDes *create_xfer_des(uintptr_t dma_op, NodeID launch_node,
151 XferDesID guid,
152 const std::vector<XferDesPortInfo> &inputs_info,
153 const std::vector<XferDesPortInfo> &outputs_info,
154 int priority, XferDesRedopInfo redop_info,
155 const void *fill_data, size_t fill_size,
156 size_t fill_total);
157
158 long submit(Request **requests, long nr);
159 };
160
161 }; // namespace HDF5
162
163}; // namespace Realm
164
165#endif
Definition bgwork.h:36
Definition channel.h:713
Definition hdf5_internal.h:97
virtual int set_rect(const RegionInstanceImpl *inst, const InstanceLayoutPieceBase *piece, size_t field_size, size_t field_offset, int ndims, const int64_t lo[], const int64_t hi[], const int order[])
std::vector< hsize_t > extent
Definition hdf5_internal.h:111
const std::string * filename
Definition hdf5_internal.h:107
std::vector< hsize_t > offset
Definition hdf5_internal.h:110
const std::string * dsetname
Definition hdf5_internal.h:108
Definition hdf5_internal.h:142
virtual XferDes * create_xfer_des(uintptr_t dma_op, NodeID launch_node, XferDesID guid, const std::vector< XferDesPortInfo > &inputs_info, const std::vector< XferDesPortInfo > &outputs_info, int priority, XferDesRedopInfo redop_info, const void *fill_data, size_t fill_size, size_t fill_total)
long submit(Request **requests, long nr)
static const bool is_ordered
Definition hdf5_internal.h:148
HDF5Channel(BackgroundWorkManager *bgwork)
Definition hdf5_internal.h:42
hid_t file_id
Definition hdf5_internal.h:54
int ndims
Definition hdf5_internal.h:55
static const int MAX_DIM
Definition hdf5_internal.h:56
hid_t dtype_id
Definition hdf5_internal.h:54
bool read_only
Definition hdf5_internal.h:58
static HDF5Dataset * open(const char *filename, const char *dsetname, bool read_only)
hid_t dset_id
Definition hdf5_internal.h:54
hsize_t dset_size[MAX_DIM]
Definition hdf5_internal.h:57
hid_t dspace_id
Definition hdf5_internal.h:54
Definition hdf5_internal.h:61
virtual ~HDF5Memory(void)
virtual void put_bytes(off_t offset, const void *src, size_t size)
virtual AllocationResult allocate_storage_immediate(RegionInstanceImpl *inst, bool need_alloc_result, bool poisoned, TimeLimit work_until)
virtual void get_bytes(off_t offset, void *dst, size_t size)
virtual void * get_direct_ptr(off_t offset, size_t size)
virtual bool attempt_register_external_resource(RegionInstanceImpl *inst, size_t &inst_offset)
virtual void unregister_external_resource(RegionInstanceImpl *inst)
HDF5Memory(RuntimeImpl *_runtime_impl, Memory _me)
static const size_t ALIGNMENT
Definition hdf5_internal.h:63
virtual void release_storage_immediate(RegionInstanceImpl *inst, bool poisoned, TimeLimit work_until)
Definition hdf5_internal.h:89
hid_t dataset_id
Definition hdf5_internal.h:92
hid_t file_space_id
Definition hdf5_internal.h:93
hid_t mem_space_id
Definition hdf5_internal.h:93
hid_t datatype_id
Definition hdf5_internal.h:92
void * mem_base
Definition hdf5_internal.h:91
Definition hdf5_internal.h:114
long get_requests(Request **requests, long nr)
void notify_request_write_done(Request *req)
virtual Request * dequeue_request()
HDF5XferDes(uintptr_t _dma_op, Channel *_channel, NodeID _launch_node, XferDesID _guid, const std::vector< XferDesPortInfo > &inputs_info, const std::vector< XferDesPortInfo > &outputs_info, int _priority, const void *_fill_data, size_t _fill_size)
bool progress_xd(HDF5Channel *channel, TimeLimit work_until)
virtual bool request_available()
virtual void enqueue_request(Request *req)
void notify_request_read_done(Request *req)
Definition inst_layout.h:266
Definition mem_impl.h:50
size_t size
Definition mem_impl.h:195
AllocationResult
Definition mem_impl.h:89
Definition memory.h:33
Definition inst_impl.h:54
Definition channel.h:103
Definition runtime_impl.h:264
Definition channel.h:1014
Definition timers.h:129
Definition channel.h:286
Channel * channel
Definition channel.h:343
Definition activemsg.h:38
int NodeID
Definition nodeset.h:40
unsigned long long XferDesID
Definition channel.h:57
Definition channel.h:210
NodeID src
Definition ucp_internal.h:1