openpilot v0.9.6 release

date: 2024-01-12T10:13:37
master commit: ba792d576a49a0899b88a753fa1c52956bedf9e6
This commit is contained in:
FrogAi
2024-01-12 22:39:28 -07:00
commit 08e9fb1edc
1881 changed files with 653708 additions and 0 deletions

View File

@@ -0,0 +1,101 @@
//==============================================================================
//
// Copyright (c) 2019 Qualcomm Technologies, Inc.
// All Rights Reserved.
// Confidential and Proprietary - Qualcomm Technologies, Inc.
//
//==============================================================================
#ifndef PSNPE_APPLICATIONBUFFERMAP_HPP
#define PSNPE_APPLICATIONBUFFERMAP_HPP
#include <vector>
#include <string>
#include <unordered_map>
#include "DlSystem/UserBufferMap.hpp"
#include "DlSystem/ZdlExportDefine.hpp"
namespace zdl
{
namespace PSNPE
{
/** @addtogroup c_plus_plus_apis C++
@{ */
/**
* @brief .
*
* A class representing the UserBufferMap of Input and Output asynchronous mode.
*/
class ZDL_EXPORT ApplicationBufferMap final
{
public:
/**
* @brief Adds a name and the corresponding buffer
* to the map
*
* @param[in] name The name of the UserBuffer
* @param[in] buffer The vector of the uint8_t data
*
* @note If a UserBuffer with the same name already exists, the new
* UserBuffer pointer would be updated.
*/
void add(const char* name, std::vector<uint8_t>& buff) noexcept;
void add(const char* name, std::vector<float>& buff) noexcept;
/**
* @brief Removes a mapping of one UserBuffer and its name by its name
*
* @param[in] name The name of UserBuffer to be removed
*
* @note If no UserBuffer with the specified name is found, nothing
* is done.
*/
void remove(const char* name) noexcept;
/**
* @brief Returns the number of UserBuffers in the map
*/
size_t size() const noexcept;
/**
* @brief .
*
* Removes all UserBuffers from the map
*/
void clear() noexcept;
/**
* @brief Returns the UserBuffer given its name.
*
* @param[in] name The name of the UserBuffer to get.
*
* @return nullptr if no UserBuffer with the specified name is
* found; otherwise, a valid pointer to the UserBuffer.
*/
const std::vector<uint8_t>& getUserBuffer(const char* name) const;
const std::vector<uint8_t>& operator[](const char* name) const;
/**
* @brief .
*
* Returns the names of all UserAsyncBufferMap
*
* @return A list of UserBuffer names.
*/
zdl::DlSystem::StringList getUserBufferNames() const;
const std::unordered_map<std::string, std::vector<uint8_t>>& getUserBuffer() const;
explicit ApplicationBufferMap();
~ApplicationBufferMap();
explicit ApplicationBufferMap(
const std::unordered_map<std::string, std::vector<uint8_t>> buffer);
private:
std::unordered_map<std::string, std::vector<uint8_t>> m_UserMap;
};
/** @} */ /* end_addtogroup c_plus_plus_apis C++ */
} // namespace PSNPE
} // namespace zdl
#endif // PSNPE_APPLICATIONBUFFERMAP_HPP

205
third_party/snpe/include/SNPE/PSNPE.hpp vendored Normal file
View File

