Jazz 1.26.+
Loading...
Searching...
No Matches
opcodes.h
1/* Jazz (c) 2018-2026 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_core/std_wrap.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
55namespace jazz_core
56{
57
60struct TensorType {
62 onnx::TensorProto::DataType onnx_proto_type;
63 ONNXTensorElementDataType onnx_rt_type;
64};
65typedef std::map<stdName, TensorType> TensorTypeDict;
66typedef std::vector<TensorType> TensorTypes;
68
69
74 onnx::AttributeProto::AttributeType onnx_proto_type;
75 bool is_multi = false;
76};
77typedef std::map<stdName, AttributeType> AttributeTypeDict;
79
80
84
85 public:
86
92 name = nam;
93 types = typ;
94 }
95
98};
99typedef std::vector<OnnxParameter> OnnxParameters;
100
101
105
106 public:
107
113 name = nam;
114 type = typ;
115 }
116
119};
120typedef std::vector<OnnxAttribute> OnnxAttributes;
121
122
126
127 public:
128
137 name = nam;
138 opset_version = version;
139 inputs = in;
140 outputs = out;
141 attributes = attr;
142 }
143
149};
151typedef std::vector<OnnxOpCode> OnnxOpCodes;
152
153
157
158 public:
159
164 stdNameVersion(stdName nam, int version) {
165 name = nam;
166 opset_version = version;
167 }
168
175 bool operator==(const stdNameVersion &o) const {
176 return (opset_version == o.opset_version) && (strcmp(name.name, o.name.name) == 0);
177 }
178
185 bool operator<(const stdNameVersion &o) const {
186 return (opset_version < o.opset_version) || ((opset_version == o.opset_version) && (strcmp(name.name, o.name.name) < 0));
187 }
188
191};
192typedef std::map<stdNameVersion, int> OnnxOpCodeDict;
193
194
197class OpCodes : public Service {
198
199 public:
200
201 OpCodes(pLogger a_logger, pConfigFile a_config);
202
203 virtual StatusCode start ();
204 virtual StatusCode shut_down();
205
210 return op_vers_latest;
211 }
212
217 bool set_opset_version(int version) {
218 if (version <= 0 || version > op_vers_latest)
219 return false;
220
221 op_vers_current = version;
222 return true;
223 }
224
231 OnnxOpCodeDict::iterator it = opcodes_idx.find(stdNameVersion(name, op_vers_current));
232
233 if (it == opcodes_idx.end())
234 return nullptr;
235
236 return &opcodes.at(it->second);
237 }
238
239#ifndef CATCH_TEST
240 private:
241#endif
242
243 bool build_opcode_dict ();
244 bool fill_op_code (OnnxOpCode &op);
246 bool fill_tensor_types (TensorTypes &types,
247 String &all_types);
249 String &type_name);
250
252 int ir_vers = 0;
257 int log_error_level = LOG_ERROR;
258};
260
261} // namespace jazz_core
262
263#endif // ifndef INCLUDED_JAZZ_BEBOP_OPCODES
An attribute for an ONNX OpCode.
Definition opcodes.h:104
OnnxAttribute(stdName nam, AttributeType typ)
The constructor for an OnnxAttribute.
Definition opcodes.h:112
AttributeType type
The types of the attribute.
Definition opcodes.h:118
stdName name
The name of the attribute.
Definition opcodes.h:117
An ONNX OpCode.
Definition opcodes.h:125
OnnxParameters inputs
The input parameters.
Definition opcodes.h:146
stdName name
The name of the ONNX OpCode.
Definition opcodes.h:144
OnnxAttributes attributes
The attributes.
Definition opcodes.h:148
OnnxOpCode(stdName nam, int version, OnnxParameters in, OnnxParameters out, OnnxAttributes attr)
The constructor for an OnnxOpCode.
Definition opcodes.h:136
int opset_version
The version of the opset.
Definition opcodes.h:145
OnnxParameters outputs
The output parameters.
Definition opcodes.h:147
A parameter (input or output) for an ONNX OpCode.
Definition opcodes.h:83
OnnxParameter(stdName nam, TensorTypes typ)
The constructor for an OnnxParameter.
Definition opcodes.h:91
stdName name
The name of the parameter.
Definition opcodes.h:96
TensorTypes types
The types of the parameter.
Definition opcodes.h:97
OpCodes: The opcodes.
Definition opcodes.h:197
bool fill_all_dict_versions()
Fill all versions of the dictionary.
Definition opcodes.cpp:295
OnnxOpCodes opcodes
The opcodes parsed as binary objects.
Definition opcodes.h:256
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
ConfigFile onnx_conf
The ONNX opcodes reference stored as a ConfigFile.
Definition opcodes.h:251
virtual StatusCode shut_down()
Definition opcodes.cpp:127
int latest_opset_version()
Get the latest opset version.
Definition opcodes.h:209
pOnnxOpCode get(stdName name)
Get an ONNX OpCode.
Definition opcodes.h:230
int log_error_level
The log level to silence it in tests.
Definition opcodes.h:257
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
bool set_opset_version(int version)
Set the opset version.
Definition opcodes.h:217
OnnxOpCodeDict opcodes_idx
The index to the opcodes.
Definition opcodes.h:255
int op_vers_current
The opset version in use, set by set_opset_version() or op_vers_latest.
Definition opcodes.h:254
int op_vers_latest
The latest opset version in onnx.ini.
Definition opcodes.h:253
int ir_vers
Argument of model.set_ir_version() (Stored as ONNX_IR_VERSION in config.)
Definition opcodes.h:252
bool fill_attribute_type(AttributeType &type, 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
virtual StatusCode start()
A simple start()/shut_down() interface (Restart is: shut_down(TRUE):start())
Definition opcodes.cpp:96
bool fill_tensor_types(TensorTypes &types, 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
A pair of a name and a version to be used as a key in a dictionary.
Definition opcodes.h:156
int opset_version
The version of the opset.
Definition opcodes.h:190
bool operator==(const stdNameVersion &o) const
Operator this == o.
Definition opcodes.h:175
stdNameVersion(stdName nam, int version)
The constructor for a stdNameVersion.
Definition opcodes.h:164
stdName name
The name of the ONNX OpCode.
Definition opcodes.h:189
bool operator<(const stdNameVersion &o) const
Operator this < o.
Definition opcodes.h:185
A wrapped Name that supports being stacked in an std::vector and used as a key in an std::map.
Definition std_wrap.h:62
Name name
The name.
Definition std_wrap.h:104
A configuration file as a key/value store.
Definition utils.h:218
A simple logger.
Definition utils.h:248
A Jazz Service is a globally instanced configurable object that may allocate RAM.
Definition utils.h:288
A language to access any container by base using locators.
Definition base_api.cpp:39
std::map< stdName, AttributeType > AttributeTypeDict
A map of AttributeType objects.
Definition opcodes.h:77
OpCodes * pOpCodes
A pointer to an OpCodes object.
Definition opcodes.h:259
TensorTypes * pTensorTypes
A pointer to a TensorTypes.
Definition opcodes.h:67
std::vector< TensorType > TensorTypes
A list of TensorType objects.
Definition opcodes.h:66
std::vector< OnnxAttribute > OnnxAttributes
A list of OnnxAttribute objects.
Definition opcodes.h:120
std::vector< OnnxParameter > OnnxParameters
A list of OnnxParameter objects.
Definition opcodes.h:99
std::map< stdName, TensorType > TensorTypeDict
A map of TensorType objects.
Definition opcodes.h:65
std::vector< OnnxOpCode > OnnxOpCodes
A list of OnnxOpCode objects.
Definition opcodes.h:151
AttributeType * pAttributeType
A pointer to a AttributeType.
Definition opcodes.h:78
std::map< stdNameVersion, int > OnnxOpCodeDict
A map of OnnxOpCode objects.
Definition opcodes.h:192
OnnxOpCode * pOnnxOpCode
A pointer to an OnnxOpCode object.
Definition opcodes.h:150
std::string String
A standard string used in many other places in Jazz.
Definition types.h:239
int StatusCode
Type returned by the Service API.
Definition utils.h:142
A type definition for attributes across Jazz native (with special codes), and ONNX protocol buffer.
Definition opcodes.h:72
bool is_multi
True if the attribute is a list of the type.
Definition opcodes.h:75
int jazz_type
The Jazz native type.
Definition opcodes.h:73
onnx::AttributeProto::AttributeType onnx_proto_type
The ONNX protocol buffer type.
Definition opcodes.h:74
A type definition for tensors across all the technologies: Jazz native, ONNX protocol buffer and ONNX...
Definition opcodes.h:60
ONNXTensorElementDataType onnx_rt_type
The ONNX runtime type.
Definition opcodes.h:63
onnx::TensorProto::DataType onnx_proto_type
The ONNX protocol buffer type.
Definition opcodes.h:62
int jazz_type
The Jazz native type.
Definition opcodes.h:61