Jazz 1.25.+
Loading...
Searching...
No Matches
opcodes.h
1/* Jazz (c) 2018-2025 kaalam.ai (The Authors of Jazz), using (under the same license):
2
3 1. Biomodelling - The AATBlockQueue class (c) Jacques BasaldĂșa, 2009-2012 licensed
4 exclusively for the use in the Jazz server software.
5
6 Copyright 2009-2012 Jacques BasaldĂșa
7
8 2. BBVA - Jazz: A lightweight analytical web server for data-driven applications.
9
10 Copyright 2016-2017 Banco Bilbao Vizcaya Argentaria, S.A.
11
12 This product includes software developed at
13
14 BBVA (https://www.bbva.com/)
15
16 3. LMDB, Copyright 2011-2017 Howard Chu, Symas Corp. All rights reserved.
17
18 Licensed under http://www.OpenLDAP.org/license.html
19
20
21 Licensed under the Apache License, Version 2.0 (the "License");
22 you may not use this file except in compliance with the License.
23 You may obtain a copy of the License at
24
25 http://www.apache.org/licenses/LICENSE-2.0
26
27 Unless required by applicable law or agreed to in writing, software
28 distributed under the License is distributed on an "AS IS" BASIS,
29 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
30 See the License for the specific language governing permissions and
31 limitations under the License.
32*/
33
34
35#include "src/jazz_bebop/space.h"
36#include "src/onnx_proto/onnx.pb.h"
37#include "onnxruntime_c_api.h"
38
39#if defined CATCH_TEST
40#ifndef INCLUDED_JAZZ_CATCH2
41#define INCLUDED_JAZZ_CATCH2
42
43#include "src/catch2/catch.hpp"
44
45#endif
46#endif
47
48
49#ifndef INCLUDED_JAZZ_BEBOP_OPCODES
50#define INCLUDED_JAZZ_BEBOP_OPCODES
51
52
58namespace jazz_bebop
59{
60
63struct TensorType {
65 onnx::TensorProto::DataType onnx_proto_type;
66 ONNXTensorElementDataType onnx_rt_type;
67};
68typedef std::map<stdName, TensorType> TensorTypeDict;
69typedef std::vector<TensorType> TensorTypes;
71
72
77 onnx::AttributeProto::AttributeType onnx_proto_type;
78 bool is_multi = false;
79};
80typedef std::map<stdName, AttributeType> AttributeTypeDict;
82
83
87
88 public:
89
95 name = nam;
96 types = typ;
97 }
98
101};
102typedef std::vector<OnnxParameter> OnnxParameters;
103
104
108
109 public:
110
116 name = nam;
117 type = typ;
118 }
119
122};
123typedef std::vector<OnnxAttribute> OnnxAttributes;
124
125
129
130 public:
131
140 name = nam;
141 opset_version = version;
142 inputs = in;
143 outputs = out;
144 attributes = attr;
145 }
146
152};
154typedef std::vector<OnnxOpCode> OnnxOpCodes;
155
156
160
161 public:
162
167 stdNameVersion(stdName nam, int version) {
168 name = nam;
169 opset_version = version;
170 }
171
178 bool operator==(const stdNameVersion &o) const {
179 return (opset_version == o.opset_version) && (strcmp(name.name, o.name.name) == 0);
180 }
181
188 bool operator<(const stdNameVersion &o) const {
189 return (opset_version < o.opset_version) || ((opset_version == o.opset_version) && (strcmp(name.name, o.name.name) < 0));
190 }
191
194};
195typedef std::map<stdNameVersion, int> OnnxOpCodeDict;
196
197
200class OpCodes : public Service {
201
202 public:
203
204 OpCodes(pLogger a_logger, pConfigFile a_config);
205
206 virtual StatusCode start ();
207 virtual StatusCode shut_down();
208
213 return op_vers_latest;
214 }
215
220 bool set_opset_version(int version) {
221 if (version <= 0 || version > op_vers_latest)
222 return false;
223
224 op_vers_current = version;
225 return true;
226 }
227
234 OnnxOpCodeDict::iterator it = opcodes_idx.find(stdNameVersion(name, op_vers_current));
235
236 if (it == opcodes_idx.end())
237 return nullptr;
238
239 return &opcodes.at(it->second);
240 }
241
242#ifndef CATCH_TEST
243 private:
244#endif
245
246 bool build_opcode_dict ();
247 bool fill_op_code (OnnxOpCode &op);
249 bool fill_tensor_types (TensorTypes &types,
250 std::string &all_types);
252 std::string &type_name);
253
255 int ir_vers = 0;
260};
262
263} // namespace jazz_bebop
264
265#endif // ifndef INCLUDED_JAZZ_BEBOP_OPCODES
An attribute for an ONNX OpCode.
Definition opcodes.h:107
OnnxAttribute(stdName nam, AttributeType typ)
The constructor for an OnnxAttribute.
Definition opcodes.h:115
stdName name
The name of the attribute.
Definition opcodes.h:120
AttributeType type
The types of the attribute.
Definition opcodes.h:121
An ONNX OpCode.
Definition opcodes.h:128
OnnxParameters inputs
The input parameters.
Definition opcodes.h:149
OnnxOpCode(stdName nam, int version, OnnxParameters in, OnnxParameters out, OnnxAttributes attr)
The constructor for an OnnxOpCode.
Definition opcodes.h:139
stdName name
The name of the ONNX OpCode.
Definition opcodes.h:147
int opset_version
The version of the opset.
Definition opcodes.h:148
OnnxAttributes attributes
The attributes.
Definition opcodes.h:151
OnnxParameters outputs
The output parameters.
Definition opcodes.h:150
A parameter (input or output) for an ONNX OpCode.
Definition opcodes.h:86
OnnxParameter(stdName nam, TensorTypes typ)
The constructor for an OnnxParameter.
Definition opcodes.h:94
TensorTypes types
The types of the parameter.
Definition opcodes.h:100
stdName name
The name of the parameter.
Definition opcodes.h:99
OpCodes: The opcodes.
Definition opcodes.h:200
bool fill_all_dict_versions()
Fill all versions of the dictionary.
Definition opcodes.cpp:295
int ir_vers
Argument of model.set_ir_version() (Stored as ONNX_IR_VERSION in config.)
Definition opcodes.h:255
int latest_opset_version()
Get the latest opset version.
Definition opcodes.h:212
ConfigFile onnx_conf
The ONNX opcodes reference stored as a ConfigFile.
Definition opcodes.h:254
OnnxOpCodeDict opcodes_idx
The index to the opcodes.
Definition opcodes.h:258
bool fill_op_code(OnnxOpCode &op)
Fill an ONNX OpCode. This completes all the fields of an OpCode other than name and version....
Definition opcodes.cpp:208
int op_vers_latest
The latest opset version in onnx.ini.
Definition opcodes.h:256
bool fill_tensor_types(TensorTypes &types, std::string &all_types)
Fill the tensor types. This fills a list of tensor types from a string with the names of the types se...
Definition opcodes.cpp:330
OnnxOpCodes opcodes
The opcodes parsed as binary objects.
Definition opcodes.h:259
bool set_opset_version(int version)
Set the opset version.
Definition opcodes.h:220
int op_vers_current
The opset version in use, set by set_opset_version() or op_vers_latest.
Definition opcodes.h:257
virtual StatusCode start()
A simple start()/shut_down() interface (Restart is: shut_down(TRUE):start())
Definition opcodes.cpp:96
virtual StatusCode shut_down()
Definition opcodes.cpp:127
bool fill_attribute_type(AttributeType &type, std::string &type_name)
Fill the attribute type. This fills an attribute type from a string with the name of the type.
Definition opcodes.cpp:354
bool build_opcode_dict()
Build the opcode dictionary. This build the vector opcodes and the dictionary opcodes_idx from the co...
Definition opcodes.cpp:137
pOnnxOpCode get(stdName name)
Get an ONNX OpCode.
Definition opcodes.h:233
A pair of a name and a version to be used as a key in a dictionary.
Definition opcodes.h:159
bool operator==(const stdNameVersion &o) const
Operator this == o.
Definition opcodes.h:178
int opset_version
The version of the opset.
Definition opcodes.h:193
stdName name
The name of the ONNX OpCode.
Definition opcodes.h:192
bool operator<(const stdNameVersion &o) const
Operator this < o.
Definition opcodes.h:188
stdNameVersion(stdName nam, int version)
The constructor for a stdNameVersion.
Definition opcodes.h:167
A wrapped Name that supports being stacked in an std::vector and used as a key in an std::map.
Definition space.h:67
Name name
The name.
Definition space.h:109
A configuration file as a key/value store.
Definition utils.h:217
A simple logger.
Definition utils.h:245
A Jazz Service is a globally instanced configurable object that may allocate RAM.
Definition utils.h:285
A language to access any container by base using locators.
Definition base_api.cpp:39
std::vector< TensorType > TensorTypes
A list of TensorType objects.
Definition opcodes.h:69
std::vector< OnnxParameter > OnnxParameters
A list of OnnxParameter objects.
Definition opcodes.h:102
TensorTypes * pTensorTypes
A pointer to a TensorTypes.
Definition opcodes.h:70
std::vector< OnnxOpCode > OnnxOpCodes
A list of OnnxOpCode objects.
Definition opcodes.h:154
OpCodes * pOpCodes
A pointer to an OpCodes object.
Definition opcodes.h:261
OnnxOpCode * pOnnxOpCode
A pointer to an OnnxOpCode object.
Definition opcodes.h:153
std::map< stdName, TensorType > TensorTypeDict
A map of TensorType objects.
Definition opcodes.h:68
std::map< stdName, AttributeType > AttributeTypeDict
A map of AttributeType objects.
Definition opcodes.h:80
AttributeType * pAttributeType
A pointer to a AttributeType.
Definition opcodes.h:81
std::map< stdNameVersion, int > OnnxOpCodeDict
A map of OnnxOpCode objects.
Definition opcodes.h:195
std::vector< OnnxAttribute > OnnxAttributes
A list of OnnxAttribute objects.
Definition opcodes.h:123
int StatusCode
Type returned by the Service API.
Definition utils.h:141
A type definition for attributes across Jazz native (with special codes), and ONNX protocol buffer.
Definition opcodes.h:75
int jazz_type
The Jazz native type.
Definition opcodes.h:76
onnx::AttributeProto::AttributeType onnx_proto_type
The ONNX protocol buffer type.
Definition opcodes.h:77
bool is_multi
True if the attribute is a list of the type.
Definition opcodes.h:78
A type definition for tensors across all the technologies: Jazz native, ONNX protocol buffer and ONNX...
Definition opcodes.h:63
onnx::TensorProto::DataType onnx_proto_type
The ONNX protocol buffer type.
Definition opcodes.h:65
int jazz_type
The Jazz native type.
Definition opcodes.h:64
ONNXTensorElementDataType onnx_rt_type
The ONNX runtime type.
Definition opcodes.h:66