@@ -0,0 +1,205 @@
// =============================================================================
//
// Copyright (c) 2019-2021 Qualcomm Technologies, Inc.
// All Rights Reserved.
// Confidential and Proprietary - Qualcomm Technologies, Inc.
//
// =============================================================================
#ifndef PSNPE_HPP
#define PSNPE_HPP
#include <cstdlib>
#include <functional>
#include "SNPE/SNPE.hpp"
#include "DlSystem/UserBufferMap.hpp"
#include "DlContainer/IDlContainer.hpp"
#include "DlSystem/DlEnums.hpp"
#include "DlSystem/ZdlExportDefine.hpp"
#include "UserBufferList.hpp"
#include "RuntimeConfigList.hpp"
#include "ApplicationBufferMap.hpp"
namespace zdl
{
namespace PSNPE
{
/** @addtogroup c_plus_plus_apis C++
@{ */
/**
*@ brief build snpe instance in serial or parallel
*
*/
enum ZDL_EXPORT BuildMode {
SERIAL = 0,
PARALLEL = 1
};
/**
* @brief Input and output transmission mode
*/
enum ZDL_EXPORT InputOutputTransmissionMode
{
sync = 0,
outputAsync = 1,
inputOutputAsync = 2
};
/**
* @brief A structure representing parameters of callback function of Async Output mode
*/
struct ZDL_EXPORT OutputAsyncCallbackParam
{
size_t dataIndex;
bool executeStatus;
std::string errorMsg;
OutputAsyncCallbackParam(size_t _index,bool _status, const std::string& _errorMsg = std::string())
: dataIndex(_index),executeStatus(_status), errorMsg(_errorMsg){};
};
/**
* @brief A structure representing parameters of callback function of Async Input/Output mode
*/
struct ZDL_EXPORT InputOutputAsyncCallbackParam
{
size_t dataIndex;
const ApplicationBufferMap& outputMap;
bool executeStatus;
std::string errorMsg;
InputOutputAsyncCallbackParam(size_t _index, const ApplicationBufferMap& output_map,bool _status,
const std::string _ErrorMsg = std::string())
: dataIndex(_index)
, outputMap(output_map)
, executeStatus(_status)
, errorMsg(_ErrorMsg){};
};
/**
* @brief This callback is called when the output data is ready, only use for Output Async mode
*/
using OutputAsyncCallbackFunc = std::function<void(OutputAsyncCallbackParam)>;
/**
* @brief This callback is called when the output data is ready, only use for Output-Input Async mode
*/
using InputOutputAsyncCallbackFunc = std::function<void(InputOutputAsyncCallbackParam)>;
/**
* @brief This callback is called when the input data is ready,only use for Output-Input Async mode
*/
using InputOutputAsyncInputCallback = std::function<std::shared_ptr<ApplicationBufferMap>(const std::vector<std::string> &,
const zdl::DlSystem::StringList &)>;
/**
* @brief .
*
* A structure PSNPE configuration
*
*/
struct ZDL_EXPORT BuildConfig final
{
BuildMode buildMode = BuildMode::SERIAL; ///< Specify build in serial mode or parallel mode
zdl::DlContainer::IDlContainer* container;///< The opened container ptr
zdl::DlSystem::StringList outputBufferNames;///< Specify the output layer name
zdl::DlSystem::StringList outputTensors;///< Specify the output layer name
RuntimeConfigList runtimeConfigList;///< The runtime config list for PSNPE, @see RuntimeConfig
size_t inputThreadNumbers = 1;///< Specify the number of threads used in the execution phase to process input data, only used in inputOutputAsync mode
size_t outputThreadNumbers = 1;///< Specify the number of threads used in the execution phase to process output data, only used in inputOutputAsync and outputAsync mode
OutputAsyncCallbackFunc outputCallback;///< The callback to deal with output data ,only used in outputAsync mode
InputOutputAsyncCallbackFunc inputOutputCallback;///< The callback to deal with output data ,only used in inputOutputAsync mode
InputOutputAsyncInputCallback inputOutputInputCallback;///< The callback to deal with input data ,only used in inputOutputAsync mode
InputOutputTransmissionMode inputOutputTransmissionMode = InputOutputTransmissionMode::sync;///< Specify execution mode
zdl::DlSystem::ProfilingLevel_t profilingLevel = zdl::DlSystem::ProfilingLevel_t::OFF;///< Specify profiling level for Diaglog
uint64_t encode[2] = {0, 0};
bool enableInitCache = false;
std::string platformOptions;
std::string diaglogOutputDir = "./diaglogs/"; ///< Specify a diaglog output directory to save the generated Diaglog files.
};
/**
* @brief .
*
* The class for executing SNPE instances in parallel.
*/
class ZDL_EXPORT PSNPE final
{
public:
~PSNPE();
explicit PSNPE() noexcept :m_TransmissionMode(InputOutputTransmissionMode::sync){};
/**
* @brief Build snpe instances.
*
*/
bool build(BuildConfig& buildConfig) noexcept;
/**
* @brief Execute snpe instances in Async Output mode and Sync mode
*
* @param[in] inputBufferList A list of user buffers that contains the input data
*
* @param[in,out] outputBufferList A list of user buffers that will hold the output data
*
*/
bool execute(UserBufferList& inputBufferList, UserBufferList& outputBufferList) noexcept;
/**
* @brief Execute snpe instances in Async Input/Output mode
*
* @param[in]inputMap A map of input buffers that contains input data. The names of buffers
* need to be matched with names retrived through getInputTensorNames()
*
* @param dataIndex Index of the input data
*
* @param isTF8buff Whether prefer to using 8 bit quantized element for inference
*
* @return True if executed successfully; flase, otherwise.
*/
bool executeInputOutputAsync(const std::vector<std::string>& inputMap, size_t dataIndex, bool isTF8buff) noexcept;
bool executeInputOutputAsync(const std::vector<std::string>& inputMap, size_t dataIndex, bool isTF8buff,bool isTF8Outputbuff) noexcept;
/**
* @brief Returns the input layer names of the network.
*
* @return StringList which contains the input layer names
*/
const zdl::DlSystem::StringList getInputTensorNames() const noexcept;
/**
* @brief Returns the output layer names of the network.
*
* @return StringList which contains the output layer names
*/
const zdl::DlSystem::StringList getOutputTensorNames() const noexcept;
/**
* @brief Returns the input tensor dimensions of the network.
*
* @return TensorShape which contains the dimensions.
*/
const zdl::DlSystem::TensorShape getInputDimensions() const noexcept;
const zdl::DlSystem::TensorShape getInputDimensions(const char *name) const noexcept;
/**
* @brief Returns attributes of buffers.
*
* @see zdl::SNPE
*
* @return BufferAttributes of input/output tensor named.
*/
const zdl::DlSystem::TensorShape getBufferAttributesDims(const char *name) const noexcept;
zdl::DlSystem::Optional<zdl::DlSystem::IBufferAttributes*> getInputOutputBufferAttributes(const char *name) const noexcept;
bool registerIonBuffers(const zdl::DlSystem::UserMemoryMap& ionBufferMap) const noexcept;
bool deregisterIonBuffers(const zdl::DlSystem::StringList& ionBufferNames) const noexcept;
const char* getLastErrorString();
private:
PSNPE(const PSNPE&) = delete;
PSNPE& operator=(const PSNPE&) = delete;
zdl::PSNPE::InputOutputTransmissionMode m_TransmissionMode;
};
/** @} */ /* end_addtogroup c_plus_plus_apis C++ */
} // namespace PSNPE
} // namespace zdl
#endif // PSNPE_HPP

