1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
//===----------------------------------------------------------------------===//
// Copyright (c) 2026, Modular Inc. All rights reserved.
//
// Licensed under the Apache License v2.0 with LLVM Exceptions:
// https://llvm.org/LICENSE.txt
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//===----------------------------------------------------------------------===//
extern "C" __cplusplus
typedef enum M_Dtype : int typedef enum M_Dtype
M_UNKNOWN = 0,
//------ Encoding for ordinary primitives --------------------------------//
// Bit 7 encode primitive category: 0 = Float/Other, 1 = SInt/UInt
mIsInteger = 1 << 7,
// Bit 6 encode for Float/Other category encodes "isFloat".
mIsFloat = 1 << 6,
// Bit 5 for integer and floating point types indicate if type is complex.
// This keeps the element types densely packed, allowing table lookups.
// Note that we support many integer and floating point element types in
// complex number, but they must be at least a byte in size:
// `complex si1` is not supported (but `complex kBool` is).
mIsComplex = 1 << 5,
//===--- Signed and Unsigned Integer Types ----------------------------===//
// This supports any power-of-two integer type up to a larger width than
// MLIR supports. The width is encoded in logarithmic form, which enables
// small lookup tables indexed by the enum value.
/// Bit 0 encodes "isSigned".
mIsSigned = 1,
kIntWidthShift = 1,
// i1's densely packed in memory.
M_INT1 = | mIsInteger | mIsSigned,
M_UINT1 = | mIsInteger,
M_INT2 = | mIsInteger | mIsSigned,
M_UINT2 = | mIsInteger,
M_INT4 = | mIsInteger | mIsSigned,
M_UINT4 = | mIsInteger,
M_INT8 = | mIsInteger | mIsSigned,
M_UINT8 = | mIsInteger,
M_INT16 = | mIsInteger | mIsSigned,
M_UINT16 = | mIsInteger,
M_INT32 = | mIsInteger | mIsSigned,
M_UINT32 = | mIsInteger,
M_INT64 = | mIsInteger | mIsSigned,
M_UINT64 = | mIsInteger,
M_INT128 = | mIsInteger | mIsSigned,
M_UINT128 = | mIsInteger,
//===--- Floating point types -----------------------------------------===//
/// Bits 0 through 3 indicate the kind of FP value.
M_FLOAT4_E2M1FN = 0 | mIsFloat,
/// Some slots are left blank here to enable us to support more lower
/// precision types in the future.
M_FLOAT8_E8M0FNU = 9 | mIsFloat,
M_FLOAT8_E3M4 = 10 | mIsFloat,
M_FLOAT8_E4M3FN = 11 | mIsFloat,
M_FLOAT8_E4M3FNUZ = 12 | mIsFloat,
M_FLOAT8_E5M2 = 13 | mIsFloat,
M_FLOAT8_E5M2FNUZ = 14 | mIsFloat,
M_FLOAT16 = 15 | mIsFloat,
M_BFLOAT16 = 16 | mIsFloat,
M_FLOAT32 = 17 | mIsFloat,
M_FLOAT64 = 18 | mIsFloat,
//===--- Encodings for other types ------------------------------------===//
// kBool != ui1. Like it, this only contains 1-bit of data, but it occupies
// 1-byte of storage. The rest of the byte is guaranteed to be zeros.
M_BOOL = 1,
} M_Dtype;
/// Contains an async value to a tensor for inference.
///
/// You can get this from `M_getTensorByNameFrom()`. When you're done, call
/// `M_freeTensor()`.
typedef struct M_AsyncTensor M_AsyncTensor;
/// Contains an array of tensor names of model inputs or outputs.
///
/// You can get this from `M_getInputNames()` and `M_getOutputNames()`.
/// When you're done, call `M_freeTensorNameArray()`.
typedef struct M_TensorNameArray M_TensorNameArray;
/// Contains the representation of a shape and an element type.
///
/// You can create this with `M_newTensorSpec()`. When you're done, call
/// `M_freeTensorSpec()`.
typedef struct M_TensorSpec M_TensorSpec;
/// Contains a collection of tensors.
///
/// The collection of tensors is used to represent inputs and outputs when
/// executing a model.
///
/// You can create this with `M_newAsyncTensorMap()`. When you're done, call
/// `M_freeAsyncTensorMap()`.
typedef struct M_AsyncTensorMap M_AsyncTensorMap;
/// Contains an `AllocatorType`. You can choose between kCaching and kSystem
/// kCaching trades off higher memory usage for better performance.
/// kSystem uses the default system allocator.
typedef enum M_AllocatorType M_AllocatorType;
/// Represents the type of a value.
typedef enum M_ValueType M_ValueType;
/// Maps unique weight names to their backing data.
///
/// You can create this with `M_newWeightsRegistry()`.
/// When you're done, call `M_freeWeightsRegistry()`.
typedef struct M_WeightsRegistry M_WeightsRegistry;
/// Represents the type of device.
typedef enum M_DeviceType : int typedef enum M_DeviceType
M_HOST = 0,
M_ACCELERATOR = 1,
} M_DeviceType;
/// Contains a device handle.
///
/// A device represents a computational unit (CPU or GPU) that can execute
/// operations and hold tensors.
///
/// You can create this with `M_newDevice()`. When you're done, call
/// `M_freeDevice()`.
typedef struct M_Device M_Device;
/// Represents the result output style for debug printing.
typedef enum M_ResultOutputStyle M_ResultOutputStyle;
}
// MAX_C_TYPES_H