-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata.jl
More file actions
318 lines (251 loc) · 8.57 KB
/
data.jl
File metadata and controls
318 lines (251 loc) · 8.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
to_cxx_vector(shape) = CxxWrap.StdVector([UInt64(d) for d in shape])
to_string(ty::LegateType) = code_type_map[code(ty)]
function Base.show(io::IO, ty::LegateType)
println(io, code_type_map[code(ty)])
end
function Base.print(ty::LegateType)
Base.show(stdout, ty)
end
"""
supported_types()
See Legate.jl supported data types
"""
supported_types() = SUPPORTED_TYPES
"""
string_to_scalar(str::AbstractString) -> Scalar
Convert a string to a `Scalar`.
"""
string_to_scalar
"""
create_array(ty::LegateType; dim::Integer=1;
nullable::Bool=false) -> LogicalArray
Create an unbound array.
# Arguments
- `ty`: Element type of the array.
- `dim`: Number of dimensions.
- `nullable`: Whether the array can contain null values.
"""
function create_array(ty::Type{T}; dim::Integer=1, nullable::Bool=false) where {T<:SUPPORTED_TYPES}
impl = create_unbound_array(to_legate_type(ty), dim, nullable) # cxxwrap call
return LogicalArray{T,dim}(impl, nothing)
end
"""
create_array(shape::Vector{B}, ty::Type{T};
nullable::Bool=false,
optimize_scalar::Bool=false)
where {T<:SUPPORTED_TYPES, B<:Integer} -> LogicalArray
Create an array with a specified shape.
# Arguments
- `shape`: Shape of the array.
- `ty`: Element type.
- `nullable`: Whether the array can contain null values.
- `optimize_scalar`: Whether to optimize scalar storage.
"""
function create_array(shape::Vector{B}, ty::Type{T};
nullable::Bool=false,
optimize_scalar::Bool=false) where {T<:SUPPORTED_TYPES,B<:Integer}
lshape = Legate.Shape(to_cxx_vector(shape)) # convert to CxxWrap type
impl = create_array(lshape, to_legate_type(ty), nullable, optimize_scalar) # cxxwrap call
return LogicalArray{T,length(shape)}(impl, Tuple(shape))
end
"""
create_store(ty::Type{T}; dim::Integer=1) -> LogicalStore
Create an unbound store.
# Arguments
- `ty`: Element type of the store.
- `dim`: Dimensionality of the store.
"""
function create_store(ty::Type{T}; dim::Integer=1) where {T<:SUPPORTED_TYPES}
impl = create_unbound_store(to_legate_type(ty), dim) # cxxwrap call
return LogicalStore{T,dim}(impl, nothing)
end
"""
create_store(shape::Vector{B}, ty::Type{T};
optimize_scalar::Bool=false)
where {T<:SUPPORTED_TYPES, B<:Integer} -> LogicalStore
Create a store with a specified shape.
# Arguments
- `shape`: Shape of the store.
- `ty`: Element type.
- `optimize_scalar`: Whether to optimize scalar storage.
"""
function create_store(shape::Vector{B}, ty::Type{T};
optimize_scalar::Bool=false) where {T<:SUPPORTED_TYPES,B<:Integer}
lshape = Legate.Shape(to_cxx_vector(shape)) # convert to CxxWrap type
impl = create_store(lshape, to_legate_type(ty), optimize_scalar) # cxxwrap call
return LogicalStore{T,length(shape)}(impl, Tuple(shape))
end
"""
create_store(scalar::T; shape::Vector{B}=[1])
where {T<:SUPPORTED_TYPES, B<:Integer} -> LogicalStore
Create a store from a scalar value.
# Arguments
- `scalar`: Scalar value to store.
- `shape`: Shape of the resulting store.
"""
function create_store(scalar::T; shape::Vector{B}=[1]) where {T<:SUPPORTED_TYPES,B<:Integer}
lshape = Legate.Shape(to_cxx_vector(shape)) # convert to CxxWrap type
impl = store_from_scalar(Legate.Scalar(scalar), lshape) # cxxwrap call
return LogicalStore{T,length(shape)}(impl, Tuple(shape))
end
"""
dim(PhysicalStore) -> Int
dim(LogicalStore) -> Int
dim(LogicalArray) -> Int
dim(PhysicalArray) -> Int
Return the number of dimensions of the array/store.
"""
dim(x::Union{LogicalArray,LogicalStore}) = dim(x.handle) # cxxwrap call
"""
type(PhysicalStore) -> LegateType
type(LogicalStore) -> LegateType
type(LogicalArray) -> LegateType
type(PhysicalArray) -> LegateType
Return the data type of elements stored in the array/store.
"""
type(x::Union{LogicalArray,LogicalStore}) = type(x.handle) # cxxwrap call
"""
code(ty::LegateType) -> Int
Return the internal code representing the `LegateType`.
"""
code
"""
is_readable(PhysicalStore) -> Bool
Check if the physical store can be read.
"""
is_readable
"""
is_writable(PhysicalStore) -> Bool
Check if the physical store can be written to.
"""
is_writable
"""
is_reducible(PhysicalStore) -> Bool
Check if the physical store supports reduction operations.
"""
is_reducible
"""
valid(PhysicalStore) -> Bool
Check if the physical store is in a valid state.
"""
valid
"""
reinterpret_as(LogicalStore, T) -> LogicalStore
Return a view of the logical store reinterpreted as type `T`.
"""
function reinterpret_as(
store::LogicalStore, ::Type{T}
) where {T<:SUPPORTED_TYPES}
impl = reinterpret_as(store.handle, to_legate_type(T)) # cxxwrap call
return LogicalStore{T,dim(impl)}(impl, store.dims)
end
"""
promote(LogicalStore, T) -> LogicalStore
Return a new logical store with elements promoted to type `T`.
"""
function promote(
store::LogicalStore, ::Type{T}
) where {T<:SUPPORTED_TYPES}
impl = promote(store.handle, to_legate_type(T)) # cxxwrap call
return LogicalStore{T,dim(impl)}(impl, store.dims)
end
"""
slice(LogicalStore, indices...) -> LogicalStore
Return a sliced view of the logical store according to the given indices.
"""
slice
"""
get_physical_store(LogicalStore) -> PhysicalStore
get_physical_store(LogicalArray) -> PhysicalStore
Return the underlying physical store of this logical store or array.
"""
function get_physical_store(x::LogicalStore)
get_physical_store(x.handle, StoreTargetOptional{StoreTarget}())
end
function get_physical_store(x::LogicalStore, target::StoreTarget)
get_physical_store(x.handle, StoreTargetOptional{StoreTarget}(target))
end
function get_physical_array(x::LogicalArray)
get_physical_array(x.handle, StoreTargetOptional{StoreTarget}())
end
function get_physical_array(x::LogicalArray, target::StoreTarget)
get_physical_array(x.handle, StoreTargetOptional{StoreTarget}(target))
end
"""
equal_storage(store1::LogicalStore, store2::LogicalStore) -> Bool
Check if two logical stores refer to the same underlying physical store.
"""
equal_storage(x::LogicalStore, y::LogicalStore) = equal_storage(x.handle, y.handle) # cxxwrap call
"""
nullable(LogicalArray) -> Bool
nullable(PhysicalArray) -> Bool
Check if the array supports null values.
"""
nullable(x::LogicalArray) = nullable(x.handle) # cxxwrap call
"""
data(PhysicalArray) -> PhysicalStore
data(LogicalArray) -> LogicalStore
Return the underlying store of the array (physical or logical).
"""
data(x::LogicalArray) = data(x.handle) # cxxwrap call
"""
unbound(LogicalArray) -> Bool
Check if the logical array is unbound (not tied to a physical store).
"""
unbound(x::LogicalArray) = unbound(x.handle) # cxxwrap call
# Delegation for wrappers
Base.eltype(x::Union{LogicalArray{T},LogicalStore{T}}) where {T} = T
"""
get_ptr(LogicalStore) -> Ptr
get_ptr(LogicalArray) -> Ptr
get_ptr(PhysicalArray) -> Ptr
get_ptr(PhysicalStore) -> Ptr
Return the pointer to the underlying data of the array/store.
"""
function get_ptr(arr::LogicalStore)
# LogicalStore -> PhysicalStore -> Ptr
return get_ptr(get_physical_store(arr)) # cxxwrap call
end
function get_ptr(arr::LogicalStore, target::StoreTarget)
return get_ptr(get_physical_store(arr, target))
end
function get_ptr(arr::LogicalArray)
# LogicalArray -> PhysicalArray -> PhysicalStore -> Ptr
return get_ptr(data(get_physical_array(arr))) # cxxwrap call
end
function get_ptr(arr::LogicalArray, target::StoreTarget)
return get_ptr(data(get_physical_array(arr, target)))
end
function get_ptr(arr::PhysicalArray)
# PhysicalArray -> PhysicalStore -> Ptr
return get_ptr(data(arr)) # cxxwrap call
end
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)
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)
write_h5(array.handle, path, dataset)
end