View File

@@ -0,0 +1,85 @@
//==============================================================================
//
// Copyright (c) 2019-2020 Qualcomm Technologies, Inc.
// All Rights Reserved.
// Confidential and Proprietary - Qualcomm Technologies, Inc.
//
//==============================================================================
#ifndef PSNPE_RUNTIMECONFIGLIST_HPP
#define PSNPE_RUNTIMECONFIGLIST_HPP
#include <iostream>
#include "DlContainer/IDlContainer.hpp"
#include "DlSystem/DlEnums.hpp"
#include "DlSystem/RuntimeList.hpp"
#include "DlSystem/TensorShapeMap.hpp"
#include "DlSystem/ZdlExportDefine.hpp"
namespace zdl {
namespace PSNPE {
/** @addtogroup c_plus_plus_apis C++
@{ */
/**
* @brief .
*
* The structure for configuring a BulkSNPE runtime
*
*/
struct ZDL_EXPORT RuntimeConfig final {
zdl::DlSystem::Runtime_t runtime;
zdl::DlSystem::RuntimeList runtimeList;
zdl::DlSystem::PerformanceProfile_t perfProfile;
zdl::DlSystem::TensorShapeMap inputDimensionsMap;
bool enableCPUFallback;
RuntimeConfig()
: runtime{zdl::DlSystem::Runtime_t::CPU_FLOAT32},
perfProfile{zdl::DlSystem::PerformanceProfile_t::HIGH_PERFORMANCE},
enableCPUFallback{false} {}
RuntimeConfig(const RuntimeConfig& other) {
runtime = other.runtime;
runtimeList = other.runtimeList;
perfProfile = other.perfProfile;
enableCPUFallback = other.enableCPUFallback;
inputDimensionsMap = other.inputDimensionsMap;
}
RuntimeConfig& operator=(const RuntimeConfig& other) {
this->runtimeList = other.runtimeList;
this->runtime = other.runtime;
this->perfProfile = other.perfProfile;
this->enableCPUFallback = other.enableCPUFallback;
this->inputDimensionsMap = other.inputDimensionsMap;
return *this;
}
~RuntimeConfig() {}
};
/**
* @brief .
*
* The class for creating a RuntimeConfig container.
*
*/
class ZDL_EXPORT RuntimeConfigList final {
public:
RuntimeConfigList();
RuntimeConfigList(const size_t size);
void push_back(const RuntimeConfig& runtimeConfig);
RuntimeConfig& operator[](const size_t index);
RuntimeConfigList& operator=(const RuntimeConfigList& other);
size_t size() const noexcept;
size_t capacity() const noexcept;
void clear() noexcept;
~RuntimeConfigList() = default;
private:
void swap(const RuntimeConfigList& other);
std::vector<RuntimeConfig> m_runtimeConfigs;
};
/** @} */ /* end_addtogroup c_plus_plus_apis C++ */
} // namespace PSNPE
} // namespace zdl
#endif // PSNPE_RUNTIMECONFIGLIST_HPP

