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/data_spaces.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
56namespace jazz_bebop
57{
58
61struct TensorType {
63 onnx::TensorProto::DataType onnx_proto_type;
64 ONNXTensorElementDataType onnx_rt_type;
65};
66typedef std::map<stdName, TensorType> TensorTypeDict;
67typedef std::vector<TensorType> TensorTypes;
69
70
75 onnx::AttributeProto::AttributeType onnx_proto_type;
76 bool is_multi = false;
77};
78typedef std::map<stdName, AttributeType> AttributeTypeDict;
80
81
85
86 public:
87
93 name = nam;
94 types = typ;
95 }
96
99};
100typedef std::vector<OnnxParameter> OnnxParameters;
101
102
106
107 public:
108
114 name = nam;
115 type = typ;
116 }
117
120};
121typedef std::vector<OnnxAttribute> OnnxAttributes;
122
123
127
128 public:
129
138 name = nam;
139 opset_version = version;
140 inputs = in;
141 outputs = out;
142 attributes = attr;
143 }
144
150};
152typedef std::vector<OnnxOpCode> OnnxOpCodes;
153
154
158
159 public:
160
165 stdNameVersion(stdName nam, int version) {
166 name = nam;
167 opset_version = version;
168 }
169
176 bool operator==(const stdNameVersion &o) const {
177 return (opset_version == o.opset_version) && (strcmp(name.name, o.name.name) == 0);
178 }
179
186 bool operator<(const stdNameVersion &o) const {
187 return (opset_version < o.opset_version) || ((opset_version == o.opset_version) && (strcmp(name.name, o.name.name) < 0));
188 }
189
192};
193typedef std::map<stdNameVersion, int> OnnxOpCodeDict;
194
195
198class OpCodes : public Service {
199
200 public:
201
202 OpCodes(pLogger a_logger, pConfigFile a_config);
203
204 virtual StatusCode start ();
205 virtual StatusCode shut_down();
206
211 return op_vers_latest;
212 }
213
218 bool set_opset_version(int version) {
219 if (version <= 0 || version > op_vers_latest)
220 return false;
221
222 op_vers_current = version;
223 return true;
224 }
225
232 OnnxOpCodeDict::iterator it = opcodes_idx.find(stdNameVersion(name, op_vers_current));
233
234 if (it == opcodes_idx.end())
235 return nullptr;
236
237 return &opcodes.at(it->second);
238 }
239
240#ifndef CATCH_TEST
241 private:
242#endif
243
244 bool build_opcode_dict ();
245 bool fill_op_code (OnnxOpCode &op);
247 bool fill_tensor_types (TensorTypes &types,
248 std::string &all_types);
250 std::string &type_name);
251
253 int ir_vers = 0;
258};
260
261} // namespace jazz_bebop
262
263#endif // ifndef INCLUDED_JAZZ_BEBOP_OPCODES
An attribute for an ONNX OpCode.
Definition opcodes.h:105
OnnxAttribute(stdName nam, AttributeType typ)
The constructor for an OnnxAttribute.
Definition opcodes.h:113
stdName name
The name of the attribute.
Definition opcodes.h:118
AttributeType type
The types of the attribute.
Definition opcodes.h:119
An ONNX OpCode.
Definition opcodes.h:126
OnnxParameters inputs
The input parameters.
Definition opcodes.h:147
OnnxOpCode(stdName nam, int version, OnnxParameters in, OnnxParameters out, OnnxAttributes attr)
The constructor for an OnnxOpCode.
Definition opcodes.h:137
stdName name
The name of the ONNX OpCode.
Definition opcodes.h:145
int opset_version
The version of the opset.
Definition opcodes.h:146
OnnxAttributes attributes
The attributes.
Definition opcodes.h:149
OnnxParameters outputs
The output parameters.
Definition opcodes.h:148
A parameter (input or output) for an ONNX OpCode.
Definition opcodes.h:84
OnnxParameter(stdName nam, TensorTypes typ)
The constructor for an OnnxParameter.
Definition opcodes.h:92
TensorTypes types
The types of the parameter.
Definition opcodes.h:98
stdName name
The name of the parameter.
Definition opcodes.h:97
OpCodes: The opcodes.
Definition opcodes.h:198
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:253
int latest_opset_version()
Get the latest opset version.
Definition opcodes.h:210
ConfigFile onnx_conf
The ONNX opcodes reference stored as a ConfigFile.
Definition opcodes.h:252
OnnxOpCodeDict opcodes_idx
The index to the opcodes.
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
int op_vers_latest
The latest opset version in onnx.ini.
Definition opcodes.h:254
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:257
bool set_opset_version(int version)
Set the opset version.
Definition opcodes.h:218
int op_vers_current
The opset version in use, set by set_opset_version() or op_vers_latest.
Definition opcodes.h:255
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:231
A pair of a name and a version to be used as a key in a dictionary.
Definition opcodes.h:157
bool operator==(const stdNameVersion &o) const
Operator this == o.
Definition opcodes.h:176
int opset_version
The version of the opset.
Definition opcodes.h:191
stdName name
The name of the ONNX OpCode.
Definition opcodes.h:190
bool operator<(const stdNameVersion &o) const
Operator this < o.
Definition opcodes.h:186
stdNameVersion(stdName nam, int version)
The constructor for a stdNameVersion.
Definition opcodes.h:165
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:67
std::vector< OnnxParameter > OnnxParameters
A list of OnnxParameter objects.
Definition opcodes.h:100
TensorTypes * pTensorTypes
A pointer to a TensorTypes.
Definition opcodes.h:68
std::vector< OnnxOpCode > OnnxOpCodes
A list of OnnxOpCode objects.
Definition opcodes.h:152
OpCodes * pOpCodes
A pointer to an OpCodes object.
Definition opcodes.h:259
OnnxOpCode * pOnnxOpCode
A pointer to an OnnxOpCode object.
Definition opcodes.h:151
std::map< stdName, TensorType > TensorTypeDict
A map of TensorType objects.
Definition opcodes.h:66
std::map< stdName, AttributeType > AttributeTypeDict
A map of AttributeType objects.
Definition opcodes.h:78
AttributeType * pAttributeType
A pointer to a AttributeType.
Definition opcodes.h:79
std::map< stdNameVersion, int > OnnxOpCodeDict
A map of OnnxOpCode objects.
Definition opcodes.h:193
std::vector< OnnxAttribute > OnnxAttributes
A list of OnnxAttribute objects.
Definition opcodes.h:121
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:73
int jazz_type
The Jazz native type.
Definition opcodes.h:74
onnx::AttributeProto::AttributeType onnx_proto_type
The ONNX protocol buffer type.
Definition opcodes.h:75
bool is_multi
True if the attribute is a list of the type.
Definition opcodes.h:76
A type definition for tensors across all the technologies: Jazz native, ONNX protocol buffer and ONNX...
Definition opcodes.h:61
onnx::TensorProto::DataType onnx_proto_type
The ONNX protocol buffer type.
Definition opcodes.h:63
int jazz_type
The Jazz native type.
Definition opcodes.h:62
ONNXTensorElementDataType onnx_rt_type
The ONNX runtime type.
Definition opcodes.h:64