clDNN
engine.hpp
1 /*
2 // Copyright (c) 2016 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 
18 #pragma once
19 #include "cldnn_defs.h"
20 
21 namespace cldnn
22 {
23 
26 
29 
31 enum class engine_types : int32_t
32 {
33  ocl = cldnn_engine_ocl
34 };
35 
38 {
39  const bool enable_profiling;
41  const bool dump_custom_program;
42  const std::string compiler_options;
43  const std::string single_kernel_name;
45  const std::string engine_log;
46  const std::string sources_dumps_dir;
47  const uint32_t priority_mode;
48 
56  bool profiling = false,
57  bool decorate_kernel_names = false,
58  bool dump_custom_program = false,
59  const std::string& options = std::string(),
60  const std::string& single_kernel = std::string(),
61  bool primitives_parallelisation = false,
62  const std::string& engine_log = std::string(),
63  const std::string& sources_dumps_dir = std::string(),
64  uint32_t priority_mode = 0)
65  : enable_profiling(profiling)
66  , meaningful_kernels_names(decorate_kernel_names)
68  , compiler_options(options)
69  , single_kernel_name(single_kernel)
70  , enable_parallelisation(primitives_parallelisation)
74  {}
75 
77  : enable_profiling(c_conf.enable_profiling != 0)
83  , engine_log(c_conf.engine_log)
86  {}
87 
89  operator ::cldnn_engine_configuration() const
90  {
91  return{
95  compiler_options.c_str(),
96  single_kernel_name.c_str(),
98  engine_log.c_str(),
99  sources_dumps_dir.c_str(),
101  };
102  }
103 };
104 
108 
110 struct engine
111 {
114  :engine(engine_types::ocl, 0, configuration)
115  {}
116 
121  engine(engine_types type, uint32_t engine_num, const engine_configuration& configuration = engine_configuration())
122  :_impl(check_status<::cldnn_engine>("failed to create engine", [&](status_t* status)
123  {
124  cldnn_engine_configuration conf = configuration;
125  return cldnn_create_engine(static_cast<int32_t>(type), engine_num, &conf, status);
126  }))
127  {}
128 
129  // TODO add move construction/assignment
130  engine(const engine& other) :_impl(other._impl)
131  {
132  retain();
133  }
134 
135  engine& operator=(const engine& other)
136  {
137  if (_impl == other._impl) return *this;
138  release();
139  _impl = other._impl;
140  retain();
141  return *this;
142  }
143 
144  ~engine()
145  {
146  release();
147  }
148 
149  friend bool operator==(const engine& lhs, const engine& rhs) { return lhs._impl == rhs._impl; }
150  friend bool operator!=(const engine& lhs, const engine& rhs) { return !(lhs == rhs); }
151 
153  static uint32_t engine_count(engine_types type)
154  {
155  return check_status<uint32_t>("engine_count failed", [=](status_t* status)
156  {
157  return cldnn_get_engine_count(static_cast<int32_t>(type), status);
158  });
159  }
160 
163  {
164  return check_status<engine_info>("engine_count failed", [=](status_t* status)
165  {
166  return cldnn_get_engine_info(_impl, status);
167  });
168  }
169 
172  {
173  return check_status<engine_types>("engine_count failed", [=](status_t* status)
174  {
175  return static_cast<engine_types>(cldnn_get_engine_type(_impl, status));
176  });
177  }
178 
180  ::cldnn_engine get() const { return _impl; }
181 
182 private:
183  friend struct network;
184  friend struct memory;
185  friend struct event;
186  engine(::cldnn_engine impl) : _impl(impl)
187  {
188  if (_impl == nullptr) throw std::invalid_argument("implementation pointer should not be null");
189  }
190  ::cldnn_engine _impl;
191 
192  void retain()
193  {
194  check_status<void>("retain engine failed", [=](status_t* status) { cldnn_retain_engine(_impl, status); });
195  }
196  void release()
197  {
198  check_status<void>("release engine failed", [=](status_t* status) { cldnn_release_engine(_impl, status); });
199  }
200 };
201 CLDNN_API_CLASS(engine)
202 
203 
206 
207 }
engine(engine_types type, uint32_t engine_num, const engine_configuration &configuration=engine_configuration())
Construct engine of the specified type, engine_num, and configuration options.
Definition: engine.hpp:121
CLDNN_API int32_t cldnn_get_engine_type(cldnn_engine engine, cldnn_status *status)
Returns the cldnn_engine_type for the particular engine.
Represents an clDNN Event object.
Definition: event.hpp:35
const bool meaningful_kernels_names
Generate meaniful names fo OpenCL kernels.
Definition: engine.hpp:40
CLDNN_API void cldnn_release_engine(cldnn_engine engine, cldnn_status *status)
Decrement reference counter for the engine object. Deletes object when counter becomes zero...
engine_configuration(bool profiling=false, bool decorate_kernel_names=false, bool dump_custom_program=false, const std::string &options=std::string(), const std::string &single_kernel=std::string(), bool primitives_parallelisation=false, const std::string &engine_log=std::string(), const std::string &sources_dumps_dir=std::string(), uint32_t priority_mode=0)
Constructs engine configuration with specified options.
Definition: engine.hpp:55
const std::string compiler_options
OpenCL compiler options string.
Definition: engine.hpp:42
struct cldnn_engine_impl * cldnn_engine
Engine object.
Definition: cldnn.h:99
engine(const engine_configuration &configuration=engine_configuration())
Constructs OpenCL engine.
Definition: engine.hpp:113
CLDNN_API uint32_t cldnn_get_engine_count(int32_t type, cldnn_status *status)
number of available engines of the particular type
const bool enable_parallelisation
Enables parallel execution of primitives which don&#39;t depend on each other. Disabled by default...
Definition: engine.hpp:44
const std::string sources_dumps_dir
Specifies a directory where sources of cldnn::program objects should be dumped. Empty by default (mea...
Definition: engine.hpp:46
const bool dump_custom_program
Dump the user OpenCL programs to files.
Definition: engine.hpp:41
engine_types get_type() const
Returns type of the engine.
Definition: engine.hpp:171
engine_info get_info() const
Returns information about properties and capabilities for the engine.
Definition: engine.hpp:162
engine_types
Defines available engine types.
Definition: engine.hpp:31
const bool enable_profiling
Enable per-primitive profiling.
Definition: engine.hpp:39
OpenCL engine.
Definition: cldnn.h:127
Information about the engine returned by cldnn_get_engine_info().
Definition: cldnn.h:145
static uint32_t engine_count(engine_types type)
Returns number of available engines of the particular type.
Definition: engine.hpp:153
const uint32_t priority_mode
Placeholder for priority mode (support of priority hints in command queue). Currently ignored...
Definition: engine.hpp:47
Configuration parameters for created engine.
Definition: cldnn.h:131
const std::string engine_log
Specifies a file to which engine log should be dumped. Empty by default (means no logging)...
Definition: engine.hpp:45
CLDNN_API void cldnn_retain_engine(cldnn_engine engine, cldnn_status *status)
Increment reference counter for the engine object.
CLDNN_API cldnn_engine cldnn_create_engine(int32_t type, uint32_t engine_num, const cldnn_engine_configuration *configuration, cldnn_status *status)
Create new engine of the specified type, engine_num, and configuration options.
CLDNN_API cldnn_engine_info cldnn_get_engine_info(cldnn_engine engine, cldnn_status *status)
Returns engine information. See cldnn_engine_info for details.
Executable network allocated from program.
Definition: network.hpp:59
Represents clDNN engine object.
Definition: engine.hpp:110
Represents buffer with particular layout.
Definition: memory.hpp:42
const std::string single_kernel_name
If provided, runs specific layer.
Definition: engine.hpp:43
Configuration parameters for created engine.
Definition: engine.hpp:37