Class SNPEFactory

Class Documentation

class SNPEFactory

The factory class for creating SNPE objects.

Public Static Functions

static bool isRuntimeAvailable(DlSystem::Runtime_t runtime, uint32_t deviceId = 0)

Indicates whether the supplied runtime is available on the current platform.

Note: It is advised to use this function to check DSP availability. If the DSP is not already initialized, it will conduct the initialization - therefore, please ensure that the appropriate arguments are passed, where relevant.

Parameters
  • runtime[in] The target runtime to check.

  • deviceId[in] deviceId in case of multi NSP devices, 0 by default.

Returns

True if the supplied runtime is available; false, otherwise.

static bool isRuntimeAvailable(DlSystem::Runtime_t runtime, DlSystem::RuntimeCheckOption_t option, uint32_t deviceId = 0)

Indicates whether the supplied runtime is available on the current platform.

Note: It is advised to use this function to check DSP availability. If the DSP is not already initialized, it will conduct the initialization - therefore, please ensure that the appropriate arguments are passed, where relevant.

Parameters
  • runtime[in] The target runtime to check.

  • option[in] Extent to perform runtime available check.

  • deviceId[in] deviceId in case of multi NSP devices, 0 by default.

Returns

True if the supplied runtime is available; false, otherwise.

static DlSystem::ITensorFactory &getTensorFactory()

Gets a reference to the tensor factory.

Returns

A reference to the tensor factory.

static DlSystem::IUserBufferFactory &getUserBufferFactory()

Gets a reference to the UserBuffer factory.

Returns

A reference to the UserBuffer factory.

static DlSystem::Version_t getLibraryVersion()

Gets the version of the SNPE library.

Returns

Version of the SNPE library.

static bool setSNPEStorageLocation(const char *storagePath)

Set the SNPE storage location for all SNPE instances in this process. Note that this may only be called once, and if so must be called before creating any SNPE instances.

Parameters

storagePath[in] Absolute path to a directory which SNPE may use for caching and other storage purposes.

Returns

True if the supplied path was succesfully set as the SNPE storage location, false otherwise.

static bool addOpPackage(const std::string &regLibraryPath)

Register a user-defined op package with SNPE.

Parameters

regLibraryPath[in] Path to the registration library that allows clients to register a set of operations that are part of the package, and share op info with SNPE

Returns

True if successful, False otherwise.

static bool isGLCLInteropSupported()

Indicates whether the OpenGL and OpenCL interoperability is supported on GPU platform.

Returns

True if the OpenGL and OpenCl interop is supported; false, otherwise.

static const char *getLastError()

Returns last error code.

Returns

Error code

static bool initializeLogging(const DlSystem::LogLevel_t &level)

Initializes logging with the specified log level. InitializeLogging with level is used on Android platforms and after successful initialization, SNPE logs are printed in android logcat logs.

It is recommended to initializeLogging before creating any SNPE instances, in order to capture information related to core initialization. If this is called again after first time initialization, subsequent calls are ignored. Also, Logging can be re-initialized after a call to terminateLogging API by calling initializeLogging again.

A typical usage of Logging life cycle can be initializeLogging() any other SNPE API like isRuntimeAvailable()

Please note, enabling logging can have performance impact.

Parameters

LogLevel_t[in] Log level (LOG_INFO, LOG_WARN, etc.).

Returns

True if successful, False otherwise.

static bool initializeLogging(const DlSystem::LogLevel_t &level, const std::string &logPath)

Initializes logging with the specified log level and log path. initializeLogging with level & log path, is used on non Android platforms and after successful initialization, SNPE logs are printed in std output & into log files created in the log path.

It is recommended to initializeLogging before creating any SNPE instances, in order to capture information related to core initialization. If this is called again after first time initialization, subsequent calls are ignored. Also, Logging can be re-initialized after a call to terminateLogging API by calling initializeLogging again.

A typical usage of Logging life cycle can be initializeLogging() any other SNPE API like isRuntimeAvailable()

Please note, enabling logging can have performance impact

Parameters
  • LogLevel_t[in] Log level (LOG_INFO, LOG_WARN, etc.).

  • Path[in] of directory to store logs. If path is empty, the default path is “./Log”. For android, the log path is ignored.

Returns

True if successful, False otherwise.

static bool setLogLevel(const DlSystem::LogLevel_t &level)

Updates the current logging level with the specified level. setLogLevel is optional, called anytime after initializeLogging and before terminateLogging, to update the log level set. Log levels can be updated multiple times by calling setLogLevel A call to setLogLevel() is ignored if it is made before initializeLogging() or after terminateLogging()

Parameters

LogLevel_t[in] Log level (LOG_INFO, LOG_WARN, etc.).

Returns

True if successful, False otherwise.

static bool terminateLogging()

Terminates logging. It is recommended to terminateLogging after initializeLogging in order to disable logging information. If this is called before initialization or after first time termination, calls are ignored.

Returns

True if successful, False otherwise.

Warning

terminateLogging() must not be called while another thread is executing. In a multi-threaded use case, the individual threads must have a cooperative life cycle management strategy for the logger.