set(NNC_INSTALL_PLUGIN_PATH ${NNC_INSTALL_LIB_PATH}/plugin) # path to where plugins will be located
set(NNC_INSTALL_CORE_PATH ${NNC_INSTALL_LIB_PATH}/core) # path to where common part of nnc will be located
+#
+# find necessary packages
+#
find_package(HDF5 COMPONENTS CXX QUIET)
# defines if hdf5 package was found
if(HDF5_FOUND)
set(NNC_HDF5_SUPPORTED OFF)
endif()
+# Try to get compiled caffe proto and return if not successful
+# Note: this creates a target called "caffeproto" that contains compiled caffe.proto sources,
+# and after linking with it caffe.pb.h will be available as "caffe/proto/caffe.pb.h"
+nncc_find_package(CaffeProto QUIET)
+if (CaffeProto_FOUND)
+ set(NNC_FRONTEND_CAFFE_ENABLED ON)
+else()
+ set(NNC_FRONTEND_CAFFE_ENABLED OFF)
+endif()
+
+# We need flatbuffer for tflite frontend
+nncc_find_package(FlatBuffers QUIET)
+if (FlatBuffers_FOUND)
+ set(NNC_FRONTEND_TFLITE_ENABLED ON)
+else()
+ set(NNC_FRONTEND_TFLITE_ENABLED OFF)
+endif()
+###
+
#
# plugins names
#
${CMAKE_CURRENT_BINARY_DIR}/include/Definitions.h)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/include)
-set(NNC_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
+set(NNC_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}})
add_subdirectory(support)
add_subdirectory(core)
add_subdirectory(plugin)
{
std::string plugin;
+ if ( clopt::caffeFrontend.isDisabled() && clopt::tflFrontend.isDisabled() )
+ {
+ throw DriverException("frontends are not available");
+ }
+
+ if ( clopt::caffeFrontend && clopt::tflFrontend )
+ {
+ throw DriverException("only one of the following options are allowed"
+ " to be set in the same time: '"
+ + clopt::caffeFrontend.getNames()[0] + "', '"
+ + clopt::tflFrontend.getNames()[0] + "'");
+ }
+
if ( clopt::caffeFrontend )
{
plugin = NNC_FRONTEND_CAFFE_NAME;
#include "support/CommandLine.h"
#include "option/Options.h"
+#include "Definitions.h"
namespace nncc
{
Option<bool> caffeFrontend(optname("--caffe"),
overview("treat input file as Caffe model"),
false,
- optional(true));
+ optional(true),
+ optvalues(""),
+ nullptr,
+ separators(""),
+#ifdef NNC_FRONTEND_CAFFE_ENABLED
+ showopt(true)
+#else
+ showopt(false)
+#endif // NNC_FRONTEND_CAFFE_ENABLED
+ );
Option<bool> tflFrontend(optname("--tflite"),
overview("treat input file as Tensor Flow Lite model"),
false,
- optional(true));
+ optional(true),
+ optvalues(""),
+ nullptr,
+ separators(""),
+#ifdef NNC_FRONTEND_TFLITE_ENABLED
+ showopt(true)
+#else
+ showopt(false)
+#endif // NNC_FRONTEND_TFLITE_ENABLED
+ );
Option<std::string> target(optname("--target"),
overview("select target language to emit for given architecture."
"Valid values are '" NNC_TARGET_X86_CPP "', '" NNC_TARGET_INTERPRETER "'"),
*/
#cmakedefine NNC_HDF5_SUPPORTED
+/**
+ * @brief define that TFLite frontend is enabled
+ */
+#cmakedefine NNC_FRONTEND_TFLITE_ENABLED
+
+/**
+ * @brief define that CAFFE frontend is enabled
+ */
+#cmakedefine NNC_FRONTEND_CAFFE_ENABLED
+
#endif //NNCC_DEFINITIONS_H
* type if verification is not passed
*/
virtual void runCheckerFunc() = 0;
+
+ /**
+ * @brief is option disabled?
+ */
+ virtual bool isDisabled() const = 0;
};
/**
* @param vals - valid values for option. Other values are interpreted as invalid
* @param checker - function verifies option
* @param seps - symbols that separates name option from value (by default is spaces)
+ * @param enabled - if this option is set to false then it won't be shown for users
*/
explicit Option(const std::vector<std::string> &optnames,
const std::string &descr,
bool is_optional = false,
const std::vector<std::string> &vals = std::vector<std::string>(),
option_checker_t checker = nullptr,
- const std::vector<char> &seps = std::vector<char>());
+ const std::vector<char> &seps = std::vector<char>(),
+ bool enabled = true);
// options must not be copyable and assignment
Option(const Option&) = delete;
}
const std::vector<char> &getSeparators() const override { return _seps; }
+
+ bool isDisabled() const override { return !_is_enabled; }
// end overridden methods
private:
std::vector<std::string> _valid_vals; // option can be initialized only by these values
option_checker_t _checker; // function verifies option and its value
std::vector<char> _seps; // these symbols separate option name and its value
+ bool _is_enabled;
};
// the following functions are helpers for users that declare new options
* @param seps - chars of separators separated by a comma
*/
std::vector<char> separators(const char *seps);
+
+/**
+ * @param is_shown - if set to false, then option won't be shown in help message
+ */
+inline bool showopt(bool is_shown) { return is_shown; }
// end of helper functions
bool is_optional,
const std::vector<std::string> &vals,
option_checker_t checker,
- const std::vector<char> &seps)
+ const std::vector<char> &seps,
+ bool enabled)
{
// save all names
for ( const auto &n : optnames )
// save checker
_checker = checker;
+ _is_enabled = enabled;
+
+ assert((_is_enabled || _is_optional) && "disabled option can't be required");
+
// register new option for parser
CommandLine::getParser()->registerOption(this);
-# Try to get compiled caffe proto and return if not successful
-# Note: this creates a target called "caffeproto" that contains compiled caffe.proto sources,
-# and after linking with it caffe.pb.h will be available as "caffe/proto/caffe.pb.h"
-# Note2: DOWNLOAD_CAFFE cmake option should be on
-nncc_find_package(CaffeProto QUIET)
-if(NOT CaffeProto_FOUND)
- return()
-endif()
-
###################
# Caffe importer #
###################
+if (NOT NNC_FRONTEND_CAFFE_ENABLED)
+ return ()
+endif()
file(GLOB caffe_importer_sources *.cpp)
file(GLOB caffe_importer_headers *.h)
-nncc_find_package(FlatBuffers OPTIONAL)
+if (NOT NNC_FRONTEND_TFLITE_ENABLED)
+ return ()
+endif()
###################
# SCHEMA #
for ( const auto opt: _options )
{
- len = 0;
- for ( const auto &n : opt->getNames() ) len += n.length();
- max_len = (max_len < len) ? len : max_len;
+ if ( !opt->isDisabled() )
+ {
+ len = 0;
+ for (const auto &n : opt->getNames()) len += n.length();
+ max_len = (max_len < len) ? len : max_len;
+ }
}
for ( const auto opt: _options )
const auto &option_descr = opt->getOverview();
const auto &names = opt->getNames();
+ if ( opt->isDisabled() )
+ {
+ // options that are disabled not have to be shown
+ continue;
+ }
+
std::string option_names(names[0]); // initialize with option name
// add option aliases to option_names and count them length
}
}
+ if ( it->second->isDisabled() )
+ {
+ // if option is disabled we don't have to recognize it
+ throw BadOption(optname, "");
+ }
+
return it->second;
} // findOption