19 #include "cldnn_defs.h" 20 #include "topology.hpp" 80 std::string cache_file_path;
92 static std::shared_ptr<const build_option>
fusing(
bool enable =
false);
95 static std::shared_ptr<const build_option>
optimize_data(
bool enable =
false);
99 static std::shared_ptr<const build_option>
debug(
bool enable =
false);
102 static std::shared_ptr<const build_option>
outputs(
const std::vector<primitive_id>& outs);
113 static std::shared_ptr<const build_option>
graph_dumps_dir(
const std::string& dir_path);
122 virtual const void* get_data()
const = 0;
128 template<build_option_type OptType>
137 : _value(reinterpret_cast<uintptr_t>(value.
data))
139 assert(value.
type == static_cast<int32_t>(OptType));
146 const void* get_data()
const override {
return reinterpret_cast<const void*
>(_value); }
161 , _outputs_ref({ _ref_store.data(), _ref_store.size() })
175 const void* get_data()
const override {
return &_outputs_ref; }
180 const std::vector<cldnn_primitive_id> _ref_store;
183 static std::vector<cldnn_primitive_id> to_refs(
const std::vector<primitive_id>& stor)
185 std::vector<cldnn_primitive_id> result(stor.size());
186 for (
size_t i = 0; i < stor.size(); i++)
188 result[i] = stor[i].c_str();
193 static std::vector<primitive_id> make_outputs_from_ref(
const cldnn_build_option& value)
196 if (value.
data ==
nullptr)
throw std::invalid_argument(
"output data is empty");
198 std::vector<primitive_id> result;
199 result.reserve(refs->size);
200 for (decltype(refs->size) i = 0; i < refs->size; i++)
202 result.push_back(refs->data[i]);
218 config_ref({
static_cast<int32_t
>(
config.mode),
config.cache_file_path.c_str() })
232 const void* get_data()
const override {
return &config_ref; }
242 if (value.
data ==
nullptr)
throw std::invalid_argument(
"Tuning config data is empty");
244 tuning_config_options result;
246 result.cache_file_path = std::string(refs->cache_file_path);
252 template<build_option_type OptType>
255 const std::string directory_path;
260 : directory_path(dir_path)
265 : directory_path(from_c_value(value))
272 const void* get_data()
const override {
return (directory_path.empty() ? nullptr : directory_path.c_str()); }
279 if (value.
type != static_cast<int32_t>(OptType))
280 throw std::invalid_argument(
"option type does not match");
281 if (value.
data ==
nullptr)
284 return{
static_cast<const char*
>(value.
data) };
291 template<build_option_type OptType>
297 static std::shared_ptr<const build_option>
make_default();
302 #ifndef DOXYGEN_SHOULD_SKIP_THIS 310 return std::make_shared<object_type>(option);
315 typedef build_option_bool<build_option_type::optimize_data>
object_type;
320 return std::make_shared<object_type>(option);
325 typedef build_option_bool<build_option_type::debug>
object_type;
330 return std::make_shared<object_type>(option);
340 return std::make_shared<object_type>(option);
350 return std::make_shared<object_type>(option);
355 typedef build_option_directory<build_option_type::graph_dumps_dir>
object_type;
360 return std::make_shared<object_type>(option);
366 #ifndef DOXYGEN_SHOULD_SKIP_THIS 369 return std::make_shared<build_option_bool<build_option_type::fusing>>(enable);
374 return std::make_shared<build_option_bool<build_option_type::optimize_data>>(enable);
379 return std::make_shared<build_option_bool<build_option_type::debug>>(enable);
382 inline std::shared_ptr<const build_option>
build_option::outputs(
const std::vector<primitive_id>& outs)
384 return std::make_shared<build_option_outputs>(outs);
389 return std::make_shared<build_option_tuning_config>(config);
394 return std::make_shared<build_option_directory<build_option_type::graph_dumps_dir>>(dir_path);
405 add_or_replace_option(opt);
409 template<
typename ...Args>
410 void set_option(std::shared_ptr<const build_option> opt, Args... args)
412 add_or_replace_option(opt);
417 template<
typename ...Args>
426 for (
auto& o : options)
428 _options.emplace_back(make_option(o));
433 template<build_option_type OptType>
434 std::shared_ptr<const typename detail::build_option_traits<OptType>::object_type>
438 for (
auto& option : _options)
440 if (option->get_type() == OptType)
441 return std::static_pointer_cast<const T>(option);
448 std::vector<std::shared_ptr<const build_option>> _options;
449 void set_option(
void) {}
452 std::vector<cldnn_build_option> get_refs()
const 454 std::vector<cldnn_build_option> result;
455 for (
auto& o : _options)
457 result.push_back({
static_cast<int32_t
>(o->get_type()), o->get_data() });
462 void add_or_replace_option(std::shared_ptr<const build_option> opt)
464 for (
auto& p : _options)
466 if (p->get_type() == opt->get_type())
472 _options.push_back(opt);
475 static std::shared_ptr<const build_option> make_option(
const cldnn_build_option& option)
491 default:
throw std::out_of_range(
"unsupported build option type");
507 :_impl(check_status<
cldnn_program>(
"program creation failed", [&](status_t* status)
509 auto options_refs = options.get_refs();
530 if (_impl == other._impl)
return *
this;
551 if (_impl ==
nullptr)
552 throw std::invalid_argument(
"implementation pointer should not be null");
557 check_status<void>(
"retain topology failed", [=](status_t* status) {
cldnn_retain_program(_impl, status); });
561 check_status<void>(
"retain topology failed", [=](status_t* status) {
cldnn_release_program(_impl, status); });
program(program const &other)
Retains the C API cldnn_program handler stored in other.
build_option_bool(bool value)
Constructs option.
static std::shared_ptr< const build_option > debug(bool enable=false)
Enable debug mode (default: false).
Tuning config (default: Tuning is disabled).
Allow primitives fusing during network build.
Represents program build options list.
::cldnn_engine get() const
get C API engine handler.
build_option specialization for program outputs list.
static std::shared_ptr< const build_option > graph_dumps_dir(const std::string &dir_path)
Specifies a directory to which stages of network compilation should be dumped (default: empty...
Tuning using the cached data (no on-line tuning for non-existing data).
build_option object_type
build_option object type which represents the particular OptType.
User selected list of network outputs.
build_option_directory(const cldnn_build_option &value)
Constructs from C API cldnn_build_option.
Represents network build option.
program & operator=(const program &other)
Assigns new value by releasing previously referenced C API cldnn_program handler and retaining the on...
build_option specialization for tuning config.
Enable implicit reordering for user input.
static std::shared_ptr< const build_option > tuning_config(const tuning_config_options &config=tuning_config_options())
Tuning configuration (default: false).
Represents user-provided program build option.
Compiled program build from topology by engine.
Tuning using the cached data (no on-line tuning for non-existing data).
struct cldnn_program_impl * cldnn_program
Compiled program build from cldnn_topology by cldnn_engine.
static std::shared_ptr< const build_option > make_option(const cldnn_build_option &option)
Make build_option from C API cldnn_build_option.
Enable debug mode (default: false).
friend bool operator==(const program &lhs, const program &rhs)
Checks whether lhs and rhs reference the same C API cldnn_program handler.
program(engine const &engine, topology const &topology, build_options const &options=build_options())
Builds executable program based on user-defined topology by specified engine.
static std::shared_ptr< const build_option > fusing(bool enable=false)
Allow primitives fusing during program build (default: false).
void set_option(std::shared_ptr< const build_option > opt, Args... args)
Adds or replace options to the options list.
void set_option(std::shared_ptr< const build_option > opt)
Adds or replace option to the options list.
build_option specialization for boolean options.
Specifies a directory to which stages of network compilation should be dumped.
Enable implicit reordering for user inputs (default: false).
Provides input data to topology.
CLDNN_API void cldnn_release_program(cldnn_program program, cldnn_status *status)
Decrement reference counter for the program object. Deletes object when counter becomes zero...
const tuning_config_options config
Tuning configuration.
bool enabled() const
Is option enabled.
build_option_tuning_config(const tuning_config_options &tuning_config)
Constructs tuning config build option.
CLDNN_API void cldnn_retain_program(cldnn_program program, cldnn_status *status)
Increment reference counter for the program object.
User selected list of program outputs.
build_option_bool(const cldnn_build_option &value)
Constructs from C API cldnn_build_option.
const int32_t mode
cldnn_tuning_mode_type.
Tuning using the cached data if exist, tune and update cache otherwise.
build_option_outputs(const std::vector< primitive_id > &outs)
Constructs option.
build_option_outputs(const cldnn_build_option &value)
Constructs from C API cldnn_build_option.
~program()
Dereferences the counter of the underlying C API cldnn_program handler.
Allow primitives fusing during program build (default: false).
Network topology to be defined by user.
Helper template to convert build_option_type value to particular build_option class.
build_option_tuning_config(const cldnn_build_option &value)
Constructs tuning config build option from C API cldnn_build_option.
Tuning using the cached data if exist, tune and update cache otherwise.
build_option_directory(const std::string &dir_path)
Constructs option.
static std::shared_ptr< const build_option > make_default()
Make default build_option corresponding OptType.
const void * data
option parameter - e.g list of outputs.
static std::shared_ptr< const build_option > outputs(const std::vector< primitive_id > &outs)
User selected list of program outputs.
Represents reference to an array of primitive ids.
cldnn_topology get() const
Returns wrapped C API cldnn_topology.
Executable network allocated from program.
int32_t type
cldnn_build_option_type.
Represents clDNN engine object.
build_option_type
Represents user-provided program build option type.
build_option specialization for selecting a directory.
friend bool operator!=(const program &lhs, const program &rhs)
Checks whether lhs and rhs reference different C API cldnn_program handlers.
CLDNN_API cldnn_program cldnn_build_program(cldnn_engine engine, cldnn_topology topology, cldnn_build_option *options, size_t options_num, cldnn_status *status)
Builds executable program based on user-defined topology by specified engine.
build_options(Args... args)
Constructs build options list from its arguments.
static std::shared_ptr< const build_option > optimize_data(bool enable=false)
Enable implicit reordering for user inputs (default: false).
const std::vector< primitive_id > outputs
The list of output ids (names)
build_options(array_ref< cldnn_build_option > options)
Constructs build options list from C API ::cldnn_build_options.
Specifies a directory to which stages of network compilation should be dumped. (default: empty...