1/*******************************************************************************
2* Copyright 2022 Intel Corporation
3*
4* Licensed under the Apache License, Version 2.0 (the "License");
5* you may not use this file except in compliance with the License.
6* You may obtain a copy of the License at
7*
8* http://www.apache.org/licenses/LICENSE-2.0
9*
10* Unless required by applicable law or agreed to in writing, software
11* distributed under the License is distributed on an "AS IS" BASIS,
12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13* See the License for the specific language governing permissions and
14* limitations under the License.
15*******************************************************************************/
16
17/// @file
18/// C API common types definitions
19
20#ifndef ONEAPI_DNNL_DNNL_COMMON_TYPES_H
21#define ONEAPI_DNNL_DNNL_COMMON_TYPES_H
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
27/// @cond DO_NOT_DOCUMENT_THIS
28#include <stddef.h>
29#include <stdint.h>
30/// @endcond
31
32/// @addtogroup dnnl_api oneDNN API
33/// @{
34
35/// @addtogroup dnnl_api_common Common API
36/// @{
37
38/// @addtogroup dnnl_api_utils
39/// @{
40
41/// Status values returned by the library functions.
42typedef enum {
43 /// The operation was successful
44 dnnl_success = 0,
45 /// The operation failed due to an out-of-memory condition
46 dnnl_out_of_memory = 1,
47 /// The operation failed because of incorrect function arguments
48 dnnl_invalid_arguments = 2,
49 /// The operation failed because requested functionality is not implemented
50 dnnl_unimplemented = 3,
51 /// The last available implementation is reached
52 dnnl_last_impl_reached = 4,
53 /// Primitive or engine failed on execution
54 dnnl_runtime_error = 5,
55 /// Queried element is not required for given primitive
56 dnnl_not_required = 6,
57 /// The graph is not legitimate
58 dnnl_invalid_graph = 7,
59 /// The operation is not legitimate according to op schema
60 dnnl_invalid_graph_op = 8,
61 /// The shape cannot be inferred or compiled
62 dnnl_invalid_shape = 9,
63 /// The data type cannot be inferred or compiled
64 dnnl_invalid_data_type = 10,
65} dnnl_status_t;
66
67/// @} dnnl_api_utils
68
69/// @addtogroup dnnl_api_data_types Data types
70/// @{
71
72/// Data type specification
73typedef enum {
74 /// Undefined data type, used for empty memory descriptors.
75 dnnl_data_type_undef = 0,
76 /// 16-bit/half-precision floating point.
77 dnnl_f16 = 1,
78 /// non-standard 16-bit (bfloat16 w/ 7 bit mantissa) floating point.
79 dnnl_bf16 = 2,
80 /// 32-bit/single-precision floating point.
81 dnnl_f32 = 3,
82 /// 32-bit signed integer.
83 dnnl_s32 = 4,
84 /// 8-bit signed integer.
85 dnnl_s8 = 5,
86 /// 8-bit unsigned integer.
87 dnnl_u8 = 6,
88 /// 64-bit/double-precision floating point.
89 dnnl_f64 = 7,
90
91 /// Parameter to allow internal only data_types without undefined behavior.
92 /// This parameter is chosen to be valid for so long as sizeof(int) >= 2.
93 dnnl_data_type_max = 0x7fff,
94} dnnl_data_type_t;
95
96/// Maximum number of dimensions a tensor can have. Only restricts the amount
97/// of space used for the tensor description. Individual computational
98/// primitives may support only tensors of certain dimensions.
99#define DNNL_MAX_NDIMS 12
100
101/// A type to describe tensor dimension.
102typedef int64_t dnnl_dim_t;
103
104/// A type to describe tensor dimensions.
105typedef dnnl_dim_t dnnl_dims_t[DNNL_MAX_NDIMS];
106
107/// @} dnnl_api_data_types
108
109/// @addtogroup dnnl_api_fpmath_mode Floating-point Math Mode
110/// @{
111
112/// Floating-point math mode
113typedef enum {
114 /// Default behavior, no downconversions allowed
115 dnnl_fpmath_mode_strict,
116 /// Implicit f32->bf16 conversions allowed
117 dnnl_fpmath_mode_bf16,
118 /// Implicit f32->f16 conversions allowed
119 dnnl_fpmath_mode_f16,
120 /// Implicit f32->f16 or f32->bf16 conversions allowed
121 dnnl_fpmath_mode_any,
122 /// Implicit f32->tf32 conversions allowed
123 dnnl_fpmath_mode_tf32,
124} dnnl_fpmath_mode_t;
125
126/// @} dnnl_api_fpmath_mode
127
128/// @addtogroup dnnl_api_engine Engine
129/// @{
130
131/// @brief Kinds of engines.
132typedef enum {
133 /// An unspecified engine.
134 dnnl_any_engine,
135 /// CPU engine.
136 dnnl_cpu,
137 /// GPU engine.
138 dnnl_gpu,
139} dnnl_engine_kind_t;
140
141/// @struct dnnl_engine
142/// @brief An opaque structure to describe an engine.
143struct dnnl_engine;
144/// @brief An engine handle.
145typedef struct dnnl_engine *dnnl_engine_t;
146#if 0
147// FIXME: looks like this never happens
148/// @brief A constant engine handle.
149typedef const struct dnnl_engine *const_dnnl_engine_t;
150#endif
151
152/// @} dnnl_api_engine
153
154/// @addtogroup dnnl_api_stream Stream
155/// @{
156
157/// @brief Stream flags.
158typedef enum {
159 // In-order execution.
160 dnnl_stream_in_order = 0x1U,
161 /// Out-of-order execution.
162 dnnl_stream_out_of_order = 0x2U,
163 /// Default stream configuration.
164 dnnl_stream_default_flags = dnnl_stream_in_order,
165} dnnl_stream_flags_t;
166
167/// @struct dnnl_stream
168/// An opaque structure to describe an execution stream.
169struct dnnl_stream;
170/// An execution stream handle.
171typedef struct dnnl_stream *dnnl_stream_t;
172/// A constant execution stream handle.
173typedef const struct dnnl_stream *const_dnnl_stream_t;
174
175/// @} dnnl_api_stream
176
177/// @addtogroup dnnl_api_service
178/// @{
179
180/// No runtime (disabled)
181#define DNNL_RUNTIME_NONE 0u
182
183/// Sequential runtime (CPU only)
184#define DNNL_RUNTIME_SEQ 1u
185
186/// OpenMP runtime (CPU only)
187#define DNNL_RUNTIME_OMP 2u
188
189/// TBB runtime (CPU only)
190#define DNNL_RUNTIME_TBB 4u
191
192/// Threadpool runtime (CPU only)
193#define DNNL_RUNTIME_THREADPOOL 8u
194
195/// OpenCL runtime
196#define DNNL_RUNTIME_OCL 256u
197
198/// SYCL runtime
199#define DNNL_RUNTIME_SYCL 512u
200
201/// DPC++ runtime
202#define DNNL_RUNTIME_DPCPP DNNL_RUNTIME_SYCL
203
204/// Structure containing version information as per [Semantic
205/// Versioning](https://semver.org)
206typedef struct {
207 int major; ///< Major version
208 int minor; ///< Minor version
209 int patch; ///< Patch version
210 const char *hash; ///< Git hash of the sources (may be absent)
211 unsigned cpu_runtime; ///< CPU runtime
212 unsigned gpu_runtime; ///< GPU runtime
213} dnnl_version_t;
214
215/// @} dnnl_api_service
216
217/// @} dnnl_api_common
218
219/// @} dnnl_api
220
221#ifdef __cplusplus
222}
223#endif
224
225#endif
226