258
third_party/snpe/include/SNPE/SNPE.hpp vendored Normal file
View File

@@ -0,0 +1,258 @@
//==============================================================================
//
// Copyright (c) 2015-2021 Qualcomm Technologies, Inc.
// All Rights Reserved.
// Confidential and Proprietary - Qualcomm Technologies, Inc.
//
//==============================================================================
#ifndef _SNPE_SNPE_HPP_
#define _SNPE_SNPE_HPP_
#include "DlSystem/DlOptional.hpp"
#include "DlSystem/DlVersion.hpp"
#include "DlSystem/IBufferAttributes.hpp"
#include "DlSystem/ITensor.hpp"
#include "DlSystem/TensorShape.hpp"
#include "DlSystem/TensorMap.hpp"
#include "DlSystem/String.hpp"
#include "DlSystem/StringList.hpp"
#include "DlSystem/IUserBuffer.hpp"
#include "DlSystem/UserBufferMap.hpp"
#include "DlSystem/UserMemoryMap.hpp"
#include "DlSystem/ZdlExportDefine.hpp"
namespace zdl {
namespace SNPE
{
class SnpeRuntime;
}
}
namespace zdl {
namespace DiagLog
{
class IDiagLog;
}
}
namespace zdl { namespace SNPE {
/** @addtogroup c_plus_plus_apis C++
@{ */
/**
* @brief .
*
* The SNPE interface class definition
*/
class ZDL_EXPORT SNPE final
{
public:
// keep this undocumented to be hidden in doxygen using HIDE_UNDOC_MEMBERS
explicit SNPE(std::unique_ptr<zdl::SNPE::SnpeRuntime>&& runtime) noexcept;
~SNPE();
/**
* @brief Gets the names of input tensors to the network
*
* To support multiple input scenarios, where multiple tensors are
* passed through execute() in a TensorMap, each tensor needs to
* be uniquely named. The names of tensors can be retrieved
* through this function.
*
* In the case of a single input, one name will be returned.
*
* @note Note that because the returned value is an Optional list,
* the list must be verified as boolean true value before being
* dereferenced.
*
* @return An Optional List of input tensor names.
*
* @see zdl::DlSystem::Optional
*/
zdl::DlSystem::Optional<zdl::DlSystem::StringList>
getInputTensorNames() const noexcept;
/**
* @brief Gets the names of output tensors to the network
*
* @return List of output tensor names.
*/
zdl::DlSystem::Optional<zdl::DlSystem::StringList>
getOutputTensorNames() const noexcept;
/**
* @brief Gets the name of output tensor from the input layer name
*
* @return Output tensor name.
*/
zdl::DlSystem::StringList
getOutputTensorNamesByLayerName(const char *name) const noexcept;
/**
* @brief Processes the input data and returns the output
*
* @param[in] A map of tensors that contains the input data for
* each input. The names of tensors needs to be
* matched with names retrieved through
* getInputTensorNames()
*
* @param[in,out] An empty map of tensors that will contain the output
* data of potentially multiple layers (the key
* in the map is the layer name) upon return
*
* @note output tensormap has to be empty. To forward propagate
* and get results in user-supplied tensors, use
* executeWithSuppliedOutputTensors.
*/
bool execute(const zdl::DlSystem::TensorMap &input,
zdl::DlSystem::TensorMap &output) noexcept;
/**
* @brief Processes the input data and returns the output
*
* @param[in] A single tensor contains the input data.
*
* @param[in,out] An empty map of tensors that will contain the output
* data of potentially multiple layers (the key
* in the map is the layer name) upon return
*
* @note output tensormap has to be empty.
*/
bool execute(const zdl::DlSystem::ITensor *input,
zdl::DlSystem::TensorMap &output) noexcept;
/**
* @brief Processes the input data and returns the output, using
* user-supplied buffers
*
* @param[in] A map of UserBuffers that contains the input data for
* each input. The names of UserBuffers needs to be
* matched with names retrieved through
* getInputTensorNames()
*
* @param[in,out] A map of UserBuffers that will hold the output
* data of potentially multiple layers (the key
* in the map is the UserBuffer name)
*
* @note input and output UserBuffer maps must be fully pre-populated. with
* dimensions matching what the network expects.
* For example, if there are 5 output UserBuffers they all have to be
* present in map.
*
* Caller must guarantee that for the duration of execute(), the buffer
* stored in UserBuffer would remain valid. For more detail on buffer
* ownership and lifetime requirements, please refer to zdl::DlSystem::UserBuffer
* documentation.
*/
bool execute(const zdl::DlSystem::UserBufferMap &input,
const zdl::DlSystem::UserBufferMap &output) noexcept;
/**
* @brief Regiter Client ION Buffers
* @param[in] A UserMemoryMap of virtual addresses
*
*/
bool registerIonBuffers(const zdl::DlSystem::UserMemoryMap& ionBufferMap) noexcept;
/**
* @brief Regiter Client ION Buffers
* @param[in] A StringList of ION Buffer names
*
*/
bool deregisterIonBuffers(const zdl::DlSystem::StringList& ionBufferNames) noexcept;
/**
* @brief Returns the version string embedded at model conversion
* time.
*
* @return Model version string, which is a free-form string
* supplied at the time of the conversion
*
*/
zdl::DlSystem::String getModelVersion() const noexcept;
/**
* @brief Returns the dimensions of the input data to the model in the
* form of TensorShape. The dimensions in TensorShape corresponds to
* what the tensor dimensions would need to be for an input tensor to
* the model.
*
* @param[in] layer input name.
*
* @note Note that this function only makes sense for networks
* that have a fixed input size. For networks in which the
* input size varies with each call of Execute(), this
* function should not be used.
*
* @note Because the returned type is an Optional instance, it must
* be verified as a boolean true value before being dereferenced.
*
* @return An Optional instance of TensorShape that maintains dimensions,
* matching the tensor dimensions for input to the model,
* where the last entry is the fastest varying dimension, etc.
*
* @see zdl::DlSystem::ITensor
* @see zdl::DlSystem::TensorShape
* @see zdl::DlSystem::Optional
*/
zdl::DlSystem::Optional<zdl::DlSystem::TensorShape>
getInputDimensions() const noexcept;
zdl::DlSystem::Optional<zdl::DlSystem::TensorShape>
getInputDimensions(const char *name) const noexcept;
/**
* @brief Gets the output layer(s) for the network.
*
* Note that the output layers returned by this function may be
* different than those specified when the network was created
* via the zdl::SNPE::SNPEBuilder. For example, if the
* network was created in debug mode with no explicit output
* layers specified, this will contain all layers.
*
* @note Note that because the returned value is an Optional StringList,
* the list must be verified as a boolean true value before being
* dereferenced.
*
* @return A List of output layer names.
*
* @see zdl::DlSystem::Optional
*/
zdl::DlSystem::Optional<zdl::DlSystem::StringList>
getOutputLayerNames() const noexcept;
/**
* @brief Returns attributes of buffers used to feed input tensors and receive result from output tensors.
*
* @param[in] Tensor name.
*
* @return BufferAttributes of input/output tensor named
*/
zdl::DlSystem::Optional<zdl::DlSystem::IBufferAttributes*> getInputOutputBufferAttributes(const char *name) const noexcept;
/**
* @brief .
*
* Get the diagnostic logging interface
*
* @note Note that because the returned type is an Optional instance,
* it must be verified as a boolean true value before being
* dereferenced.
*
* @see zdl::DlSystem::Optional
*/
zdl::DlSystem::Optional<zdl::DiagLog::IDiagLog*>
getDiagLogInterface() noexcept;
private:
SNPE(const SNPE&) = delete;
SNPE& operator=(const SNPE&) = delete;
std::unique_ptr<SnpeRuntime> m_Runtime;
};
/** @} */ /* end_addtogroup c_plus_plus_apis C++ */
}}
#endif

