onnxruntime 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +1 -1
- data/lib/onnxruntime.rb +2 -2
- data/lib/onnxruntime/ffi.rb +113 -51
- data/lib/onnxruntime/inference_session.rb +42 -35
- data/lib/onnxruntime/version.rb +1 -1
- data/vendor/ThirdPartyNotices.txt +263 -0
- data/vendor/libonnxruntime.dylib +0 -0
- data/vendor/libonnxruntime.so +0 -0
- data/vendor/onnxruntime.dll +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: afd6fe4f0c5f23a4a27142648722ef9c60e5e0489a0dc16d5db02b4a6ab71a0d
|
4
|
+
data.tar.gz: c83b43e38e32193c0f2c520cbb7ca49f41cdb851cf74e1d90bbc342ecaaaea9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 63aba3f83a48732b607aa78e76d3bc003e486cfe7578a6c77c4794ecfd42c626befe6fd6339ea7e17e059a724dc729c84dde6860fa553ce455e08b2ffcf2e74d
|
7
|
+
data.tar.gz: 60fbfacb022d8347a0d5fdaefe0313b267ab34f201bae5869b8afbd05dd48c60d2aad3443125ec8e23267053148bf517a8f953ee4b500bebf9185469d0a09ff4
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -52,7 +52,7 @@ model.predict({x: [1, 2, 3]}, output_names: ["label"])
|
|
52
52
|
|
53
53
|
## Inference Session API
|
54
54
|
|
55
|
-
You can also use the Inference Session API, which follows the [Python API](https://microsoft.github.io/onnxruntime/api_summary.html).
|
55
|
+
You can also use the Inference Session API, which follows the [Python API](https://microsoft.github.io/onnxruntime/python/api_summary.html).
|
56
56
|
|
57
57
|
```ruby
|
58
58
|
session = OnnxRuntime::InferenceSession.new("model.onnx")
|
data/lib/onnxruntime.rb
CHANGED
@@ -15,10 +15,10 @@ module OnnxRuntime
|
|
15
15
|
end
|
16
16
|
lib_name = ::FFI.map_library_name("onnxruntime")
|
17
17
|
vendor_lib = File.expand_path("../vendor/#{lib_name}", __dir__)
|
18
|
-
self.ffi_lib = [
|
18
|
+
self.ffi_lib = [vendor_lib]
|
19
19
|
|
20
20
|
def self.lib_version
|
21
|
-
FFI.
|
21
|
+
FFI.OrtGetApiBase[:GetVersionString].call
|
22
22
|
end
|
23
23
|
|
24
24
|
# friendlier error message
|
data/lib/onnxruntime/ffi.rb
CHANGED
@@ -16,58 +16,120 @@ module OnnxRuntime
|
|
16
16
|
TensorElementDataType = enum(:undefined, :float, :uint8, :int8, :uint16, :int16, :int32, :int64, :string, :bool, :float16, :double, :uint32, :uint64, :complex64, :complex128, :bfloat16)
|
17
17
|
OnnxType = enum(:unknown, :tensor, :sequence, :map, :opaque, :sparsetensor)
|
18
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
|
-
|
19
|
+
class Api < ::FFI::Struct
|
20
|
+
layout \
|
21
|
+
:CreateStatus, callback(%i[int string], :pointer),
|
22
|
+
:GetErrorCode, callback(%i[pointer], :pointer),
|
23
|
+
:GetErrorMessage, callback(%i[pointer], :string),
|
24
|
+
:CreateEnv, callback(%i[int string pointer], :pointer),
|
25
|
+
:CreateEnvWithCustomLogger, callback(%i[], :pointer),
|
26
|
+
:EnableTelemetryEvents, callback(%i[pointer], :pointer),
|
27
|
+
:DisableTelemetryEvents, callback(%i[pointer], :pointer),
|
28
|
+
:CreateSession, callback(%i[pointer string pointer pointer], :pointer),
|
29
|
+
:CreateSessionFromArray, callback(%i[pointer pointer size_t pointer pointer], :pointer),
|
30
|
+
:Run, callback(%i[pointer pointer pointer pointer size_t pointer size_t pointer], :pointer),
|
31
|
+
:CreateSessionOptions, callback(%i[pointer], :pointer),
|
32
|
+
:SetOptimizedModelFilePath, callback(%i[], :pointer),
|
33
|
+
:CloneSessionOptions, callback(%i[], :pointer),
|
34
|
+
:SetSessionExecutionMode, callback(%i[], :pointer),
|
35
|
+
:EnableProfiling, callback(%i[], :pointer),
|
36
|
+
:DisableProfiling, callback(%i[], :pointer),
|
37
|
+
:EnableMemPattern, callback(%i[], :pointer),
|
38
|
+
:DisableMemPattern, callback(%i[], :pointer),
|
39
|
+
:EnableCpuMemArena, callback(%i[], :pointer),
|
40
|
+
:DisableCpuMemArena, callback(%i[], :pointer),
|
41
|
+
:SetSessionLogId, callback(%i[], :pointer),
|
42
|
+
:SetSessionLogVerbosityLevel, callback(%i[], :pointer),
|
43
|
+
:SetSessionLogSeverityLevel, callback(%i[], :pointer),
|
44
|
+
:SetSessionGraphOptimizationLevel, callback(%i[], :pointer),
|
45
|
+
:SetIntraOpNumThreads, callback(%i[], :pointer),
|
46
|
+
:SetInterOpNumThreads, callback(%i[], :pointer),
|
47
|
+
:CreateCustomOpDomain, callback(%i[], :pointer),
|
48
|
+
:CustomOpDomain_Add, callback(%i[], :pointer),
|
49
|
+
:AddCustomOpDomain, callback(%i[], :pointer),
|
50
|
+
:RegisterCustomOpsLibrary, callback(%i[], :pointer),
|
51
|
+
:SessionGetInputCount, callback(%i[pointer pointer], :pointer),
|
52
|
+
:SessionGetOutputCount, callback(%i[pointer pointer], :pointer),
|
53
|
+
:SessionGetOverridableInitializerCount, callback(%i[], :pointer),
|
54
|
+
:SessionGetInputTypeInfo, callback(%i[pointer size_t pointer], :pointer),
|
55
|
+
:SessionGetOutputTypeInfo, callback(%i[pointer size_t pointer], :pointer),
|
56
|
+
:SessionGetOverridableInitializerTypeInfo, callback(%i[], :pointer),
|
57
|
+
:SessionGetInputName, callback(%i[pointer size_t pointer pointer], :pointer),
|
58
|
+
:SessionGetOutputName, callback(%i[pointer size_t pointer pointer], :pointer),
|
59
|
+
:SessionGetOverridableInitializerName, callback(%i[], :pointer),
|
60
|
+
:CreateRunOptions, callback(%i[], :pointer),
|
61
|
+
:RunOptionsSetRunLogVerbosityLevel, callback(%i[], :pointer),
|
62
|
+
:RunOptionsSetRunLogSeverityLevel, callback(%i[], :pointer),
|
63
|
+
:RunOptionsSetRunTag, callback(%i[], :pointer),
|
64
|
+
:RunOptionsGetRunLogVerbosityLevel, callback(%i[], :pointer),
|
65
|
+
:RunOptionsGetRunLogSeverityLevel, callback(%i[], :pointer),
|
66
|
+
:RunOptionsGetRunTag, callback(%i[], :pointer),
|
67
|
+
:RunOptionsSetTerminate, callback(%i[], :pointer),
|
68
|
+
:RunOptionsUnsetTerminate, callback(%i[], :pointer),
|
69
|
+
:CreateTensorAsOrtValue, callback(%i[pointer pointer size_t int pointer], :pointer),
|
70
|
+
:CreateTensorWithDataAsOrtValue, callback(%i[pointer pointer size_t pointer size_t int pointer], :pointer),
|
71
|
+
:IsTensor, callback(%i[], :pointer),
|
72
|
+
:GetTensorMutableData, callback(%i[pointer pointer], :pointer),
|
73
|
+
:FillStringTensor, callback(%i[pointer pointer size_t], :pointer),
|
74
|
+
:GetStringTensorDataLength, callback(%i[], :pointer),
|
75
|
+
:GetStringTensorContent, callback(%i[], :pointer),
|
76
|
+
:CastTypeInfoToTensorInfo, callback(%i[pointer pointer], :pointer),
|
77
|
+
:GetOnnxTypeFromTypeInfo, callback(%i[pointer pointer], :pointer),
|
78
|
+
:CreateTensorTypeAndShapeInfo, callback(%i[], :pointer),
|
79
|
+
:SetTensorElementType, callback(%i[], :pointer),
|
80
|
+
:SetDimensions, callback(%i[], :pointer),
|
81
|
+
:GetTensorElementType, callback(%i[pointer pointer], :pointer),
|
82
|
+
:GetDimensionsCount, callback(%i[pointer pointer], :pointer),
|
83
|
+
:GetDimensions, callback(%i[pointer pointer size_t], :pointer),
|
84
|
+
:GetSymbolicDimensions, callback(%i[], :pointer),
|
85
|
+
:GetTensorShapeElementCount, callback(%i[pointer pointer], :pointer),
|
86
|
+
:GetTensorTypeAndShape, callback(%i[pointer pointer], :pointer),
|
87
|
+
:GetTypeInfo, callback(%i[pointer pointer], :pointer),
|
88
|
+
:GetValueType, callback(%i[pointer pointer], :pointer),
|
89
|
+
:CreateMemoryInfo, callback(%i[], :pointer),
|
90
|
+
:CreateCpuMemoryInfo, callback(%i[int int pointer], :pointer),
|
91
|
+
:CompareMemoryInfo, callback(%i[], :pointer),
|
92
|
+
:MemoryInfoGetName, callback(%i[], :pointer),
|
93
|
+
:MemoryInfoGetId, callback(%i[], :pointer),
|
94
|
+
:MemoryInfoGetMemType, callback(%i[], :pointer),
|
95
|
+
:MemoryInfoGetType, callback(%i[], :pointer),
|
96
|
+
:AllocatorAlloc, callback(%i[], :pointer),
|
97
|
+
:AllocatorFree, callback(%i[], :pointer),
|
98
|
+
:AllocatorGetInfo, callback(%i[], :pointer),
|
99
|
+
:GetAllocatorWithDefaultOptions, callback(%i[pointer], :pointer),
|
100
|
+
:AddFreeDimensionOverride, callback(%i[], :pointer),
|
101
|
+
:GetValue, callback(%i[pointer int pointer pointer], :pointer),
|
102
|
+
:GetValueCount, callback(%i[pointer pointer], :pointer),
|
103
|
+
:CreateValue, callback(%i[], :pointer),
|
104
|
+
:CreateOpaqueValue, callback(%i[], :pointer),
|
105
|
+
:GetOpaqueValue, callback(%i[], :pointer),
|
106
|
+
:KernelInfoGetAttribute_float, callback(%i[], :pointer),
|
107
|
+
:KernelInfoGetAttribute_int64, callback(%i[], :pointer),
|
108
|
+
:KernelInfoGetAttribute_string, callback(%i[], :pointer),
|
109
|
+
:KernelContext_GetInputCount, callback(%i[], :pointer),
|
110
|
+
:KernelContext_GetOutputCount, callback(%i[], :pointer),
|
111
|
+
:KernelContext_GetInput, callback(%i[], :pointer),
|
112
|
+
:KernelContext_GetOutput, callback(%i[], :pointer),
|
113
|
+
:ReleaseEnv, callback(%i[pointer], :void),
|
114
|
+
:ReleaseStatus, callback(%i[pointer], :void),
|
115
|
+
:ReleaseMemoryInfo, callback(%i[pointer], :void),
|
116
|
+
:ReleaseSession, callback(%i[pointer], :void),
|
117
|
+
:ReleaseValue, callback(%i[pointer], :void),
|
118
|
+
:ReleaseRunOptions, callback(%i[pointer], :void),
|
119
|
+
:ReleaseTypeInfo, callback(%i[pointer], :void),
|
120
|
+
:ReleaseTensorTypeAndShapeInfo, callback(%i[pointer], :void),
|
121
|
+
:ReleaseSessionOptions, callback(%i[pointer], :void),
|
122
|
+
:ReleaseCustomOpDomain, callback(%i[pointer], :void)
|
123
|
+
end
|
63
124
|
|
64
|
-
|
65
|
-
|
66
|
-
|
125
|
+
class ApiBase < ::FFI::Struct
|
126
|
+
# use uint32 instead of uint32_t
|
127
|
+
# to prevent "unable to resolve type" error on Ubuntu
|
128
|
+
layout \
|
129
|
+
:GetApi, callback(%i[uint32], Api.by_ref),
|
130
|
+
:GetVersionString, callback(%i[], :string)
|
131
|
+
end
|
67
132
|
|
68
|
-
|
69
|
-
attach_function :OrtReleaseEnv, %i[pointer], :pointer
|
70
|
-
attach_function :OrtReleaseTypeInfo, %i[pointer], :pointer
|
71
|
-
attach_function :OrtReleaseStatus, %i[pointer], :pointer
|
133
|
+
attach_function :OrtGetApiBase, %i[], ApiBase.by_ref
|
72
134
|
end
|
73
135
|
end
|
@@ -5,7 +5,7 @@ module OnnxRuntime
|
|
5
5
|
def initialize(path_or_bytes)
|
6
6
|
# session options
|
7
7
|
session_options = ::FFI::MemoryPointer.new(:pointer)
|
8
|
-
check_status
|
8
|
+
check_status api[:CreateSessionOptions].call(session_options)
|
9
9
|
|
10
10
|
# session
|
11
11
|
@session = ::FFI::MemoryPointer.new(:pointer)
|
@@ -17,14 +17,14 @@ module OnnxRuntime
|
|
17
17
|
end
|
18
18
|
|
19
19
|
if path_or_bytes.encoding == Encoding::BINARY
|
20
|
-
check_status
|
20
|
+
check_status api[:CreateSessionFromArray].call(env.read_pointer, path_or_bytes, path_or_bytes.bytesize, session_options.read_pointer, @session)
|
21
21
|
else
|
22
|
-
check_status
|
22
|
+
check_status api[:CreateSession].call(env.read_pointer, path_or_bytes, session_options.read_pointer, @session)
|
23
23
|
end
|
24
24
|
|
25
25
|
# input info
|
26
26
|
allocator = ::FFI::MemoryPointer.new(:pointer)
|
27
|
-
check_status
|
27
|
+
check_status api[:GetAllocatorWithDefaultOptions].call(allocator)
|
28
28
|
@allocator = allocator
|
29
29
|
|
30
30
|
@inputs = []
|
@@ -32,23 +32,23 @@ module OnnxRuntime
|
|
32
32
|
|
33
33
|
# input
|
34
34
|
num_input_nodes = ::FFI::MemoryPointer.new(:size_t)
|
35
|
-
check_status
|
35
|
+
check_status api[:SessionGetInputCount].call(read_pointer, num_input_nodes)
|
36
36
|
read_size_t(num_input_nodes).times do |i|
|
37
37
|
name_ptr = ::FFI::MemoryPointer.new(:string)
|
38
|
-
check_status
|
38
|
+
check_status api[:SessionGetInputName].call(read_pointer, i, @allocator.read_pointer, name_ptr)
|
39
39
|
typeinfo = ::FFI::MemoryPointer.new(:pointer)
|
40
|
-
check_status
|
40
|
+
check_status api[:SessionGetInputTypeInfo].call(read_pointer, i, typeinfo)
|
41
41
|
@inputs << {name: name_ptr.read_pointer.read_string}.merge(node_info(typeinfo))
|
42
42
|
end
|
43
43
|
|
44
44
|
# output
|
45
45
|
num_output_nodes = ::FFI::MemoryPointer.new(:size_t)
|
46
|
-
check_status
|
46
|
+
check_status api[:SessionGetOutputCount].call(read_pointer, num_output_nodes)
|
47
47
|
read_size_t(num_output_nodes).times do |i|
|
48
48
|
name_ptr = ::FFI::MemoryPointer.new(:string)
|
49
|
-
check_status
|
49
|
+
check_status api[:SessionGetOutputName].call(read_pointer, i, allocator.read_pointer, name_ptr)
|
50
50
|
typeinfo = ::FFI::MemoryPointer.new(:pointer)
|
51
|
-
check_status
|
51
|
+
check_status api[:SessionGetOutputTypeInfo].call(read_pointer, i, typeinfo)
|
52
52
|
@outputs << {name: name_ptr.read_pointer.read_string}.merge(node_info(typeinfo))
|
53
53
|
end
|
54
54
|
end
|
@@ -62,7 +62,7 @@ module OnnxRuntime
|
|
62
62
|
input_node_names = create_node_names(input_feed.keys.map(&:to_s))
|
63
63
|
output_node_names = create_node_names(output_names.map(&:to_s))
|
64
64
|
# TODO support run options
|
65
|
-
check_status
|
65
|
+
check_status api[:Run].call(read_pointer, nil, input_node_names, input_tensor, input_feed.size, output_node_names, output_names.size, output_tensor)
|
66
66
|
|
67
67
|
output_names.size.times.map do |i|
|
68
68
|
create_from_onnx_value(output_tensor[i].read_pointer)
|
@@ -73,7 +73,7 @@ module OnnxRuntime
|
|
73
73
|
|
74
74
|
def create_input_tensor(input_feed)
|
75
75
|
allocator_info = ::FFI::MemoryPointer.new(:pointer)
|
76
|
-
check_status =
|
76
|
+
check_status = api[:CreateCpuMemoryInfo].call(1, 0, allocator_info)
|
77
77
|
input_tensor = ::FFI::MemoryPointer.new(:pointer, input_feed.size)
|
78
78
|
|
79
79
|
input_feed.each_with_index do |(input_name, input), idx|
|
@@ -100,8 +100,8 @@ module OnnxRuntime
|
|
100
100
|
input_tensor_values = ::FFI::MemoryPointer.new(:pointer, input_tensor_size)
|
101
101
|
input_tensor_values.write_array_of_pointer(flat_input.map { |v| ::FFI::MemoryPointer.from_string(v) })
|
102
102
|
type_enum = FFI::TensorElementDataType[:string]
|
103
|
-
check_status
|
104
|
-
check_status
|
103
|
+
check_status api[:CreateTensorAsOrtValue].call(@allocator.read_pointer, input_node_dims, shape.size, type_enum, input_tensor[idx])
|
104
|
+
check_status api[:FillStringTensor].call(input_tensor[idx].read_pointer, input_tensor_values, flat_input.size)
|
105
105
|
else
|
106
106
|
tensor_types = [:float, :uint8, :int8, :uint16, :int16, :int32, :int64, :bool, :double, :uint32, :uint64].map { |v| ["tensor(#{v})", v] }.to_h
|
107
107
|
tensor_type = tensor_types[inp[:type]]
|
@@ -118,7 +118,7 @@ module OnnxRuntime
|
|
118
118
|
unsupported_type("input", inp[:type])
|
119
119
|
end
|
120
120
|
|
121
|
-
check_status
|
121
|
+
check_status api[:CreateTensorWithDataAsOrtValue].call(allocator_info.read_pointer, input_tensor_values, input_tensor_values.size, input_node_dims, shape.size, type_enum, input_tensor[idx])
|
122
122
|
end
|
123
123
|
end
|
124
124
|
|
@@ -133,21 +133,21 @@ module OnnxRuntime
|
|
133
133
|
|
134
134
|
def create_from_onnx_value(out_ptr)
|
135
135
|
out_type = ::FFI::MemoryPointer.new(:int)
|
136
|
-
check_status =
|
136
|
+
check_status = api[:GetValueType].call(out_ptr, out_type)
|
137
137
|
type = FFI::OnnxType[out_type.read_int]
|
138
138
|
|
139
139
|
case type
|
140
140
|
when :tensor
|
141
141
|
typeinfo = ::FFI::MemoryPointer.new(:pointer)
|
142
|
-
check_status
|
142
|
+
check_status api[:GetTensorTypeAndShape].call(out_ptr, typeinfo)
|
143
143
|
|
144
144
|
type, shape = tensor_type_and_shape(typeinfo)
|
145
145
|
|
146
146
|
tensor_data = ::FFI::MemoryPointer.new(:pointer)
|
147
|
-
check_status
|
147
|
+
check_status api[:GetTensorMutableData].call(out_ptr, tensor_data)
|
148
148
|
|
149
149
|
out_size = ::FFI::MemoryPointer.new(:size_t)
|
150
|
-
output_tensor_size =
|
150
|
+
output_tensor_size = api[:GetTensorShapeElementCount].call(typeinfo.read_pointer, out_size)
|
151
151
|
output_tensor_size = read_size_t(out_size)
|
152
152
|
|
153
153
|
# TODO support more types
|
@@ -165,11 +165,11 @@ module OnnxRuntime
|
|
165
165
|
Utils.reshape(arr, shape)
|
166
166
|
when :sequence
|
167
167
|
out = ::FFI::MemoryPointer.new(:size_t)
|
168
|
-
check_status
|
168
|
+
check_status api[:GetValueCount].call(out_ptr, out)
|
169
169
|
|
170
170
|
read_size_t(out).times.map do |i|
|
171
171
|
seq = ::FFI::MemoryPointer.new(:pointer)
|
172
|
-
check_status
|
172
|
+
check_status api[:GetValue].call(out_ptr, i, @allocator.read_pointer, seq)
|
173
173
|
create_from_onnx_value(seq.read_pointer)
|
174
174
|
end
|
175
175
|
when :map
|
@@ -178,10 +178,10 @@ module OnnxRuntime
|
|
178
178
|
map_values = ::FFI::MemoryPointer.new(:pointer)
|
179
179
|
elem_type = ::FFI::MemoryPointer.new(:int)
|
180
180
|
|
181
|
-
check_status
|
182
|
-
check_status
|
183
|
-
check_status
|
184
|
-
check_status
|
181
|
+
check_status api[:GetValue].call(out_ptr, 0, @allocator.read_pointer, map_keys)
|
182
|
+
check_status api[:GetValue].call(out_ptr, 1, @allocator.read_pointer, map_values)
|
183
|
+
check_status api[:GetTensorTypeAndShape].call(map_keys.read_pointer, type_shape)
|
184
|
+
check_status api[:GetTensorElementType].call(type_shape.read_pointer, elem_type)
|
185
185
|
|
186
186
|
# TODO support more types
|
187
187
|
elem_type = FFI::TensorElementDataType[elem_type.read_int]
|
@@ -208,21 +208,21 @@ module OnnxRuntime
|
|
208
208
|
|
209
209
|
def check_status(status)
|
210
210
|
unless status.null?
|
211
|
-
message =
|
212
|
-
|
211
|
+
message = api[:GetErrorMessage].call(status)
|
212
|
+
api[:ReleaseStatus].call(status)
|
213
213
|
raise OnnxRuntime::Error, message
|
214
214
|
end
|
215
215
|
end
|
216
216
|
|
217
217
|
def node_info(typeinfo)
|
218
218
|
onnx_type = ::FFI::MemoryPointer.new(:int)
|
219
|
-
check_status
|
219
|
+
check_status api[:GetOnnxTypeFromTypeInfo].call(typeinfo.read_pointer, onnx_type)
|
220
220
|
|
221
221
|
type = FFI::OnnxType[onnx_type.read_int]
|
222
222
|
case type
|
223
223
|
when :tensor
|
224
224
|
tensor_info = ::FFI::MemoryPointer.new(:pointer)
|
225
|
-
check_status
|
225
|
+
check_status api[:CastTypeInfoToTensorInfo].call(typeinfo.read_pointer, tensor_info)
|
226
226
|
|
227
227
|
type, shape = tensor_type_and_shape(tensor_info)
|
228
228
|
{
|
@@ -245,19 +245,19 @@ module OnnxRuntime
|
|
245
245
|
unsupported_type("ONNX", type)
|
246
246
|
end
|
247
247
|
ensure
|
248
|
-
|
248
|
+
api[:ReleaseTypeInfo].call(typeinfo.read_pointer)
|
249
249
|
end
|
250
250
|
|
251
251
|
def tensor_type_and_shape(tensor_info)
|
252
252
|
type = ::FFI::MemoryPointer.new(:int)
|
253
|
-
check_status
|
253
|
+
check_status api[:GetTensorElementType].call(tensor_info.read_pointer, type)
|
254
254
|
|
255
255
|
num_dims_ptr = ::FFI::MemoryPointer.new(:size_t)
|
256
|
-
check_status
|
256
|
+
check_status api[:GetDimensionsCount].call(tensor_info.read_pointer, num_dims_ptr)
|
257
257
|
num_dims = read_size_t(num_dims_ptr)
|
258
258
|
|
259
259
|
node_dims = ::FFI::MemoryPointer.new(:int64, num_dims)
|
260
|
-
check_status
|
260
|
+
check_status api[:GetDimensions].call(tensor_info.read_pointer, node_dims, num_dims)
|
261
261
|
|
262
262
|
[type.read_int, node_dims.read_array_of_int64(num_dims)]
|
263
263
|
end
|
@@ -275,13 +275,20 @@ module OnnxRuntime
|
|
275
275
|
end
|
276
276
|
end
|
277
277
|
|
278
|
+
def api
|
279
|
+
@api ||= FFI.OrtGetApiBase[:GetApi].call(1)
|
280
|
+
end
|
281
|
+
|
278
282
|
def env
|
279
283
|
# use mutex for thread-safety
|
280
284
|
Utils.mutex.synchronize do
|
281
285
|
@@env ||= begin
|
282
286
|
env = ::FFI::MemoryPointer.new(:pointer)
|
283
|
-
check_status
|
284
|
-
at_exit {
|
287
|
+
check_status api[:CreateEnv].call(3, "Default", env)
|
288
|
+
at_exit { api[:ReleaseEnv].call(env.read_pointer) }
|
289
|
+
# disable telemetry
|
290
|
+
# https://github.com/microsoft/onnxruntime/blob/master/docs/Privacy.md
|
291
|
+
check_status api[:DisableTelemetryEvents].call(env)
|
285
292
|
env
|
286
293
|
end
|
287
294
|
end
|
data/lib/onnxruntime/version.rb
CHANGED
@@ -3532,3 +3532,266 @@ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
3532
3532
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
3533
3533
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
3534
3534
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
3535
|
+
|
3536
|
+
----
|
3537
|
+
|
3538
|
+
abseil-cpp
|
3539
|
+
https://github.com/abseil/abseil-cpp
|
3540
|
+
|
3541
|
+
Apache License
|
3542
|
+
Version 2.0, January 2004
|
3543
|
+
https://www.apache.org/licenses/
|
3544
|
+
|
3545
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
3546
|
+
|
3547
|
+
1. Definitions.
|
3548
|
+
|
3549
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
3550
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
3551
|
+
|
3552
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
3553
|
+
the copyright owner that is granting the License.
|
3554
|
+
|
3555
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
3556
|
+
other entities that control, are controlled by, or are under common
|
3557
|
+
control with that entity. For the purposes of this definition,
|
3558
|
+
"control" means (i) the power, direct or indirect, to cause the
|
3559
|
+
direction or management of such entity, whether by contract or
|
3560
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
3561
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
3562
|
+
|
3563
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
3564
|
+
exercising permissions granted by this License.
|
3565
|
+
|
3566
|
+
"Source" form shall mean the preferred form for making modifications,
|
3567
|
+
including but not limited to software source code, documentation
|
3568
|
+
source, and configuration files.
|
3569
|
+
|
3570
|
+
"Object" form shall mean any form resulting from mechanical
|
3571
|
+
transformation or translation of a Source form, including but
|
3572
|
+
not limited to compiled object code, generated documentation,
|
3573
|
+
and conversions to other media types.
|
3574
|
+
|
3575
|
+
"Work" shall mean the work of authorship, whether in Source or
|
3576
|
+
Object form, made available under the License, as indicated by a
|
3577
|
+
copyright notice that is included in or attached to the work
|
3578
|
+
(an example is provided in the Appendix below).
|
3579
|
+
|
3580
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
3581
|
+
form, that is based on (or derived from) the Work and for which the
|
3582
|
+
editorial revisions, annotations, elaborations, or other modifications
|
3583
|
+
represent, as a whole, an original work of authorship. For the purposes
|
3584
|
+
of this License, Derivative Works shall not include works that remain
|
3585
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
3586
|
+
the Work and Derivative Works thereof.
|
3587
|
+
|
3588
|
+
"Contribution" shall mean any work of authorship, including
|
3589
|
+
the original version of the Work and any modifications or additions
|
3590
|
+
to that Work or Derivative Works thereof, that is intentionally
|
3591
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
3592
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
3593
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
3594
|
+
means any form of electronic, verbal, or written communication sent
|
3595
|
+
to the Licensor or its representatives, including but not limited to
|
3596
|
+
communication on electronic mailing lists, source code control systems,
|
3597
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
3598
|
+
Licensor for the purpose of discussing and improving the Work, but
|
3599
|
+
excluding communication that is conspicuously marked or otherwise
|
3600
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
3601
|
+
|
3602
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
3603
|
+
on behalf of whom a Contribution has been received by Licensor and
|
3604
|
+
subsequently incorporated within the Work.
|
3605
|
+
|
3606
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
3607
|
+
this License, each Contributor hereby grants to You a perpetual,
|
3608
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
3609
|
+
copyright license to reproduce, prepare Derivative Works of,
|
3610
|
+
publicly display, publicly perform, sublicense, and distribute the
|
3611
|
+
Work and such Derivative Works in Source or Object form.
|
3612
|
+
|
3613
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
3614
|
+
this License, each Contributor hereby grants to You a perpetual,
|
3615
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
3616
|
+
(except as stated in this section) patent license to make, have made,
|
3617
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
3618
|
+
where such license applies only to those patent claims licensable
|
3619
|
+
by such Contributor that are necessarily infringed by their
|
3620
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
3621
|
+
with the Work to which such Contribution(s) was submitted. If You
|
3622
|
+
institute patent litigation against any entity (including a
|
3623
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
3624
|
+
or a Contribution incorporated within the Work constitutes direct
|
3625
|
+
or contributory patent infringement, then any patent licenses
|
3626
|
+
granted to You under this License for that Work shall terminate
|
3627
|
+
as of the date such litigation is filed.
|
3628
|
+
|
3629
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
3630
|
+
Work or Derivative Works thereof in any medium, with or without
|
3631
|
+
modifications, and in Source or Object form, provided that You
|
3632
|
+
meet the following conditions:
|
3633
|
+
|
3634
|
+
(a) You must give any other recipients of the Work or
|
3635
|
+
Derivative Works a copy of this License; and
|
3636
|
+
|
3637
|
+
(b) You must cause any modified files to carry prominent notices
|
3638
|
+
stating that You changed the files; and
|
3639
|
+
|
3640
|
+
(c) You must retain, in the Source form of any Derivative Works
|
3641
|
+
that You distribute, all copyright, patent, trademark, and
|
3642
|
+
attribution notices from the Source form of the Work,
|
3643
|
+
excluding those notices that do not pertain to any part of
|
3644
|
+
the Derivative Works; and
|
3645
|
+
|
3646
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
3647
|
+
distribution, then any Derivative Works that You distribute must
|
3648
|
+
include a readable copy of the attribution notices contained
|
3649
|
+
within such NOTICE file, excluding those notices that do not
|
3650
|
+
pertain to any part of the Derivative Works, in at least one
|
3651
|
+
of the following places: within a NOTICE text file distributed
|
3652
|
+
as part of the Derivative Works; within the Source form or
|
3653
|
+
documentation, if provided along with the Derivative Works; or,
|
3654
|
+
within a display generated by the Derivative Works, if and
|
3655
|
+
wherever such third-party notices normally appear. The contents
|
3656
|
+
of the NOTICE file are for informational purposes only and
|
3657
|
+
do not modify the License. You may add Your own attribution
|
3658
|
+
notices within Derivative Works that You distribute, alongside
|
3659
|
+
or as an addendum to the NOTICE text from the Work, provided
|
3660
|
+
that such additional attribution notices cannot be construed
|
3661
|
+
as modifying the License.
|
3662
|
+
|
3663
|
+
You may add Your own copyright statement to Your modifications and
|
3664
|
+
may provide additional or different license terms and conditions
|
3665
|
+
for use, reproduction, or distribution of Your modifications, or
|
3666
|
+
for any such Derivative Works as a whole, provided Your use,
|
3667
|
+
reproduction, and distribution of the Work otherwise complies with
|
3668
|
+
the conditions stated in this License.
|
3669
|
+
|
3670
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
3671
|
+
any Contribution intentionally submitted for inclusion in the Work
|
3672
|
+
by You to the Licensor shall be under the terms and conditions of
|
3673
|
+
this License, without any additional terms or conditions.
|
3674
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
3675
|
+
the terms of any separate license agreement you may have executed
|
3676
|
+
with Licensor regarding such Contributions.
|
3677
|
+
|
3678
|
+
6. Trademarks. This License does not grant permission to use the trade
|
3679
|
+
names, trademarks, service marks, or product names of the Licensor,
|
3680
|
+
except as required for reasonable and customary use in describing the
|
3681
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
3682
|
+
|
3683
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
3684
|
+
agreed to in writing, Licensor provides the Work (and each
|
3685
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
3686
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
3687
|
+
implied, including, without limitation, any warranties or conditions
|
3688
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
3689
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
3690
|
+
appropriateness of using or redistributing the Work and assume any
|
3691
|
+
risks associated with Your exercise of permissions under this License.
|
3692
|
+
|
3693
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
3694
|
+
whether in tort (including negligence), contract, or otherwise,
|
3695
|
+
unless required by applicable law (such as deliberate and grossly
|
3696
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
3697
|
+
liable to You for damages, including any direct, indirect, special,
|
3698
|
+
incidental, or consequential damages of any character arising as a
|
3699
|
+
result of this License or out of the use or inability to use the
|
3700
|
+
Work (including but not limited to damages for loss of goodwill,
|
3701
|
+
work stoppage, computer failure or malfunction, or any and all
|
3702
|
+
other commercial damages or losses), even if such Contributor
|
3703
|
+
has been advised of the possibility of such damages.
|
3704
|
+
|
3705
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
3706
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
3707
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
3708
|
+
or other liability obligations and/or rights consistent with this
|
3709
|
+
License. However, in accepting such obligations, You may act only
|
3710
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
3711
|
+
of any other Contributor, and only if You agree to indemnify,
|
3712
|
+
defend, and hold each Contributor harmless for any liability
|
3713
|
+
incurred by, or claims asserted against, such Contributor by reason
|
3714
|
+
of your accepting any such warranty or additional liability.
|
3715
|
+
|
3716
|
+
END OF TERMS AND CONDITIONS
|
3717
|
+
|
3718
|
+
APPENDIX: How to apply the Apache License to your work.
|
3719
|
+
|
3720
|
+
To apply the Apache License to your work, attach the following
|
3721
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
3722
|
+
replaced with your own identifying information. (Don't include
|
3723
|
+
the brackets!) The text should be enclosed in the appropriate
|
3724
|
+
comment syntax for the file format. We also recommend that a
|
3725
|
+
file or class name and description of purpose be included on the
|
3726
|
+
same "printed page" as the copyright notice for easier
|
3727
|
+
identification within third-party archives.
|
3728
|
+
|
3729
|
+
Copyright [yyyy] [name of copyright owner]
|
3730
|
+
|
3731
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
3732
|
+
you may not use this file except in compliance with the License.
|
3733
|
+
You may obtain a copy of the License at
|
3734
|
+
|
3735
|
+
https://www.apache.org/licenses/LICENSE-2.0
|
3736
|
+
|
3737
|
+
Unless required by applicable law or agreed to in writing, software
|
3738
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
3739
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
3740
|
+
See the License for the specific language governing permissions and
|
3741
|
+
limitations under the License.
|
3742
|
+
|
3743
|
+
|
3744
|
+
-----
|
3745
|
+
|
3746
|
+
NVlabs/cub
|
3747
|
+
|
3748
|
+
Copyright (c) 2010-2011, Duane Merrill. All rights reserved.
|
3749
|
+
Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved.
|
3750
|
+
|
3751
|
+
Redistribution and use in source and binary forms, with or without
|
3752
|
+
modification, are permitted provided that the following conditions are met:
|
3753
|
+
* Redistributions of source code must retain the above copyright
|
3754
|
+
notice, this list of conditions and the following disclaimer.
|
3755
|
+
* Redistributions in binary form must reproduce the above copyright
|
3756
|
+
notice, this list of conditions and the following disclaimer in the
|
3757
|
+
documentation and/or other materials provided with the distribution.
|
3758
|
+
* Neither the name of the NVIDIA CORPORATION nor the
|
3759
|
+
names of its contributors may be used to endorse or promote products
|
3760
|
+
derived from this software without specific prior written permission.
|
3761
|
+
|
3762
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
3763
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
3764
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
3765
|
+
DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY
|
3766
|
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
3767
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
3768
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
3769
|
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
3770
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
3771
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
3772
|
+
|
3773
|
+
-----
|
3774
|
+
|
3775
|
+
microsoft/wil
|
3776
|
+
|
3777
|
+
MIT License
|
3778
|
+
|
3779
|
+
Copyright (c) Microsoft Corporation. All rights reserved.
|
3780
|
+
|
3781
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
3782
|
+
of this software and associated documentation files (the "Software"), to deal
|
3783
|
+
in the Software without restriction, including without limitation the rights
|
3784
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
3785
|
+
copies of the Software, and to permit persons to whom the Software is
|
3786
|
+
furnished to do so, subject to the following conditions:
|
3787
|
+
|
3788
|
+
The above copyright notice and this permission notice shall be included in all
|
3789
|
+
copies or substantial portions of the Software.
|
3790
|
+
|
3791
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
3792
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
3793
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
3794
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
3795
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
3796
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
3797
|
+
SOFTWARE
|
data/vendor/libonnxruntime.dylib
CHANGED
Binary file
|
data/vendor/libonnxruntime.so
CHANGED
Binary file
|
data/vendor/onnxruntime.dll
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.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-10-
|
11
|
+
date: 2019-10-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|