onnxruntime 0.10.2-aarch64-linux → 0.11.0-aarch64-linux
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +2 -0
- data/lib/onnxruntime/ffi.rb +10 -2
- data/lib/onnxruntime/inference_session.rb +48 -68
- data/lib/onnxruntime/model.rb +1 -6
- data/lib/onnxruntime/ort_value.rb +34 -45
- data/lib/onnxruntime/pointer.rb +29 -0
- data/lib/onnxruntime/utils.rb +16 -17
- data/lib/onnxruntime/version.rb +1 -1
- data/lib/onnxruntime.rb +8 -7
- data/vendor/ThirdPartyNotices.txt +0 -35
- data/vendor/libonnxruntime.arm64.so +0 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 66dadc7597304d333d32c30098ad235652d696352fb75c85561d09acd42a3b58
|
|
4
|
+
data.tar.gz: b010ec14f69aa0f58a7b25197b684e2c658157c0412647ee59994cf8e51fa52b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 20a15fc6002173ebef6241ae36b9aa652af8d07c0bbf6dc635108c258f842c729f03ad3c480feb81ebf6befd3512ca9d669f678d080fa332dd40ce4b06f8dbf0
|
|
7
|
+
data.tar.gz: 8eff1bb690d3e1c901897c227a00b1c5bb8047641c0e022a3c9a42097c12dc1a9220590ca351841ccf30d49b57b49bdcc7e4d1574b0b664bc90f5287559878c6
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
data/lib/onnxruntime/ffi.rb
CHANGED
|
@@ -2,12 +2,20 @@ module OnnxRuntime
|
|
|
2
2
|
module FFI
|
|
3
3
|
extend ::FFI::Library
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
begin
|
|
6
|
+
ffi_lib OnnxRuntime.ffi_lib
|
|
7
|
+
rescue LoadError => e
|
|
8
|
+
if e.message.include?("Could not open library '/usr/local/opt/onnxruntime/lib/libonnxruntime.dylib'")
|
|
9
|
+
raise LoadError, "ONNX Runtime not found. Run `brew install onnxruntime`"
|
|
10
|
+
else
|
|
11
|
+
raise e
|
|
12
|
+
end
|
|
13
|
+
end
|
|
6
14
|
|
|
7
15
|
# https://github.com/microsoft/onnxruntime/blob/master/include/onnxruntime/core/session/onnxruntime_c_api.h
|
|
8
16
|
# keep same order
|
|
9
17
|
|
|
10
|
-
ORT_API_VERSION =
|
|
18
|
+
ORT_API_VERSION = 24
|
|
11
19
|
|
|
12
20
|
# enums
|
|
13
21
|
TensorElementDataType = enum(:undefined, :float, :uint8, :int8, :uint16, :int16, :int32, :int64, :string, :bool, :float16, :double, :uint32, :uint64, :complex64, :complex128, :bfloat16)
|
|
@@ -7,9 +7,8 @@ module OnnxRuntime
|
|
|
7
7
|
env
|
|
8
8
|
|
|
9
9
|
# session options
|
|
10
|
-
session_options =
|
|
11
|
-
check_status api[:CreateSessionOptions].call(session_options)
|
|
12
|
-
session_options = ::FFI::AutoPointer.new(session_options.read_pointer, api[:ReleaseSessionOptions])
|
|
10
|
+
session_options = Pointer.new(api[:ReleaseSessionOptions])
|
|
11
|
+
check_status api[:CreateSessionOptions].call(session_options.ref)
|
|
13
12
|
|
|
14
13
|
if enable_cpu_mem_arena
|
|
15
14
|
check_status api[:EnableCpuMemArena].call(session_options)
|
|
@@ -67,9 +66,8 @@ module OnnxRuntime
|
|
|
67
66
|
|
|
68
67
|
case provider
|
|
69
68
|
when "CUDAExecutionProvider"
|
|
70
|
-
cuda_options =
|
|
71
|
-
check_status api[:CreateCUDAProviderOptions].call(cuda_options)
|
|
72
|
-
cuda_options = ::FFI::AutoPointer.new(cuda_options.read_pointer, api[:ReleaseCUDAProviderOptions])
|
|
69
|
+
cuda_options = Pointer.new(api[:ReleaseCUDAProviderOptions])
|
|
70
|
+
check_status api[:CreateCUDAProviderOptions].call(cuda_options.ref)
|
|
73
71
|
check_status api[:SessionOptionsAppendExecutionProvider_CUDA_V2].call(session_options, cuda_options)
|
|
74
72
|
when "CoreMLExecutionProvider"
|
|
75
73
|
unless FFI.respond_to?(:OrtSessionOptionsAppendExecutionProvider_CoreML)
|
|
@@ -106,9 +104,7 @@ module OnnxRuntime
|
|
|
106
104
|
# TODO support logid
|
|
107
105
|
def run_with_ort_values(output_names, input_feed, log_severity_level: nil, log_verbosity_level: nil, logid: nil, terminate: nil)
|
|
108
106
|
input_tensor = ::FFI::MemoryPointer.new(:pointer, input_feed.size)
|
|
109
|
-
input_feed.
|
|
110
|
-
input_tensor[i].write_pointer(input.to_ptr)
|
|
111
|
-
end
|
|
107
|
+
input_tensor.write_array_of_pointer(input_feed.values)
|
|
112
108
|
|
|
113
109
|
output_names ||= @outputs.map { |v| v[:name] }
|
|
114
110
|
|
|
@@ -118,9 +114,8 @@ module OnnxRuntime
|
|
|
118
114
|
output_node_names = create_node_names(output_names.map(&:to_s), refs)
|
|
119
115
|
|
|
120
116
|
# run options
|
|
121
|
-
run_options =
|
|
122
|
-
check_status api[:CreateRunOptions].call(run_options)
|
|
123
|
-
run_options = ::FFI::AutoPointer.new(run_options.read_pointer, api[:ReleaseRunOptions])
|
|
117
|
+
run_options = Pointer.new(api[:ReleaseRunOptions])
|
|
118
|
+
check_status api[:CreateRunOptions].call(run_options.ref)
|
|
124
119
|
|
|
125
120
|
check_status api[:RunOptionsSetRunLogSeverityLevel].call(run_options, log_severity_level) if log_severity_level
|
|
126
121
|
check_status api[:RunOptionsSetRunLogVerbosityLevel].call(run_options, log_verbosity_level) if log_verbosity_level
|
|
@@ -129,51 +124,42 @@ module OnnxRuntime
|
|
|
129
124
|
|
|
130
125
|
check_status api[:Run].call(@session, run_options, input_node_names, input_tensor, input_feed.size, output_node_names, output_names.size, output_tensor)
|
|
131
126
|
|
|
132
|
-
output_names.size.
|
|
127
|
+
output_tensor.read_array_of_pointer(output_names.size).map { |v| OrtValue.new(v) }
|
|
133
128
|
end
|
|
134
129
|
|
|
135
130
|
def modelmeta
|
|
136
|
-
metadata =
|
|
137
|
-
check_status api[:SessionGetModelMetadata].call(@session, metadata)
|
|
138
|
-
metadata = ::FFI::AutoPointer.new(metadata.read_pointer, api[:ReleaseModelMetadata])
|
|
131
|
+
metadata = Pointer.new(api[:ReleaseModelMetadata])
|
|
132
|
+
check_status api[:SessionGetModelMetadata].call(@session, metadata.ref)
|
|
139
133
|
|
|
140
|
-
keys =
|
|
134
|
+
keys = Pointer.new(method(:allocator_free))
|
|
141
135
|
num_keys = ::FFI::MemoryPointer.new(:int64_t)
|
|
142
|
-
check_status api[:ModelMetadataGetCustomMetadataMapKeys].call(metadata, @allocator, keys, num_keys)
|
|
143
|
-
keys = ::FFI::AutoPointer.new(keys.read_pointer, method(:allocator_free))
|
|
136
|
+
check_status api[:ModelMetadataGetCustomMetadataMapKeys].call(metadata, @allocator, keys.ref, num_keys)
|
|
144
137
|
key_ptrs =
|
|
145
138
|
keys.read_array_of_pointer(num_keys.read(:int64_t)).map do |ptr|
|
|
146
139
|
::FFI::AutoPointer.new(ptr, method(:allocator_free))
|
|
147
140
|
end
|
|
148
141
|
|
|
149
|
-
custom_metadata_map =
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
custom_metadata_map[key] = value.read_string
|
|
156
|
-
end
|
|
142
|
+
custom_metadata_map =
|
|
143
|
+
key_ptrs.to_h do |key|
|
|
144
|
+
value = Pointer.new(method(:allocator_free))
|
|
145
|
+
check_status api[:ModelMetadataLookupCustomMetadataMap].call(metadata, @allocator, key, value.ref)
|
|
146
|
+
[key.read_string, value.read_string]
|
|
147
|
+
end
|
|
157
148
|
|
|
158
|
-
description =
|
|
159
|
-
check_status api[:ModelMetadataGetDescription].call(metadata, @allocator, description)
|
|
160
|
-
description = ::FFI::AutoPointer.new(description.read_pointer, method(:allocator_free))
|
|
149
|
+
description = Pointer.new(method(:allocator_free))
|
|
150
|
+
check_status api[:ModelMetadataGetDescription].call(metadata, @allocator, description.ref)
|
|
161
151
|
|
|
162
|
-
domain =
|
|
163
|
-
check_status api[:ModelMetadataGetDomain].call(metadata, @allocator, domain)
|
|
164
|
-
domain = ::FFI::AutoPointer.new(domain.read_pointer, method(:allocator_free))
|
|
152
|
+
domain = Pointer.new(method(:allocator_free))
|
|
153
|
+
check_status api[:ModelMetadataGetDomain].call(metadata, @allocator, domain.ref)
|
|
165
154
|
|
|
166
|
-
graph_name =
|
|
167
|
-
check_status api[:ModelMetadataGetGraphName].call(metadata, @allocator, graph_name)
|
|
168
|
-
graph_name = ::FFI::AutoPointer.new(graph_name.read_pointer, method(:allocator_free))
|
|
155
|
+
graph_name = Pointer.new(method(:allocator_free))
|
|
156
|
+
check_status api[:ModelMetadataGetGraphName].call(metadata, @allocator, graph_name.ref)
|
|
169
157
|
|
|
170
|
-
graph_description =
|
|
171
|
-
check_status api[:ModelMetadataGetGraphDescription].call(metadata, @allocator, graph_description)
|
|
172
|
-
graph_description = ::FFI::AutoPointer.new(graph_description.read_pointer, method(:allocator_free))
|
|
158
|
+
graph_description = Pointer.new(method(:allocator_free))
|
|
159
|
+
check_status api[:ModelMetadataGetGraphDescription].call(metadata, @allocator, graph_description.ref)
|
|
173
160
|
|
|
174
|
-
producer_name =
|
|
175
|
-
check_status api[:ModelMetadataGetProducerName].call(metadata, @allocator, producer_name)
|
|
176
|
-
producer_name = ::FFI::AutoPointer.new(producer_name.read_pointer, method(:allocator_free))
|
|
161
|
+
producer_name = Pointer.new(method(:allocator_free))
|
|
162
|
+
check_status api[:ModelMetadataGetProducerName].call(metadata, @allocator, producer_name.ref)
|
|
177
163
|
|
|
178
164
|
version = ::FFI::MemoryPointer.new(:int64_t)
|
|
179
165
|
check_status api[:ModelMetadataGetVersion].call(metadata, version)
|
|
@@ -191,23 +177,22 @@ module OnnxRuntime
|
|
|
191
177
|
|
|
192
178
|
# return value has double underscore like Python
|
|
193
179
|
def end_profiling
|
|
194
|
-
out =
|
|
195
|
-
check_status api[:SessionEndProfiling].call(@session, @allocator, out)
|
|
196
|
-
out = ::FFI::AutoPointer.new(out.read_pointer, method(:allocator_free))
|
|
180
|
+
out = Pointer.new(method(:allocator_free))
|
|
181
|
+
check_status api[:SessionEndProfiling].call(@session, @allocator, out.ref)
|
|
197
182
|
out.read_string
|
|
198
183
|
end
|
|
199
184
|
|
|
200
185
|
# no way to set providers with C API yet
|
|
201
186
|
# so we can return all available providers
|
|
202
187
|
def providers
|
|
203
|
-
out_ptr =
|
|
188
|
+
out_ptr = Pointer.new
|
|
204
189
|
length_ptr = ::FFI::MemoryPointer.new(:int)
|
|
205
|
-
check_status api[:GetAvailableProviders].call(out_ptr, length_ptr)
|
|
190
|
+
check_status api[:GetAvailableProviders].call(out_ptr.ref, length_ptr)
|
|
206
191
|
length = length_ptr.read_int
|
|
207
192
|
begin
|
|
208
|
-
out_ptr.
|
|
193
|
+
out_ptr.read_array_of_pointer(length).map(&:read_string)
|
|
209
194
|
ensure
|
|
210
|
-
api[:ReleaseAvailableProviders].call(out_ptr
|
|
195
|
+
api[:ReleaseAvailableProviders].call(out_ptr, length)
|
|
211
196
|
end
|
|
212
197
|
end
|
|
213
198
|
|
|
@@ -223,13 +208,13 @@ module OnnxRuntime
|
|
|
223
208
|
false
|
|
224
209
|
end
|
|
225
210
|
|
|
226
|
-
session =
|
|
211
|
+
session = Pointer.new(api[:ReleaseSession])
|
|
227
212
|
if from_memory
|
|
228
|
-
check_status api[:CreateSessionFromArray].call(env, path_or_bytes, path_or_bytes.bytesize, session_options, session)
|
|
213
|
+
check_status api[:CreateSessionFromArray].call(env, path_or_bytes, path_or_bytes.bytesize, session_options, session.ref)
|
|
229
214
|
else
|
|
230
|
-
check_status api[:CreateSession].call(env, ort_string(path_or_bytes), session_options, session)
|
|
215
|
+
check_status api[:CreateSession].call(env, ort_string(path_or_bytes), session_options, session.ref)
|
|
231
216
|
end
|
|
232
|
-
|
|
217
|
+
session
|
|
233
218
|
end
|
|
234
219
|
|
|
235
220
|
def load_inputs
|
|
@@ -237,13 +222,11 @@ module OnnxRuntime
|
|
|
237
222
|
check_status api[:SessionGetInputCount].call(@session, num_input_nodes)
|
|
238
223
|
|
|
239
224
|
num_input_nodes.read(:size_t).times.map do |i|
|
|
240
|
-
name_ptr =
|
|
241
|
-
check_status api[:SessionGetInputName].call(@session, i, @allocator, name_ptr)
|
|
242
|
-
name_ptr = ::FFI::AutoPointer.new(name_ptr.read_pointer, method(:allocator_free))
|
|
225
|
+
name_ptr = Pointer.new(method(:allocator_free))
|
|
226
|
+
check_status api[:SessionGetInputName].call(@session, i, @allocator, name_ptr.ref)
|
|
243
227
|
|
|
244
|
-
typeinfo =
|
|
245
|
-
check_status api[:SessionGetInputTypeInfo].call(@session, i, typeinfo)
|
|
246
|
-
typeinfo = ::FFI::AutoPointer.new(typeinfo.read_pointer, api[:ReleaseTypeInfo])
|
|
228
|
+
typeinfo = Pointer.new(api[:ReleaseTypeInfo])
|
|
229
|
+
check_status api[:SessionGetInputTypeInfo].call(@session, i, typeinfo.ref)
|
|
247
230
|
|
|
248
231
|
{name: name_ptr.read_string}.merge(Utils.node_info(typeinfo))
|
|
249
232
|
end
|
|
@@ -254,13 +237,11 @@ module OnnxRuntime
|
|
|
254
237
|
check_status api[:SessionGetOutputCount].call(@session, num_output_nodes)
|
|
255
238
|
|
|
256
239
|
num_output_nodes.read(:size_t).times.map do |i|
|
|
257
|
-
name_ptr =
|
|
258
|
-
check_status api[:SessionGetOutputName].call(@session, i, @allocator, name_ptr)
|
|
259
|
-
name_ptr = ::FFI::AutoPointer.new(name_ptr.read_pointer, method(:allocator_free))
|
|
240
|
+
name_ptr = Pointer.new(method(:allocator_free))
|
|
241
|
+
check_status api[:SessionGetOutputName].call(@session, i, @allocator, name_ptr.ref)
|
|
260
242
|
|
|
261
|
-
typeinfo =
|
|
262
|
-
check_status api[:SessionGetOutputTypeInfo].call(@session, i, typeinfo)
|
|
263
|
-
typeinfo = ::FFI::AutoPointer.new(typeinfo.read_pointer, api[:ReleaseTypeInfo])
|
|
243
|
+
typeinfo = Pointer.new(api[:ReleaseTypeInfo])
|
|
244
|
+
check_status api[:SessionGetOutputTypeInfo].call(@session, i, typeinfo.ref)
|
|
264
245
|
|
|
265
246
|
{name: name_ptr.read_string}.merge(Utils.node_info(typeinfo))
|
|
266
247
|
end
|
|
@@ -333,9 +314,8 @@ module OnnxRuntime
|
|
|
333
314
|
# use mutex for thread-safety
|
|
334
315
|
Utils.mutex.synchronize do
|
|
335
316
|
@@env ||= begin
|
|
336
|
-
env =
|
|
337
|
-
check_status api[:CreateEnv].call(3, "Default", env)
|
|
338
|
-
env = ::FFI::AutoPointer.new(env.read_pointer, api[:ReleaseEnv])
|
|
317
|
+
env = Pointer.new(api[:ReleaseEnv])
|
|
318
|
+
check_status api[:CreateEnv].call(3, "Default", env.ref)
|
|
339
319
|
# disable telemetry
|
|
340
320
|
# https://github.com/microsoft/onnxruntime/blob/master/docs/Privacy.md
|
|
341
321
|
check_status api[:DisableTelemetryEvents].call(env)
|
data/lib/onnxruntime/model.rb
CHANGED
|
@@ -7,12 +7,7 @@ module OnnxRuntime
|
|
|
7
7
|
def predict(input_feed, output_names: nil, **run_options)
|
|
8
8
|
predictions = @session.run(output_names, input_feed, **run_options)
|
|
9
9
|
output_names ||= outputs.map { |o| o[:name] }
|
|
10
|
-
|
|
11
|
-
result = {}
|
|
12
|
-
output_names.zip(predictions).each do |k, v|
|
|
13
|
-
result[k.to_s] = v
|
|
14
|
-
end
|
|
15
|
-
result
|
|
10
|
+
output_names.zip(predictions).to_h { |k, v| [k.to_s, v] }
|
|
16
11
|
end
|
|
17
12
|
|
|
18
13
|
def inputs
|
|
@@ -22,18 +22,18 @@ module OnnxRuntime
|
|
|
22
22
|
input_node_dims = ::FFI::MemoryPointer.new(:int64, shape.size)
|
|
23
23
|
input_node_dims.write_array_of_int64(shape)
|
|
24
24
|
|
|
25
|
-
ptr =
|
|
25
|
+
ptr = Pointer.new
|
|
26
26
|
if element_type == :string
|
|
27
27
|
# keep reference to _str_ptrs until FillStringTensor call
|
|
28
28
|
input_tensor_values, _str_ptrs = create_input_strings(input)
|
|
29
|
-
Utils.check_status FFI.api[:CreateTensorAsOrtValue].call(Utils.allocator, input_node_dims, shape.size, type_enum, ptr)
|
|
30
|
-
Utils.check_status FFI.api[:FillStringTensor].call(ptr
|
|
29
|
+
Utils.check_status FFI.api[:CreateTensorAsOrtValue].call(Utils.allocator, input_node_dims, shape.size, type_enum, ptr.ref)
|
|
30
|
+
Utils.check_status FFI.api[:FillStringTensor].call(ptr, input_tensor_values, input_tensor_values.size / input_tensor_values.type_size)
|
|
31
31
|
else
|
|
32
32
|
input_tensor_values = create_input_data(input, element_type)
|
|
33
|
-
Utils.check_status FFI.api[:CreateTensorWithDataAsOrtValue].call(allocator_info, input_tensor_values, input_tensor_values.size, input_node_dims, shape.size, type_enum, ptr)
|
|
33
|
+
Utils.check_status FFI.api[:CreateTensorWithDataAsOrtValue].call(allocator_info, input_tensor_values, input_tensor_values.size, input_node_dims, shape.size, type_enum, ptr.ref)
|
|
34
34
|
end
|
|
35
35
|
|
|
36
|
-
new(ptr.
|
|
36
|
+
new(ptr.to_ptr, input_tensor_values)
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
def self.from_shape_and_type(shape, element_type)
|
|
@@ -43,10 +43,10 @@ module OnnxRuntime
|
|
|
43
43
|
input_node_dims = ::FFI::MemoryPointer.new(:int64, shape.size)
|
|
44
44
|
input_node_dims.write_array_of_int64(shape)
|
|
45
45
|
|
|
46
|
-
ptr =
|
|
47
|
-
Utils.check_status FFI.api[:CreateTensorAsOrtValue].call(Utils.allocator, input_node_dims, shape.size, type_enum, ptr)
|
|
46
|
+
ptr = Pointer.new
|
|
47
|
+
Utils.check_status FFI.api[:CreateTensorAsOrtValue].call(Utils.allocator, input_node_dims, shape.size, type_enum, ptr.ref)
|
|
48
48
|
|
|
49
|
-
new(ptr.
|
|
49
|
+
new(ptr.to_ptr)
|
|
50
50
|
end
|
|
51
51
|
|
|
52
52
|
def self.create_input_data(input, tensor_type)
|
|
@@ -85,9 +85,8 @@ module OnnxRuntime
|
|
|
85
85
|
|
|
86
86
|
def data_type
|
|
87
87
|
@data_type ||= begin
|
|
88
|
-
typeinfo =
|
|
89
|
-
Utils.check_status FFI.api[:GetTypeInfo].call(@ptr, typeinfo)
|
|
90
|
-
typeinfo = ::FFI::AutoPointer.new(typeinfo.read_pointer, FFI.api[:ReleaseTypeInfo])
|
|
88
|
+
typeinfo = Pointer.new(FFI.api[:ReleaseTypeInfo])
|
|
89
|
+
Utils.check_status FFI.api[:GetTypeInfo].call(@ptr, typeinfo.ref)
|
|
91
90
|
Utils.node_info(typeinfo)[:type]
|
|
92
91
|
end
|
|
93
92
|
end
|
|
@@ -117,9 +116,9 @@ module OnnxRuntime
|
|
|
117
116
|
end
|
|
118
117
|
|
|
119
118
|
def data_ptr
|
|
120
|
-
tensor_data =
|
|
121
|
-
FFI.api[:GetTensorMutableData].call(@ptr, tensor_data)
|
|
122
|
-
tensor_data.
|
|
119
|
+
tensor_data = Pointer.new
|
|
120
|
+
FFI.api[:GetTensorMutableData].call(@ptr, tensor_data.ref)
|
|
121
|
+
tensor_data.to_ptr
|
|
123
122
|
end
|
|
124
123
|
|
|
125
124
|
private
|
|
@@ -134,9 +133,8 @@ module OnnxRuntime
|
|
|
134
133
|
|
|
135
134
|
def type_and_shape_info
|
|
136
135
|
@type_and_shape_info ||= begin
|
|
137
|
-
typeinfo =
|
|
138
|
-
Utils.check_status FFI.api[:GetTensorTypeAndShape].call(@ptr, typeinfo)
|
|
139
|
-
typeinfo = ::FFI::AutoPointer.new(typeinfo.read_pointer, FFI.api[:ReleaseTensorTypeAndShapeInfo])
|
|
136
|
+
typeinfo = Pointer.new(FFI.api[:ReleaseTensorTypeAndShapeInfo])
|
|
137
|
+
Utils.check_status FFI.api[:GetTensorTypeAndShape].call(@ptr, typeinfo.ref)
|
|
140
138
|
Utils.tensor_type_and_shape(typeinfo)
|
|
141
139
|
end
|
|
142
140
|
end
|
|
@@ -148,14 +146,13 @@ module OnnxRuntime
|
|
|
148
146
|
|
|
149
147
|
case type
|
|
150
148
|
when :tensor
|
|
151
|
-
typeinfo =
|
|
152
|
-
Utils.check_status FFI.api[:GetTensorTypeAndShape].call(out_ptr, typeinfo)
|
|
153
|
-
typeinfo = ::FFI::AutoPointer.new(typeinfo.read_pointer, FFI.api[:ReleaseTensorTypeAndShapeInfo])
|
|
149
|
+
typeinfo = Pointer.new(FFI.api[:ReleaseTensorTypeAndShapeInfo])
|
|
150
|
+
Utils.check_status FFI.api[:GetTensorTypeAndShape].call(out_ptr, typeinfo.ref)
|
|
154
151
|
|
|
155
152
|
type, shape = Utils.tensor_type_and_shape(typeinfo)
|
|
156
153
|
|
|
157
|
-
tensor_data =
|
|
158
|
-
Utils.check_status FFI.api[:GetTensorMutableData].call(out_ptr, tensor_data)
|
|
154
|
+
tensor_data = Pointer.new
|
|
155
|
+
Utils.check_status FFI.api[:GetTensorMutableData].call(out_ptr, tensor_data.ref)
|
|
159
156
|
|
|
160
157
|
out_size = ::FFI::MemoryPointer.new(:size_t)
|
|
161
158
|
Utils.check_status FFI.api[:GetTensorShapeElementCount].call(typeinfo, out_size)
|
|
@@ -174,15 +171,15 @@ module OnnxRuntime
|
|
|
174
171
|
else
|
|
175
172
|
numo_type = Utils.numo_types[type]
|
|
176
173
|
Utils.unsupported_type("element", type) unless numo_type
|
|
177
|
-
numo_type.from_binary(tensor_data.
|
|
174
|
+
numo_type.from_binary(tensor_data.to_ptr.read_bytes(output_tensor_size * numo_type::ELEMENT_BYTE_SIZE), shape)
|
|
178
175
|
end
|
|
179
176
|
when :ruby
|
|
180
177
|
arr =
|
|
181
178
|
case type
|
|
182
179
|
when :float, :uint8, :int8, :uint16, :int16, :int32, :int64, :double, :uint32, :uint64
|
|
183
|
-
tensor_data.
|
|
180
|
+
tensor_data.to_ptr.send("read_array_of_#{type}", output_tensor_size)
|
|
184
181
|
when :bool
|
|
185
|
-
tensor_data.
|
|
182
|
+
tensor_data.to_ptr.read_array_of_uint8(output_tensor_size).map { |v| v == 1 }
|
|
186
183
|
when :string
|
|
187
184
|
create_strings_from_onnx_value(out_ptr, output_tensor_size, [])
|
|
188
185
|
else
|
|
@@ -198,23 +195,19 @@ module OnnxRuntime
|
|
|
198
195
|
Utils.check_status FFI.api[:GetValueCount].call(out_ptr, out)
|
|
199
196
|
|
|
200
197
|
out.read(:size_t).times.map do |i|
|
|
201
|
-
seq =
|
|
202
|
-
Utils.check_status FFI.api[:GetValue].call(out_ptr, i, Utils.allocator, seq)
|
|
203
|
-
seq = ::FFI::AutoPointer.new(seq.read_pointer, FFI.api[:ReleaseValue])
|
|
198
|
+
seq = Pointer.new(FFI.api[:ReleaseValue])
|
|
199
|
+
Utils.check_status FFI.api[:GetValue].call(out_ptr, i, Utils.allocator, seq.ref)
|
|
204
200
|
create_from_onnx_value(seq, output_type)
|
|
205
201
|
end
|
|
206
202
|
when :map
|
|
207
|
-
map_keys =
|
|
208
|
-
Utils.check_status FFI.api[:GetValue].call(out_ptr, 0, Utils.allocator, map_keys)
|
|
209
|
-
map_keys = ::FFI::AutoPointer.new(map_keys.read_pointer, FFI.api[:ReleaseValue])
|
|
203
|
+
map_keys = Pointer.new(FFI.api[:ReleaseValue])
|
|
204
|
+
Utils.check_status FFI.api[:GetValue].call(out_ptr, 0, Utils.allocator, map_keys.ref)
|
|
210
205
|
|
|
211
|
-
map_values =
|
|
212
|
-
Utils.check_status FFI.api[:GetValue].call(out_ptr, 1, Utils.allocator, map_values)
|
|
213
|
-
map_values = ::FFI::AutoPointer.new(map_values.read_pointer, FFI.api[:ReleaseValue])
|
|
206
|
+
map_values = Pointer.new(FFI.api[:ReleaseValue])
|
|
207
|
+
Utils.check_status FFI.api[:GetValue].call(out_ptr, 1, Utils.allocator, map_values.ref)
|
|
214
208
|
|
|
215
|
-
type_shape =
|
|
216
|
-
Utils.check_status FFI.api[:GetTensorTypeAndShape].call(map_keys, type_shape)
|
|
217
|
-
type_shape = ::FFI::AutoPointer.new(type_shape.read_pointer, FFI.api[:ReleaseTensorTypeAndShapeInfo])
|
|
209
|
+
type_shape = Pointer.new(FFI.api[:ReleaseTensorTypeAndShapeInfo])
|
|
210
|
+
Utils.check_status FFI.api[:GetTensorTypeAndShape].call(map_keys, type_shape.ref)
|
|
218
211
|
|
|
219
212
|
elem_type = ::FFI::MemoryPointer.new(:int)
|
|
220
213
|
Utils.check_status FFI.api[:GetTensorElementType].call(type_shape, elem_type)
|
|
@@ -223,13 +216,9 @@ module OnnxRuntime
|
|
|
223
216
|
elem_type = FFI::TensorElementDataType[elem_type.read_int]
|
|
224
217
|
case elem_type
|
|
225
218
|
when :int64
|
|
226
|
-
ret = {}
|
|
227
219
|
keys = create_from_onnx_value(map_keys, output_type)
|
|
228
220
|
values = create_from_onnx_value(map_values, output_type)
|
|
229
|
-
keys.zip(values).
|
|
230
|
-
ret[k] = v
|
|
231
|
-
end
|
|
232
|
-
ret
|
|
221
|
+
keys.zip(values).to_h
|
|
233
222
|
else
|
|
234
223
|
Utils.unsupported_type("element", elem_type)
|
|
235
224
|
end
|
|
@@ -264,9 +253,9 @@ module OnnxRuntime
|
|
|
264
253
|
|
|
265
254
|
def self.allocator_info
|
|
266
255
|
@allocator_info ||= begin
|
|
267
|
-
allocator_info =
|
|
268
|
-
Utils.check_status FFI.api[:CreateCpuMemoryInfo].call(1, 0, allocator_info)
|
|
269
|
-
|
|
256
|
+
allocator_info = Pointer.new(FFI.api[:ReleaseMemoryInfo])
|
|
257
|
+
Utils.check_status FFI.api[:CreateCpuMemoryInfo].call(1, 0, allocator_info.ref)
|
|
258
|
+
allocator_info
|
|
270
259
|
end
|
|
271
260
|
end
|
|
272
261
|
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module OnnxRuntime
|
|
2
|
+
class Pointer
|
|
3
|
+
attr_reader :ref
|
|
4
|
+
|
|
5
|
+
def initialize(free = nil)
|
|
6
|
+
@ref = ::FFI::MemoryPointer.new(:pointer)
|
|
7
|
+
ObjectSpace.define_finalizer(self, self.class.finalize(@ref, free)) if free
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def self.finalize(ref, free)
|
|
11
|
+
proc do
|
|
12
|
+
ptr = ref.read_pointer
|
|
13
|
+
free.(ptr) unless ptr.null?
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def to_ptr
|
|
18
|
+
@ref.read_pointer
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def read_string(...)
|
|
22
|
+
to_ptr.read_string(...)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def read_array_of_pointer(...)
|
|
26
|
+
to_ptr.read_array_of_pointer(...)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
data/lib/onnxruntime/utils.rb
CHANGED
|
@@ -49,9 +49,9 @@ module OnnxRuntime
|
|
|
49
49
|
case type
|
|
50
50
|
when :tensor
|
|
51
51
|
# don't free tensor_info
|
|
52
|
-
tensor_info =
|
|
53
|
-
check_status api[:CastTypeInfoToTensorInfo].call(typeinfo, tensor_info)
|
|
54
|
-
type, shape = Utils.tensor_type_and_shape(tensor_info
|
|
52
|
+
tensor_info = Pointer.new
|
|
53
|
+
check_status api[:CastTypeInfoToTensorInfo].call(typeinfo, tensor_info.ref)
|
|
54
|
+
type, shape = Utils.tensor_type_and_shape(tensor_info)
|
|
55
55
|
|
|
56
56
|
{
|
|
57
57
|
type: "tensor(#{FFI::TensorElementDataType[type]})",
|
|
@@ -59,12 +59,11 @@ module OnnxRuntime
|
|
|
59
59
|
}
|
|
60
60
|
when :sequence
|
|
61
61
|
# don't free sequence_info
|
|
62
|
-
sequence_type_info =
|
|
63
|
-
check_status api[:CastTypeInfoToSequenceTypeInfo].call(typeinfo, sequence_type_info)
|
|
62
|
+
sequence_type_info = Pointer.new
|
|
63
|
+
check_status api[:CastTypeInfoToSequenceTypeInfo].call(typeinfo, sequence_type_info.ref)
|
|
64
64
|
|
|
65
|
-
nested_type_info =
|
|
66
|
-
check_status api[:GetSequenceElementType].call(sequence_type_info
|
|
67
|
-
nested_type_info = ::FFI::AutoPointer.new(nested_type_info.read_pointer, api[:ReleaseTypeInfo])
|
|
65
|
+
nested_type_info = Pointer.new(api[:ReleaseTypeInfo])
|
|
66
|
+
check_status api[:GetSequenceElementType].call(sequence_type_info, nested_type_info.ref)
|
|
68
67
|
v = node_info(nested_type_info)[:type]
|
|
69
68
|
|
|
70
69
|
{
|
|
@@ -73,18 +72,17 @@ module OnnxRuntime
|
|
|
73
72
|
}
|
|
74
73
|
when :map
|
|
75
74
|
# don't free map_type_info
|
|
76
|
-
map_type_info =
|
|
77
|
-
check_status api[:CastTypeInfoToMapTypeInfo].call(typeinfo, map_type_info)
|
|
75
|
+
map_type_info = Pointer.new
|
|
76
|
+
check_status api[:CastTypeInfoToMapTypeInfo].call(typeinfo, map_type_info.ref)
|
|
78
77
|
|
|
79
78
|
# key
|
|
80
79
|
key_type = ::FFI::MemoryPointer.new(:int)
|
|
81
|
-
check_status api[:GetMapKeyType].call(map_type_info
|
|
80
|
+
check_status api[:GetMapKeyType].call(map_type_info, key_type)
|
|
82
81
|
k = FFI::TensorElementDataType[key_type.read_int]
|
|
83
82
|
|
|
84
83
|
# value
|
|
85
|
-
value_type_info =
|
|
86
|
-
check_status api[:GetMapValueType].call(map_type_info
|
|
87
|
-
value_type_info = ::FFI::AutoPointer.new(value_type_info.read_pointer, api[:ReleaseTypeInfo])
|
|
84
|
+
value_type_info = Pointer.new(api[:ReleaseTypeInfo])
|
|
85
|
+
check_status api[:GetMapValueType].call(map_type_info, value_type_info.ref)
|
|
88
86
|
v = node_info(value_type_info)[:type]
|
|
89
87
|
|
|
90
88
|
{
|
|
@@ -132,9 +130,10 @@ module OnnxRuntime
|
|
|
132
130
|
|
|
133
131
|
def self.allocator
|
|
134
132
|
@allocator ||= begin
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
allocator.
|
|
133
|
+
# do not free default allocator
|
|
134
|
+
allocator = Pointer.new
|
|
135
|
+
check_status api[:GetAllocatorWithDefaultOptions].call(allocator.ref)
|
|
136
|
+
allocator
|
|
138
137
|
end
|
|
139
138
|
end
|
|
140
139
|
end
|
data/lib/onnxruntime/version.rb
CHANGED
data/lib/onnxruntime.rb
CHANGED
|
@@ -6,6 +6,7 @@ require_relative "onnxruntime/datasets"
|
|
|
6
6
|
require_relative "onnxruntime/inference_session"
|
|
7
7
|
require_relative "onnxruntime/model"
|
|
8
8
|
require_relative "onnxruntime/ort_value"
|
|
9
|
+
require_relative "onnxruntime/pointer"
|
|
9
10
|
require_relative "onnxruntime/utils"
|
|
10
11
|
require_relative "onnxruntime/version"
|
|
11
12
|
|
|
@@ -15,24 +16,24 @@ module OnnxRuntime
|
|
|
15
16
|
class << self
|
|
16
17
|
attr_accessor :ffi_lib
|
|
17
18
|
end
|
|
19
|
+
vendor = File.expand_path("../vendor", __dir__)
|
|
18
20
|
lib_name =
|
|
19
21
|
if Gem.win_platform?
|
|
20
|
-
"onnxruntime.dll"
|
|
22
|
+
"#{vendor}/onnxruntime.dll"
|
|
21
23
|
elsif RbConfig::CONFIG["host_os"] =~ /darwin/i
|
|
22
24
|
if RbConfig::CONFIG["host_cpu"] =~ /arm|aarch64/i
|
|
23
|
-
"libonnxruntime.arm64.dylib"
|
|
25
|
+
"#{vendor}/libonnxruntime.arm64.dylib"
|
|
24
26
|
else
|
|
25
|
-
"libonnxruntime.dylib"
|
|
27
|
+
"/usr/local/opt/onnxruntime/lib/libonnxruntime.dylib"
|
|
26
28
|
end
|
|
27
29
|
else
|
|
28
30
|
if RbConfig::CONFIG["host_cpu"] =~ /arm|aarch64/i
|
|
29
|
-
"libonnxruntime.arm64.so"
|
|
31
|
+
"#{vendor}/libonnxruntime.arm64.so"
|
|
30
32
|
else
|
|
31
|
-
"libonnxruntime.so"
|
|
33
|
+
"#{vendor}/libonnxruntime.so"
|
|
32
34
|
end
|
|
33
35
|
end
|
|
34
|
-
|
|
35
|
-
self.ffi_lib = [vendor_lib]
|
|
36
|
+
self.ffi_lib = [lib_name]
|
|
36
37
|
|
|
37
38
|
def self.lib_version
|
|
38
39
|
FFI.OrtGetApiBase[:GetVersionString].call.read_string
|
|
@@ -5806,41 +5806,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
5806
5806
|
|
|
5807
5807
|
_____
|
|
5808
5808
|
|
|
5809
|
-
composable_kernel
|
|
5810
|
-
|
|
5811
|
-
https://github.com/ROCmSoftwarePlatform/composable_kernel
|
|
5812
|
-
|
|
5813
|
-
Copyright (c) 2018- , Advanced Micro Devices, Inc. (Chao Liu, Jing Zhang)
|
|
5814
|
-
Copyright (c) 2019- , Advanced Micro Devices, Inc. (Letao Qin, Qianfeng Zhang, Liang Huang, Shaojie Wang)
|
|
5815
|
-
Copyright (c) 2022- , Advanced Micro Devices, Inc. (Anthony Chang, Chunyu Lai, Illia Silin, Adam Osewski, Poyen Chen, Jehandad Khan)
|
|
5816
|
-
Copyright (c) 2019-2021, Advanced Micro Devices, Inc. (Hanwen Chang)
|
|
5817
|
-
Copyright (c) 2019-2020, Advanced Micro Devices, Inc. (Tejash Shah)
|
|
5818
|
-
Copyright (c) 2020 , Advanced Micro Devices, Inc. (Xiaoyan Zhou)
|
|
5819
|
-
Copyright (c) 2021-2022, Advanced Micro Devices, Inc. (Jianfeng Yan)
|
|
5820
|
-
|
|
5821
|
-
SPDX-License-Identifier: MIT
|
|
5822
|
-
Copyright (c) 2018-2023, Advanced Micro Devices, Inc. All rights reserved.
|
|
5823
|
-
|
|
5824
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5825
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
5826
|
-
in the Software without restriction, including without limitation the rights
|
|
5827
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
5828
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
5829
|
-
furnished to do so, subject to the following conditions:
|
|
5830
|
-
|
|
5831
|
-
The above copyright notice and this permission notice shall be included in all
|
|
5832
|
-
copies or substantial portions of the Software.
|
|
5833
|
-
|
|
5834
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
5835
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
5836
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
5837
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
5838
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
5839
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
5840
|
-
SOFTWARE.
|
|
5841
|
-
|
|
5842
|
-
_____
|
|
5843
|
-
|
|
5844
5809
|
neural-speed
|
|
5845
5810
|
|
|
5846
5811
|
https://github.com/intel/neural-speed
|
|
Binary file
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: onnxruntime
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.11.0
|
|
5
5
|
platform: aarch64-linux
|
|
6
6
|
authors:
|
|
7
7
|
- Andrew Kane
|
|
@@ -37,6 +37,7 @@ files:
|
|
|
37
37
|
- lib/onnxruntime/inference_session.rb
|
|
38
38
|
- lib/onnxruntime/model.rb
|
|
39
39
|
- lib/onnxruntime/ort_value.rb
|
|
40
|
+
- lib/onnxruntime/pointer.rb
|
|
40
41
|
- lib/onnxruntime/utils.rb
|
|
41
42
|
- lib/onnxruntime/version.rb
|
|
42
43
|
- vendor/LICENSE
|