View File

@@ -0,0 +1,306 @@
//==============================================================================
//
// Copyright (c) 2017-2021 Qualcomm Technologies, Inc.
// All Rights Reserved.
// Confidential and Proprietary - Qualcomm Technologies, Inc.
//
//==============================================================================
#ifndef _SNPE_BUILDER_HPP_
#define _SNPE_BUILDER_HPP_
#include "SNPE/SNPE.hpp"
#include "DlSystem/DlEnums.hpp"
#include "DlSystem/UDLFunc.hpp"
#include "DlSystem/DlOptional.hpp"
#include "DlSystem/TensorShapeMap.hpp"
#include "DlSystem/PlatformConfig.hpp"
#include "DlSystem/IOBufferDataTypeMap.hpp"
#include "DlSystem/RuntimeList.hpp"
namespace zdl {
namespace DlContainer
{
class IDlContainer;
}
}
struct SNPEBuilderImpl;
namespace zdl { namespace SNPE {
/** @addtogroup c_plus_plus_apis C++
@{ */
/**
* The builder class for creating SNPE objects.
* Not meant to be extended.
*/
class ZDL_EXPORT SNPEBuilder final
{
private:
std::unique_ptr<::SNPEBuilderImpl> m_Impl;
public:
/**
* @brief Constructor of NeuralNetwork Builder with a supplied model.
*
* @param[in] container A container holding the model.
*
* @return A new instance of a SNPEBuilder object
* that can be used to configure and build
* an instance of SNPE.
*
*/
explicit SNPEBuilder(
zdl::DlContainer::IDlContainer* container);
~SNPEBuilder();
/**
* NOTE: DEPRECATED, MAY BE REMOVED IN THE FUTURE. Please use
* setRuntimeProcessorOrder()
*
* @brief Sets the runtime processor.
*
* @param[in] targetRuntimeProcessor The target runtime.
*
* @return The current instance of SNPEBuilder.
*/
SNPEBuilder& setRuntimeProcessor(
zdl::DlSystem::Runtime_t targetRuntimeProcessor);
/**
* @brief Requests a performance profile.
*
* @param[in] targetRuntimeProfile The target performance profile.
*
* @return The current instance of SNPEBuilder.
*/
SNPEBuilder& setPerformanceProfile(
zdl::DlSystem::PerformanceProfile_t performanceProfile);
/**
* @brief Sets the profiling level. Default profiling level for
* SNPEBuilder is off. Off and basic only applies to DSP runtime.
*
* @param[in] profilingLevel The target profiling level.
*
* @return The current instance of SNPEBuilder.
*/
SNPEBuilder& setProfilingLevel(
zdl::DlSystem::ProfilingLevel_t profilingLevel);
/**
* @brief Sets a preference for execution priority.
*
* This allows the caller to give coarse hint to SNPE runtime
* about the priority of the network. SNPE runtime is free to use
* this information to co-ordinate between different workloads
* that may or may not extend beyond SNPE.
*
* @param[in] ExecutionPriorityHint_t The target performance profile.
*
* @return The current instance of SNPEBuilder.
*/
SNPEBuilder& setExecutionPriorityHint(
zdl::DlSystem::ExecutionPriorityHint_t priority);
/**
* @brief Sets the layers that will generate output.
*
* @param[in] outputLayerNames List of layer names to
* output. An empty list will
* result in only the final
* layer of the model being
* the output layer. The list
* will be copied.
*
* @return The current instance of SNPEBuilder.
*/
SNPEBuilder& setOutputLayers(
const zdl::DlSystem::StringList& outputLayerNames);
/**
* @brief Sets the output tensor names.
*
* @param[in] outputTensorNames List of tensor names to
* output. An empty list will
* result in producing output for the final
* output tensor of the model.
* The list will be copied.
*
* @return The current instance of SNPEBuilder.
*/
SNPEBuilder& setOutputTensors(
const zdl::DlSystem::StringList& outputTensorNames);
/**
* @brief Passes in a User-defined layer.
*
* @param udlBundle Bundle of udl factory function and a cookie
*
* @return The current instance of SNPEBuilder.
*/
SNPEBuilder& setUdlBundle(
zdl::DlSystem::UDLBundle udlBundle);
/**
* @brief Sets whether this neural network will perform inference with
* input from user-supplied buffers, and write output to user-supplied
* buffers. Default behaviour is to use tensors created by
* ITensorFactory.
*
* @param[in] bufferMode Whether to use user-supplied buffer or not.
*
* @return The current instance of SNPEBuilder.
*/
SNPEBuilder& setUseUserSuppliedBuffers(
bool bufferMode);
/**
* @brief Sets the debug mode of the runtime.
*
* @param[in] debugMode This enables debug mode for the runtime. It
* does two things. For an empty
* outputLayerNames list, all layers will be
* output. It might also disable some internal
* runtime optimizations (e.g., some networks
* might be optimized by combining layers,
* etc.).
*
* @return The current instance of SNPEBuilder.
*/
SNPEBuilder& setDebugMode(
bool debugMode);
/**
* NOTE: DEPRECATED, MAY BE REMOVED IN THE FUTURE. Please use
* setRuntimeProcessorOrder()
*
* @brief Sets the mode of CPU fallback functionality.
*
* @param[in] mode This flag enables/disables the functionality
* of CPU fallback. When the CPU fallback
* functionality is enabled, layers in model that
* violates runtime constraints will run on CPU
* while the rest of non-violating layers will
* run on the chosen runtime processor. In
* disabled mode, models with layers violating
* runtime constraints will NOT run on the chosen
* runtime processor and will result in runtime
* exception. By default, the functionality is
* enabled.
*
* @return The current instance of SNPEBuilder.
*/
SNPEBuilder& setCPUFallbackMode(
bool mode);
/**
* @brief Sets network's input dimensions to enable resizing of
* the spatial dimensions of each layer for fully convolutional networks,
* and the batch dimension for all networks.
*
* @param[in] tensorShapeMap The map of input names and their new dimensions.
* The new dimensions overwrite the input dimensions
* embedded in the model and then resize each layer
* of the model. If the model contains
* layers whose dimensions cannot be resized e.g FullyConnected,
* exception will be thrown when SNPE instance is actually built.
* In general the batch dimension is always resizable.
* After resizing of layers' dimensions in model based
* on new input dimensions, the new model is revalidated
* against all runtime constraints, whose failures may
* result in cpu fallback situation.
*
* @return The current instance of SNPEBuilder.
*/
SNPEBuilder& setInputDimensions(const zdl::DlSystem::TensorShapeMap& inputDimensionsMap);
/**
* @brief Sets the mode of init caching functionality.
*
* @param[in] mode This flag enables/disables the functionality of init caching.
* When init caching functionality is enabled, a set of init caches
* will be created during network building/initialization process
* and will be added to DLC container. If such DLC container is saved
* by the user, in subsequent network building/initialization processes
* these init caches will be loaded from the DLC so as to reduce initialization time.
* In disable mode, no init caches will be added to DLC container.
*
* @return The current instance of SNPEBuilder.
*/
SNPEBuilder& setInitCacheMode(
bool cacheMode);
/**
* @brief Returns an instance of SNPE based on the current parameters.
*
* @return A new instance of a SNPE object that can be used
* to execute models or null if any errors occur.
*/
std::unique_ptr<SNPE> build() noexcept;
/**
* @brief Sets the platform configuration.
*
* @param[in] platformConfig The platform configuration.
*
* @return The current instance of SNPEBuilder.
*/
SNPEBuilder& setPlatformConfig(const zdl::DlSystem::PlatformConfig& platformConfig);
/**
* @brief Sets network's runtime order of precedence. Example:
* CPU_FLOAT32, GPU_FLOAT16, AIP_FIXED8_TF
* Note:- setRuntimeProcessor() or setCPUFallbackMode() will be silently ignored when
* setRuntimeProcessorOrder() is invoked
*
* @param[in] runtimeList The list of runtime in order of precedence
*
* @return The current instance of SNPEBuilder.
*/
SNPEBuilder& setRuntimeProcessorOrder(const zdl::DlSystem::RuntimeList& runtimeList);
/**
* @brief Sets the unconsumed tensors as output
*
* @param[in] setOutput This enables unconsumed tensors (i.e)
* outputs which are not inputs to any
* layer (basically dead ends) to be marked
* for output
*
* @return The current instance of SNPEBuilder.
*/
SNPEBuilder& setUnconsumedTensorsAsOutputs(
bool setOutput);
/**
* @brief Execution terminated when exceeding time limit.
* Only valid for dsp runtime currently.
*
* @param[in] timeout Time limit value
*
* @return The current instance of SNPEBuilder.
*/
SNPEBuilder& setTimeOut(
uint64_t timeout);
/**
* @brief Sets the datatype of the buffer.
* Only valid for dsp runtime currently.
*
* @param[in] Map of the buffer names and the datatype that needs to be set.
*
* @return The current instance of SNPEBuilder.
*/
SNPEBuilder& setBufferDataType(const zdl::DlSystem::IOBufferDataTypeMap& dataTypeMap);
};
/** @} */ /* end_addtogroup c_plus_plus_apis C++ */
}}
#endif

