SNPEFactory.hpp 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. //==============================================================================
  2. //
  3. // Copyright (c) 2015-2021 Qualcomm Technologies, Inc.
  4. // All Rights Reserved.
  5. // Confidential and Proprietary - Qualcomm Technologies, Inc.
  6. //
  7. //==============================================================================
  8. #ifndef _SNPE_FACTORY_HPP_
  9. #define _SNPE_FACTORY_HPP_
  10. #include "SNPE/SNPE.hpp"
  11. #include "DlSystem/DlEnums.hpp"
  12. #include "DlSystem/UDLFunc.hpp"
  13. #include "DlSystem/ZdlExportDefine.hpp"
  14. #include "DlSystem/DlOptional.hpp"
  15. namespace zdl {
  16. namespace DlSystem
  17. {
  18. class ITensorFactory;
  19. class IUserBufferFactory;
  20. }
  21. namespace DlContainer
  22. {
  23. class IDlContainer;
  24. }
  25. }
  26. namespace zdl { namespace SNPE {
  27. /** @addtogroup c_plus_plus_apis C++
  28. @{ */
  29. /**
  30. * The factory class for creating SNPE objects.
  31. *
  32. */
  33. class ZDL_EXPORT SNPEFactory
  34. {
  35. public:
  36. /**
  37. * Indicates whether the supplied runtime is available on the
  38. * current platform.
  39. *
  40. * @param[in] runtime The target runtime to check.
  41. *
  42. * @return True if the supplied runtime is available; false,
  43. * otherwise.
  44. */
  45. static bool isRuntimeAvailable(zdl::DlSystem::Runtime_t runtime);
  46. /**
  47. * Indicates whether the supplied runtime is available on the
  48. * current platform.
  49. *
  50. * @param[in] runtime The target runtime to check.
  51. *
  52. * @param[in] option Extent to perform runtime available check.
  53. *
  54. * @return True if the supplied runtime is available; false,
  55. * otherwise.
  56. */
  57. static bool isRuntimeAvailable(zdl::DlSystem::Runtime_t runtime,
  58. zdl::DlSystem::RuntimeCheckOption_t option);
  59. /**
  60. * Gets a reference to the tensor factory.
  61. *
  62. * @return A reference to the tensor factory.
  63. */
  64. static zdl::DlSystem::ITensorFactory& getTensorFactory();
  65. /**
  66. * Gets a reference to the UserBuffer factory.
  67. *
  68. * @return A reference to the UserBuffer factory.
  69. */
  70. static zdl::DlSystem::IUserBufferFactory& getUserBufferFactory();
  71. /**
  72. * Gets the version of the SNPE library.
  73. *
  74. * @return Version of the SNPE library.
  75. *
  76. */
  77. static zdl::DlSystem::Version_t getLibraryVersion();
  78. /**
  79. * Set the SNPE storage location for all SNPE instances in this
  80. * process. Note that this may only be called once, and if so
  81. * must be called before creating any SNPE instances.
  82. *
  83. * @param[in] storagePath Absolute path to a directory which SNPE may
  84. * use for caching and other storage purposes.
  85. *
  86. * @return True if the supplied path was succesfully set as
  87. * the SNPE storage location, false otherwise.
  88. */
  89. static bool setSNPEStorageLocation(const char* storagePath);
  90. /**
  91. * @brief Register a user-defined op package with SNPE.
  92. *
  93. * @param[in] regLibraryPath Path to the registration library
  94. * that allows clients to register a set of operations that are
  95. * part of the package, and share op info with SNPE
  96. *
  97. * @return True if successful, False otherwise.
  98. */
  99. static bool addOpPackage( const std::string& regLibraryPath );
  100. /**
  101. * Indicates whether the OpenGL and OpenCL interoperability is supported
  102. * on GPU platform.
  103. *
  104. * @return True if the OpenGL and OpenCl interop is supported; false,
  105. * otherwise.
  106. */
  107. static bool isGLCLInteropSupported();
  108. static const char* getLastError();
  109. /**
  110. * Initializes logging with the specified log level.
  111. * initializeLogging with level, is used on Android platforms
  112. * and after successful initialization, SNPE
  113. * logs are printed in android logcat logs.
  114. *
  115. * It is recommended to initializeLogging before creating any
  116. * SNPE instances, in order to capture information related to
  117. * core initialization. If this is called again after first
  118. * time initialization, subsequent calls are ignored.
  119. * Also, Logging can be re-initialized after a call to
  120. * terminateLogging API by calling initializeLogging again.
  121. *
  122. * A typical usage of Logging life cycle can be
  123. * initializeLogging()
  124. * any other SNPE API like isRuntimeAvailable()
  125. * * setLogLevel() - optional - can be called anytime
  126. * between initializeLogging & terminateLogging
  127. * SNPE instance creation, inference, destroy
  128. * terminateLogging().
  129. *
  130. * Please note, enabling logging can have performance impact.
  131. *
  132. * @param[in] LogLevel_t Log level (LOG_INFO, LOG_WARN, etc.).
  133. *
  134. * @return True if successful, False otherwise.
  135. */
  136. static bool initializeLogging(const zdl::DlSystem::LogLevel_t& level);
  137. /**
  138. * Initializes logging with the specified log level and log path.
  139. * initializeLogging with level & log path, is used on non Android
  140. * platforms and after successful initialization, SNPE
  141. * logs are printed in std output & into log files created in the
  142. * log path.
  143. *
  144. * It is recommended to initializeLogging before creating any
  145. * SNPE instances, in order to capture information related to
  146. * core initialization. If this is called again after first
  147. * time initialization, subsequent calls are ignored.
  148. * Also, Logging can be re-initialized after a call to
  149. * terminateLogging API by calling initializeLogging again.
  150. *
  151. * A typical usage of Logging life cycle can be
  152. * initializeLogging()
  153. * any other SNPE API like isRuntimeAvailable()
  154. * * setLogLevel() - optional - can be called anytime
  155. * between initializeLogging & terminateLogging
  156. * SNPE instance creation, inference, destroy
  157. * terminateLogging()
  158. *
  159. * Please note, enabling logging can have performance impact
  160. *
  161. * @param[in] LogLevel_t Log level (LOG_INFO, LOG_WARN, etc.).
  162. *
  163. * @param[in] Path of directory to store logs.
  164. * If path is empty, the default path is "./Log".
  165. * For android, the log path is ignored.
  166. *
  167. * @return True if successful, False otherwise.
  168. */
  169. static bool initializeLogging(const zdl::DlSystem::LogLevel_t& level, const std::string& logPath);
  170. /**
  171. * Updates the current logging level with the specified level.
  172. * setLogLevel is optional, called anytime after initializeLogging
  173. * and before terminateLogging, to update the log level set.
  174. * Log levels can be updated multiple times by calling setLogLevel
  175. * A call to setLogLevel() is ignored if it is made before
  176. * initializeLogging() or after terminateLogging()
  177. *
  178. * @param[in] LogLevel_t Log level (LOG_INFO, LOG_WARN, etc.).
  179. *
  180. * @return True if successful, False otherwise.
  181. */
  182. static bool setLogLevel(const zdl::DlSystem::LogLevel_t& level);
  183. /**
  184. * Terminates logging.
  185. *
  186. * It is recommended to terminateLogging after initializeLogging
  187. * in order to disable logging information.
  188. * If this is called before initialization or after first time termination,
  189. * calls are ignored.
  190. *
  191. * @return True if successful, False otherwise.
  192. */
  193. static bool terminateLogging(void);
  194. };
  195. /** @} */ /* end_addtogroup c_plus_plus_apis C++ */
  196. }}
  197. #endif