2 // Copyright (c) 2016-2019 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 ///////////////////////////////////////////////////////////////////////////////////////////////////
18 #include "api/C/cldnn.h"
20 #include "engine_impl.h"
21 #include "topology_impl.h"
22 #include "program_impl.h"
23 #include "primitive_type.h"
24 #include "network_impl.h"
25 #include "memory_impl.h"
26 #include "primitive_inst.h"
29 last_err& last_err::instance()
31 thread_local static last_err _instance;
36 #define SHOULD_NOT_BE_NULL(arg, msg_prefix) \
38 throw std::invalid_argument( std::string(msg_prefix) + " should not be null.");
39 #define SHOULD_NOT_EQUAL_0(arg, msg_prefix) \
41 throw std::invalid_argument( std::string(msg_prefix) + " should not equals 0.");
46 #ifndef CLDNN_VERSION_MAJOR
47 #define CLDNN_VERSION_MAJOR (0)
50 #ifndef CLDNN_VERSION_MINOR
51 #define CLDNN_VERSION_MINOR (0)
54 #ifndef CLDNN_VERSION_BUILD
55 #define CLDNN_VERSION_BUILD (0)
58 #ifndef CLDNN_VERSION_REVISION
59 #define CLDNN_VERSION_REVISION (0)
62 cldnn_version cldnn_get_version(cldnn_status* status)
64 return exception_handler<cldnn_version>(CLDNN_ERROR, status, {}, []() -> cldnn_version
66 return { CLDNN_VERSION_MAJOR, CLDNN_VERSION_MINOR, CLDNN_VERSION_BUILD, CLDNN_VERSION_REVISION };
71 cldnn_topology cldnn_create_topology(cldnn_status* status)
73 return exception_handler<cldnn_topology>(CLDNN_ERROR, status, nullptr, [&]()
75 return api_cast(new cldnn::topology_impl());
79 void cldnn_add_primitive(cldnn_topology topology, const CLDNN_PRIMITIVE_DESC(primitive)* dto, cldnn_status* status)
81 return exception_handler(CLDNN_ERROR, status, [&]()
83 SHOULD_NOT_BE_NULL(topology, "Topology");
84 SHOULD_NOT_BE_NULL(dto, "Primitive");
85 SHOULD_NOT_BE_NULL(dto->id, "Primitive id");
86 SHOULD_NOT_BE_NULL(dto->type, "Primitive type");
87 api_cast(topology)->add(dto->type->from_dto(dto));
91 void cldnn_change_input_layout(cldnn_topology topology, cldnn_primitive_id id, cldnn_layout new_layout, cldnn_status* status)
93 return exception_handler(CLDNN_ERROR, status, [&]()
95 SHOULD_NOT_BE_NULL(topology, "Topology");
96 SHOULD_NOT_BE_NULL(id, "Input layout id");
97 if (new_layout.format < cldnn_format_any || new_layout.format >= cldnn_format_format_num)
98 throw std::invalid_argument("Unknown format of layout.");
99 if (new_layout.data_type != cldnn_data_type::cldnn_f16 &&
100 new_layout.data_type != cldnn_data_type::cldnn_f32 &&
101 new_layout.data_type != cldnn_data_type::cldnn_i8 &&
102 new_layout.data_type != cldnn_data_type::cldnn_u8 &&
103 new_layout.data_type != cldnn_data_type::cldnn_i32 &&
104 new_layout.data_type != cldnn_data_type::cldnn_i64)
105 throw std::invalid_argument("Unknown data_type of layout.");
106 api_cast(topology)->change_input_layout(id, new_layout);
110 static void primitive_id_vector_to_char_array(
114 cldnn_status* status,
115 const std::vector<primitive_id>& vec)
117 *size_ret = std::accumulate(
120 size_t(1), // final zero symbol
121 [](size_t acc, const cldnn::primitive_id& id)
123 return acc + id.size() + 1; // plus zero symbol
126 if (size < *size_ret)
128 if (status) *status = CLDNN_INVALID_ARG;
135 // workaround for Microsoft VC++
137 #pragma warning(push)
138 #pragma warning(disable: 4996)
140 i += id.copy(names + i, size - i - 2);
144 names[i++] = 0; // plus zero symbol
147 names[i] = 0; // final zero symbol
150 void cldnn_get_primitive_ids(cldnn_topology topology, char* ids, size_t size, size_t* size_ret, cldnn_status* status)
152 return exception_handler(CLDNN_ERROR, status, [&]()
154 SHOULD_NOT_BE_NULL(topology, "Topology");
155 auto ids_size = api_cast(topology)->get_primitives().size();
156 SHOULD_NOT_EQUAL_0(ids_size, "Primitives number");
157 auto&& primitives_ids = api_cast(topology)->get_primitives_id();
158 primitive_id_vector_to_char_array(ids, size, size_ret, status, primitives_ids);
162 void cldnn_retain_topology(cldnn_topology topology, cldnn_status* status)
164 return exception_handler(CLDNN_ERROR, status, [&]()
166 SHOULD_NOT_BE_NULL(topology, "Topology");
167 api_cast(topology)->add_ref();
170 void cldnn_release_topology(cldnn_topology topology, cldnn_status* status)
172 return exception_handler(CLDNN_ERROR, status, [&]()
174 SHOULD_NOT_BE_NULL(topology, "Topology");
175 api_cast(topology)->release();
179 uint32_t cldnn_get_engine_count(/*cldnn_engine_type*/ int32_t type, cldnn_status* status)
181 if (type == cldnn_engine_type::cldnn_engine_ocl)
183 if (status) *status = CLDNN_SUCCESS;
188 if (status) *status = CLDNN_DEVICE_ERROR;
193 void cldnn_release_pending_memory(cldnn_engine engine, cldnn_status* status)
195 return exception_handler(CLDNN_ERROR, status, [&]()
197 SHOULD_NOT_BE_NULL(engine, "engine");
198 api_cast(engine)->release_pending_memory();
202 cldnn_engine cldnn_create_engine(/*cldnn_engine_type*/ int32_t type, uint32_t engine_num, const cldnn_engine_configuration* configuration, cldnn_status* status)
204 if (engine_num > 0 || (type != cldnn_engine_type::cldnn_engine_ocl))
207 *status = CLDNN_DEVICE_ERROR;
211 return exception_handler<cldnn_engine>(CLDNN_ERROR, status, nullptr, [&]()
213 return api_cast(new cldnn::engine_impl(configuration ? cldnn::engine_configuration(*configuration) : cldnn::engine_configuration()));
217 void cldnn_retain_engine(cldnn_engine engine, cldnn_status* status)
219 exception_handler(CLDNN_ERROR, status, [&]()
221 SHOULD_NOT_BE_NULL(engine, "Engine");
222 api_cast(engine)->add_ref();
226 void cldnn_release_engine(cldnn_engine engine, cldnn_status* status)
228 exception_handler(CLDNN_ERROR, status, [&]()
230 SHOULD_NOT_BE_NULL(engine, "Engine");
231 api_cast(engine)->release();
235 cldnn_engine_info cldnn_get_engine_info(cldnn_engine engine, cldnn_status* status)
237 return exception_handler<cldnn_engine_info>(CLDNN_ERROR, status, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, [&]() -> cldnn_engine_info
239 SHOULD_NOT_BE_NULL(engine, "Engine");
240 auto info = api_cast(engine)->get_engine_info();
245 info.max_work_group_size,
246 info.max_local_mem_size,
247 info.max_global_mem_size,
248 info.max_alloc_mem_size,
249 info.max_image2d_width,
250 info.max_image2d_height,
252 info.supports_fp16_denorms,
253 info.supports_subgroups_short,
259 /*cldnn_engine_type*/ int32_t cldnn_get_engine_type(cldnn_engine engine, cldnn_status* status)
261 return exception_handler<int32_t>(CLDNN_ERROR, status, cldnn_engine_ocl, [&]()
263 SHOULD_NOT_BE_NULL(engine, "Engine");
264 return static_cast<int32_t>(api_cast(engine)->type());
268 int64_t cldnn_get_max_used_device_memory_size(cldnn_engine engine, cldnn_status* status)
270 return exception_handler<int32_t>(CLDNN_ERROR, status, cldnn_engine_ocl, [&]()
272 SHOULD_NOT_BE_NULL(engine, "Engine");
273 return static_cast<int32_t>(api_cast(engine)->get_max_used_device_memory());
277 int64_t cldnn_get_temp_used_device_memory_size(cldnn_engine engine, cldnn_status* status)
279 return exception_handler<int32_t>(CLDNN_ERROR, status, cldnn_engine_ocl, [&]()
281 SHOULD_NOT_BE_NULL(engine, "Engine");
282 return static_cast<int32_t>(api_cast(engine)->get_used_device_memory());
286 cldnn_event cldnn_create_user_event(cldnn_engine engine, cldnn_status* status)
288 return exception_handler<cldnn_event>(CLDNN_ERROR, status, nullptr, [&]()
290 SHOULD_NOT_BE_NULL(engine, "Engine");
291 event_impl* e = api_cast(engine)->create_user_event().detach();
296 CLDNN_API int32_t cldnn_is_user_event(cldnn_event event, cldnn_status * status)
298 return exception_handler<int32_t>(CLDNN_ERROR, status, 0, [&]()
300 SHOULD_NOT_BE_NULL(event, "Event");
301 auto user_ev = dynamic_cast<user_event*>(api_cast(event));
302 return (user_ev != nullptr);
306 void cldnn_retain_event(cldnn_event event, cldnn_status* status)
309 exception_handler(CLDNN_ERROR, status, [&]()
311 SHOULD_NOT_BE_NULL(event, "Event");
312 api_cast(event)->add_ref();
316 void cldnn_release_event(cldnn_event event, cldnn_status* status)
318 exception_handler(CLDNN_ERROR, status, [&]()
320 SHOULD_NOT_BE_NULL(event, "Event");
321 api_cast(event)->release();
325 void cldnn_wait_for_event(cldnn_event event, cldnn_status* status)
327 exception_handler(CLDNN_ERROR, status, [&]()
329 SHOULD_NOT_BE_NULL(event, "Event");
330 api_cast(event)->wait();
334 void cldnn_set_event(cldnn_event event, cldnn_status* status)
336 exception_handler(CLDNN_ERROR, status, [&]()
338 SHOULD_NOT_BE_NULL(event, "Event");
339 if (auto user_ev = dynamic_cast<user_event*>(api_cast(event)))
342 throw std::invalid_argument("Event passed to cldnn_set_event should be an user event");
346 void cldnn_add_event_handler(cldnn_event event, cldnn_event_handler handler, void* param, cldnn_status* status)
348 exception_handler(CLDNN_ERROR, status, [&]()
350 SHOULD_NOT_BE_NULL(handler, "Handler");
351 SHOULD_NOT_BE_NULL(event, "Event");
352 api_cast(event)->add_event_handler(handler, param);
356 void cldnn_get_event_profiling_info(cldnn_event event, cldnn_profiling_interval* profiling, size_t size, size_t* size_ret, cldnn_status* status)
358 exception_handler(CLDNN_ERROR, status, [&]()
360 SHOULD_NOT_BE_NULL(event, "Event");
361 if (!profiling && !size_ret)
363 if (status) *status = CLDNN_INVALID_ARG;
366 auto& profiling_info = api_cast(event)->get_profiling_info();
368 *size_ret = profiling_info.size();
369 if(profiling != nullptr)
371 if (size != profiling_info.size())
373 if (status) *status = CLDNN_INVALID_ARG;
377 for (auto& info : profiling_info)
379 profiling[i].name = info.name;
380 profiling[i].nanoseconds = info.nanoseconds;
387 cldnn_program cldnn_build_program(cldnn_engine engine, cldnn_topology topology, cldnn_build_option* options, size_t options_num, cldnn_status* status)
389 return exception_handler<cldnn_program>(CLDNN_ERROR, status, nullptr, [&]()
391 SHOULD_NOT_BE_NULL(engine, "Engine");
392 SHOULD_NOT_BE_NULL(topology, "Topology");
393 cldnn::build_options options_obj(cldnn::array_ref<cldnn_build_option>(options, options_num));
395 cldnn::program_impl* prog = api_cast(engine)->build_program(*api_cast(topology), options_obj).detach();
396 return api_cast(prog);
400 void cldnn_retain_program(cldnn_program program, cldnn_status* status)
402 exception_handler(CLDNN_ERROR, status, [&]()
404 SHOULD_NOT_BE_NULL(program, "Program");
405 api_cast(program)->add_ref();
409 void cldnn_release_program(cldnn_program program, cldnn_status* status)
411 exception_handler(CLDNN_ERROR, status, [&]()
413 SHOULD_NOT_BE_NULL(program, "Program");
414 api_cast(program)->release();
418 cldnn_network cldnn_allocate_network(cldnn_program program, cldnn_status* status)
420 return exception_handler<cldnn_network>(CLDNN_ERROR, status, nullptr, [&]()
422 SHOULD_NOT_BE_NULL(program, "Program");
423 network_impl* p = api_cast(program)->get_engine().allocate_network(*api_cast(program)).detach();
428 cldnn_network cldnn_build_network(cldnn_engine engine, cldnn_topology topology, cldnn_build_option* options, size_t options_num, cldnn_status* status)
430 cldnn_program program = cldnn_build_program(engine, topology, options, options_num, status);
434 cldnn_network network = cldnn_allocate_network(program, status);
435 cldnn_release_program(program, nullptr);
438 void cldnn_retain_network(cldnn_network network, cldnn_status* status)
440 exception_handler(CLDNN_ERROR, status, [&]()
442 SHOULD_NOT_BE_NULL(network, "Network");
443 api_cast(network)->add_ref();
447 void cldnn_release_network(cldnn_network network, cldnn_status* status)
449 exception_handler(CLDNN_ERROR, status, [&]()
451 SHOULD_NOT_BE_NULL(network, "Network");
452 api_cast(network)->release();
456 void cldnn_set_network_input(cldnn_network network, cldnn_primitive_id id, cldnn_memory mem, cldnn_status* status)
458 exception_handler(CLDNN_ERROR, status, [&]()
460 SHOULD_NOT_BE_NULL(mem, "Mem");
461 auto mem_size = api_cast(mem)->size();
462 SHOULD_NOT_BE_NULL(network, "Network");
463 SHOULD_NOT_BE_NULL(id, "Id");
464 SHOULD_NOT_EQUAL_0(mem_size, "Memory size");
465 api_cast(network)->set_input_data(id, *api_cast(mem));
469 void cldnn_set_learning_rate(cldnn_network network, float lr, cldnn_status* status)
471 exception_handler(CLDNN_ERROR, status, [&]()
473 api_cast(network)->set_learning_rate(lr);
477 float cldnn_get_learning_rate(cldnn_network network, cldnn_status* status)
479 return exception_handler<float>(CLDNN_ERROR, status, 0, [&]()
481 return api_cast(network)->get_learning_rate();
485 cldnn_engine cldnn_get_network_engine(cldnn_network network, cldnn_status* status)
487 return exception_handler<cldnn_engine>(CLDNN_ERROR, status, nullptr, [&]()
489 SHOULD_NOT_BE_NULL(network, "Network");
490 refcounted_obj_ptr<cldnn::engine_impl> ptr{&api_cast(network)->get_engine()};
491 return api_cast(ptr.detach());
495 cldnn_program cldnn_get_network_program(cldnn_network network, cldnn_status* status)
497 return exception_handler<cldnn_program>(CLDNN_ERROR, status, nullptr, [&]()
499 SHOULD_NOT_BE_NULL(network, "Network");
500 refcounted_obj_ptr<cldnn::program_impl> ptr{const_cast<cldnn::program_impl*>(&api_cast(network)->get_program())};
501 return api_cast(ptr.detach());
505 void cldnn_get_primitive_info(cldnn_network network, cldnn_primitive_id prim_id, char* info, size_t size, size_t* size_ret, cldnn_status* status)
507 return exception_handler(CLDNN_ERROR, status, [&]()
509 SHOULD_NOT_BE_NULL(network, "Network");
510 const auto& prim_info = api_cast(network)->get_primitive_info(prim_id);
511 *size_ret = prim_info.size()+1;
513 if (size < *size_ret)
515 if (status) *status = CLDNN_INVALID_ARG;
520 for (const auto c : prim_info)
525 info[i] = 0; // final zero symbol
529 void cldnn_get_network_output_names(cldnn_network network, char* names, size_t size, size_t* size_ret, cldnn_status* status)
531 exception_handler(CLDNN_ERROR, status, [&]()
533 SHOULD_NOT_BE_NULL(network, "Network");
534 auto&& output_ids = api_cast(network)->get_output_ids();
535 SHOULD_NOT_EQUAL_0(output_ids.size(), "Output size");
536 primitive_id_vector_to_char_array(names, size, size_ret, status, output_ids);
540 void cldnn_get_network_executed_primitive_names(cldnn_network network, char* names, size_t size, size_t* size_ret, cldnn_status* status)
542 exception_handler(CLDNN_ERROR, status, [&]()
544 SHOULD_NOT_BE_NULL(network, "Network");
545 auto&& primitive_ids = api_cast(network)->get_executed_primitive_ids();
546 SHOULD_NOT_EQUAL_0(primitive_ids.size(), "Primitives size");
547 primitive_id_vector_to_char_array(names, size, size_ret, status, primitive_ids);
551 void cldnn_get_network_all_primitive_names(cldnn_network network, char* names, size_t size, size_t* size_ret, cldnn_status* status)
553 exception_handler(CLDNN_ERROR, status, [&]()
555 SHOULD_NOT_BE_NULL(network, "Network");
556 auto&& primitive_ids = api_cast(network)->get_all_primitive_ids();
557 SHOULD_NOT_EQUAL_0(primitive_ids.size(), "Primitives size");
558 primitive_id_vector_to_char_array(names, size, size_ret, status, primitive_ids);
562 void cldnn_get_network_all_primitive_org_names(cldnn_network network, char* names, size_t size, size_t* size_ret, cldnn_status* status)
564 exception_handler(CLDNN_ERROR, status, [&]()
566 SHOULD_NOT_BE_NULL(network, "Network");
567 auto&& primitive_ids = api_cast(network)->get_all_primitive_org_ids();
568 SHOULD_NOT_EQUAL_0(primitive_ids.size(), "Primitives size");
569 primitive_id_vector_to_char_array(names, size, size_ret, status, primitive_ids);
573 void cldnn_execute_network(cldnn_network network, cldnn_event* dependencies, size_t deps_num, cldnn_status* status)
575 exception_handler(CLDNN_ERROR, status, [&]()
577 SHOULD_NOT_BE_NULL(network, "Network");
578 std::vector<cldnn::refcounted_obj_ptr<cldnn::event_impl>> deps;
579 deps.reserve(deps_num);
580 for(size_t i = 0; i < deps_num; i++)
582 deps.emplace_back(api_cast(dependencies[i]));
585 api_cast(network)->execute(deps);
589 cldnn_network_output cldnn_get_network_output(cldnn_network network, const char* name, cldnn_status* status)
591 cldnn_network_output error_result = { nullptr, nullptr };
592 return exception_handler<cldnn_network_output>(CLDNN_ERROR, status, error_result, [&]() -> cldnn_network_output
594 SHOULD_NOT_BE_NULL(network, "Network");
595 SHOULD_NOT_BE_NULL(name, "ID of primitive");
596 cldnn::primitive_id id(name);
597 auto event = api_cast(network)->get_primitive_event(id);
598 auto& mem_result = api_cast(network)->get_primitive(id)->output_memory();
599 refcounted_obj_ptr<cldnn::memory_impl> mem_ptr{&mem_result};
601 api_cast(event.detach()),
602 api_cast(mem_ptr.detach())
607 cldnn_memory cldnn_get_network_output_memory(cldnn_network network, const char* name, cldnn_status* status)
609 cldnn_memory error_result = nullptr;
610 return exception_handler<cldnn_memory>(CLDNN_ERROR, status, error_result, [&]() -> cldnn_memory
612 SHOULD_NOT_BE_NULL(network, "Network");
613 SHOULD_NOT_BE_NULL(name, "ID of primitive");
614 cldnn::primitive_id id(name);
615 auto& mem_result = api_cast(network)->get_primitive(id)->output_memory();
616 refcounted_obj_ptr<cldnn::memory_impl> mem_ptr{&mem_result};
617 return api_cast(mem_ptr.detach());
621 cldnn_event cldnn_get_network_output_event(cldnn_network network, const char* name, cldnn_status* status)
623 cldnn_event error_result = nullptr;
624 return exception_handler<cldnn_event>(CLDNN_ERROR, status, error_result, [&]() -> cldnn_event
626 SHOULD_NOT_BE_NULL(network, "Network");
627 SHOULD_NOT_BE_NULL(name, "ID of primitive");
628 cldnn::primitive_id id(name);
629 auto event = api_cast(network)->get_primitive_event(id);
630 return api_cast(event.detach());
634 cldnn_memory cldnn_allocate_memory(cldnn_engine engine, cldnn_layout layout, cldnn_status* status)
636 return exception_handler<cldnn_memory>(CLDNN_ERROR, status, nullptr, [&]()
638 SHOULD_NOT_BE_NULL(engine, "Engine");
639 if (layout.format < cldnn_format_any || layout.format >= cldnn_format_format_num)
640 throw std::invalid_argument("Unknown format of layout.");
641 if (layout.data_type != cldnn_data_type::cldnn_f16 &&
642 layout.data_type != cldnn_data_type::cldnn_f32 &&
643 layout.data_type != cldnn_data_type::cldnn_i8 &&
644 layout.data_type != cldnn_data_type::cldnn_u8 &&
645 layout.data_type != cldnn_data_type::cldnn_i32 &&
646 layout.data_type != cldnn_data_type::cldnn_i64)
647 throw std::invalid_argument("Unknown data_type of layout.");
649 cldnn::memory_impl* mem_ptr = api_cast(engine)->allocate_memory(layout).detach();
650 return api_cast(mem_ptr);
654 cldnn_memory cldnn_attach_memory(cldnn_layout layout, void* pointer, size_t size, cldnn_status* status)
656 return exception_handler<cldnn_memory>(CLDNN_ERROR, status, nullptr, [&]()
658 cldnn::layout layout_obj(layout);
659 if (layout_obj.bytes_count() > size)
660 throw std::invalid_argument("buffer size does not match layout size");
661 return api_cast(new cldnn::simple_attached_memory(layout_obj, pointer));
665 CLDNN_API int32_t cldnn_is_the_same_buffer(cldnn_memory mem1, cldnn_memory mem2, cldnn_status* status)
667 return static_cast<int32_t>(exception_handler<bool>(CLDNN_ERROR, status, false, [&]()
669 SHOULD_NOT_BE_NULL(mem1, "Memory");
670 SHOULD_NOT_BE_NULL(mem2, "Memory");
675 if (api_cast(mem1)->get_engine() != api_cast(mem2)->get_engine())
678 //memories were allocated by the user so just check if pointers match
679 if (!api_cast(mem1)->get_engine())
680 return api_cast(mem1)->lock() == api_cast(mem2)->lock();
682 //memories were allocated by the engine so let it decide whether they refer to the same buffer
683 return api_cast(mem1)->get_engine()->is_the_same_buffer(*api_cast(mem1), *api_cast(mem2));
687 void cldnn_retain_memory(cldnn_memory memory, cldnn_status* status)
689 exception_handler(CLDNN_ERROR, status, [&]()
691 SHOULD_NOT_BE_NULL(memory, "Memory");
692 api_cast(memory)->add_ref();
696 void cldnn_release_memory(cldnn_memory memory, cldnn_status* status)
698 exception_handler(CLDNN_ERROR, status, [&]()
700 SHOULD_NOT_BE_NULL(memory, "Memory");
701 api_cast(memory)->release();
705 void* cldnn_lock_memory(cldnn_memory memory, cldnn_status* status)
707 return exception_handler<void*>(CLDNN_ERROR, status, nullptr, [&]()
709 SHOULD_NOT_BE_NULL(memory, "Memory");
710 return api_cast(memory)->lock();
714 void cldnn_unlock_memory(cldnn_memory memory, cldnn_status* status)
716 exception_handler(CLDNN_ERROR, status, [&]()
718 SHOULD_NOT_BE_NULL(memory, "Memory");
719 api_cast(memory)->unlock();
723 cldnn_layout cldnn_get_memory_layout(cldnn_memory memory, cldnn_status* status)
725 cldnn_layout error_result = cldnn::layout(cldnn::data_types::f32, cldnn::format::bfyx, {0, 0, 0, 0});
727 return exception_handler<cldnn_layout>(CLDNN_ERROR, status, error_result, [&]()
729 SHOULD_NOT_BE_NULL(memory, "Memory");
730 auto memory_size = api_cast(memory)->size();
731 SHOULD_NOT_EQUAL_0(memory_size, "Memory size");
732 return api_cast(memory)->get_layout();
736 cldnn_engine cldnn_get_memory_engine(cldnn_memory memory, cldnn_status* status)
738 return exception_handler<cldnn_engine>(CLDNN_ERROR, status, nullptr, [&]()
740 SHOULD_NOT_BE_NULL(memory, "Memory");
741 auto engine = api_cast(memory)->get_engine();
742 return api_cast(engine.detach());
746 const char* cldnn_get_last_error_message()
749 return cldnn::last_err::instance().get_last_error_message().c_str();
753 return "Reading error message failed.";
758 CLDNN_API uint16_t cldnn_float_to_half(float value, cldnn_status* status)
760 return exception_handler<uint16_t>(CLDNN_ERROR, status, 0, [&]()
762 return cldnn::float_to_half(value);
766 CLDNN_API float cldnn_half_to_float(uint16_t value, cldnn_status* status)
768 return exception_handler<float>(CLDNN_ERROR, status, 0.0f, [&]()
770 return cldnn::half_to_float(value);
776 #define PRIMITIVE_TYPE_ID_CALL_IMPL(PType) \
777 namespace cldnn { primitive_type_id PType##_type_id(); }\
778 extern "C" CLDNN_API cldnn_primitive_type_id cldnn_##PType##_type_id(cldnn_status* status)\
780 return exception_handler<cldnn_primitive_type_id>(CLDNN_ERROR, status, nullptr, []()\
782 return cldnn::PType##_type_id();\
786 PRIMITIVE_TYPE_ID_CALL_IMPL(activation)
787 PRIMITIVE_TYPE_ID_CALL_IMPL(activation_grad)
788 PRIMITIVE_TYPE_ID_CALL_IMPL(arg_max_min)
789 PRIMITIVE_TYPE_ID_CALL_IMPL(average_unpooling)
790 PRIMITIVE_TYPE_ID_CALL_IMPL(batch_norm)
791 PRIMITIVE_TYPE_ID_CALL_IMPL(batch_norm_grad)
792 PRIMITIVE_TYPE_ID_CALL_IMPL(border)
793 PRIMITIVE_TYPE_ID_CALL_IMPL(broadcast)
794 PRIMITIVE_TYPE_ID_CALL_IMPL(convolution)
795 PRIMITIVE_TYPE_ID_CALL_IMPL(crop)
796 PRIMITIVE_TYPE_ID_CALL_IMPL(data)
797 PRIMITIVE_TYPE_ID_CALL_IMPL(embed)
798 PRIMITIVE_TYPE_ID_CALL_IMPL(mutable_data)
799 PRIMITIVE_TYPE_ID_CALL_IMPL(deconvolution)
800 PRIMITIVE_TYPE_ID_CALL_IMPL(concatenation)
801 PRIMITIVE_TYPE_ID_CALL_IMPL(eltwise)
802 PRIMITIVE_TYPE_ID_CALL_IMPL(fully_connected)
803 PRIMITIVE_TYPE_ID_CALL_IMPL(fused_conv_bn_scale)
804 PRIMITIVE_TYPE_ID_CALL_IMPL(fused_conv_eltwise)
805 PRIMITIVE_TYPE_ID_CALL_IMPL(input_layout)
806 PRIMITIVE_TYPE_ID_CALL_IMPL(lookup_table)
807 PRIMITIVE_TYPE_ID_CALL_IMPL(lrn)
808 PRIMITIVE_TYPE_ID_CALL_IMPL(max_unpooling)
809 PRIMITIVE_TYPE_ID_CALL_IMPL(permute)
810 PRIMITIVE_TYPE_ID_CALL_IMPL(pooling)
811 PRIMITIVE_TYPE_ID_CALL_IMPL(reorder)
812 PRIMITIVE_TYPE_ID_CALL_IMPL(reshape)
813 PRIMITIVE_TYPE_ID_CALL_IMPL(scale)
814 PRIMITIVE_TYPE_ID_CALL_IMPL(scale_grad_input)
815 PRIMITIVE_TYPE_ID_CALL_IMPL(scale_grad_weights)
816 PRIMITIVE_TYPE_ID_CALL_IMPL(softmax)
817 PRIMITIVE_TYPE_ID_CALL_IMPL(region_yolo)
818 PRIMITIVE_TYPE_ID_CALL_IMPL(reorg_yolo)
819 PRIMITIVE_TYPE_ID_CALL_IMPL(proposal)
820 PRIMITIVE_TYPE_ID_CALL_IMPL(roi_pooling)
821 PRIMITIVE_TYPE_ID_CALL_IMPL(prior_box)
822 PRIMITIVE_TYPE_ID_CALL_IMPL(detection_output)
823 PRIMITIVE_TYPE_ID_CALL_IMPL(detection_output_sort)
824 PRIMITIVE_TYPE_ID_CALL_IMPL(normalize)
825 PRIMITIVE_TYPE_ID_CALL_IMPL(generic_layer)
826 PRIMITIVE_TYPE_ID_CALL_IMPL(custom_gpu_primitive)
827 PRIMITIVE_TYPE_ID_CALL_IMPL(split)
828 PRIMITIVE_TYPE_ID_CALL_IMPL(upsampling)
829 PRIMITIVE_TYPE_ID_CALL_IMPL(convolution_grad_weights)
830 PRIMITIVE_TYPE_ID_CALL_IMPL(apply_adam)
831 PRIMITIVE_TYPE_ID_CALL_IMPL(mvn)
832 PRIMITIVE_TYPE_ID_CALL_IMPL(fully_connected_grad_input)
833 PRIMITIVE_TYPE_ID_CALL_IMPL(fully_connected_grad_weights)
834 PRIMITIVE_TYPE_ID_CALL_IMPL(lstm)
835 PRIMITIVE_TYPE_ID_CALL_IMPL(lstm_gemm)
836 PRIMITIVE_TYPE_ID_CALL_IMPL(lstm_elt)
837 PRIMITIVE_TYPE_ID_CALL_IMPL(softmax_loss_grad)
838 PRIMITIVE_TYPE_ID_CALL_IMPL(tile)
839 PRIMITIVE_TYPE_ID_CALL_IMPL(gemm)
840 PRIMITIVE_TYPE_ID_CALL_IMPL(select)
841 PRIMITIVE_TYPE_ID_CALL_IMPL(index_select)
842 PRIMITIVE_TYPE_ID_CALL_IMPL(condition)
843 PRIMITIVE_TYPE_ID_CALL_IMPL(pyramid_roi_align)
844 PRIMITIVE_TYPE_ID_CALL_IMPL(contract)
845 PRIMITIVE_TYPE_ID_CALL_IMPL(one_hot)
846 PRIMITIVE_TYPE_ID_CALL_IMPL(gather)
847 PRIMITIVE_TYPE_ID_CALL_IMPL(depth_to_space)
848 PRIMITIVE_TYPE_ID_CALL_IMPL(shuffle_channels)
849 PRIMITIVE_TYPE_ID_CALL_IMPL(strided_slice)
850 PRIMITIVE_TYPE_ID_CALL_IMPL(reverse_sequence)