Upgrade to SNPE 1.41.0 (#2285)

* snpe 1.41.0

* cleanup

* unignored

* where is my symphony

* add snpe/dsp to release files

Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
albatross
ZwX1616 2020-10-08 17:18:01 -07:00 committed by GitHub
parent 018267dfec
commit 80515576d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
54 changed files with 1555 additions and 134 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,6 +1,6 @@
//=============================================================================
//
// Copyright (c) 2015 Qualcomm Technologies, Inc.
// Copyright (c) 2015, 2020 Qualcomm Technologies, Inc.
// All Rights Reserved.
// Confidential and Proprietary - Qualcomm Technologies, Inc.
//
@ -8,14 +8,11 @@
#ifndef __IDIAGLOG_HPP_
#define __IDIAGLOG_HPP_
#ifndef ZDL_LOGGING_EXPORT
#define ZDL_LOGGING_EXPORT __attribute__((visibility("default")))
#endif
#include <string>
#include "DiagLog/Options.hpp"
#include "DlSystem/String.hpp"
#include "DlSystem/ZdlExportDefine.hpp"
namespace zdl
{
@ -26,10 +23,10 @@ namespace DiagLog
@{ */
/// @brief .
///
///
/// Interface for controlling logging for zdl components.
class ZDL_LOGGING_EXPORT IDiagLog
class ZDL_EXPORT IDiagLog
{
public:
@ -48,7 +45,7 @@ public:
///
/// @return Diag log options object.
virtual Options getOptions() = 0;
/// @brief .
///
/// Allows for setting the log mask once diag logging has started

View File

@ -1,6 +1,6 @@
//=============================================================================
//
// Copyright (c) 2015 Qualcomm Technologies, Inc.
// Copyright (c) 2015, 2020 Qualcomm Technologies, Inc.
// All Rights Reserved.
// Confidential and Proprietary - Qualcomm Technologies, Inc.
//
@ -8,12 +8,8 @@
#ifndef __DIAGLOG_OPTIONS_HPP_
#define __DIAGLOG_OPTIONS_HPP_
#ifndef ZDL_LOGGING_EXPORT
#define ZDL_LOGGING_EXPORT __attribute__((visibility("default")))
#endif
#include <string>
#include <set>
#include "DlSystem/ZdlExportDefine.hpp"
namespace zdl
{
@ -25,7 +21,7 @@ namespace DiagLog
/// @brief .
///
/// Options for setting up diagnostic logging for zdl components.
class ZDL_LOGGING_EXPORT Options
class ZDL_EXPORT Options
{
public:
Options() :
@ -40,12 +36,12 @@ public:
}
/// @brief .
///
///
/// Enables diag logging only on the specified area mask (DNN_RUNTIME=ON | OFF)
std::string DiagLogMask;
/// @brief .
///
///
/// The path to the directory where log files will be written.
/// The path may be relative or absolute. Relative paths are interpreted
/// from the current working directory.
@ -53,15 +49,15 @@ public:
std::string LogFileDirectory;
/// @brief .
///
///
//// The name used for log files. If this value is empty then BaseName will be
/// used as the default file name.
/// Default value is "DiagLog"
std::string LogFileName;
/// @brief .
///
/// The maximum number of log files to create. If set to 0 no log rotation
///
/// The maximum number of log files to create. If set to 0 no log rotation
/// will be used and the log file name specified will be used each time, overwriting
/// any existing log file that may exist.
/// Default value is 20

View File

@ -1,6 +1,6 @@
//=============================================================================
//
// Copyright (c) 2015,2019 Qualcomm Technologies, Inc.
// Copyright (c) 2015-2020 Qualcomm Technologies, Inc.
// All Rights Reserved.
// Confidential and Proprietary - Qualcomm Technologies, Inc.
//
@ -14,7 +14,6 @@
#include <string>
#include <vector>
#include <set>
#include <stdexcept>
#include "DlSystem/ZdlExportDefine.hpp"
#include "DlSystem/String.hpp"
@ -76,7 +75,7 @@ public:
*
* @return A pointer to the initialized container
*/
ZDL_EXPORT static std::unique_ptr<IDlContainer>
static std::unique_ptr<IDlContainer>
open(const std::string &filename) noexcept;
/**
@ -86,7 +85,7 @@ public:
*
* @return A pointer to the initialized container
*/
ZDL_EXPORT static std::unique_ptr<IDlContainer>
static std::unique_ptr<IDlContainer>
open(const zdl::DlSystem::String &filename) noexcept;
/**
@ -97,7 +96,7 @@ public:
*
* @return A pointer to the initialized container
*/
ZDL_EXPORT static std::unique_ptr<IDlContainer>
static std::unique_ptr<IDlContainer>
open(const std::vector<uint8_t> &buffer) noexcept;
/**
@ -110,7 +109,7 @@ public:
*
* @return A pointer to the initialized container
*/
ZDL_EXPORT static std::unique_ptr<IDlContainer>
static std::unique_ptr<IDlContainer>
open(const uint8_t* buffer, const size_t size) noexcept;

View File

@ -1,6 +1,6 @@
//==============================================================================
//
// Copyright (c) 2014-2019 Qualcomm Technologies, Inc.
// Copyright (c) 2014-2020 Qualcomm Technologies, Inc.
// All Rights Reserved.
// Confidential and Proprietary - Qualcomm Technologies, Inc.
//
@ -128,9 +128,13 @@ enum class ProfilingLevel_t
BASIC = 1,
/// Detailed profiling
/// Collects more runtime stats in the DiagLog
/// Collects more runtime stats in the DiagLog, including per-layer statistics
/// Performance may be impacted
DETAILED = 2
DETAILED = 2,
/// Moderate profiling
/// Collects more runtime stats in the DiagLog, no per-layer statistics
MODERATE = 3
};
/**

View File

@ -1,6 +1,6 @@
//==============================================================================
//
// Copyright (c) 2016-2019 Qualcomm Technologies, Inc.
// Copyright (c) 2016-2020 Qualcomm Technologies, Inc.
// All Rights Reserved.
// Confidential and Proprietary - Qualcomm Technologies, Inc.
//
@ -79,6 +79,7 @@ enum class ZDL_EXPORT ErrorCode : uint32_t {
SNPE_DLCONTAINER_BAD_DNN_FORMAT_VERSION = 312,
SNPE_DLCONTAINER_UNKNOWN_AXIS_ANNOTATION = 313,
SNPE_DLCONTAINER_UNKNOWN_SHUFFLE_TYPE = 314,
SNPE_DLCONTAINER_TEMP_FILE_FAILURE = 315,
// Network errors
SNPE_NETWORK_EMPTY_NETWORK = 400,
@ -191,7 +192,11 @@ enum class ZDL_EXPORT ErrorCode : uint32_t {
// DlCaching errors
SNPE_DLCACHING_INVALID_METADATA = 1500,
SNPE_DLCACHING_INVALID_INITBLOB = 1501
SNPE_DLCACHING_INVALID_INITBLOB = 1501,
// Infrastructure Errors
SNPE_INFRA_CLUSTERMGR_INSTANCE_INVALID = 1600,
SNPE_INFRA_CLUSTERMGR_EXECUTE_SYNC_FAILED = 1601
};

View File

@ -1,6 +1,6 @@
//==============================================================================
//
// Copyright (c) 2016 Qualcomm Technologies, Inc.
// Copyright (c) 2016, 2020 Qualcomm Technologies, Inc.
// All Rights Reserved.
// Confidential and Proprietary - Qualcomm Technologies, Inc.
//
@ -11,6 +11,7 @@
#include <cstdio>
#include <utility>
#include <stdexcept>
#include "DlSystem/ZdlExportDefine.hpp"
@ -173,25 +174,25 @@ private:
template <typename Q = T>
typename std::enable_if<std::is_same<U, Q>::value, const Q&>::type GetReference() const noexcept {
if (!isReference()) throw std::bad_exception();
if (!isReference()) std::terminate();
return *static_cast<const Q*>(m_StoragePtr);
}
template <typename Q = T>
typename std::enable_if<std::is_same<U*, Q>::value, const Q&>::type GetReference() const noexcept {
if (!isPointer()) throw std::bad_exception();
if (!isPointer()) std::terminate();
return static_cast<const Q&>(m_StoragePtr);
}
template <typename Q = T>
typename std::enable_if<std::is_same<U, Q>::value, Q&>::type GetReference() noexcept {
if (!isReference()) throw std::bad_exception();
if (!isReference()) std::terminate();
return *m_StoragePtr;
}
template <typename Q = T>
typename std::enable_if<std::is_same<U*, Q>::value, Q&>::type GetReference() noexcept {
if (!isPointer()) throw std::bad_exception();
if (!isPointer()) std::terminate();
return m_StoragePtr;
}

View File

@ -1,6 +1,6 @@
//=============================================================================
//
// Copyright (c) 2015-2018 Qualcomm Technologies, Inc.
// Copyright (c) 2015-2020 Qualcomm Technologies, Inc.
// All Rights Reserved.
// Confidential and Proprietary - Qualcomm Technologies, Inc.
//
@ -14,7 +14,6 @@
#include "TensorShape.hpp"
#include "ZdlExportDefine.hpp"
#include <memory>
#include <vector>
#include <ostream>
#include <cmath>

View File

@ -1,6 +1,6 @@
//=============================================================================
//
// Copyright (c) 2015 Qualcomm Technologies, Inc.
// Copyright (c) 2015-2020 Qualcomm Technologies, Inc.
// All Rights Reserved.
// Confidential and Proprietary - Qualcomm Technologies, Inc.
//
@ -13,7 +13,6 @@
#include <memory>
#include <iterator>
#include <vector>
namespace DlSystem
{

View File

@ -1,6 +1,6 @@
//==============================================================================
//
// Copyright (c) 2017-2019 Qualcomm Technologies, Inc.
// Copyright (c) 2017-2020 Qualcomm Technologies, Inc.
// All Rights Reserved.
// Confidential and Proprietary - Qualcomm Technologies, Inc.
//
@ -160,6 +160,14 @@ public:
m_StepExactly0(stepFor0),
m_QuantizedStepSize(stepSize) {};
UserBufferEncodingTf8(const zdl::DlSystem::UserBufferEncoding &ubEncoding) : UserBufferEncodingUnsigned8Bit(ubEncoding.getElementType()){
const zdl::DlSystem::UserBufferEncodingTf8* ubEncodingTf8
= dynamic_cast <const zdl::DlSystem::UserBufferEncodingTf8*> (&ubEncoding);
if (ubEncodingTf8) {
m_StepExactly0 = ubEncodingTf8->getStepExactly0();
m_QuantizedStepSize = ubEncodingTf8->getQuantizedStepSize();
}
}
/**
* @brief Sets the step value that represents 0
@ -246,6 +254,17 @@ public:
bitWidth(bWidth),
m_StepExactly0(stepFor0),
m_QuantizedStepSize(stepSize){};
UserBufferEncodingTfN(const zdl::DlSystem::UserBufferEncoding &ubEncoding) : UserBufferEncoding(ubEncoding.getElementType()){
const zdl::DlSystem::UserBufferEncodingTfN* ubEncodingTfN
= dynamic_cast <const zdl::DlSystem::UserBufferEncodingTfN*> (&ubEncoding);
if (ubEncodingTfN) {
m_StepExactly0 = ubEncodingTfN->getStepExactly0();
m_QuantizedStepSize = ubEncodingTfN->getQuantizedStepSize();
bitWidth = ubEncodingTfN->bitWidth;
}
}
size_t getElementSize() const noexcept override;
/**
* @brief Sets the step value that represents 0
@ -283,7 +302,7 @@ public:
* @return Minimum representable floating point value
*/
float getMin() const {
return m_QuantizedStepSize * (0 - (double)m_StepExactly0);
return static_cast<float>(m_QuantizedStepSize * (0 - (double)m_StepExactly0));
}
/**
@ -293,7 +312,7 @@ public:
* @return Maximum representable floating point value
*/
float getMax() const{
return m_QuantizedStepSize * (pow(2,bitWidth)-1 - (double)m_StepExactly0);
return static_cast<float>(m_QuantizedStepSize * (pow(2,bitWidth)-1 - (double)m_StepExactly0));
};
/**

View File

@ -1,6 +1,6 @@
//=============================================================================
//
// Copyright (c) 2017 Qualcomm Technologies, Inc.
// Copyright (c) 2017, 2020 Qualcomm Technologies, Inc.
// All Rights Reserved.
// Confidential and Proprietary - Qualcomm Technologies, Inc.
//
@ -12,10 +12,7 @@
#include <cstdio>
#include <string>
#include <ostream>
#ifndef ZDL_EXPORT
#define ZDL_EXPORT __attribute__((visibility("default")))
#endif
#include "DlSystem/ZdlExportDefine.hpp"
namespace zdl
{
@ -105,4 +102,3 @@ ZDL_EXPORT std::ostream& operator<<(std::ostream& os, const String& str) noexcep
/** @} */ /* end_addtogroup c_plus_plus_apis C++ */
#endif // PLATFORM_STANDARD_STRING_HPP

View File

@ -1,6 +1,6 @@
//=============================================================================
//
// Copyright (c) 2017 Qualcomm Technologies, Inc.
// Copyright (c) 2017-2020 Qualcomm Technologies, Inc.
// All Rights Reserved.
// Confidential and Proprietary - Qualcomm Technologies, Inc.
//
@ -8,7 +8,6 @@
#include <initializer_list>
#include <cstdio>
#include <memory>
#include <vector>
#include "ZdlExportDefine.hpp"
#include "DlSystem/TensorShape.hpp"
#include "DlSystem/StringList.hpp"

View File

@ -1,16 +1,13 @@
//=============================================================================
//
// Copyright (c) 2015 Qualcomm Technologies, Inc.
// Copyright (c) 2015, 2020 Qualcomm Technologies, Inc.
// All Rights Reserved.
// Confidential and Proprietary - Qualcomm Technologies, Inc.
//
//=============================================================================
#ifndef _ZDL_EXPORT_DEFINE_HPP_
#define _ZDL_EXPORT_DEFINE_HPP_
#pragma once
#ifndef ZDL_EXPORT
#define ZDL_EXPORT __attribute__((visibility("default")))
#endif
#define ZDL_EXPORT
#endif

View File

@ -0,0 +1,93 @@
// =============================================================================
//
// Copyright (c) 2018-2019 Qualcomm Technologies, Inc.
// All Rights Reserved.
// Confidential and Proprietary - Qualcomm Technologies, Inc.
//
// =============================================================================
#ifndef SNPE_PLATFORMVALIDATOR_HPP
#define SNPE_PLATFORMVALIDATOR_HPP
#include "DlSystem/DlEnums.hpp"
#include "DlSystem/DlMacros.hpp"
SNPE_DISABLE_WARNINGS("-Wdelete-non-virtual-dtor","-Wdelete-non-virtual-dtor")
#include <string>
#include <memory>
SNPE_ENABLE_WARNINGS
namespace zdl
{
namespace SNPE
{
class PlatformValidator;
class IPlatformValidatorRuntime;
}
}
/** @addtogroup c_plus_plus_apis C++
@{ */
/**
* The class for checking SNPE compatibility/capability of a device.
*
*/
class zdl::SNPE::PlatformValidator
{
public:
/**
* @brief Default Constructor of the PlatformValidator Class
*
* @return A new instance of a PlatformValidator object
* that can be used to check the SNPE compatibility
* of a device
*/
PlatformValidator();
~PlatformValidator();
/**
* @brief Sets the runtime processor for compatibility check
*
* @return Void
*/
void setRuntime(zdl::DlSystem::Runtime_t runtime);
/**
* @brief Checks if the Runtime prerequisites for SNPE are available.
*
* @return True if the Runtime prerequisites are available, else false.
*/
bool isRuntimeAvailable();
/**
* @brief Returns the core version for the Runtime selected.
*
* @return String which contains the actual core version value
*/
std::string getCoreVersion();
/**
* @brief Returns the library version for the Runtime selected.
*
* @return String which contains the actual lib version value
*/
std::string getLibVersion();
/**
* @brief Runs a small program on the runtime and Checks if SNPE is supported for Runtime.
*
* @return If True, the device is ready for SNPE execution, else not.
*/
bool runtimeCheck();
private:
zdl::DlSystem::Runtime_t m_runtimeType;
std::unique_ptr<IPlatformValidatorRuntime> m_platformValidatorRuntime;
};
/** @} */ /* end_addtogroup c_plus_plus_apis C++ */
#endif //SNPE_PLATFORMVALIDATOR_HPP

View File

@ -1,6 +1,6 @@
// =============================================================================
//
// Copyright (c) 2019 Qualcomm Technologies, Inc.
// Copyright (c) 2019-2020 Qualcomm Technologies, Inc.
// All Rights Reserved.
// Confidential and Proprietary - Qualcomm Technologies, Inc.
//
@ -10,7 +10,6 @@
#define PSNPE_HPP
#include <cstdlib>
#include <unordered_map>
#include <functional>
#include "SNPE/SNPE.hpp"
#include "DlSystem/UserBufferMap.hpp"
@ -73,22 +72,40 @@ struct ZDL_EXPORT InputOutputAsyncCallbackParam
};
};
/**
* @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 BulkSNPE configuration
* A structure PSNPE configuration
*
*/
struct ZDL_EXPORT BuildConfig final
{
BuildMode buildMode = BuildMode::SERIAL;
zdl::DlContainer::IDlContainer* container;
zdl::DlSystem::StringList outputBufferNames;
RuntimeConfigList runtimeConfigList;
OutputAsyncCallbackFunc outputCallback;
InputOutputAsyncCallbackFunc inputOutputCallback;
InputOutputTransmissionMode inputOutputTransmissionMode = InputOutputTransmissionMode::sync;
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
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;
};
/**
* @brief .
@ -130,7 +147,8 @@ class ZDL_EXPORT PSNPE final
*
* @return True if executed successfully; flase, otherwise.
*/
bool executeInputOutputAsync(const ApplicationBufferMap& inputMap, size_t dataIndex, bool isTF8buff) noexcept;
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.
*
@ -161,6 +179,8 @@ class ZDL_EXPORT PSNPE final
*/
const zdl::DlSystem::TensorShape getBufferAttributesDims(const char *name) const noexcept;
zdl::DlSystem::Optional<zdl::DlSystem::IBufferAttributes*> getInputOutputBufferAttributes(const char *name) const noexcept;
private:
PSNPE(const PSNPE&) = delete;
PSNPE& operator=(const PSNPE&) = delete;

View File

@ -1,6 +1,6 @@
//==============================================================================
//
// Copyright (c) 2019 Qualcomm Technologies, Inc.
// Copyright (c) 2019-2020 Qualcomm Technologies, Inc.
// All Rights Reserved.
// Confidential and Proprietary - Qualcomm Technologies, Inc.
//
@ -9,80 +9,77 @@
#define PSNPE_RUNTIMECONFIGLIST_HPP
#include <iostream>
#include "DlSystem/DlEnums.hpp"
#include "DlContainer/IDlContainer.hpp"
#include "DlSystem/ZdlExportDefine.hpp"
#include "DlSystem/DlEnums.hpp"
#include "DlSystem/RuntimeList.hpp"
#include "DlSystem/TensorShapeMap.hpp"
#include "DlSystem/ZdlExportDefine.hpp"
namespace zdl {
namespace PSNPE
{
namespace PSNPE {
/** @addtogroup c_plus_plus_apis C++
@{ */
/**
* @brief .
*
* The structure for configuring a BulkSNPE runtime
*
*/
* @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;
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;
}
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;
return *this;
}
~RuntimeConfig() {}
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;
* @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
} // namespace PSNPE
} // namespace zdl
#endif // PSNPE_RUNTIMECONFIGLIST_HPP

View File

@ -1,6 +1,6 @@
//==============================================================================
//
// Copyright (c) 2015-2017 Qualcomm Technologies, Inc.
// Copyright (c) 2015-2020 Qualcomm Technologies, Inc.
// All Rights Reserved.
// Confidential and Proprietary - Qualcomm Technologies, Inc.
//
@ -9,9 +9,6 @@
#ifndef _SNPE_SNPE_HPP_
#define _SNPE_SNPE_HPP_
#include <map>
#include <vector>
#include "DlSystem/DlOptional.hpp"
#include "DlSystem/DlVersion.hpp"
#include "DlSystem/IBufferAttributes.hpp"

View File

@ -0,0 +1,483 @@
//==============================================================================
//
// Copyright (c) 2019-2020 Qualcomm Technologies, Inc.
// All Rights Reserved.
// Confidential and Proprietary - Qualcomm Technologies, Inc.
//
//==============================================================================
#ifndef SNPE_UDO_BASE_H
#define SNPE_UDO_BASE_H
#include <stdint.h>
// Provide values to use for API version.
#define API_VERSION_MAJOR 1
#define API_VERSION_MINOR 5
#define API_VERSION_TEENY 0
/** @addtogroup c_plus_plus_apis C++
@{ */
// Defines a bitmask of enum values.
typedef uint32_t SnpeUdo_Bitmask_t;
// A string of characters, rather than an array of bytes.
// Assumed to be UTF-8.
typedef char* SnpeUdo_String_t;
// The maximum allowable length of a SnpeUdo_String_t in bytes,
// including null terminator. SNPE will truncate strings longer
// than this.
#define SNPE_UDO_MAX_STRING_SIZE 1024
/**
* An enum which holds the various error types.
* The error types are divided to classes :
* 0 - 99 : generic errors
* 100 - 200 : errors related to configuration
*
*/
typedef enum
{
/// No Error
SNPE_UDO_NO_ERROR = 0,
/// Unsupported value for core type
SNPE_UDO_WRONG_CORE = 1,
/// Invalid attribute/argument passed into UDO API
SNPE_UDO_INVALID_ARGUMENT = 2,
/// Unsupported feature error
SNPE_UDO_UNSUPPORTED_FEATURE = 3,
/// Error relating to memory allocation
SNPE_UDO_MEM_ALLOC_ERROR = 4,
/* Configuration Specific errors */
/// No op with given attributes available in library
SNPE_UDO_WRONG_OPERATION = 100,
/// Unsupported value for core type in UDO configuration
SNPE_UDO_WRONG_CORE_TYPE = 101,
/// Wrong number of params in UDO definition
SNPE_UDO_WRONG_NUM_OF_PARAMS = 102,
/// Wrong number of dimensions for tensor(s) in UDO definition
SNPE_UDO_WRONG_NUM_OF_DIMENSIONS = 103,
/// Wrong number of input tensors in UDO definition
SNPE_UDO_WRONG_NUM_OF_INPUTS = 104,
/// Wrong number of output tensors in UDO definition
SNPE_UDO_WRONG_NUM_OF_OUTPUTS = 105,
SNPE_UDO_PROGRAM_CACHE_NOT_FOUND = 106,
SNPE_UDO_UNKNOWN_ERROR = 0xFFFFFFFF
} SnpeUdo_ErrorType_t;
/**
* An enum which holds the various data types.
* Designed to be used as single values or combined into a bitfield parameter
* (0x1, 0x2, 0x4, etc)
* \n FIXED_XX types are targeted for data in tensors.
* \n UINT / INT types are targeted for scalar params
*/
typedef enum
{
/// data type: 16-bit floating point
SNPE_UDO_DATATYPE_FLOAT_16 = 0x01,
/// data type: 32-bit floating point
SNPE_UDO_DATATYPE_FLOAT_32 = 0x02,
/// data type: 4-bit fixed point
SNPE_UDO_DATATYPE_FIXED_4 = 0x04,
/// data type: 8-bit fixed point
SNPE_UDO_DATATYPE_FIXED_8 = 0x08,
/// data type: 16-bit fixed point
SNPE_UDO_DATATYPE_FIXED_16 = 0x10,
/// data type: 32-bit fixed point
SNPE_UDO_DATATYPE_FIXED_32 = 0x20,
/// data type: 8-bit unsigned integer
SNPE_UDO_DATATYPE_UINT_8 = 0x100,
/// data type: 16-bit unsigned integer
SNPE_UDO_DATATYPE_UINT_16 = 0x200,
/// data type: 32-bit unsigned integer
SNPE_UDO_DATATYPE_UINT_32 = 0x400,
/// data type: 8-bit signed integer
SNPE_UDO_DATATYPE_INT_8 = 0x1000,
/// data type: 16-bit signed integer
SNPE_UDO_DATATYPE_INT_16 = 0x2000,
/// data type: 32-bit signed integer
SNPE_UDO_DATATYPE_INT_32 = 0x4000,
SNPE_UDO_DATATYPE_LAST = 0xFFFFFFFF
} SnpeUdo_DataType_t;
/**
* An enum which holds the various layouts.
* Designed to be used as single values or combined into a bitfield parameter
* (0x1, 0x2, 0x4, etc)
*/
typedef enum
{
/// data layout (4D): NHWC (batch-height-width-channel)
SNPE_UDO_LAYOUT_NHWC = 0x01,
/// data layout (4D): NCHW (batch-channel-height-width)
SNPE_UDO_LAYOUT_NCHW = 0x02,
/// data layout (5D): NDHWC (batch-dimension-height-width-channel)
SNPE_UDO_LAYOUT_NDHWC = 0x04,
SNPE_UDO_LAYOUT_GPU_OPTIMAL1 = 0x08,
SNPE_UDO_LAYOUT_GPU_OPTIMAL2 = 0x10,
SNPE_UDO_LAYOUT_DSP_OPTIMAL1 = 0x11,
SNPE_UDO_LAYOUT_DSP_OPTIMAL2 = 0x12,
// Indicates no data will be allocated for this tensor.
// Used to specify optional inputs/outputs positionally.
SNPE_UDO_LAYOUT_NULL = 0x13,
SNPE_UDO_LAYOUT_LAST = 0xFFFFFFFF
} SnpeUdo_TensorLayout_t;
/**
* An enum which holds the UDO library Core type .
* Designed to be used as single values or combined into a bitfield parameter
* (0x1, 0x2, 0x4, etc)
*/
typedef enum
{
/// Library target IP Core is undefined
SNPE_UDO_CORETYPE_UNDEFINED = 0x00,
/// Library target IP Core is CPU
SNPE_UDO_CORETYPE_CPU = 0x01,
/// Library target IP Core is GPU
SNPE_UDO_CORETYPE_GPU = 0x02,
/// Library target IP Core is DSP
SNPE_UDO_CORETYPE_DSP = 0x04,
SNPE_UDO_CORETYPE_LAST = 0xFFFFFFFF
} SnpeUdo_CoreType_t;
/**
* An enum to specify the parameter type : Scalar or Tensor
*/
typedef enum
{
/// UDO static param type: scalar
SNPE_UDO_PARAMTYPE_SCALAR,
/// UDO static param type: string
SNPE_UDO_PARAMTYPE_STRING,
/// UDO static param type: tensor
SNPE_UDO_PARAMTYPE_TENSOR,
SNPE_UDO_PARAMTYPE_LAST = 0xFFFFFFFF
} SnpeUdo_ParamType_t;
/**
* An enum to specify quantization type
*/
typedef enum
{
/// Tensor Quantization type: NONE. Signifies unquantized tensor data
SNPE_UDO_QUANTIZATION_NONE,
/// Tensor Quantization type: Tensorflow-style
SNPE_UDO_QUANTIZATION_TF,
SNPE_UDO_QUANTIZATION_QMN,
SNPE_UDO_QUANTIZATION_LAST = 0xFFFFFFFF
} SnpeUdo_QuantizationType_t;
/**
* @brief A struct which is used to provide a version number using 3 values : major, minor, teeny
*
*/
typedef struct
{
/// version field: major - for backward-incompatible changes
uint32_t major;
/// version field: minor - for backward-compatible feature updates
uint32_t minor;
/// version field: teeny - for minor bug-fixes and clean-up
uint32_t teeny;
} SnpeUdo_Version_t;
/**
* @brief A struct returned from version query, contains the Library version and API version
*
*/
typedef struct
{
/// Version of UDO library. Controlled by users
SnpeUdo_Version_t libVersion;
/// Version of SNPE UDO API used in compiling library. Determined by SNPE
SnpeUdo_Version_t apiVersion;
} SnpeUdo_LibVersion_t;
/**
* @brief A union to hold the value of a generic type. Allows defining a parameter struct
* in a generic way, with a "value" location that holds the data regardless of the type.
*
*/
typedef union
{
/// value type: float
float floatValue;
/// value type: unsigned 32-bit integer
uint32_t uint32Value;
/// value type: signed 32-bit integer
int32_t int32Value;
/// value type: unsigned 16-bit integer
uint16_t uint16Value;
/// value type: signed 16-bit integer
int16_t int16Value;
/// value type: unsigned 8-bit integer
uint8_t uint8Value;
/// value type: signed 8-bit integer
int8_t int8Value;
} SnpeUdo_Value_t;
/**
* @brief A struct which defines a scalar parameter : name, data type, and union of values
*
*/
typedef struct
{
/// The parameter data type : float, int, etc.
SnpeUdo_DataType_t dataType;
/// a union of specified type which holds the data
SnpeUdo_Value_t dataValue;
} SnpeUdo_ScalarParam_t;
/**
* @brief A struct which defines the quantization parameters in case of Tensorflow style quantization
*
*/
typedef struct
{
/// minimum value of the quantization range of data
float minValue;
/// maximum value of the quantization range of data
float maxValue;
} SnpeUdo_TFQuantize_t;
/**
* @brief A struct which defines the quantization type, and union of supported quantization structs
*
*/
typedef struct
{
/// quantization type (only TF-style currently supported)
SnpeUdo_QuantizationType_t quantizeType;
union
{
/// TF-style min-max quantization ranges
SnpeUdo_TFQuantize_t TFParams;
};
} SnpeUdo_QuantizeParams_t;
/**
* @brief A struct which defines the datatype associated with a specified core-type
* This should be used to denote the datatypes for a single tensor info, depending
* on the intended execution core.
*
*/
typedef struct
{
/// The IP Core
SnpeUdo_CoreType_t coreType;
/// The associated datatype for this coreType
SnpeUdo_DataType_t dataType;
} SnpeUdo_PerCoreDatatype_t;
/**
* @brief A struct which defines a tensor parameter : name, data type, layout, quantization, more.
* Also holds a pointer to the tensor data.
*
*/
typedef struct
{
/// The maximum allowable dimensions of the tensor. The memory held in
/// _tensorData_ is guaranteed to be large enough for this.
uint32_t* maxDimensions;
/// The current dimensions of the tensor. An operation may modify the current
/// dimensions of its output, to indicate cases where the output has been
/// "resized".
/// Note that for static parameters, the current and max dimensions must
/// match.
uint32_t* currDimensions;
/// Quantization params applicable to the tensor. Currently only supports
/// Tensorflow quantization style.
SnpeUdo_QuantizeParams_t quantizeParams;
/// Number of dimensions to the tensor: 3D, 4D, etc.
uint32_t tensorRank;
/// The parameter data type: float, int, etc.
SnpeUdo_DataType_t dataType;
/// The tensor layout type: NCHW, NHWC, etc.
SnpeUdo_TensorLayout_t layout;
/// Opaque pointer to tensor data. User may be required to re-interpret the pointer
/// based on core-specific definitions.
void* tensorData;
} SnpeUdo_TensorParam_t;
/**
* @brief A struct which defines tensor information for activation tensors only
*
* It describes an activation tensor object using its name, the intended layout and the datatype
* it will take depending on the intended runtime core. The repeated field indicates that
* that the tensor info describes several input/output activation tensors, which all share the
* aforementioned properties.
*/
typedef struct
{
/// The tensor name
SnpeUdo_String_t tensorName;
/// The tensor layout type: NCHW, NHWC, etc.
SnpeUdo_TensorLayout_t layout;
/// The per core datatype: {SNPE_UDO_DATATYPE, SNPE_UDO_CORE_TYPE}
SnpeUdo_PerCoreDatatype_t* perCoreDatatype;
/// A boolean field indicating that this tensorinfo will be repeated e.x for ops such as Concat or Split
bool repeated;
} SnpeUdo_TensorInfo_t;
/**
* @brief struct which defines a UDO parameter - a union of scalar, tensor and string parameters
*
*/
typedef struct
{
/// Type is scalar or tensor
SnpeUdo_ParamType_t paramType;
/// The param name, for example : "offset", "activation_type"
SnpeUdo_String_t paramName;
union
{
/// scalar param value
SnpeUdo_ScalarParam_t scalarParam;
/// tensor param value
SnpeUdo_TensorParam_t tensorParam;
/// string param value
SnpeUdo_String_t stringParam;
};
} SnpeUdo_Param_t;
/**
* @brief A struct which defines Operation information which is specific for IP core (CPU, GPU, DSP ...)
*
*/
typedef struct
{
/// The IP Core
SnpeUdo_CoreType_t udoCoreType;
/// Bitmask, defines supported internal calculation types (like FLOAT_32, etc)
/// Based on SnpeUdo_DataType
SnpeUdo_Bitmask_t operationCalculationTypes;
} SnpeUdo_OpCoreInfo_t;
/**
* @brief A struct which defines the common and core-specific Operation information
*
*/
typedef struct
{
/// Operation type
SnpeUdo_String_t operationType;
/// A bitmask describing which IP Cores (CPU, GPU, DSP ...) support this operation
/// Translated based on SnpeUdo_CoreType
SnpeUdo_Bitmask_t supportedByCores;
/// Number of static parameters defined by the op
uint32_t numOfStaticParams;
/// Array of static parameters. Can be scalar or tensor params
SnpeUdo_Param_t* staticParams;
/// Number of input tensors this op receives
uint32_t numOfInputs;
/// Array of input tensor names to this operation
SnpeUdo_String_t* inputNames;
/// Number of output tensors this op receives
uint32_t numOfOutputs;
/// Array of output tensor names to this operation
SnpeUdo_String_t* outputNames;
/// Number of cores that the op can execute on
uint32_t numOfCoreInfo;
/// Array of per-core information entries
SnpeUdo_OpCoreInfo_t* opPerCoreInfo;
/// Array of input tensor infos for this operation
SnpeUdo_TensorInfo_t* inputInfos;
/// Array of output tensor infos for this operation
SnpeUdo_TensorInfo_t* outputInfos;
} SnpeUdo_OperationInfo_t;
/**
* @brief A struct which provides the implementation library info : type, name
*
*/
typedef struct
{
/// Defines the IP Core that this implementation library is targeting
SnpeUdo_CoreType_t udoCoreType;
/// library name. will be looked at in the standard library path
SnpeUdo_String_t libraryName;
} SnpeUdo_LibraryInfo_t;
/**
* @brief A struct returned by the registration library and contains information on the UDO package :
* name, operations, libraries, etc.
*
*/
typedef struct
{
/// A string containing the package name
SnpeUdo_String_t packageName;
/// A bitmask describing supported IP cores (CPU, GPU, DSP ...)
/// Translated based on SnpeUdo_CoreType
SnpeUdo_Bitmask_t supportedCoreTypes;
/// The number of implementation libraries in the package
uint32_t numOfImplementationLib;
/// Array of implementation libraries names/types
SnpeUdo_LibraryInfo_t* implementationLib;
/// A string containing all operation types separated by space
SnpeUdo_String_t operationsString;
/// Number of supported operations
uint32_t numOfOperations;
/// Array of Operation info structs. Each entry describes one
/// Operation (name, params, inputs, outputs)
SnpeUdo_OperationInfo_t* operationsInfo;
} SnpeUdo_RegInfo_t;
/**
* @brief A struct returned by the implementation library and contains information on the
* specific library: name, IP Core, operations, etc.
*
*/
typedef struct
{
/// Defines the IP Core that this implementation library is targeting
SnpeUdo_CoreType_t udoCoreType;
/// A string containing the package name
SnpeUdo_String_t packageName;
/// A string containing all operation types separated by space
SnpeUdo_String_t operationsString;
/// Number of supported operations
uint32_t numOfOperations;
} SnpeUdo_ImpInfo_t;
/**
* @brief This struct defines an operation. It is used for validation
* or creation of an operation.
* In case of using it for creation, the static params which are tensors
* contain pointers to the real data (weights, for example), and input/output
* tensors also include pointers to the buffers used.
*/
typedef struct
{
/// The IP Core that the operation is defined for - CPU, GPU, DSP...
SnpeUdo_CoreType_t udoCoreType;
/// Operation type
SnpeUdo_String_t operationType;
/// The number of static parameters provided in the staticParams array.
/// this number has to match the number provided by the UDO Registration library information
uint32_t numOfStaticParams;
/// Array of static parameters
SnpeUdo_Param_t* staticParams;
/// The number of input parameters provided in inputs array.
/// this number has to match the number provided by the UDO Registration library information
uint32_t numOfInputs;
/// Array of input tensors, providing layout, data type, sizes, etc
/// When used to create an operation, also contains the initial location of the data
SnpeUdo_TensorParam_t* inputs;
/// The number of output parameters provided in inputs array.
/// this number has to match the number provided by the UDO Registration library information
uint32_t numOfOutputs;
/// Array of output tensors, providing layout, data type, sizes, etc
/// When used to create an operation, also contains the initial location of the data
SnpeUdo_TensorParam_t* outputs;
} SnpeUdo_OpDefinition_t;
/** @} */ /* end_addtogroup c_plus_plus_apis C++ */
#endif //SNPE_UDO_BASE_H

View File

@ -0,0 +1,323 @@
//==============================================================================
//
// Copyright (c) 2019-2020 Qualcomm Technologies, Inc.
// All Rights Reserved.
// Confidential and Proprietary - Qualcomm Technologies, Inc.
//
//==============================================================================
#ifndef SNPE_UDO_IMPL_H
#define SNPE_UDO_IMPL_H
#include <stdbool.h>
#include "SnpeUdo/UdoShared.h"
#ifdef __cplusplus
extern "C"
{
#endif
/** @addtogroup c_plus_plus_apis C++
@{ */
typedef struct _SnpeUdo_OpFactory_t* SnpeUdo_OpFactory_t;
typedef struct _SnpeUdo_Operation_t* SnpeUdo_Operation_t;
/**
* @brief Initialize the shared library's data structures. Calling any other
* library function before this one will result in error.
*
* @param[in] globalInfrastructure Global core-specific infrastructure to be
* used by operations created in this library. The definition and
* semantics of this object will be defined in the corresponding
* implementation header for the core type.
* @return Error code
*/
SnpeUdo_ErrorType_t
SnpeUdo_initImplLibrary(void* globalInfrastructure);
typedef SnpeUdo_ErrorType_t
(*SnpeUdo_InitImplLibraryFunction_t)(void*);
/**
* @brief A function to query the API version of the UDO implementation library.
* The function populates a SnpeUdo_LibVersion_t struct, which contains a SnpeUdo_Version_t
* struct for API version and library version.
*
* @param[in, out] version A pointer to struct which contains major, minor, teeny information for
* library and api versions.
*
* @return Error code
*/
SnpeUdo_ErrorType_t
SnpeUdo_getImplVersion(SnpeUdo_LibVersion_t** version);
typedef SnpeUdo_ErrorType_t
(*SnpeUdo_getImplVersion_t)(SnpeUdo_LibVersion_t** version);
/**
* @brief Release the shared library's data structures, and invalidate any
* handles returned by the library. The behavior of any outstanding
* asynchronous calls made to this library when this function is called
* are undefined. All library functions (except SnpeUdo_initImplLibrary) will
* return an error after this function has been successfully called.
*
* It should be possible to call SnpeUdo_initImplLibrary after calling this
* function, and re-initialize the library.
*
* @return Error code
*/
SnpeUdo_ErrorType_t
SnpeUdo_terminateImplLibrary(void);
typedef SnpeUdo_ErrorType_t
(*SnpeUdo_TerminateImplLibraryFunction_t)(void);
/**
* @brief A function to query info on the UDO implementation library.
* The function populates a structure which contains information about
* operations that are part of this library
*
* @param[in, out] implementationInfo A pointer to struct which contains information
* on the operations
*
* @return error code
*
*/
SnpeUdo_ErrorType_t
SnpeUdo_getImpInfo(SnpeUdo_ImpInfo_t** implementationInfo);
typedef SnpeUdo_ErrorType_t
(*SnpeUdo_GetImpInfoFunction_t)(SnpeUdo_ImpInfo_t** implementationInfo);
/**
* @brief A function to create an operation factory.
* The function receives the operation type, and an array of static parameters,
* and returns operation factory handler
*
* @param[in] udoCoreType The Core type to create the operation on. An error will
* be returned if this does not match the core type of the library.
*
* @param[in] perFactoryInfrastructure CreateOpFactory infrastructure appropriate to this
* core type. The definition and semantics of this object will be defined
* in the corresponding implementation header for the core type.
*
* @param[in] operationType A string containing Operation type. for example "MY_CONV"
*
* @param[in] numOfStaticParams The number of static parameters.
*
* @param[in] staticParams Array of static parameters
*
* @param[in,out] opFactory Handler to Operation Factory, to be used when creating operations
*
* @return Error Code
*/
SnpeUdo_ErrorType_t
SnpeUdo_createOpFactory(SnpeUdo_CoreType_t udoCoreType,
void* perFactoryInfrastructure,
SnpeUdo_String_t operationType,
uint32_t numOfStaticParams,
SnpeUdo_Param_t* staticParams,
SnpeUdo_OpFactory_t* opFactory);
typedef SnpeUdo_ErrorType_t
(*SnpeUdo_CreateOpFactoryFunction_t)(SnpeUdo_CoreType_t,
void*,
SnpeUdo_String_t,
uint32_t,
SnpeUdo_Param_t*,
SnpeUdo_OpFactory_t*);
/**
* @brief A function to release the resources allocated for an operation factory
* created by this library.
*
* @param[in] factory The operation factory to release. Upon success this handle will be invalidated.
*
* @return Error Code
*/
SnpeUdo_ErrorType_t
SnpeUdo_releaseOpFactory(SnpeUdo_OpFactory_t opFactory);
typedef SnpeUdo_ErrorType_t
(*SnpeUdo_ReleaseOpFactoryFunction_t)(SnpeUdo_OpFactory_t);
/**
* @brief A function to create an operation from the factory.
* The function receives array of inputs and array of outputs, and creates an operation
* instance, returning the operation instance handler.
*
* @param[in] opFactory OpFactory instance containing the parameters for this operation.
*
* @param[in] perOpInfrastructure Per-Op infrastructure for this operation. The definition
* and semantics of this object will be defined in the implementation header
* appropriate to this core type.
*
* @param[in] numOfInputs The number of input tensors this operation will receive.
*
* @param[in] inputs Array of input tensors, providing both the sizes and initial
* location of the data.
*
* @param[in] numOfOutputs Number of output tensors this operation will produce.
*
* @param[in] outputs Array of output tensors, providing both the sizes and
* initial location of the data.
*
* @param[in,out] operation Handle for newly created operation instance.
*
* @return Error Code
*/
SnpeUdo_ErrorType_t
SnpeUdo_createOperation(SnpeUdo_OpFactory_t opFactory,
void* perOpInfrastructure,
uint32_t numOfInputs,
SnpeUdo_TensorParam_t* inputs,
uint32_t numOfOutputs,
SnpeUdo_TensorParam_t* outputs,
SnpeUdo_Operation_t* operation);
typedef SnpeUdo_ErrorType_t
(*SnpeUdo_CreateOperationFunction_t)(SnpeUdo_OpFactory_t,
void*,
uint32_t,
SnpeUdo_TensorParam_t*,
uint32_t,
SnpeUdo_TensorParam_t*,
SnpeUdo_Operation_t*);
/**
* @brief A pointer to notification function.
*
* The notification function supports the non-blocking (e.g. asynchronous) execution use-case.
* In case an "executeUdoOp" function is called with "blocking" set to zero, and a
* notify function, this function will be called by the implementation library at the
* end of execution. The implementation library will pass the notify function the ID
* that was provided to it when "executeUdoOp" was called.
*
* @param[in] ID 32-bit value, that was provided to executeUdoOp by the calling entity.
* Can be used to track the notifications, in case of multiple execute calls issued.
*
* @return Error code
*
*/
typedef SnpeUdo_ErrorType_t
(*SnpeUdo_ExternalNotify_t)(const uint32_t ID);
/**
* @brief Operation execution function.
*
* Calling this function will run the operation on set of inputs, generating a set of outputs.
* The call can be blocking (synchronous) or non-blocking (asynchronous). To support the
* non-blocking mode, the calling entity can pass an ID and a notification function.
* At the end of the execution this notification function would be called, passing it the ID.
* <b> NOTE: Asynchronous execution mode not supported in this release. </b>
*
* @param[in] operation handle to the operation on which execute is invoked
* @param[in] blocking flag to indicate execution mode.
* If set, execution is blocking,
* e.g SnpeUdo_executeOp call does not return until execution is done.
* If not set, SnpeUdo_executeOp returns immediately, and the
* library will call the notification function (if set) when execution is done.
*
* @param[in] ID 32-bit number that can be used by the calling entity to track execution
* in case of non-blocking execution.
* For example, it can be a sequence number, increased by one on each call.
*
* @param[in] notifyFunc Pointer to notification function. if the pointer is set, and execution is
* non-blocking, the library will call this function at end of execution,
* passing the number provided as ID
*
* @return Error code
*
*/
SnpeUdo_ErrorType_t
SnpeUdo_executeOp(SnpeUdo_Operation_t operation,
bool blocking,
const uint32_t ID,
SnpeUdo_ExternalNotify_t notifyFunc);
typedef SnpeUdo_ErrorType_t
(*SnpeUdo_ExecuteOpFunction_t)(SnpeUdo_Operation_t,
bool,
const uint32_t,
SnpeUdo_ExternalNotify_t);
/**
* @brief A function to setting the inputs & outputs. part of SnpeUdo_Operation struct,
* returned from creation of a new operation instance.
* <b> Not supported in this release. </b>
*
* This function allows the calling entity to change some of the inputs and outputs
* between calls to execute.
* Note that the change is limited to changing the <b> pointer </b> to the tensor data only.
* Any other change may be rejected by the implementation library, causing
* immediate invalidation of the operation instance
*
* @param[in] operation Operation on which IO tensors are set
*
* @param[in] inputs array of tensor parameters. The calling entity may provide a subset of the
* operation inputs, providing only those that it wants to change.
*
* @param[in] outputs array of tensor parameters. The calling entity may provide a subset of the
* operation outputs, providing only those that it wants to change.
*
* @return Error code
*
*/
SnpeUdo_ErrorType_t
SnpeUdo_setOpIO(SnpeUdo_Operation_t operation,
SnpeUdo_TensorParam_t* inputs,
SnpeUdo_TensorParam_t* outputs);
typedef SnpeUdo_ErrorType_t
(*SnpeUdo_SetOpIOFunction_t)(SnpeUdo_Operation_t,
SnpeUdo_TensorParam_t*,
SnpeUdo_TensorParam_t*);
/**
* @brief A function to return execution times.
*
* This function can be called to query the operation execution times on the IP core
* on which the operation is run. The time is provided in micro-seconds
*
* @param[in] operation Handle to operation whose execution time is being profiled
*
* @param[in,out] executionTime pointer to a uint32 value.This function writes the operation
* execution time in usec into this value.
*
* @return Error code
*
*/
SnpeUdo_ErrorType_t
SnpeUdo_profileOp(SnpeUdo_Operation_t operation, uint32_t *executionTime);
typedef SnpeUdo_ErrorType_t
(*SnpeUdo_ProfileOpFunction_t)(SnpeUdo_Operation_t, uint32_t*);
/**
* @brief A function to release the operation instance
* \n When it is called, the implementation library needs to release all resources
* allocated for this operation instance.
* \n Note that all function pointers which are part of SnpeUdo_Operation become
* <b> invalid </b> once releaseUdoOp call returns.
*
* @param[in] operation Handle to operation to be released
* @return Error code
*
*/
SnpeUdo_ErrorType_t
SnpeUdo_releaseOp(SnpeUdo_Operation_t operation);
typedef SnpeUdo_ErrorType_t
(*SnpeUdo_ReleaseOpFunction_t)(SnpeUdo_Operation_t);
/** @} */ /* end_addtogroup c_plus_plus_apis C++ */
#ifdef __cplusplus
} // extern "C"
#endif
#endif //SNPE_UDO_IMPL_H

View File

@ -0,0 +1,44 @@
//==============================================================================
//
// Copyright (c) 2019-2020 Qualcomm Technologies, Inc.
// All Rights Reserved.
// Confidential and Proprietary - Qualcomm Technologies, Inc.
//
//==============================================================================
// Header to be used by a CPU UDO Implementation library
#ifndef SNPE_UDO_IMPL_CPU_H
#define SNPE_UDO_IMPL_CPU_H
#include <stdio.h>
/** @addtogroup c_plus_plus_apis C++
@{ */
/**
* @brief This struct provides the infrastructure needed by a developer of
* CPU UDO Implementation library.
*
* The framework/runtime which loads the CPU UDO implementation library provides
* this infrastructure data to the loaded library at the time of op factory creation.
* as an opaque pointer. It contains hooks for the UDO library to invoke supported
* functionality at the time of execution
*
* @param getData function pointer to retrieve raw tensor data from opaque pointer
* passed into the UDO when creating an instance.
* @param getDataSize function pointer to retrieve tensor data size from opaque pointer
*/
typedef struct
{
/// function pointer to retrieve raw tensor data from opaque pointer
/// passed into the UDO when creating an instance.
float* (*getData)(void*);
/// function pointer to retrieve tensor data size from opaque pointer
size_t (*getDataSize) (void*);
} SnpeUdo_CpuInfrastructure_t;
/** @} */ /* end_addtogroup c_plus_plus_apis C++ */
#endif // SNPE_UDO_IMPL_CPU_H

View File

@ -0,0 +1,187 @@
//==============================================================================
//
// Copyright (c) 2019-2020 Qualcomm Technologies, Inc.
// All Rights Reserved.
// Confidential and Proprietary - Qualcomm Technologies, Inc.
//
//==============================================================================
//==============================================================================
/*
* THIS HEADER FILE IS COPIED FROM HEXAGON-NN PROJECT
*
*/
//==============================================================================
// Header to be used by a DSP Hexnn UDO Implementation library
#ifndef SNPE_UDO_IMPL_DSP_H
#define SNPE_UDO_IMPL_DSP_H
#include <stdio.h>
#include "SnpeUdo/UdoImpl.h"
/** @addtogroup c_plus_plus_apis C++
@{ */
/**
* @brief A function to validate that a set of params is supported by an operation
* This function is HexNN specific, use case is when registration library is not in use.
* Optional function.
*
* @param[in] operationType Operation type
* @param[in] numOfStaticParams Number of static params defined by the op
* @param[in] staticParams Array of static params to the op
* @return Error code, indicating if the operation can be created on this set of configuration or not.
*
*/
SnpeUdo_ErrorType_t
SnpeUdo_validateOperation (SnpeUdo_String_t operationType,
uint32_t numOfStaticParams,
const SnpeUdo_Param_t* staticParams);
typedef SnpeUdo_ErrorType_t (*SnpeUdo_ValidateOperationFunction_t) (SnpeUdo_String_t,
uint32_t,
const SnpeUdo_Param_t*);
// enum used for indicating input/outout tensor data layouts on DSP, plain vs d32
typedef enum {
SNPE_UDO_DSP_TENSOR_LAYOUT_PLAIN,
SNPE_UDO_DSP_TENSOR_LAYOUT_D32
} SnpeUdo_HexNNTensorLayout_t;
/**
* @brief A function to query numbers of inputs and outputs,
* quantization type of each input and each output as arrays,
* and data layout (plain vs d32) of each input and each output as arrays
* of an operation.
* inputsQuantTypes and inputsLayouts should point to arrays of size numOfInputs
* outputsQuantTypes and outputsLayouts should point to arrays of size numOfOutputs
*
* Note: inputsLayouts and inputsLayouts can point to NULL, in this case, it is
* assumed all inputs and/or outputs have plain data layouts, i.e. no D32
*
* @param[in] operationType Operation type
* @param[in] numOfStaticParams Number of static params defined by the op
* @param[in] staticParams Array of static params to the op
* @param[in,out] numOfInputs Number of input tensors to the op
* @param[in,out] inputsQuantTypes Array of Quantization info for each input tensor
* @param[in,out] inputsLayouts Array of layout type for each input tensor
* @param[in,out] numOfOutputs Number of output tensors to the op
* @param[in,out] outputsQuantTypes Array of Quantization info for each output tensor
* @param[in,out] outputsLayouts Array of layout type for each output tensor
* @return error code, indicating status of query
*/
SnpeUdo_ErrorType_t
SnpeUdo_queryOperation (SnpeUdo_String_t operationType,
uint32_t numOfStaticParams,
const SnpeUdo_Param_t* staticParams,
uint32_t* numOfInputs,
SnpeUdo_QuantizationType_t** inputsQuantTypes,
SnpeUdo_HexNNTensorLayout_t** inputsLayouts,
uint32_t* numOfOutputs,
SnpeUdo_QuantizationType_t** outputsQuantTypes,
SnpeUdo_HexNNTensorLayout_t** outputsLayouts);
typedef SnpeUdo_ErrorType_t (*SnpeUdo_QueryOperationFunction_t) (SnpeUdo_String_t,
uint32_t,
const SnpeUdo_Param_t*,
uint32_t*,
SnpeUdo_QuantizationType_t**,
SnpeUdo_HexNNTensorLayout_t**,
uint32_t*,
SnpeUdo_QuantizationType_t**,
SnpeUdo_HexNNTensorLayout_t**);
// Global infrastructure functions supported by Hexagon-NN v2
typedef void (*workerThread_t) (void* perOpInfrastructure, void* userData);
typedef int (*udoSetOutputTensorSize_t) (void* perOpInfrastructure, uint32_t outIdx, uint32_t size);
typedef int (*udoGetInputD32Paddings_t) (void* perOpInfrastructure, uint32_t inIdx,
uint32_t* heightPadBefore, uint32_t* heightPadAfter,
uint32_t* widthPadBefore, uint32_t* widthPadAfter,
uint32_t* depthPadBefore, uint32_t* depthPadAfter);
typedef int (*udoSetOutputD32ShapeSizePaddings_t) (void* perOpInfrastructure, uint32_t outIdx,
uint32_t batch,
uint32_t height, uint32_t heightPadBefore, uint32_t heightPadAfter,
uint32_t width, uint32_t widthPadBefore, uint32_t widthPadAfter,
uint32_t depth, uint32_t depthPadBefore, uint32_t depthPadAfter,
SnpeUdo_DataType_t dataType);
typedef void* (*udoMemalign_t) (size_t n, size_t size);
typedef void* (*udoMalloc_t) (size_t size);
typedef void* (*udoCalloc_t) (size_t n, size_t size);
typedef void (*udoFree_t) (void* ptr);
typedef uint32_t (*udoGetVtcmSize_t) (void* perOpInfrastructure);
typedef void* (*udoGetVtcmPtr_t) (void* perOpInfrastructure);
typedef uint32_t (*udoVtcmIsReal_t) (void* perOpInfrastructure);
typedef void (*udoRunWorkerThreads_t) (void* perOpInfrastructure, uint32_t nThreads, workerThread_t w, void* userData);
typedef struct hexNNv2GlobalInfra {
udoSetOutputTensorSize_t udoSetOutputTensorSize;
udoGetInputD32Paddings_t udoGetInputD32Paddings;
udoSetOutputD32ShapeSizePaddings_t udoSetOutputD32ShapeSizePaddings;
udoMemalign_t udoMemalign;
udoMalloc_t udoMalloc;
udoCalloc_t udoCalloc;
udoFree_t udoFree;
udoGetVtcmSize_t udoGetVtcmSize;
udoGetVtcmPtr_t udoGetVtcmPtr;
udoVtcmIsReal_t udoVtcmIsReal;
udoRunWorkerThreads_t udoRunWorkerThreads;
} SnpeUdo_HexNNv2GlobalInfra_t;
// hexnn types
typedef enum hexnnInfraType {
UDO_INFRA_HEXNN_V2,
UDO_INFRA_HEXNN_V3 // reserved, do not use
} SnpeUdo_HexNNInfraType_t;
/**
* @brief Infrastructures needed by a developer of DSP Hexnn UDO Implementation library.
*
* The framework/runtime which loads the Hexnn UDO implementation library provides
* this infrastructure to the loaded library by calling "SnpeUdo_initImplLibrary"
* function, and passing it (cast to void*). The Hexnn UDO library is expected
* to cast it back to this structure.
*
*/
typedef struct dspGlobalInfrastructure {
SnpeUdo_Version_t dspInfraVersion; // api version
SnpeUdo_HexNNInfraType_t infraType;
SnpeUdo_HexNNv2GlobalInfra_t hexNNv2Infra;
} SnpeUdo_DspGlobalInfrastructure_t;
/**
* hexnn v2 per op factory infrastructure
*
* The framework/runtime passes per op factory infrastructure as a void pointer
* to HexNN UDO implementation library by calling function "SnpeUdo_createOpFactory".
* UDO implementation library is expected to cast it back to this following struct.
*
*/
typedef struct hexnnv2OpFactoryInfra {
unsigned long graphId;
} SnpeUdo_HexNNv2OpFactoryInfra_t;
/**
* hexnn v2 per operation infrastructure
*
* The framework/runtime passes per operation infrastructure as a void pointer
* to HexNN UDO implementation library by calling function "SnpeUdo_createOperation".
* UDO implementation library is expected to cast it to the following type and save it.
*
* This is needed to be passed back into some functions from global infrastructure.
*
*/
typedef void* SnpeUdo_HexNNv2OpInfra_t;
/** @} */ /* end_addtogroup c_plus_plus_apis C++ */
#endif // SNPE_UDO_IMPL_DSP_H

View File

@ -0,0 +1,112 @@
//==============================================================================
//
// Copyright (c) 2019-2020 Qualcomm Technologies, Inc.
// All Rights Reserved.
// Confidential and Proprietary - Qualcomm Technologies, Inc.
//
//==============================================================================
// Header to be used by a GPU UDO Implementation library
#ifndef SNPE_UDO_IMPL_GPU_H
#define SNPE_UDO_IMPL_GPU_H
#include "CL/cl.h"
#include "SnpeUdo/UdoBase.h"
/** @addtogroup c_plus_plus_apis C++
@{ */
/**
* This header defines version 0.0.0 of the GPU UDO Infrastructure.
* It defines the interpretation of the global and per-OpFactory infrastructure pointers
* as well as the interpretation of tensorData pointers.
*
* The per-Operation infrastructure pointer is defined to be null, and should not be used.
*
* The SnpeUdoTensorParam_t struct below provides the interpretation for
* the tensorData opaque pointer for SnpeUdoTensorParams representing inputs or outputs.
*
* The tensorData opaque pointer populated in SnpeUdoScalarParam_t structs should be interpreted
* as a host-readable data pointer.
*
*/
/**
* @brief Function to retrieve opencl program from Program Cache repository.
* @param programCache is opaque pointer to Program Cache repository provided by
* SNPE GPU UDO runtime.
* @param programName is name associated with opencl program for UDO.
* @param program is pointer to opencl program which will be populated with
* valid opencl program if found in Program Cache repository.
* @return SnpeUdo_ErrorType_t is error type returned. SNPE_UDO_NO_ERROR is returned
* on success.
*/
typedef SnpeUdo_ErrorType_t (*SnpeUdo_getProgram_t)
(void* programCache, const char* programName, cl_program* program);
/**
* @brief Function to store valid opencl program in Program Cache repository.
* @param programCache is opaque pointer to Program Cache repository provided by
* SNPE GPU UDO runtime.
* @param programName is name associated with opencl program for UDO.
* @param program is valid opencl program after program is built.
* @return SnpeUdo_ErrorType_t is error type returned. SNPE_UDO_NO_ERROR is returned
* on success.
* */
typedef SnpeUdo_ErrorType_t (*SnpeUdo_storeProgram_t)
(void* programCache, const char * programName, cl_program program);
/**
* @brief Global Infrastructure Definition for GPU UDO Implementations.
*/
typedef struct {
// Infrastructure definition version. This header is 0.0.0
SnpeUdo_Version_t gpuInfraVersion;
SnpeUdo_getProgram_t SnpeUdo_getProgram;
SnpeUdo_storeProgram_t SnpeUdo_storeProgram;
} SnpeUdo_GpuInfrastructure_t;
/**
* @brief Per OpFactory Infrastructure Definition for GPU UDO Implementations.
* @note This version of the infrastructure definition guarantees that the same
* Per OpFactory infrastructure pointer will be provided to all OpFactories
* in the same network.
*/
typedef struct
{
cl_context context;
cl_command_queue commandQueue;
void* programCache;
} SnpeUdo_GpuOpFactoryInfrastructure_t;
/**
* @brief Opaque tensorData definition for operation inputs and outputs.
*
* The following is a list of all SnpeUdoTensorLayout_t values supported by the
* GPU UDO implementation, and how the parameters of the struct should be
* interpreted in each case:
*
* SNPE_UDO_LAYOUT_NHWC:
* mem shall be single-element array, pointing to a cl buffer memory object.
* the dimensions of this object match the dimensions specified in the encompassing
* SnpeUdoTensorParam_t's currDimensions.
*
* memCount shall be 1.
*
* paddedRank and paddedDimensions are undefined and shall be ignored by the UDO
* implementation.
*
*/
typedef struct
{
cl_mem* mem;
uint32_t memCount;
uint32_t paddedRank;
uint32_t* paddedDimensions;
} SnpeUdo_GpuTensorData_t;
/** @} */ /* end_addtogroup c_plus_plus_apis C++ */
#endif // SNPE_UDO_IMPL_GPU_H

View File

@ -0,0 +1,108 @@
//==============================================================================
//
// Copyright (c) 2019-2020 Qualcomm Technologies, Inc.
// All Rights Reserved.
// Confidential and Proprietary - Qualcomm Technologies, Inc.
//
//==============================================================================
#ifndef SNPE_UDO_REG_H
#define SNPE_UDO_REG_H
#include "SnpeUdo/UdoShared.h"
#ifdef __cplusplus
extern "C"
{
#endif
/** @addtogroup c_plus_plus_apis C++
@{ */
/**
* @brief Initialize the shared library's data structures. Calling any other
* library function before this one will result in an error being returned.
*
* @return Error code
*/
SnpeUdo_ErrorType_t
SnpeUdo_initRegLibrary(void);
typedef SnpeUdo_ErrorType_t
(*SnpeUdo_InitRegLibraryFunction_t)(void);
/**
* @brief A function to query the API version of the UDO registration library.
* The function populates a SnpeUdo_LibVersion_t struct, which contains a SnpeUdo_Version_t
* struct for API version and library version.
*
* @param[in, out] version A pointer to struct which contains major, minor, teeny information for
* library and api versions.
*
* @return Error code
*/
SnpeUdo_ErrorType_t
SnpeUdo_getRegLibraryVersion(SnpeUdo_LibVersion_t** version);
typedef SnpeUdo_ErrorType_t
(*SnpeUdo_getRegLibraryVersion_t)(SnpeUdo_LibVersion_t** version);
/**
* @brief Release the shared library's data structures, and invalidate any
* handles returned by the library. The behavior of any outstanding
* asynchronous calls made to this library when this function is called
* are undefined. All library functions (except SnpeUdo_InitRegLibrary) will
* return an error after this function has been successfully called.
*
* It should be possible to call SnpeUdo_InitRegLibrary after calling this
* function, and re-initialize the library.
*
* @return Error code
*/
SnpeUdo_ErrorType_t
SnpeUdo_terminateRegLibrary(void);
typedef SnpeUdo_ErrorType_t
(*SnpeUdo_TerminateRegLibraryFunction_t)(void);
/**
* @brief A function to query the info on the UDO set.
* The function populates a structure which contains information about
* the package and operations contained in it.
*
* @param[in, out] registrationInfo A struct which contains information on the set of UDOs
*
* @return Error code
*
*/
SnpeUdo_ErrorType_t
SnpeUdo_getRegInfo(SnpeUdo_RegInfo_t** registrationInfo);
typedef SnpeUdo_ErrorType_t
(*SnpeUdo_GetRegInfoFunction_t)(SnpeUdo_RegInfo_t** registrationInfo);
/**
* @brief A function to validate that a set of params is supported by an operation
* The function receives an operation definition struct, and returns if this configuration is
* supported (e.g. if an operation can be created using this configuration)
*
* @param[in] opDefinition A struct of SnpeUdo_OpDefinition type, containing the information needed to
* validate that an operation can be created with this configuration.
*
* @return Error code, indicating is the operation can be created on this set or not.
*
*/
SnpeUdo_ErrorType_t
SnpeUdo_validateOperation(SnpeUdo_OpDefinition_t* opDefinition);
typedef SnpeUdo_ErrorType_t
(*SnpeUdo_ValidateOperationFunction_t)(SnpeUdo_OpDefinition_t* opDefinition);
/** @} */ /* end_addtogroup c_plus_plus_apis C++ */
#ifdef __cplusplus
} // extern "C"
#endif
#endif //SNPE_UDO_REG_H

View File

@ -0,0 +1,46 @@
//==============================================================================
//
// Copyright (c) 2019-2020 Qualcomm Technologies, Inc.
// All Rights Reserved.
// Confidential and Proprietary - Qualcomm Technologies, Inc.
//
//==============================================================================
#ifndef SNPE_UDO_SHARED_H
#define SNPE_UDO_SHARED_H
#include "SnpeUdo/UdoBase.h"
#ifdef __cplusplus
extern "C"
{
#endif
/** @addtogroup c_plus_plus_apis C++
@{ */
/**
* @brief A function to return the various versions as they relate to the UDO
* The function returns a struct containing the the following:
* libVersion: the version of the implementation library compiled for the UDO. Set by user
* apiVersion: the version of the UDO API used in compiling the implementation library.
* Set by SNPE
*
* @param[in, out] version A pointer to Version struct of type SnpeUdo_LibVersion_t
*
* @return Error code
*
*/
SnpeUdo_ErrorType_t
SnpeUdo_getVersion (SnpeUdo_LibVersion_t** version);
typedef SnpeUdo_ErrorType_t
(*SnpeUdo_GetVersionFunction_t) (SnpeUdo_LibVersion_t** version);
#ifdef __cplusplus
} // extern "C"
#endif
/** @} */ /* end_addtogroup c_plus_plus_apis C++ */
#endif // SNPE_UDO_SHARED_H

Binary file not shown.

View File

@ -434,6 +434,7 @@ phonelibs/libyuv/lib/**
phonelibs/snpe/include/**
phonelibs/snpe/aarch64**
phonelibs/snpe/dsp**
phonelibs/android_frameworks_native/**
phonelibs/android_hardware_libhardware/**

View File

@ -3,11 +3,10 @@
if [ -d /system ]; then
if [ -f /TICI ]; then # QCOM2
export LD_LIBRARY_PATH="/usr/lib/aarch64-linux-gnu:/data/pythonpath/phonelibs/snpe/larch64:$LD_LIBRARY_PATH"
export ADSP_LIBRARY_PATH="/data/pythonpath/phonelibs/snpe/larch64/"
else # QCOM
export LD_LIBRARY_PATH="/data/pythonpath/phonelibs/snpe/aarch64/:$LD_LIBRARY_PATH"
export ADSP_LIBRARY_PATH="/data/pythonpath/phonelibs/snpe/aarch64/"
fi
export ADSP_LIBRARY_PATH="/data/pythonpath/phonelibs/snpe/dsp/"
else
# PC
export LD_LIBRARY_PATH="$HOME/openpilot/phonelibs/snpe/x86_64-linux-clang:/openpilot/phonelibs/snpe/x86_64:$HOME/openpilot/phonelibs/snpe/x86_64:$LD_LIBRARY_PATH"