View File

@@ -0,0 +1,220 @@
//==============================================================================
//
// Copyright (c) 2015-2021 Qualcomm Technologies, Inc.
// All Rights Reserved.
// Confidential and Proprietary - Qualcomm Technologies, Inc.
//
//==============================================================================
#ifndef _SNPE_FACTORY_HPP_
#define _SNPE_FACTORY_HPP_
#include "SNPE/SNPE.hpp"
#include "DlSystem/DlEnums.hpp"
#include "DlSystem/UDLFunc.hpp"
#include "DlSystem/ZdlExportDefine.hpp"
#include "DlSystem/DlOptional.hpp"
namespace zdl {
namespace DlSystem
{
class ITensorFactory;
class IUserBufferFactory;
}
namespace DlContainer
{
class IDlContainer;
}
}
namespace zdl { namespace SNPE {
/** @addtogroup c_plus_plus_apis C++
@{ */
/**
* The factory class for creating SNPE objects.
*
*/
class ZDL_EXPORT SNPEFactory
{
public:
/**
* Indicates whether the supplied runtime is available on the
* current platform.
*
* @param[in] runtime The target runtime to check.
*
* @return True if the supplied runtime is available; false,
* otherwise.
*/
static bool isRuntimeAvailable(zdl::DlSystem::Runtime_t runtime);
/**
* Indicates whether the supplied runtime is available on the
* current platform.
*
* @param[in] runtime The target runtime to check.
*
* @param[in] option Extent to perform runtime available check.
*
* @return True if the supplied runtime is available; false,
* otherwise.
*/
static bool isRuntimeAvailable(zdl::DlSystem::Runtime_t runtime,
zdl::DlSystem::RuntimeCheckOption_t option);
/**
* Gets a reference to the tensor factory.
*
* @return A reference to the tensor factory.
*/
static zdl::DlSystem::ITensorFactory& getTensorFactory();
/**
* Gets a reference to the UserBuffer factory.
*
* @return A reference to the UserBuffer factory.
*/
static zdl::DlSystem::IUserBufferFactory& getUserBufferFactory();
/**
* Gets the version of the SNPE library.
*
* @return Version of the SNPE library.
*
*/
static zdl::DlSystem::Version_t getLibraryVersion();
/**
* 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.
*
* @param[in] storagePath Absolute path to a directory which SNPE may
* use for caching and other storage purposes.
*
* @return True if the supplied path was succesfully set as
* the SNPE storage location, false otherwise.
*/
static bool setSNPEStorageLocation(const char* storagePath);
/**
* @brief Register a user-defined op package with SNPE.
*
* @param[in] regLibraryPath 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
*
* @return True if successful, False otherwise.
*/
static bool addOpPackage( const std::string& regLibraryPath );
/**
* Indicates whether the OpenGL and OpenCL interoperability is supported
* on GPU platform.
*
* @return True if the OpenGL and OpenCl interop is supported; false,
* otherwise.
*/
static bool isGLCLInteropSupported();
static const char* getLastError();
/**
* 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()
* * setLogLevel() - optional - can be called anytime
* between initializeLogging & terminateLogging
* SNPE instance creation, inference, destroy
* terminateLogging().
*
* Please note, enabling logging can have performance impact.
*
* @param[in] LogLevel_t Log level (LOG_INFO, LOG_WARN, etc.).
*
* @return True if successful, False otherwise.
*/
static bool initializeLogging(const zdl::DlSystem::LogLevel_t& level);
/**
* 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()
* * setLogLevel() - optional - can be called anytime
* between initializeLogging & terminateLogging
* SNPE instance creation, inference, destroy
* terminateLogging()
*
* Please note, enabling logging can have performance impact
*
* @param[in] LogLevel_t Log level (LOG_INFO, LOG_WARN, etc.).
*
* @param[in] Path of directory to store logs.
* If path is empty, the default path is "./Log".
* For android, the log path is ignored.
*
* @return True if successful, False otherwise.
*/
static bool initializeLogging(const zdl::DlSystem::LogLevel_t& level, const std::string& logPath);
/**
* 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()
*
* @param[in] LogLevel_t Log level (LOG_INFO, LOG_WARN, etc.).
*
* @return True if successful, False otherwise.
*/
static bool setLogLevel(const zdl::DlSystem::LogLevel_t& level);
/**
* 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.
*
* @return True if successful, False otherwise.
*/
static bool terminateLogging(void);
};
/** @} */ /* end_addtogroup c_plus_plus_apis C++ */
}}
#endif

