2 // Copyright (c) 2016-2018 Intel Corporation
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
17 ///////////////////////////////////////////////////////////////////////////////////////////////////
21 // exporting symbols form dynamic library
22 #ifdef EXPORT_NEURAL_SYMBOLS
23 # if defined(_MSC_VER)
25 # define CLDNN_API __declspec(dllexport)
26 # elif defined(__GNUC__)
28 # define CLDNN_API __attribute__((visibility("default")))
31 # pragma warning Unknown dynamic link import/export semantics.
34 # if defined(_MSC_VER)
36 # define CLDNN_API __declspec(dllimport)
37 # elif defined(__GNUC__)
42 # pragma warning Unknown dynamic link import/export semantics.
49 /// @addtogroup c_api C API
52 /// @defgroup c_memory Memory Management
54 /// @defgroup c_topology Network Topology
56 /// @defgroup c_engine Execution Engine
58 /// @defgroup c_network Network Execution
60 /// @defgroup c_error Error Handling
62 /// @defgroup c_version Version Information
68 /// @addtogroup c_error
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
81 /// @brief Represents errors status for all API calls
82 typedef int32_t cldnn_status;
85 /// @addtogroup c_version
87 /// @brief Represents version information of API.
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).
98 /// @brief Engine object
99 typedef struct cldnn_engine_impl* cldnn_engine;
101 /// @ingroup c_network
102 /// @brief Event object
103 typedef struct cldnn_event_impl* cldnn_event;
105 /// @ingroup c_topology
106 /// @brief Network topology to be defined by user
107 typedef struct cldnn_topology_impl* cldnn_topology;
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;
113 /// @ingroup c_network
114 /// @brief Executable network allocated from @ref cldnn_program
115 typedef struct cldnn_network_impl* cldnn_network;
117 /// @ingroup c_memory
118 /// @brief Memory object
119 typedef struct cldnn_memory_impl* cldnn_memory;
121 /// @addtogroup c_engine
124 /// @brief Defines available engine types
125 typedef enum /*:int32_t*/
127 cldnn_engine_ocl ///< OpenCL engine
130 /// @brief Priority modes.
131 typedef enum /*:int16_t*/
133 cldnn_priority_disabled,
137 } cldnn_priority_mode_type;
139 /// @brief Throttle modes.
140 typedef enum /*:int16_t*/
142 cldnn_throttle_disabled,
146 } cldnn_throttle_mode_type;
148 /// @brief Configuration parameters for created engine.
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.
163 const char* tuning_cache_path; ///< Enables defining other than default path to tuning cache json
164 } cldnn_engine_configuration;
166 /// @brief Information about the engine returned by cldnn_get_engine_info().
169 uint32_t cores_count; ///< Number of available HW cores.
170 uint32_t core_frequency; ///< Clock frequency in MHz.
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.
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.
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).
186 uint8_t supports_imad; ///< Does engine support int8 mad.
187 uint8_t supports_immad; ///< Does engine support int8 multi mad.
191 /// @addtogroup c_network
194 /// @brief user-defined event handler callback.
195 typedef void(*cldnn_event_handler)(void*);
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.
202 const char* name; ///< Profiling interval name.
203 uint64_t nanoseconds;
204 } cldnn_profiling_interval;
206 /// @brief Network build option types.
207 typedef enum /*:int32_t*/
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;
221 /// @brief Tuning modes.
222 typedef enum /*:int32_t*/
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;
229 /// @brief Tuning config.
230 struct cldnn_tuning_config
232 const int32_t mode; ///< #cldnn_tuning_mode_type.
233 const char* cache_file_path; ///< A path to the tuning cache file.
236 /// @brief Learning params.
237 struct cldnn_learning_params
239 const float momentum;
240 const float weights_decay;
243 /// @brief Represents network build option.
246 int32_t type; ///< #cldnn_build_option_type.
247 const void* data; ///< option parameter - e.g list of outputs.
248 } cldnn_build_option;
250 /// @brief Output information for executed @a cldnn_network.
251 /// @details User should wait for event before accessing the memory.
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;
261 /// @addtogroup c_memory
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
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*/
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
316 #define CLDNN_FLOAT_TYPE_MASK 0x80
317 #define CLDNN_UINT_TYPE_MASK 0x40
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
325 /// @brief N-dimensional vector. Mostly used to represent memory size.
332 int32_t sizes[CLDNN_TENSOR_DIM_MAX];
335 /// @brief Padding information.
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
345 /// @brief Data type stored in memory.
346 typedef enum /*:size_t*/
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)
357 /// @brief Memory layout description.
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.
367 /// @addtogroup c_topology
370 /// @brief Represents reference to an array of floats.
373 const float* data; ///< Pointer to float array.
374 size_t size; ///< Size (in floats) of the array.
377 /// @brief Represents reference to an array of uint16_t.
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;
384 /// @brief Represents reference to an array of uint8_t.
387 const uint8_t* data; ///< Pointer to uint8_t array.
388 size_t size; ///< Size (in uint8_t) of the array.
391 /// @brief Represents reference to an array of tensor.
394 const cldnn_tensor* data; ///< Pointer to tensor array.
395 size_t size; ///< Size (in tensor) of the array.
398 /// @brief Globally unique primitive's type id
399 typedef const struct cldnn_primitive_type* cldnn_primitive_type_id;
401 /// @brief Unique @p id of a primitive within a topology.
402 typedef const char* cldnn_primitive_id;
404 /// @brief Represents reference to an array of primitive ids.
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;
413 cldnn_data_type data_type;
414 // No bool type available...
416 } cldnn_optional_data_type;
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;
429 /// @brief Custom primitive kernel argument type
430 typedef enum cldnn_arg_type_t
436 /// @brief Custom primitive kernel argument index
437 typedef uint32_t cldnn_arg_index;
439 /// @brief Custom primitive kernel argument type
440 typedef struct cldnn_arg_t
442 cldnn_arg_type arg_type;
443 cldnn_arg_index index;
446 /// @brief Custom primitive kernel argument array
447 typedef const cldnn_arg* cldnn_kernel_arguments;
449 /// @brief activation functions
450 typedef enum cldnn_activation_func_t
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;
476 /// @brief activation gradient functions
477 typedef enum cldnn_activation_grad_func_t
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;
484 /// @brief activation additional params
485 typedef struct cldnn_activation_additional_params_t
488 } cldnn_activation_additional_params;
490 /// @brief Axis which index_select primitive will index.
491 typedef enum index_select_axis_name_t
497 } index_select_axis_name;
499 /// @brief Axis which index_select primitive will index array
500 typedef const index_select_axis_name* index_select_axis_name_arr;
502 /// @brief reorder mean operation modes
503 typedef enum cldnn_reorder_mean_mode_t
506 mean_subtract, // val - mean
507 mean_mul, // val * mean
508 mean_div, // val/mean
509 } cldnn_reorder_mean_mode;
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. */
522 /// @brief Close primitive descriptor definition.
523 #define CLDNN_END_PRIMITIVE_DESC(PType) };
525 #define CLDNN_PRIMITIVE_DESC(PType) cldnn_##PType##_desc
527 /// @brief Basic primitive descriptor structure.
528 CLDNN_BEGIN_PRIMITIVE_DESC(primitive)
529 CLDNN_END_PRIMITIVE_DESC(primitive)
533 /// @addtogroup c_version
535 /// @brief Get information about version of clDNN.
536 CLDNN_API cldnn_version cldnn_get_version(cldnn_status* status);
539 /// @addtogroup c_topology
542 /// @brief Create empty network topology
543 CLDNN_API cldnn_topology cldnn_create_topology(cldnn_status* status);
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);
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);
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);
561 /// @brief Increment reference counter for the topology object.
562 CLDNN_API void cldnn_retain_topology(cldnn_topology topology, cldnn_status* status);
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);
568 /// @addtogroup c_engine
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);
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);
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);
586 /// @brief Increment reference counter for the engine object.
587 CLDNN_API void cldnn_retain_engine(cldnn_engine engine, cldnn_status* status);
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);
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);
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);
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);
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);
605 /// @addtogroup c_network
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);
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);
614 /// @brief Increment reference counter for the event object.
615 CLDNN_API void cldnn_retain_event(cldnn_event event, cldnn_status* status);
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);
620 /// @brief Waits for event completion or error.
621 CLDNN_API void cldnn_wait_for_event(cldnn_event event, cldnn_status* status);
623 /// @brief Set event status to @p completed.
624 CLDNN_API void cldnn_set_event(cldnn_event event, cldnn_status* status);
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);
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);
638 /// @addtogroup c_program
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);
648 /// @brief Increment reference counter for the program object.
649 CLDNN_API void cldnn_retain_program(cldnn_program program, cldnn_status* status);
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);
655 /// @addtogroup c_network
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);
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);
669 /// @brief Increment reference counter for the network object.
670 CLDNN_API void cldnn_retain_network(cldnn_network network, cldnn_status* status);
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);
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);
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);
686 /// @brief Returns learning rate value.
687 CLDNN_API float cldnn_get_learning_rate(cldnn_network network, cldnn_status* status);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
764 /// @addtogroup c_memory
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*);
798 /// @addtogroup c_error
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();
815 #define CLDNN_DECLARE_PRIMITIVE_TYPE_ID(PType) extern "C" CLDNN_API cldnn_primitive_type_id cldnn_##PType##_type_id(cldnn_status* status)
817 #define CLDNN_DECLARE_PRIMITIVE_TYPE_ID(PType) CLDNN_API cldnn_primitive_type_id cldnn_##PType##_type_id(cldnn_status* status)