19 #include "cldnn_defs.h" 20 #include "compounds.h" 22 #include "program.hpp" 55 friend struct network;
64 :_impl(check_status<
cldnn_network>(
"network allocation failed", [&](status_t* status)
81 if (_impl ==
nullptr)
throw std::invalid_argument(
"implementation pointer should not be null");
93 if (_impl == other._impl)
return *
this;
106 friend bool operator==(
const network& lhs,
const network& rhs) {
return lhs._impl == rhs._impl; }
107 friend bool operator!=(
const network& lhs,
const network& rhs) {
return !(lhs == rhs); }
112 return check_status<cldnn_engine>(
"get network engine failed", [&](status_t* status) {
return cldnn_get_network_engine(_impl, status); });
118 return check_status<cldnn_program>(
"get network program failed", [&](status_t* status) {
return cldnn_get_network_program(_impl, status); });
124 check_status<void>(
"set network input failed", [&](status_t* status) {
cldnn_set_network_input(_impl,
id.c_str(), mem.
get(), status); });
128 std::string get_primitive_info(
const primitive_id&
id)
const 131 status_t err_invalid_arg = CLDNN_SUCCESS;
134 assert(err_invalid_arg == CLDNN_INVALID_ARG);
135 assert(size_ret > 0);
136 std::vector<char> names_buf(size_ret);
138 check_status<void>(
"get primitive info failed", [&](status_t* status)
142 assert(names_buf.size() == size_ret);
144 std::string result(names_buf.begin(), names_buf.end());
176 check_status<cldnn_network_output>(
"get network output failed", [&](status_t* status)
187 check_status<cldnn_memory>(
"get output memory failed", [&](status_t* status)
198 check_status<cldnn_event>(
"get output event failed", [&](status_t* status)
212 std::vector<primitive_id> optimized_primitives;
213 for (decltype(all_primitive_org_ids.size()) i = 0; i < all_primitive_org_ids.size(); i++)
215 if (all_primitive_ids[i] ==
"_optimized_")
216 optimized_primitives.push_back(all_primitive_org_ids[i]);
218 std::map<primitive_id, event> result;
219 for (
auto&
id : primitive_ids)
221 if(std::find(optimized_primitives.begin(), optimized_primitives.end(), id) == optimized_primitives.end())
234 std::map<primitive_id, primitive_id> result;
235 for (decltype(primitive_org_ids.size()) i = 0; i < primitive_org_ids.size(); i++)
237 result.emplace(primitive_org_ids[i], primitive_ids[i]);
246 std::map<primitive_id, network_output>
execute(
const std::vector<event>& dependencies = {})
const 248 std::vector<cldnn_event> dep_refs(dependencies.size());
249 for(decltype(dependencies.size()) i = 0; i < dependencies.size(); i++)
251 dep_refs[i] = dependencies[i].get();
254 check_status<void>(
"network execute failed", [&](status_t* status)
260 std::map<primitive_id, network_output> result;
261 for(
auto&
id : output_ids)
278 check_status<void>(
"retain topology failed", [=](status_t* status) {
cldnn_retain_network(_impl, status); });
282 check_status<void>(
"retain topology failed", [=](status_t* status) {
cldnn_release_network(_impl, status); });
285 std::vector<primitive_id> get_prim_ids(get_prim_ids_func_t func)
const 288 status_t err_invalid_arg = CLDNN_SUCCESS;
289 func(_impl,
nullptr, 0, &size_ret, &err_invalid_arg);
290 assert(err_invalid_arg == CLDNN_INVALID_ARG);
291 assert(size_ret > 0);
292 std::vector<char> names_buf(size_ret);
294 check_status<void>(
"get network output ids failed", [&](status_t* status)
296 func(_impl, names_buf.data(), names_buf.size(), &size_ret, status);
298 assert(names_buf.size() == size_ret);
300 std::vector<primitive_id> result;
301 for (
auto buf_ptr = names_buf.data(); *buf_ptr != 0; buf_ptr += result.back().size() + 1)
303 result.emplace_back(buf_ptr);
309 CLDNN_API_CLASS(network)
cldnn_memory get() const
C API memory handle.
CLDNN_API void cldnn_get_network_output_names(cldnn_network network, char *names, size_t size, size_t *size_ret, cldnn_status *status)
Returns names of network outputs.
Represents an clDNN Event object.
CLDNN_API void cldnn_get_network_all_primitive_names(cldnn_network network, char *names, size_t size, size_t *size_ret, cldnn_status *status)
Returns names of all primitives in network.
Represents program build options list.
program get_program() const
Returns network internal program.
event get_primitive_event(const primitive_id &output_id) const
Returns event object for particular primitive. Can't be called before network execution.
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)
Returns names of all primitives in network before graph optimization.
std::map< primitive_id, network_output > execute(const std::vector< event > &dependencies={}) const
Executes network and returns the list of network_output.
CLDNN_API void cldnn_release_network(cldnn_network network, cldnn_status *status)
Decrement reference counter for the network object. Deletes object when counter becomes zero...
void set_input_data(const primitive_id &id, const memory &mem) const
Provides memory for input_layout primitives defined by user in source topology.
CLDNN_API cldnn_memory cldnn_get_network_output_memory(cldnn_network network, const char *name, cldnn_status *status)
Returns memory corresponding to output with name.
std::map< primitive_id, event > get_executed_primitives() const
Returns the list of event for the primitives that were executed in network.
network(cldnn_network impl)
Constructs network object from C API cldnn_network.
Compiled program build from topology by engine.
CLDNN_API void cldnn_get_network_executed_primitive_names(cldnn_network network, char *names, size_t size, size_t *size_ret, cldnn_status *status)
Returns names of executed primitives.
Represents network output returned by network::get_output().
network(const engine &engine, const topology &topology, const build_options &options=build_options())
Constructs network object from implicitly created program object. This is a shorthand for network(pro...
CLDNN_API void cldnn_retain_network(cldnn_network network, cldnn_status *status)
Increment reference counter for the network object.
std::map< primitive_id, primitive_id > get_all_primitives() const
Returns the list of primitive ids before and after graph optimization.
std::vector< primitive_id > get_all_primitive_org_ids() const
Returns the list of all primitives ids in network before graph optimization.
network & operator=(const network &other)
Copy assignment.
CLDNN_API cldnn_event cldnn_get_network_output_event(cldnn_network network, const char *name, cldnn_status *status)
Returns event corresponding to output with name.
memory get_memory() const
Returns memory object of the output. Blocked until associated event is not complete.
~network()
Releases wrapped C API cldnn_network.
struct cldnn_event_impl * cldnn_event
Event object.
int32_t cldnn_status
Represents errors status for all API calls.
engine get_engine() const
Returns engine by which network was built.
struct cldnn_memory_impl * cldnn_memory
Memory object.
network_output get_output(const primitive_id &output_id) const
Returns network_output object for particular output. Can't be called before network execution...
CLDNN_API void cldnn_execute_network(cldnn_network network, cldnn_event *dependencies, size_t deps_num, cldnn_status *status)
Executes network.
network(program const &program)
Allocate network.
void wait() const
Wait for event completion.
CLDNN_API cldnn_engine cldnn_get_network_engine(cldnn_network network, cldnn_status *status)
Returns engine associated with the network.
Network topology to be defined by user.
std::vector< primitive_id > get_all_primitive_ids() const
Returns the list of all primitives ids in network.
cldnn_event event
Event to be waited.
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)
Returns information about particular primitive.
Executable network allocated from program.
std::vector< primitive_id > get_executed_primitive_ids() const
Returns the list of executed primitives.
std::string primitive_id
Unique id of a primitive within a topology.
memory get_output_memory(const primitive_id &output_id) const
Returns memory object for particular output. Can be called before network execution.
std::vector< primitive_id > get_output_ids() const
Returns the list of available network outputs.
::cldnn_program get() const
Returns wrapped C API cldnn_program handler.
Represents clDNN engine object.
network(const network &other)
Copy construction.
CLDNN_API cldnn_network cldnn_allocate_network(cldnn_program program, cldnn_status *status)
Allocates memory for a new network which will be able to execute specified program.
CLDNN_API cldnn_network_output cldnn_get_network_output(cldnn_network network, const char *name, cldnn_status *status)
Returns executed network output information.
Represents buffer with particular layout.
Output information for executed cldnn_network.
event get_event() const
Returns event associated with the output.
CLDNN_API cldnn_program cldnn_get_network_program(cldnn_network network, cldnn_status *status)
Returns program associated with the network.
struct cldnn_network_impl * cldnn_network
Executable network allocated from cldnn_program.
CLDNN_API void cldnn_set_network_input(cldnn_network network, cldnn_primitive_id id, cldnn_memory mem, cldnn_status *status)
Provides user input data to the network (for input_layout primitives).