View File

@@ -0,0 +1,49 @@
//==============================================================================
//
// Copyright (c) 2019 Qualcomm Technologies, Inc.
// All Rights Reserved.
// Confidential and Proprietary - Qualcomm Technologies, Inc.
//
//==============================================================================
#ifndef PSNPE_USERBUFFERLIST_HPP
#define PSNPE_USERBUFFERLIST_HPP
#include <vector>
#include "DlSystem/UserBufferMap.hpp"
#include "DlSystem/ZdlExportDefine.hpp"
namespace zdl {
namespace PSNPE
{
/** @addtogroup c_plus_plus_apis C++
@{ */
/**
* @brief .
*
* The class for creating a UserBufferMap container.
*
*/
class ZDL_EXPORT UserBufferList final
{
public:
UserBufferList();
UserBufferList(const size_t size);
void push_back(const zdl::DlSystem::UserBufferMap &userBufferMap);
zdl::DlSystem::UserBufferMap& operator[](const size_t index);
UserBufferList& operator =(const UserBufferList &other);
size_t size() const noexcept;
size_t capacity() const noexcept;
void clear() noexcept;
~UserBufferList() = default;
private:
void swap(const UserBufferList &other);
std::vector<zdl::DlSystem::UserBufferMap> m_userBufferMaps;
};
/** @} */ /* end_addtogroup c_plus_plus_apis C++ */
} // namespace PSNPE
} // namespace zdl
#endif //PSNPE_USERBUFFERLIST_HPP