Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / clDNN / api / C / cldnn.h
1 /*
2 // Copyright (c) 2016-2018 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 ///////////////////////////////////////////////////////////////////////////////////////////////////
18 #ifndef CLDNN_H
19 #define CLDNN_H
20
21 // exporting symbols form dynamic library
22 #ifdef EXPORT_NEURAL_SYMBOLS
23 #   if defined(_MSC_VER)
24 //  Microsoft
25 #      define CLDNN_API __declspec(dllexport)
26 #   elif defined(__GNUC__)
27 //  GCC
28 #      define CLDNN_API __attribute__((visibility("default")))
29 #   else
30 #      define CLDNN_API
31 #      pragma warning Unknown dynamic link import/export semantics.
32 #   endif
33 #else //import dll
34 #   if defined(_MSC_VER)
35 //  Microsoft
36 #      define CLDNN_API __declspec(dllimport)
37 #   elif defined(__GNUC__)
38 //  GCC
39 #      define CLDNN_API
40 #   else
41 #      define CLDNN_API
42 #      pragma warning Unknown dynamic link import/export semantics.
43 #   endif
44 #endif
45
46 #include <stdint.h>
47 #include <stddef.h>
48
49 /// @addtogroup c_api C API
50 /// @{
51
52 /// @defgroup c_memory Memory Management
53
54 /// @defgroup c_topology Network Topology
55
56 /// @defgroup c_engine Execution Engine
57
58 /// @defgroup c_network Network Execution
59
60 /// @defgroup c_error Error Handling
61
62 /// @defgroup c_version Version Information
63
64 #ifdef __cplusplus
65 extern "C" {
66 #endif
67
68 /// @addtogroup c_error
69 /// @{
70 #define CLDNN_SUCCESS                0
71 #define CLDNN_ERROR                 -1
72 #define CLDNN_INVALID_ARG           -2
73 #define CLDNN_OUT_OF_RESOURCES      -3
74 #define CLDNN_DEVICE_ERROR          -4
75 #define CLDNN_UNSUPPORTED_SIZE      -5
76 #define CLDNN_UNSUPPORTED_FORMAT    -6
77 #define CLDNN_DIMENSION_MISMATCH    -7
78 #define CLDNN_ALLOC_SIZE_EXCEEDED   -8
79 #define CLDNN_GLOBAL_SIZE_EXCEEDED  -9
80
81 /// @brief Represents errors status for all API calls
82 typedef int32_t cldnn_status;
83 /// @}
84
85 /// @addtogroup c_version
86 /// @{
87 /// @brief Represents version information of API.
88 typedef struct
89 {
90     int32_t major;    ///< Major version component (major version of clDNN API interface).
91     int32_t minor;    ///< Minor version component (minor version of API interface - correlated with IE API version).
92     int32_t build;    ///< Build version component (version/revision of official Open Source drop of clDNN library).
93     int32_t revision; ///< Revision version component (incremental identifier of current build/compilation).
94 } cldnn_version;
95 /// @}
96
97 /// @ingroup c_engine
98 /// @brief Engine object
99 typedef struct cldnn_engine_impl* cldnn_engine;
100
101 /// @ingroup c_network
102 /// @brief Event object
103 typedef struct cldnn_event_impl* cldnn_event;
104
105 /// @ingroup c_topology
106 /// @brief Network topology to be defined by user
107 typedef struct cldnn_topology_impl* cldnn_topology;
108
109 /// @ingroup c_program
110 /// @brief Compiled program build from @ref cldnn_topology by @ref cldnn_engine
111 typedef struct cldnn_program_impl* cldnn_program;
112
113 /// @ingroup c_network
114 /// @brief Executable network allocated from @ref cldnn_program
115 typedef struct cldnn_network_impl* cldnn_network;
116
117 /// @ingroup c_memory
118 /// @brief Memory object
119 typedef struct cldnn_memory_impl* cldnn_memory;
120
121 /// @addtogroup c_engine
122 /// @{
123
124 /// @brief Defines available engine types
125 typedef enum /*:int32_t*/
126 {
127     cldnn_engine_ocl ///< OpenCL engine
128 } cldnn_engine_type;
129
130 /// @brief Priority modes.
131 typedef enum /*:int16_t*/
132 {
133     cldnn_priority_disabled,
134     cldnn_priority_low,
135     cldnn_priority_med,
136     cldnn_priority_high
137 } cldnn_priority_mode_type;
138
139 /// @brief Throttle modes.
140 typedef enum /*:int16_t*/
141 {
142     cldnn_throttle_disabled,
143     cldnn_throttle_low,
144     cldnn_throttle_med,
145     cldnn_throttle_high
146 } cldnn_throttle_mode_type;
147
148 /// @brief Configuration parameters for created engine.
149 typedef struct
150 {
151     uint32_t enable_profiling;                          ///< Enable per-primitive profiling.
152     uint32_t meaningful_kernels_names;                  ///< Generate meaniful names fo OpenCL kernels.
153     uint32_t dump_custom_program;                       ///< dump the custom generated program to files 
154     const char* compiler_options;                       ///< OpenCL compiler options string.
155     const char* single_kernel_name;                     ///< If provided, runs specific layer.
156     uint32_t enable_parallelisation;                    ///< Enables parallel execution of primitives which don't depend on each other. Disabled by default.
157     const char* engine_log;                             ///< Specifies a file to which engine log should be dumped. Null/empty values means no logging.
158     const char* sources_dumps_dir;                      ///< Specifies a directory where sources of cldnn::program objects should be dumped. Null/empty values means no loggins.
159     /*cldnn_priority_mode_type*/ int16_t priority_mode; ///< Priority mode (support of OpenCL priority hints in command queue).
160     /*cldnn_throttle_mode_type*/ int16_t throttle_mode; ///< Throttle mode (support of throttle hints in command queue).
161     uint32_t enable_memory_pool;                        ///< Enables memory usage optimization. memory objects will be reused when possible. 
162     void* context;
163     const char* tuning_cache_path;                      ///< Enables defining other than default path to tuning cache json 
164 }  cldnn_engine_configuration;
165
166 /// @brief Information about the engine returned by cldnn_get_engine_info().
167 typedef struct
168 {
169     uint32_t cores_count;              ///< Number of available HW cores.
170     uint32_t core_frequency;           ///< Clock frequency in MHz.
171
172     uint64_t max_work_group_size;      ///< Maximum number of work-items in a work-group executing a kernel using the data parallel execution model.
173     uint64_t max_local_mem_size;       ///< Maximum size of local memory arena in bytes.
174     uint64_t max_global_mem_size;      ///< Maximum size of global device memory in bytes.
175     uint64_t max_alloc_mem_size;       ///< Maximum size of memory object allocation in bytes.
176
177     uint64_t max_image2d_width;        ///< Maximum image 2d width supported by the device.
178     uint64_t max_image2d_height;       ///< Maximum image 2d height supported by the device.
179
180     // Flags (for layout compatibility fixed size types are used).
181     uint8_t supports_fp16;             ///< Does engine support FP16.
182     uint8_t supports_fp16_denorms;     ///< Does engine support denormalized FP16.
183     uint8_t supports_subgroups_short;  ///< Does engine support cl_intel_subgroups_short.
184     uint8_t supports_image;            ///< Does engine support images (CL_DEVICE_IMAGE_SUPPORT cap).
185
186     uint8_t supports_imad;             ///< Does engine support int8 mad.
187     uint8_t supports_immad;            ///< Does engine support int8 multi mad.
188 }  cldnn_engine_info;
189 /// @}
190
191 /// @addtogroup c_network
192 /// @{
193
194 /// @brief user-defined event handler callback.
195 typedef void(*cldnn_event_handler)(void*);
196
197 /// @brief Profiling information for an executed network primitive.
198 /// @details Every @ref cldnn_event associated with @ref cldnn_network_output.
199 /// can contain one or more profiling information intervals.
200 typedef struct
201 {
202     const char* name;                   ///< Profiling interval name.
203     uint64_t nanoseconds;
204 } cldnn_profiling_interval;
205
206 /// @brief Network build option types.
207 typedef enum /*:int32_t*/
208 {
209     cldnn_build_option_fusing,                  ///< Allow primitives fusing during network build.
210     cldnn_build_option_optimize_data,           ///< Enable implicit reordering for user input.
211     cldnn_build_option_debug,                   ///< Enable debug mode.
212     cldnn_build_option_outputs,                 ///< User selected list of network outputs.
213     cldnn_build_option_tuning_config,           ///< Tuning config.
214     cldnn_build_option_graph_dumps_dir,         ///< Specifies a directory to which stages of network compilation should be dumped.
215     cldnn_build_option_serialization,           ///< Specifies a name of files to which serialization should be dumped.
216     cldnn_build_option_load_program,            ///< Specifies a name of load_program process.
217     cldnn_build_option_learning_config,         ///< User defined learning parameters.
218     cldnn_build_option_detection_output_gpu     ///< Run detection output layer always on GPU, regardless performance
219 } cldnn_build_option_type;
220
221 /// @brief Tuning modes.
222 typedef enum /*:int32_t*/
223 {
224     cldnn_tuning_disabled,          ///< Tuning is disabled.
225     cldnn_tuning_use_cache,         ///< Tuning using the cached data (no on-line tuning for non-existing data).
226     cldnn_tuning_tune_and_cache,    ///< Tuning using the cached data if exist, tune and update cache otherwise.
227 } cldnn_tuning_mode_type;
228
229 /// @brief Tuning config.
230 struct cldnn_tuning_config
231 {
232     const int32_t mode;             ///< #cldnn_tuning_mode_type.
233     const char* cache_file_path;    ///< A path to the tuning cache file.
234 };
235
236 /// @brief Learning params.
237 struct cldnn_learning_params
238 {
239         const float momentum;
240         const float weights_decay;
241 };
242
243 /// @brief Represents network build option.
244 typedef struct
245 {
246     int32_t type;                       ///< #cldnn_build_option_type.
247     const void* data;                   ///< option parameter - e.g list of outputs.
248 }  cldnn_build_option;
249
250 /// @brief Output information for executed @a cldnn_network.
251 /// @details User should wait for event before accessing the memory.
252 typedef struct
253 {
254     cldnn_event event;                  ///< Event to be waited.
255     cldnn_memory memory;                ///< Output memory.
256                                         ///< User should wait for the event before access this field.
257 } cldnn_network_output;
258
259 /// @}
260
261 /// @addtogroup c_memory
262 /// @{
263
264 /// @brief Represents memory formats (orders).
265 /// @n In CNN most of data is describe as 4 dimensional blocks. In Intel(R) clDNN library we describe memory with 4 letters
266 /// - b - number of blocks in batch. For weights formats: output features - conv, neurons - inner product
267 /// - f - number of feature maps, features or channels. For weights formats: input features - conv, inputs, inner product
268 /// - x - spatial, width
269 /// - y - spatial, height
270 /// /n
271 /// For explanation how each format type is implemented in memory we will use naming shown bellow (b=2,f=3,y=3,x=3):
272 /// \image html layout_memory_representation.jpg
273 typedef enum /*:int32_t*/
274 {
275     cldnn_format_yxfb,          ///< batch first, feature and than spatials \n \image html yxfb.jpg
276     cldnn_format_byxf,          ///< used in bitmaps, input from user i.e b images of RGB format \n \image html byxf.jpg
277     cldnn_format_bfyx,          ///< the most common format for activations in clDNN. \n \image html bfyx.jpg
278     cldnn_format_fyxb,          ///< format not used inside clDNN, but supported in reorder as extension for user provided formats.
279     cldnn_format_os_iyx_osv16,  ///< format used only for convolution weights: os - output feature maps slice, i - input feature maps, yx - spatials, sv16 - 16 values of single slice.
280                                 ///< \n \image html os_iyx_osv16.jpg
281     cldnn_format_os_iyx_osv32,  ///< format used only for convolution weights: os - output feature maps slice, i - input feature maps, yx - spatials, sv32 - 32 values of single slice.
282     cldnn_format_os_iyx_osv64,  ///< format used only for convolution weights: os - output feature maps slice, i - input feature maps, yx - spatials, sv64 - 64 values of single slice.
283     cldnn_format_bs_xs_xsv8_bsv8, ///< format used only for fully connected weights: bs - batch slice, xs - x slice, bsv8 - 8 values of single slice.
284                                   ///< \n \image html bs_xs_xsv8_bsv8.jpg
285     cldnn_format_bs_xs_xsv8_bsv16,///< format used only for fully connected weights: bs - batch slice, xs - x slice, bsv16 - 16 values of single slice.
286                                   ///< \n \image html bs_xs_xsv8_bsv16.jpg
287     cldnn_format_bs_x_bsv16,    ///< format used only for fully connected weights fp16 batch=1 : bs - batch slice (responses slice), bsv16 - 16 values of single batch slice, x - flattened plane of (fyx).
288                                 ///< \n \image html bs_x_bsv16.jpg
289     cldnn_format_bf8_xy16,      ///< format used only for convolution 1x1 input, xy aligned to 16, f aligned to 8
290                                 ///< \n \image html bf8_xy16.jpg
291     cldnn_format_image_2d_weights_c4_fyx_b, ///< image format for weights, image 2d, 4-channel, width size is f*y*x/4 (4-channels filled with fyx data), height is b
292                                       ///< \n \image html image_2d_weights_c4_fyx_b.jpg
293     cldnn_format_image_2d_weights_c1_b_fyx, ///< image format for weights, image 2d, single channel, width size is b, height is f*y*x
294                                       ///< \n \image html image_2d_weights_c1_b_fyx.jpg
295     cldnn_format_winograd_2x3_s1_data,       ///< format used for input for winograd convolution, F(2,3) -- filter 3x3 with stride 1
296     cldnn_format_winograd_2x3_s1_weights,    ///< format used for weights for winograd non-fused convolution, F(2,3) -- filter 3x3 with stride 1
297     cldnn_format_winograd_2x3_s1_fused_weights,    ///< format used for weights for winograd fused convolution, F(2,3) -- filter 3x3 with stride 1
298     cldnn_format_winograd_6x3_s1_fused_weights,    ///< format used for weights for winograd fused convolution, F(6,3) -- filter 3x3 with stride 1
299     cldnn_format_image_2d_weights_winograd_6x3_s1_fbxyb, ///< image format used for weights for winograd fused convolution, F(6,3) -- filter 3x3 with stride 1
300     cldnn_format_image_2d_weights_winograd_6x3_s1_xfbyb, ///< image format used for weights for winograd fused convolution, F(6,3) -- filter 3x3 with stride 1
301     cldnn_format_byxf_af32,               /// < \n format for input for primitives using MMAD
302     cldnn_format_byx8_f4,                 /// < \n format for input for MMAD convolutions
303     cldnn_format_fs_bs_yx_bs4_fs32,       /// < \n format for batched input for primitives using MMAD
304     cldnn_format_os_is_yx_isa8_osv8_isv4, /// < \n format for weights for MMAD convolutions, stored as ((aligned_to_8(O)/8) * (aligned_to_32(I)/32) * Y * X * ( 8 ) * ( 8 ) * ( 4 )
305     cldnn_format_os_is_yx_isa8_osv8_isv4_swizzled_by_4, /// < \n format for weights for MMAD convolutions
306     cldnn_format_is_o_yx_isv32, /// < \n format for weights for 1x1 MMAD convolutions 
307     cldnn_format_is_o32_yx_isv32_swizzled_by_4, /// < \n format for weights for 1x1 MMAD convolutions
308     cldnn_format_os_is_y_x8_osv8_isv4, /// < n\ format for weights for MMAD convolutions
309     cldnn_bf_lyx_yx,                      /// < \n format for local convolution weights
310     cldnn_format_b_fs_yx_fsv4,            /// < \n format for input for IMAD convolutions
311     cldnn_format_os_is_yx_osv16_isv4,     /// < \n format for weights for IMAD convolutions
312     cldnn_format_format_num,    ///< number of format types
313     cldnn_format_any = -1
314 } cldnn_format_type;
315
316 #define CLDNN_FLOAT_TYPE_MASK 0x80
317 #define CLDNN_UINT_TYPE_MASK 0x40
318
319 #define CLDNN_TENSOR_BATCH_DIM_MAX 1
320 #define CLDNN_TENSOR_FEATURE_DIM_MAX 1
321 #define CLDNN_TENSOR_SPATIAL_DIM_MAX 2
322 #define CLDNN_TENSOR_LOCAL_DIM_MAX 2
323 #define CLDNN_TENSOR_DIM_MAX 8
324
325 /// @brief N-dimensional vector. Mostly used to represent memory size.
326 typedef struct
327 {
328     size_t batch_num;
329     size_t feature_num;
330     size_t spatial_num;
331     size_t local_num;
332     int32_t sizes[CLDNN_TENSOR_DIM_MAX];
333 } cldnn_tensor;
334
335 /// @brief Padding information.
336 typedef struct
337 {
338     cldnn_tensor lower_size; ///< Lower padding sizes. For spatials, it means size of left (X) and top (Y) padding.
339     cldnn_tensor upper_size; ///< Upper padding sizes. For spatials, it means size of right (X) and bottom (Y) padding.
340     float filling_value;     ///< Filling value for an element of padding. If data type of elements is different than float it is converted
341                              ///< to it using round-towards-nearest-even (for floating-point data types) or round-towards-zero (for integral
342                              ///< data types).
343 } cldnn_padding;
344
345 /// @brief Data type stored in memory.
346 typedef enum /*:size_t*/
347 {
348         cldnn_i8  = sizeof(int8_t),
349     cldnn_f16 = sizeof(int16_t) | CLDNN_FLOAT_TYPE_MASK,
350     cldnn_f32 = sizeof(float) | CLDNN_FLOAT_TYPE_MASK,
351     cldnn_u8  = sizeof(uint8_t) | CLDNN_UINT_TYPE_MASK, // TODO: move to top of list and re-compile inference engine
352     cldnn_i32 = sizeof(int32_t),
353     cldnn_i64 = sizeof(int64_t)
354
355 } cldnn_data_type;
356
357 /// @brief Memory layout description.
358 typedef struct
359 {
360     size_t data_type;       ///< data type (@ref cldnn_data_type) stored in memory.
361     int32_t format;         ///< Memor format (@ref cldnn_format_type)
362     cldnn_tensor size;      ///< N-dimensional vector describes size (in elements) of memory (excluding padding).
363     cldnn_padding padding;  ///< Explicitly added padding to memory buffer.
364 } cldnn_layout;
365 /// @}
366
367 /// @addtogroup c_topology
368 /// @{
369
370 /// @brief Represents reference to an array of floats.
371 typedef struct
372 {
373     const float* data; ///< Pointer to float array.
374     size_t size;       ///< Size (in floats) of the array.
375 } cldnn_float_arr;
376
377 /// @brief Represents reference to an array of uint16_t.
378 typedef struct
379 {
380     const uint16_t* data; ///< Pointer to uint16_t array.
381     size_t size;       ///< Size (in uint16_t) of the array.
382 } cldnn_uint16_t_arr;
383
384 /// @brief Represents reference to an array of uint8_t.
385 typedef struct
386 {
387     const uint8_t* data; ///< Pointer to uint8_t array.
388     size_t size;       ///< Size (in uint8_t) of the array.
389 } cldnn_uint8_t_arr;
390
391 /// @brief Represents reference to an array of tensor.
392 typedef struct
393 {
394     const cldnn_tensor* data; ///< Pointer to tensor array.
395     size_t size;       ///< Size (in tensor) of the array.
396 } cldnn_tensor_arr;
397
398 /// @brief Globally unique primitive's type id
399 typedef const struct cldnn_primitive_type* cldnn_primitive_type_id;
400
401 /// @brief Unique @p id of a primitive within a topology.
402 typedef const char* cldnn_primitive_id;
403
404 /// @brief Represents reference to an array of primitive ids.
405 typedef struct
406 {
407     const cldnn_primitive_id* data; ///< Pointer to ids array.
408     size_t size;                    ///< Number of ids in the array.
409 } cldnn_primitive_id_arr;
410
411 typedef struct
412 {
413     cldnn_data_type data_type;
414     // No bool type available...
415     char enabled;
416 } cldnn_optional_data_type;
417
418 /// @brief Custom primitive kernel source code
419 typedef const char*  cldnn_kernel_code;
420 /// @brief Custom primitive kernel source code array
421 typedef cldnn_kernel_code* cldnn_kernels_code;
422 /// @brief Custom primitive kernel entry point
423 typedef const char*  cldnn_kernel_entry_point;
424 /// @brief Custom primitive kernel build options
425 typedef const char*  cldnn_kernel_build_options;
426 /// @brief Custom primitive kernel workgroup sizes
427 typedef const size_t*  cldnn_work_group_sizes;
428
429 /// @brief Custom primitive kernel argument type
430 typedef enum cldnn_arg_type_t
431 {
432     arg_input,
433     arg_output,
434 } cldnn_arg_type;
435
436 /// @brief Custom primitive kernel argument index
437 typedef uint32_t cldnn_arg_index;
438
439 /// @brief Custom primitive kernel argument type
440 typedef struct cldnn_arg_t
441 {
442     cldnn_arg_type arg_type;
443     cldnn_arg_index index;
444 } cldnn_arg;
445
446 /// @brief Custom primitive kernel argument array
447 typedef const cldnn_arg* cldnn_kernel_arguments;
448
449 /// @brief activation functions
450 typedef enum cldnn_activation_func_t
451 {
452     activation_none,                    // val
453     activation_logistic,                // 1/(1 + exp(-val))
454     activation_hyperbolic_tan,          // tanh(val)
455     activation_relu,                    // max(0, val)
456     activation_relu_negative_slope,     // max(0, val) + a * min(0, val)    (a is additional param)
457     activation_clamp,                   // max(a, min(b, val)               (a,b are additional param)
458     activation_softrelu,                // log(1 + exp(val))
459     activation_abs,                     // abs(val)
460     activation_linear,                  // a*val + b                        (a,b are additional params) 
461     activation_square,                  // val*val
462     activation_sqrt,                    // sqrt(val)
463     activation_elu,                     // max(0, val) + a * (exp(min(0, val) - 1) (a is additional param)
464     activation_sin,                     // sin(val)
465     activation_asin,                    // asin(val)
466     activation_sinh,                    // sinh(val)
467     activation_cos,                     // cos(val)
468     activation_acos,                    // acos(val)
469     activation_cosh,                    // cosh(val)
470     activation_log,                     // log(val)
471     activation_log2,                    // log2(val)
472     activation_exp,                     // exp(val)
473     activation_not                      // !(val)
474 } cldnn_activation_func;
475
476 /// @brief activation gradient functions
477 typedef enum cldnn_activation_grad_func_t
478 {
479     activation_grad_none,                    // val
480     activation_grad_relu,                    // val * (input > 0)
481     activation_grad_relu_negative_slope,     // val * ((input > 0) + a * (input <= 0)    (a is additional param)
482 } cldnn_activation_grad_func;
483
484 /// @brief activation additional params
485 typedef struct cldnn_activation_additional_params_t
486 {
487     float a, b;
488 } cldnn_activation_additional_params;
489
490 /// @brief Axis which index_select primitive will index.
491 typedef enum index_select_axis_name_t
492 {
493     along_b,
494     along_f,
495     along_y,
496     along_x
497 } index_select_axis_name;
498
499 /// @brief  Axis which index_select primitive will index array
500 typedef const index_select_axis_name* index_select_axis_name_arr;
501
502 /// @brief reorder mean operation modes
503 typedef enum cldnn_reorder_mean_mode_t
504 {
505     mean_none,                    // val
506     mean_subtract,                // val - mean
507     mean_mul,                     // val * mean
508     mean_div,                     // val/mean
509 } cldnn_reorder_mean_mode;
510
511 /// @brief Begin primitive description definition
512 /// @details Defines @p 'cldnn_primitive_type_desc' structure with first 5 fields
513 /// common for all primitive descriptors. Other fields should be added after this macro.
514 /// primitive descriptor definition should be closed by @ref CLDNN_END_PRIMITIVE_DESC.
515 #define CLDNN_BEGIN_PRIMITIVE_DESC(PType) struct cldnn_##PType##_desc {\
516     cldnn_primitive_type_id type; /**< @brief Primitive type identificator. */\
517     cldnn_primitive_id id;        /**< @brief Primitive id unique within a topology. */\
518     cldnn_primitive_id_arr input; /**< @brief Input primitives ids. */\
519     cldnn_padding output_padding; /**< @brief Output padding information. */\
520     cldnn_optional_data_type output_data_type; /**< @brief If specified, describes an explicit change of the output precision of the primitive. */
521
522 /// @brief Close primitive descriptor definition.
523 #define CLDNN_END_PRIMITIVE_DESC(PType) };
524
525 #define CLDNN_PRIMITIVE_DESC(PType) cldnn_##PType##_desc
526
527 /// @brief Basic primitive descriptor structure.
528 CLDNN_BEGIN_PRIMITIVE_DESC(primitive)
529 CLDNN_END_PRIMITIVE_DESC(primitive)
530
531 /// @}
532
533 /// @addtogroup c_version
534 /// @{
535 /// @brief Get information about version of clDNN.
536 CLDNN_API cldnn_version cldnn_get_version(cldnn_status* status);
537 /// @}
538
539 /// @addtogroup c_topology
540 /// @{
541
542 /// @brief Create empty network topology
543 CLDNN_API cldnn_topology cldnn_create_topology(cldnn_status* status);
544
545 /// @brief Add new primitive to the topology.
546 /// @param[in] dto The pointer to a structure defined by @ref CLDNN_BEGIN_PRIMITIVE_DESC and @ref CLDNN_END_PRIMITIVE_DESC
547 CLDNN_API void cldnn_add_primitive(cldnn_topology topology, const struct CLDNN_PRIMITIVE_DESC(primitive)* dto, cldnn_status* status);
548
549 /// @brief Change input layout of the topology.
550 /// @param[in] id of the input layout in the topology
551 /// @param[in] new_layout of the input layout
552 CLDNN_API void cldnn_change_input_layout(cldnn_topology topology, cldnn_primitive_id id, cldnn_layout new_layout, cldnn_status* status);
553
554 /// @brief Return all primitives id from topology.
555 /// @details Function fills user provided buffer by primitive ids. Each id is followed by '\0'.
556 /// @param[in] ids Pointer to user-allocated buffer to store names.
557 /// @param[in] size Size (in chars) of the buffer.
558 /// @param[out] size_ret Required size (in chars) to store result.
559 CLDNN_API void cldnn_get_primitive_ids(cldnn_topology topology, char* ids, size_t size, size_t* size_ret, cldnn_status* status);
560
561 /// @brief Increment reference counter for the topology object.
562 CLDNN_API void cldnn_retain_topology(cldnn_topology topology, cldnn_status* status);
563
564 /// @brief Decrement reference counter for the topology object. Deletes object when counter becomes zero.
565 CLDNN_API void cldnn_release_topology(cldnn_topology topology, cldnn_status* status);
566 /// @}
567
568 /// @addtogroup c_engine
569 /// @{
570
571 /// @brief number of available engines of the particular type
572 CLDNN_API uint32_t cldnn_get_engine_count(/*cldnn_engine_type*/ int32_t type, cldnn_status* status);
573
574 /// @brief Release pending memory allocated in OpenCL context.
575 /// @param[in] type Engine type @ref cldnn_engine_type. Only OCL engine is supported.
576 /// @details OpenCL does not guarantee that the memory will be released (even with cl:Buffers releaed).
577 /// Use this function to force releasing whole pending memory.
578 CLDNN_API void cldnn_release_pending_memory(cldnn_engine engine, cldnn_status* status);
579
580 /// @brief Create new engine of the specified @p type, @p engine_num, and @p configuration options.
581 /// @param[in] type Engine type @ref cldnn_engine_type. Only OCL engine is supported.
582 /// @param[in] engine_num Engine index. Should be 0.
583 /// @param[in] configuration Pointer to engine configuration options.
584 CLDNN_API cldnn_engine cldnn_create_engine(/*cldnn_engine_type*/ int32_t type, uint32_t engine_num, const cldnn_engine_configuration* configuration, cldnn_status* status);
585
586 /// @brief Increment reference counter for the engine object.
587 CLDNN_API void cldnn_retain_engine(cldnn_engine engine, cldnn_status* status);
588
589 /// @brief Decrement reference counter for the engine object. Deletes object when counter becomes zero.
590 CLDNN_API void cldnn_release_engine(cldnn_engine engine, cldnn_status* status);
591
592 /// @brief Returns engine information. See @ref cldnn_engine_info for details.
593 CLDNN_API cldnn_engine_info cldnn_get_engine_info(cldnn_engine engine, cldnn_status* status);
594
595 /// @brief Returns the @ref cldnn_engine_type for the particular engine
596 CLDNN_API /*cldnn_engine_type*/ int32_t cldnn_get_engine_type(cldnn_engine engine, cldnn_status* status);
597
598 /// @brief Returns total size of all resources allocated using given engine
599 CLDNN_API int64_t cldnn_get_temp_used_device_memory_size(cldnn_engine engine, cldnn_status* status);
600 /// @}
601
602 /// @brief Returns max size of resources allocated using given engine
603 CLDNN_API int64_t cldnn_get_max_used_device_memory_size(cldnn_engine engine, cldnn_status* status);
604
605 /// @addtogroup c_network
606 /// @{
607
608 /// @brief Creates an event which can be set by user.
609 CLDNN_API cldnn_event cldnn_create_user_event(cldnn_engine engine, cldnn_status* status);
610
611 /// @brief Checks if an event was created by user.
612 CLDNN_API int32_t cldnn_is_user_event(cldnn_event event, cldnn_status* status);
613
614 /// @brief Increment reference counter for the event object.
615 CLDNN_API void cldnn_retain_event(cldnn_event event, cldnn_status* status);
616
617 /// @brief Decrement reference counter for the event object. Deletes object when counter becomes zero.
618 CLDNN_API void cldnn_release_event(cldnn_event event, cldnn_status* status);
619
620 /// @brief Waits for event completion or error.
621 CLDNN_API void cldnn_wait_for_event(cldnn_event event, cldnn_status* status);
622
623 /// @brief Set event status to @p completed.
624 CLDNN_API void cldnn_set_event(cldnn_event event, cldnn_status* status);
625
626 /// @brief Register call back to be called on event completion.
627 /// @param[in] handler Pointer to @ref cldnn_event_handler call-back function.
628 /// @param[in] param user-defined value to be passed to the call back function.
629 CLDNN_API void cldnn_add_event_handler(cldnn_event event, cldnn_event_handler handler, void* param, cldnn_status* status);
630
631 /// @brief Returns the profiling information for an network primitive associated with event.
632 /// @param[in] profiling Pointer to the array of @ref cldnn_profiling_interval where information to be stored.
633 /// @param[in] size Number of elements in the array of @ref cldnn_profiling_interval.
634 /// @param[out] size_ret Number of elements required to store profiling information.
635 CLDNN_API void cldnn_get_event_profiling_info(cldnn_event event, cldnn_profiling_interval* profiling, size_t size, size_t* size_ret, cldnn_status* status);
636 /// @}
637
638 /// @addtogroup c_program
639 /// @{
640
641 /// @brief Builds executable program based on user-defined @p topology by specified @p engine.
642 /// @param[in] engine The engine which will be used to build the program.
643 /// @param[in] topology The user-defined topology on which the network will be based.
644 /// @param[in] options The pointer of array of @ref cldnn_build_option which define network build options.
645 /// @param[in] options_num Number of elements in the @p options array.
646 CLDNN_API cldnn_program cldnn_build_program(cldnn_engine engine, cldnn_topology topology, cldnn_build_option* options, size_t options_num, cldnn_status* status);
647
648 /// @brief Increment reference counter for the program object.
649 CLDNN_API void cldnn_retain_program(cldnn_program program, cldnn_status* status);
650
651 /// @brief Decrement reference counter for the program object. Deletes object when counter becomes zero.
652 CLDNN_API void cldnn_release_program(cldnn_program program, cldnn_status* status);
653 /// @}
654
655 /// @addtogroup c_network
656 /// @{
657
658 /// @brief Builds and allocates executable network based on user-defined @p topology by specified @p engine. This is a shorthand for cldnn_build_program and cldnn_allocate_network.
659 /// @param[in] engine The engine which will be used to build the metwork.
660 /// @param[in] topology The user-defined topology on which the network will be based.
661 /// @param[in] options The pointer of array of @ref cldnn_build_option which define network build options.
662 /// @param[in] options_num Number of elements in the @p options array.
663 CLDNN_API        cldnn_network cldnn_build_network(cldnn_engine engine, cldnn_topology topology, cldnn_build_option* options, size_t options_num, cldnn_status* status);
664
665 /// @brief Allocates memory for a new network which will be able to execute specified @p program.
666 /// @param[in] program The program object which holds binaries compiled from some topology and engine. Multiple network objects can share the same program.
667 CLDNN_API        cldnn_network cldnn_allocate_network(cldnn_program program, cldnn_status* status);
668
669 /// @brief Increment reference counter for the network object.
670 CLDNN_API                 void cldnn_retain_network(cldnn_network network, cldnn_status* status);
671
672 /// @brief Decrement reference counter for the network object. Deletes object when counter becomes zero.
673 CLDNN_API                 void cldnn_release_network(cldnn_network network, cldnn_status* status);
674
675 /// @brief Provides user input data to the network (for @p input_layout primitives).
676 /// @param[in] id Primitive @p id of @p input_layout primitive defined in @p topology.
677 /// @param[in] mem Memory object with user data which @p layout matches the @p input_layout defined in @p topology.
678 /// @details User should set the input data for every @p input_layout primitive defined in @p topology
679 /// by calling this function before call to cldnn_execute_network().
680 CLDNN_API                 void cldnn_set_network_input(cldnn_network network, cldnn_primitive_id id, cldnn_memory mem, cldnn_status* status);
681
682 /// @brief Sets learning rate for training primitives in network.
683 /// @param[in] lr Learning rate.
684 CLDNN_API void cldnn_set_learning_rate(cldnn_network network, float lr, cldnn_status* status);
685
686 /// @brief Returns learning rate value.
687 CLDNN_API float cldnn_get_learning_rate(cldnn_network network, cldnn_status* status);
688
689 /// @brief Returns information about particular primitive.
690 /// @details Function fills user provided buffer by primitive description.
691 /// @param[in] id Primitive @p id of @p input_layout primitive defined in @p topology.
692 /// @param[in] info Pointer to user-allocated buffer to store names.
693 /// @param[in] size Size (in chars) of the buffer.
694 /// @param[out] size_ret Required size (in chars) to store result.
695 /// @returns pointer to array of chars with detailed information about particular primitive.
696 CLDNN_API void cldnn_get_primitive_info(cldnn_network network, cldnn_primitive_id id, char* info, size_t size, size_t* size_ret, cldnn_status* status);
697
698 /// @brief Returns @p engine associated with the @p network.
699 CLDNN_API         cldnn_engine cldnn_get_network_engine(cldnn_network network, cldnn_status* status);
700
701 /// @brief Returns @p program associated with the @p network.
702 CLDNN_API        cldnn_program cldnn_get_network_program(cldnn_network network, cldnn_status* status);
703
704 /// @brief Returns names of network outputs.
705 /// @details Function fills user provided buffer by primitive names. Each name is followed by '\0'.
706 /// Empty name "\0\0" means end of data.
707 /// @param[in] names Pointer to user-allocated buffer to store names.
708 /// @param[in] size Size (in chars) of the buffer.
709 /// @param[out] size_ret Required size (in chars) to store result.
710 CLDNN_API                 void cldnn_get_network_output_names(cldnn_network network, char* names, size_t size, size_t* size_ret, cldnn_status* status);
711
712 /// @brief Returns names of executed primitives.
713 /// @details Function fills user provided buffer by primitive names. Each name is followed by '\0'.
714 /// Empty name "\0\0" means end of data.
715 /// @param[in] names Pointer to user-allocated buffer to store names.
716 /// @param[in] size Size (in chars) of the buffer.
717 /// @param[out] size_ret Required size (in chars) to store result.
718 CLDNN_API                 void cldnn_get_network_executed_primitive_names(cldnn_network network, char* names, size_t size, size_t* size_ret, cldnn_status* status);
719
720 /// @brief Returns names of all primitives in network.
721 /// @details Function fills user provided buffer by primitive names. Each name is followed by '\0'.
722 /// Empty name "\0\0" means end of data.
723 /// @param[in] names Pointer to user-allocated buffer to store names.
724 /// @param[in] size Size (in chars) of the buffer.
725 /// @param[out] size_ret Required size (in chars) to store result.
726 CLDNN_API                 void cldnn_get_network_all_primitive_names(cldnn_network network, char* names, size_t size, size_t* size_ret, cldnn_status* status);
727
728 /// @brief Returns names of all primitives in network before graph optimization.
729 /// @details Function fills user provided buffer by primitive names. Each name is followed by '\0'.
730 /// Empty name "\0\0" means end of data.
731 /// @param[in] names Pointer to user-allocated buffer to store names.
732 /// @param[in] size Size (in chars) of the buffer.
733 /// @param[out] size_ret Required size (in chars) to store result.
734 CLDNN_API                 void cldnn_get_network_all_primitive_org_names(cldnn_network network, char* names, size_t size, size_t* size_ret, cldnn_status* status);
735
736 /// @brief Executes network.
737 /// @details User should call cldnn_set_network_input() for every @p input_layout defined in tho source @p topology.
738 /// Function returns immediately, even if @p dependencies are not set yet.
739 /// @params dependencies Pointer to an array of @ref cldnn_events to be waited for network execution.
740 /// @param deps_num Number of elements in the @p dependencies array.
741 CLDNN_API                 void cldnn_execute_network(cldnn_network network, cldnn_event* dependencies, size_t deps_num, cldnn_status* status);
742
743 /// @brief Returns executed network output information.
744 /// @details User should call this function after cldnn_execute_network() to get result of network execution.
745 /// @param name Output name to get the result.
746 /// @returns @ref cldnn_network_output structure with the output information.
747 /// To work with the result of this function, user should first wait for cldnn_network_output::event
748 /// before getting an access to cldnn_network_output::memory.
749 CLDNN_API cldnn_network_output cldnn_get_network_output(cldnn_network network, const char* name, cldnn_status* status);
750
751 /// @brief Returns @ref memory corresponding to output with @p name.
752 /// @details User can call this function even before calling cldnn_execute_network(), but then content of memory is uninitialized.
753 /// @param name Output name to get the result.
754 /// @returns @ref cldnn_memory structure with the output information.
755 CLDNN_API cldnn_memory cldnn_get_network_output_memory(cldnn_network network, const char* name, cldnn_status* status);
756
757 /// @brief Returns @ref event corresponding to output with @p name.
758 /// @details User can call this function even before calling cldnn_execute_network(), but then content of memory is uninitialized.
759 /// @param name Output name to get the result.
760 /// @returns @ref cldnn_event structure with the output information.
761 CLDNN_API cldnn_event cldnn_get_network_output_event(cldnn_network network, const char* name, cldnn_status* status);
762 /// @}
763
764 /// @addtogroup c_memory
765 /// @{
766
767 /// @brief Allocate memory on @p engine using specified @p layout.
768 CLDNN_API cldnn_memory cldnn_allocate_memory(cldnn_engine engine, cldnn_layout layout, cldnn_status* status);
769 /// @brief Create memory object attached to the buffer allocated by user.
770 /// @note User is responsible for buffer deallocation. Buffer lifetime should be bigger than lifetime of the memory object.
771 CLDNN_API cldnn_memory cldnn_attach_memory(cldnn_layout layout, void* pointer, size_t size, cldnn_status* status);
772 /// @brief Checks if two memory objects refer to the same underlaying buffer.
773 CLDNN_API int32_t cldnn_is_the_same_buffer(cldnn_memory mem1, cldnn_memory mem2, cldnn_status* status);
774 /// @brief Increment reference counter for the memory object.
775 CLDNN_API void cldnn_retain_memory(cldnn_memory memory, cldnn_status* status);
776 /// @brief Decrement reference counter for the memory object. Deletes object when counter becomes zero.
777 CLDNN_API void cldnn_release_memory(cldnn_memory memory, cldnn_status* status);
778 /// @brief Locks memory buffer. Provides direct access to memory data.
779 /// @returns Direct pointer to the memory data.
780 CLDNN_API void* cldnn_lock_memory(cldnn_memory memory, cldnn_status* status);
781 /// @brief Unlocks memory locked by cldnn_lock_memory(cldnn_memory memory, cldnn_status* status).
782 CLDNN_API void cldnn_unlock_memory(cldnn_memory memory, cldnn_status* status);
783 /// @brief Returns memory layout
784 /// @returns @ref cldnn_layout which describes memory.
785 CLDNN_API cldnn_layout cldnn_get_memory_layout(cldnn_memory memory, cldnn_status* status);
786 /// @brief Returns reference to the engine associated with memory object.
787 /// @returns The engine associated with memory object. Or NULL if memory was attached to user-allocated buffer.
788 CLDNN_API cldnn_engine cldnn_get_memory_engine(cldnn_memory memory, cldnn_status* status);
789 /// @brief converts float(32 bit) to half_t(fp16 bit)
790 /// @returns 16bit half_t
791 CLDNN_API uint16_t cldnn_float_to_half(float,cldnn_status*);
792 /// @brief converts  half_t(f16 bit) to float(32 bit) 
793 /// @returns 32bit float
794 CLDNN_API float cldnn_half_to_float(uint16_t, cldnn_status*);
795
796 /// @}
797
798 /// @addtogroup c_error
799 /// @{
800
801 /// @brief If cldnn function returns status different than CLDNN_SUCCESS, user call this function to get more details.
802 /// @returns pointer to array of chars with more detailed description of last error.
803 /// @note If sequence of error occure, description of only last error will avaiable
804 CLDNN_API const char* cldnn_get_last_error_message();
805 /// @}
806
807 #ifdef __cplusplus
808 }
809 #endif
810
811 /// @}
812
813 //primitives
814 #ifdef __cplusplus
815 #define CLDNN_DECLARE_PRIMITIVE_TYPE_ID(PType) extern "C" CLDNN_API cldnn_primitive_type_id cldnn_##PType##_type_id(cldnn_status* status)
816 #else
817 #define CLDNN_DECLARE_PRIMITIVE_TYPE_ID(PType) CLDNN_API cldnn_primitive_type_id cldnn_##PType##_type_id(cldnn_status* status)
818 #endif
819
820
821 #endif /* CLDNN_H */