onnxruntime 0.7.0-x86_64-linux → 0.7.3-x86_64-linux
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -0
- data/README.md +5 -1
- data/lib/onnxruntime/ffi.rb +90 -14
- data/lib/onnxruntime/inference_session.rb +69 -8
- data/lib/onnxruntime/version.rb +1 -1
- data/vendor/libonnxruntime.so +0 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d8e4e67deb998574714c80df2b7dcb939cd370c9896695620e3d2cd92a33bc8c
|
4
|
+
data.tar.gz: 61ba717b2c18c97442b63d0e68e997b02f4c84a530447d92a43fdcad411f7914
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c29c9f3184ef3a96f1108cbc05c1df705b1b9f4a2b597ddba9747d5512e484a601c053b3fec1a42a04cb7560f62252c2a46fdf56d0357a2e3cf8ad234238a1f
|
7
|
+
data.tar.gz: ebe329dc80dfcfdd828097e324dc9850a2ba1c60138e81e524ac30abf0ab84ce45564ea35f3f8b22a85c634d35f50184abcbb1ea802c21d9262c72b8fc1402e4
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,20 @@
|
|
1
|
+
## 0.7.3 (2022-07-23)
|
2
|
+
|
3
|
+
- Updated ONNX Runtime to 1.12.0
|
4
|
+
|
5
|
+
## 0.7.2 (2022-05-04)
|
6
|
+
|
7
|
+
- Updated ONNX Runtime to 1.11.1
|
8
|
+
|
9
|
+
## 0.7.1 (2022-03-28)
|
10
|
+
|
11
|
+
- Added `graph_description` to metadata
|
12
|
+
- Added `free_dimension_overrides_by_denotation` and `free_dimension_overrides_by_name` options
|
13
|
+
- Added `profile_file_prefix` option
|
14
|
+
- Added `session_config_entries` option
|
15
|
+
- Fixed memory leaks
|
16
|
+
- Fixed `enable_cpu_mem_arena: false`
|
17
|
+
|
1
18
|
## 0.7.0 (2022-03-27)
|
2
19
|
|
3
20
|
- Added platform-specific gems
|
data/README.md
CHANGED
@@ -64,13 +64,17 @@ OnnxRuntime::Model.new(path_or_bytes, {
|
|
64
64
|
enable_mem_pattern: true,
|
65
65
|
enable_profiling: false,
|
66
66
|
execution_mode: :sequential, # :sequential or :parallel
|
67
|
+
free_dimension_overrides_by_denotation: nil,
|
68
|
+
free_dimension_overrides_by_name: nil,
|
67
69
|
graph_optimization_level: nil, # :none, :basic, :extended, or :all
|
68
70
|
inter_op_num_threads: nil,
|
69
71
|
intra_op_num_threads: nil,
|
70
72
|
log_severity_level: 2,
|
71
73
|
log_verbosity_level: 0,
|
72
74
|
logid: nil,
|
73
|
-
optimized_model_filepath: nil
|
75
|
+
optimized_model_filepath: nil,
|
76
|
+
profile_file_prefix: "onnxruntime_profile_",
|
77
|
+
session_config_entries: nil
|
74
78
|
})
|
75
79
|
```
|
76
80
|
|
data/lib/onnxruntime/ffi.rb
CHANGED
@@ -2,19 +2,13 @@ module OnnxRuntime
|
|
2
2
|
module FFI
|
3
3
|
extend ::FFI::Library
|
4
4
|
|
5
|
-
|
6
|
-
ffi_lib OnnxRuntime.ffi_lib
|
7
|
-
rescue LoadError => e
|
8
|
-
if e.message.include?("Library not loaded: /usr/local/opt/libomp/lib/libomp.dylib") && e.message.include?("Reason: image not found")
|
9
|
-
raise LoadError, "OpenMP not found. Run `brew install libomp`"
|
10
|
-
else
|
11
|
-
raise e
|
12
|
-
end
|
13
|
-
end
|
5
|
+
ffi_lib OnnxRuntime.ffi_lib
|
14
6
|
|
15
7
|
# https://github.com/microsoft/onnxruntime/blob/master/include/onnxruntime/core/session/onnxruntime_c_api.h
|
16
8
|
# keep same order
|
17
9
|
|
10
|
+
ORT_API_VERSION = 11
|
11
|
+
|
18
12
|
# enums
|
19
13
|
TensorElementDataType = enum(:undefined, :float, :uint8, :int8, :uint16, :int16, :int32, :int64, :string, :bool, :float16, :double, :uint32, :uint64, :complex64, :complex128, :bfloat16)
|
20
14
|
OnnxType = enum(:unknown, :tensor, :sequence, :map, :opaque, :sparsetensor)
|
@@ -84,7 +78,7 @@ module OnnxRuntime
|
|
84
78
|
:GetTensorElementType, callback(%i[pointer pointer], :pointer),
|
85
79
|
:GetDimensionsCount, callback(%i[pointer pointer], :pointer),
|
86
80
|
:GetDimensions, callback(%i[pointer pointer size_t], :pointer),
|
87
|
-
:GetSymbolicDimensions, callback(%i[], :pointer),
|
81
|
+
:GetSymbolicDimensions, callback(%i[pointer pointer size_t], :pointer),
|
88
82
|
:GetTensorShapeElementCount, callback(%i[pointer pointer], :pointer),
|
89
83
|
:GetTensorTypeAndShape, callback(%i[pointer pointer], :pointer),
|
90
84
|
:GetTypeInfo, callback(%i[pointer pointer], :pointer),
|
@@ -97,10 +91,10 @@ module OnnxRuntime
|
|
97
91
|
:MemoryInfoGetMemType, callback(%i[], :pointer),
|
98
92
|
:MemoryInfoGetType, callback(%i[], :pointer),
|
99
93
|
:AllocatorAlloc, callback(%i[], :pointer),
|
100
|
-
:AllocatorFree, callback(%i[], :pointer),
|
94
|
+
:AllocatorFree, callback(%i[pointer pointer], :pointer),
|
101
95
|
:AllocatorGetInfo, callback(%i[], :pointer),
|
102
96
|
:GetAllocatorWithDefaultOptions, callback(%i[pointer], :pointer),
|
103
|
-
:AddFreeDimensionOverride, callback(%i[], :pointer),
|
97
|
+
:AddFreeDimensionOverride, callback(%i[pointer string int64], :pointer),
|
104
98
|
:GetValue, callback(%i[pointer int pointer pointer], :pointer),
|
105
99
|
:GetValueCount, callback(%i[pointer pointer], :pointer),
|
106
100
|
:CreateValue, callback(%i[], :pointer),
|
@@ -145,9 +139,91 @@ module OnnxRuntime
|
|
145
139
|
:CreateThreadingOptions, callback(%i[], :pointer),
|
146
140
|
:ReleaseThreadingOptions, callback(%i[], :pointer),
|
147
141
|
:ModelMetadataGetCustomMetadataMapKeys, callback(%i[pointer pointer pointer pointer], :pointer),
|
148
|
-
:AddFreeDimensionOverrideByName, callback(%i[], :pointer),
|
142
|
+
:AddFreeDimensionOverrideByName, callback(%i[pointer string int64], :pointer),
|
149
143
|
:GetAvailableProviders, callback(%i[pointer pointer], :pointer),
|
150
|
-
:ReleaseAvailableProviders, callback(%i[pointer int], :pointer)
|
144
|
+
:ReleaseAvailableProviders, callback(%i[pointer int], :pointer),
|
145
|
+
:GetStringTensorElementLength, callback(%i[], :pointer),
|
146
|
+
:GetStringTensorElement, callback(%i[], :pointer),
|
147
|
+
:FillStringTensorElement, callback(%i[], :pointer),
|
148
|
+
:AddSessionConfigEntry, callback(%i[pointer string string], :pointer),
|
149
|
+
:CreateAllocator, callback(%i[], :pointer),
|
150
|
+
:ReleaseAllocator, callback(%i[], :pointer),
|
151
|
+
:RunWithBinding, callback(%i[], :pointer),
|
152
|
+
:CreateIoBinding, callback(%i[], :pointer),
|
153
|
+
:ReleaseIoBinding, callback(%i[], :pointer),
|
154
|
+
:BindInput, callback(%i[], :pointer),
|
155
|
+
:BindOutput, callback(%i[], :pointer),
|
156
|
+
:BindOutputToDevice, callback(%i[], :pointer),
|
157
|
+
:GetBoundOutputNames, callback(%i[], :pointer),
|
158
|
+
:GetBoundOutputValues, callback(%i[], :pointer),
|
159
|
+
:ClearBoundInputs, callback(%i[], :pointer),
|
160
|
+
:ClearBoundOutputs, callback(%i[], :pointer),
|
161
|
+
:TensorAt, callback(%i[], :pointer),
|
162
|
+
:CreateAndRegisterAllocator, callback(%i[], :pointer),
|
163
|
+
:SetLanguageProjection, callback(%i[], :pointer),
|
164
|
+
:SessionGetProfilingStartTimeNs, callback(%i[], :pointer),
|
165
|
+
:SetGlobalIntraOpNumThreads, callback(%i[], :pointer),
|
166
|
+
:SetGlobalInterOpNumThreads, callback(%i[], :pointer),
|
167
|
+
:SetGlobalSpinControl, callback(%i[], :pointer),
|
168
|
+
:AddInitializer, callback(%i[], :pointer),
|
169
|
+
:CreateEnvWithCustomLoggerAndGlobalThreadPools, callback(%i[], :pointer),
|
170
|
+
:SessionOptionsAppendExecutionProvider_CUDA, callback(%i[], :pointer),
|
171
|
+
:SessionOptionsAppendExecutionProvider_ROCM, callback(%i[], :pointer),
|
172
|
+
:SessionOptionsAppendExecutionProvider_OpenVINO, callback(%i[], :pointer),
|
173
|
+
:SetGlobalDenormalAsZero, callback(%i[], :pointer),
|
174
|
+
:CreateArenaCfg, callback(%i[], :pointer),
|
175
|
+
:ReleaseArenaCfg, callback(%i[], :pointer),
|
176
|
+
:ModelMetadataGetGraphDescription, callback(%i[pointer pointer pointer], :pointer),
|
177
|
+
:SessionOptionsAppendExecutionProvider_TensorRT, callback(%i[], :pointer),
|
178
|
+
:SetCurrentGpuDeviceId, callback(%i[], :pointer),
|
179
|
+
:GetCurrentGpuDeviceId, callback(%i[], :pointer),
|
180
|
+
:KernelInfoGetAttributeArray_float, callback(%i[], :pointer),
|
181
|
+
:KernelInfoGetAttributeArray_int64, callback(%i[], :pointer),
|
182
|
+
:CreateArenaCfgV2, callback(%i[], :pointer),
|
183
|
+
:AddRunConfigEntry, callback(%i[], :pointer),
|
184
|
+
:CreatePrepackedWeightsContainer, callback(%i[], :pointer),
|
185
|
+
:ReleasePrepackedWeightsContainer, callback(%i[], :pointer),
|
186
|
+
:CreateSessionWithPrepackedWeightsContainer, callback(%i[], :pointer),
|
187
|
+
:CreateSessionFromArrayWithPrepackedWeightsContainer, callback(%i[], :pointer),
|
188
|
+
:SessionOptionsAppendExecutionProvider_TensorRT_V2, callback(%i[], :pointer),
|
189
|
+
:CreateTensorRTProviderOptions, callback(%i[], :pointer),
|
190
|
+
:UpdateTensorRTProviderOptions, callback(%i[], :pointer),
|
191
|
+
:GetTensorRTProviderOptionsAsString, callback(%i[], :pointer),
|
192
|
+
:ReleaseTensorRTProviderOptions, callback(%i[], :pointer),
|
193
|
+
:EnableOrtCustomOps, callback(%i[], :pointer),
|
194
|
+
:RegisterAllocator, callback(%i[], :pointer),
|
195
|
+
:UnregisterAllocator, callback(%i[], :pointer),
|
196
|
+
:IsSparseTensor, callback(%i[], :pointer),
|
197
|
+
:CreateSparseTensorAsOrtValue, callback(%i[], :pointer),
|
198
|
+
:FillSparseTensorCoo, callback(%i[], :pointer),
|
199
|
+
:FillSparseTensorCsr, callback(%i[], :pointer),
|
200
|
+
:FillSparseTensorBlockSparse, callback(%i[], :pointer),
|
201
|
+
:CreateSparseTensorWithValuesAsOrtValue, callback(%i[], :pointer),
|
202
|
+
:UseCsrIndices, callback(%i[], :pointer),
|
203
|
+
:UseBlockSparseIndices, callback(%i[], :pointer),
|
204
|
+
:GetSparseTensorFormat, callback(%i[], :pointer),
|
205
|
+
:GetSparseTensorValuesTypeAndShape, callback(%i[], :pointer),
|
206
|
+
:GetSparseTensorValues, callback(%i[], :pointer),
|
207
|
+
:GetSparseTensorIndicesTypeShape, callback(%i[], :pointer),
|
208
|
+
:GetSparseTensorIndices, callback(%i[], :pointer),
|
209
|
+
:HasValue, callback(%i[], :pointer),
|
210
|
+
:KernelContext_GetGPUComputeStream, callback(%i[], :pointer),
|
211
|
+
:GetTensorMemoryInfo, callback(%i[], :pointer),
|
212
|
+
:GetExecutionProviderApi, callback(%i[], :pointer),
|
213
|
+
:SessionOptionsSetCustomCreateThreadFn, callback(%i[], :pointer),
|
214
|
+
:SessionOptionsSetCustomThreadCreationOptions, callback(%i[], :pointer),
|
215
|
+
:SessionOptionsSetCustomJoinThreadFn, callback(%i[], :pointer),
|
216
|
+
:SetGlobalCustomCreateThreadFn, callback(%i[], :pointer),
|
217
|
+
:SetGlobalCustomThreadCreationOptions, callback(%i[], :pointer),
|
218
|
+
:SetGlobalCustomJoinThreadFn, callback(%i[], :pointer),
|
219
|
+
:SynchronizeBoundInputs, callback(%i[], :pointer),
|
220
|
+
:SynchronizeBoundOutputs, callback(%i[], :pointer),
|
221
|
+
:SessionOptionsAppendExecutionProvider_CUDA_V2, callback(%i[], :pointer),
|
222
|
+
:CreateCUDAProviderOptions, callback(%i[], :pointer),
|
223
|
+
:UpdateCUDAProviderOptions, callback(%i[], :pointer),
|
224
|
+
:GetCUDAProviderOptionsAsString, callback(%i[], :pointer),
|
225
|
+
:ReleaseCUDAProviderOptions, callback(%i[], :pointer),
|
226
|
+
:SessionOptionsAppendExecutionProvider_MIGraphX, callback(%i[], :pointer)
|
151
227
|
end
|
152
228
|
|
153
229
|
class ApiBase < ::FFI::Struct
|
@@ -2,19 +2,41 @@ module OnnxRuntime
|
|
2
2
|
class InferenceSession
|
3
3
|
attr_reader :inputs, :outputs
|
4
4
|
|
5
|
-
def initialize(path_or_bytes, enable_cpu_mem_arena: true, enable_mem_pattern: true, enable_profiling: false, execution_mode: nil, graph_optimization_level: nil, inter_op_num_threads: nil, intra_op_num_threads: nil, log_severity_level: nil, log_verbosity_level: nil, logid: nil, optimized_model_filepath: nil)
|
5
|
+
def initialize(path_or_bytes, enable_cpu_mem_arena: true, enable_mem_pattern: true, enable_profiling: false, execution_mode: nil, free_dimension_overrides_by_denotation: nil, free_dimension_overrides_by_name: nil, graph_optimization_level: nil, inter_op_num_threads: nil, intra_op_num_threads: nil, log_severity_level: nil, log_verbosity_level: nil, logid: nil, optimized_model_filepath: nil, profile_file_prefix: nil, session_config_entries: nil)
|
6
6
|
# session options
|
7
7
|
session_options = ::FFI::MemoryPointer.new(:pointer)
|
8
8
|
check_status api[:CreateSessionOptions].call(session_options)
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
if enable_cpu_mem_arena
|
10
|
+
check_status api[:EnableCpuMemArena].call(session_options.read_pointer)
|
11
|
+
else
|
12
|
+
check_status api[:DisableCpuMemArena].call(session_options.read_pointer)
|
13
|
+
end
|
14
|
+
if enable_mem_pattern
|
15
|
+
check_status api[:EnableMemPattern].call(session_options.read_pointer)
|
16
|
+
else
|
17
|
+
check_status api[:DisableMemPattern].call(session_options.read_pointer)
|
18
|
+
end
|
19
|
+
if enable_profiling
|
20
|
+
check_status api[:EnableProfiling].call(session_options.read_pointer, ort_string(profile_file_prefix || "onnxruntime_profile_"))
|
21
|
+
else
|
22
|
+
check_status api[:DisableProfiling].call(session_options.read_pointer)
|
23
|
+
end
|
12
24
|
if execution_mode
|
13
25
|
execution_modes = {sequential: 0, parallel: 1}
|
14
26
|
mode = execution_modes[execution_mode]
|
15
27
|
raise ArgumentError, "Invalid execution mode" unless mode
|
16
28
|
check_status api[:SetSessionExecutionMode].call(session_options.read_pointer, mode)
|
17
29
|
end
|
30
|
+
if free_dimension_overrides_by_denotation
|
31
|
+
free_dimension_overrides_by_denotation.each do |k, v|
|
32
|
+
check_status api[:AddFreeDimensionOverride].call(session_options.read_pointer, k.to_s, v)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
if free_dimension_overrides_by_name
|
36
|
+
free_dimension_overrides_by_name.each do |k, v|
|
37
|
+
check_status api[:AddFreeDimensionOverrideByName].call(session_options.read_pointer, k.to_s, v)
|
38
|
+
end
|
39
|
+
end
|
18
40
|
if graph_optimization_level
|
19
41
|
optimization_levels = {none: 0, basic: 1, extended: 2, all: 99}
|
20
42
|
level = optimization_levels[graph_optimization_level]
|
@@ -27,6 +49,11 @@ module OnnxRuntime
|
|
27
49
|
check_status api[:SetSessionLogVerbosityLevel].call(session_options.read_pointer, log_verbosity_level) if log_verbosity_level
|
28
50
|
check_status api[:SetSessionLogId].call(session_options.read_pointer, logid) if logid
|
29
51
|
check_status api[:SetOptimizedModelFilePath].call(session_options.read_pointer, ort_string(optimized_model_filepath)) if optimized_model_filepath
|
52
|
+
if session_config_entries
|
53
|
+
session_config_entries.each do |k, v|
|
54
|
+
check_status api[:AddSessionConfigEntry].call(session_options.read_pointer, k.to_s, v.to_s)
|
55
|
+
end
|
56
|
+
end
|
30
57
|
|
31
58
|
# session
|
32
59
|
@session = ::FFI::MemoryPointer.new(:pointer)
|
@@ -47,6 +74,7 @@ module OnnxRuntime
|
|
47
74
|
ObjectSpace.define_finalizer(self, self.class.finalize(@session))
|
48
75
|
|
49
76
|
# input info
|
77
|
+
# don't free allocator
|
50
78
|
allocator = ::FFI::MemoryPointer.new(:pointer)
|
51
79
|
check_status api[:GetAllocatorWithDefaultOptions].call(allocator)
|
52
80
|
@allocator = allocator
|
@@ -60,9 +88,11 @@ module OnnxRuntime
|
|
60
88
|
num_input_nodes.read(:size_t).times do |i|
|
61
89
|
name_ptr = ::FFI::MemoryPointer.new(:string)
|
62
90
|
check_status api[:SessionGetInputName].call(read_pointer, i, @allocator.read_pointer, name_ptr)
|
91
|
+
# freed in node_info
|
63
92
|
typeinfo = ::FFI::MemoryPointer.new(:pointer)
|
64
93
|
check_status api[:SessionGetInputTypeInfo].call(read_pointer, i, typeinfo)
|
65
94
|
@inputs << {name: name_ptr.read_pointer.read_string}.merge(node_info(typeinfo))
|
95
|
+
allocator_free name_ptr
|
66
96
|
end
|
67
97
|
|
68
98
|
# output
|
@@ -71,12 +101,14 @@ module OnnxRuntime
|
|
71
101
|
num_output_nodes.read(:size_t).times do |i|
|
72
102
|
name_ptr = ::FFI::MemoryPointer.new(:string)
|
73
103
|
check_status api[:SessionGetOutputName].call(read_pointer, i, allocator.read_pointer, name_ptr)
|
104
|
+
# freed in node_info
|
74
105
|
typeinfo = ::FFI::MemoryPointer.new(:pointer)
|
75
106
|
check_status api[:SessionGetOutputTypeInfo].call(read_pointer, i, typeinfo)
|
76
107
|
@outputs << {name: name_ptr.read_pointer.read_string}.merge(node_info(typeinfo))
|
108
|
+
allocator_free name_ptr
|
77
109
|
end
|
78
110
|
ensure
|
79
|
-
|
111
|
+
release :SessionOptions, session_options
|
80
112
|
end
|
81
113
|
|
82
114
|
# TODO support logid
|
@@ -112,6 +144,7 @@ module OnnxRuntime
|
|
112
144
|
release :Value, input_tensor[i]
|
113
145
|
end
|
114
146
|
end
|
147
|
+
# output values released in create_from_onnx_value
|
115
148
|
end
|
116
149
|
|
117
150
|
def modelmeta
|
@@ -120,6 +153,7 @@ module OnnxRuntime
|
|
120
153
|
description = ::FFI::MemoryPointer.new(:string)
|
121
154
|
domain = ::FFI::MemoryPointer.new(:string)
|
122
155
|
graph_name = ::FFI::MemoryPointer.new(:string)
|
156
|
+
graph_description = ::FFI::MemoryPointer.new(:string)
|
123
157
|
producer_name = ::FFI::MemoryPointer.new(:string)
|
124
158
|
version = ::FFI::MemoryPointer.new(:int64_t)
|
125
159
|
|
@@ -129,15 +163,21 @@ module OnnxRuntime
|
|
129
163
|
custom_metadata_map = {}
|
130
164
|
check_status api[:ModelMetadataGetCustomMetadataMapKeys].call(metadata.read_pointer, @allocator.read_pointer, keys, num_keys)
|
131
165
|
num_keys.read(:int64_t).times do |i|
|
132
|
-
|
166
|
+
key_ptr = keys.read_pointer[i * ::FFI::Pointer.size]
|
167
|
+
key = key_ptr.read_pointer.read_string
|
133
168
|
value = ::FFI::MemoryPointer.new(:string)
|
134
169
|
check_status api[:ModelMetadataLookupCustomMetadataMap].call(metadata.read_pointer, @allocator.read_pointer, key, value)
|
135
170
|
custom_metadata_map[key] = value.read_pointer.read_string
|
171
|
+
|
172
|
+
allocator_free key_ptr
|
173
|
+
allocator_free value
|
136
174
|
end
|
175
|
+
allocator_free keys
|
137
176
|
|
138
177
|
check_status api[:ModelMetadataGetDescription].call(metadata.read_pointer, @allocator.read_pointer, description)
|
139
178
|
check_status api[:ModelMetadataGetDomain].call(metadata.read_pointer, @allocator.read_pointer, domain)
|
140
179
|
check_status api[:ModelMetadataGetGraphName].call(metadata.read_pointer, @allocator.read_pointer, graph_name)
|
180
|
+
check_status api[:ModelMetadataGetGraphDescription].call(metadata.read_pointer, @allocator.read_pointer, graph_description)
|
141
181
|
check_status api[:ModelMetadataGetProducerName].call(metadata.read_pointer, @allocator.read_pointer, producer_name)
|
142
182
|
check_status api[:ModelMetadataGetVersion].call(metadata.read_pointer, version)
|
143
183
|
|
@@ -146,11 +186,17 @@ module OnnxRuntime
|
|
146
186
|
description: description.read_pointer.read_string,
|
147
187
|
domain: domain.read_pointer.read_string,
|
148
188
|
graph_name: graph_name.read_pointer.read_string,
|
189
|
+
graph_description: graph_description.read_pointer.read_string,
|
149
190
|
producer_name: producer_name.read_pointer.read_string,
|
150
191
|
version: version.read(:int64_t)
|
151
192
|
}
|
152
193
|
ensure
|
153
194
|
release :ModelMetadata, metadata
|
195
|
+
allocator_free description
|
196
|
+
allocator_free domain
|
197
|
+
allocator_free graph_name
|
198
|
+
allocator_free graph_description
|
199
|
+
allocator_free producer_name
|
154
200
|
end
|
155
201
|
|
156
202
|
# return value has double underscore like Python
|
@@ -250,6 +296,8 @@ module OnnxRuntime
|
|
250
296
|
refs << allocator_info
|
251
297
|
|
252
298
|
input_tensor
|
299
|
+
ensure
|
300
|
+
release :MemoryInfo, allocator_info
|
253
301
|
end
|
254
302
|
|
255
303
|
def create_node_names(names, refs)
|
@@ -352,6 +400,8 @@ module OnnxRuntime
|
|
352
400
|
else
|
353
401
|
unsupported_type("ONNX", type)
|
354
402
|
end
|
403
|
+
ensure
|
404
|
+
api[:ReleaseValue].call(out_ptr) unless out_ptr.null?
|
355
405
|
end
|
356
406
|
|
357
407
|
def create_strings_from_onnx_value(out_ptr, output_tensor_size, result)
|
@@ -445,8 +495,15 @@ module OnnxRuntime
|
|
445
495
|
|
446
496
|
node_dims = ::FFI::MemoryPointer.new(:int64, num_dims)
|
447
497
|
check_status api[:GetDimensions].call(tensor_info.read_pointer, node_dims, num_dims)
|
498
|
+
dims = node_dims.read_array_of_int64(num_dims)
|
499
|
+
|
500
|
+
# TODO uncomment in 0.8.0
|
501
|
+
# symbolic_dims = ::FFI::MemoryPointer.new(:pointer, num_dims)
|
502
|
+
# check_status api[:GetSymbolicDimensions].call(tensor_info.read_pointer, symbolic_dims, num_dims)
|
503
|
+
# named_dims = num_dims.times.map { |i| symbolic_dims[i].read_pointer.read_string }
|
504
|
+
# dims = named_dims.zip(dims).map { |n, d| n.empty? ? d : n }
|
448
505
|
|
449
|
-
[type.read_int,
|
506
|
+
[type.read_int, dims]
|
450
507
|
end
|
451
508
|
|
452
509
|
def unsupported_type(name, type)
|
@@ -485,8 +542,12 @@ module OnnxRuntime
|
|
485
542
|
self.class.release(*args)
|
486
543
|
end
|
487
544
|
|
545
|
+
def allocator_free(ptr)
|
546
|
+
api[:AllocatorFree].call(@allocator.read_pointer, ptr.read_pointer)
|
547
|
+
end
|
548
|
+
|
488
549
|
def self.api
|
489
|
-
@api ||= FFI.OrtGetApiBase[:GetApi].call(
|
550
|
+
@api ||= FFI.OrtGetApiBase[:GetApi].call(FFI::ORT_API_VERSION)
|
490
551
|
end
|
491
552
|
|
492
553
|
def self.release(type, pointer)
|
data/lib/onnxruntime/version.rb
CHANGED
data/vendor/libonnxruntime.so
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: onnxruntime
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.3
|
5
5
|
platform: x86_64-linux
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-07-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|