C++ API

class SimaMlsocApi

Public Functions

void setLogVerbosity(SiMaLogLevel level) noexcept

Set the logs level.

Parameters:

level – Verbosity of the logs enum SiMaLogLevel

vector<string> enumerateDeviceGuids() noexcept

Enumerates all devices and returns a lists all sima device in the system.

Parameters:

void

Return values:

Vector – of guids of all sima device in the system.

shared_ptr<SiMaDevice> openDevice(string guid) noexcept

Open sima device and starts management interface.

Parameters:

guid – GUID of the device to be opened

Return values:

Shared_ptrSiMaDevice

shared_ptr<SiMaBundle> load(const shared_ptr<SiMaDevice> simaDevicePtr, SiMaBundle bundle) noexcept

Load API takes preparsed bundle and updates simaModelPtr and simaDevicePtr. It creates and initialises data queue and starts receiver thread.

User has to call this method only if mpk deploy is done successfully and bundle is updaed with input/output tensor details, PID and data_qid.

Parameters:
  • simaDevicePtr – Shared ptr of SiMaDevice class

  • SiMaModel – Parsed Model containing input and output shapes

Return values:

shared_ptr – SiMaBundle

shared_ptr<SiMaBundle> load(const shared_ptr<SiMaDevice> simaDevicePtr, string bundlePath, SiMaBundle bundle) noexcept

@breif Load API takes preparsed bundle and mpk file and transfers mpk file to SOC. This API generates transfer_mpk and deploy_json message and sends them to SoC. Then calls load(simaDevicePtr, bundle) API. Check examples/load_unload_example1.cpp to know more on API usage.

Parameters:
  • simaDevicePtr – Shared ptr of SiMaDevice class

  • bundlePath – path to Sima mpk file

Return values:

shared_ptr – SiMaBundle

shared_ptr<SiMaBundle> load(const shared_ptr<SiMaDevice> simaDevicePtr, string bundlePath, int data_qid) noexcept

@breif Load API parses mpk.json file and extracts input and output tensors details from it. Validates input output tensors and calls load(simaDevicePtr, bundlepath, bundle) API. Check examples/load_unload_example2.cpp to know more about API usage.

Parameters:
  • simaDevicePtr – Shared ptr of SiMaDevice class

  • bundlePath – MPK file path

  • data_qid – Data queue ID

Return values:

shared_ptr – SiMaBundle

SiMaErrorCode unload(const shared_ptr<SiMaBundle> bundle) noexcept

Unload API unloads mpk from SoC by sending kill_json message and then closes the device. Cleans up all internal vectors and terminates receiver thread.

Parameters:

shared_ptr – SiMaBundle

Return values:
  • SiMaErrorCode – invalid_input

  • SiMaErrorCode – success

bool isAppActive(const shared_ptr<SiMaBundle> bundle) noexcept

Check if runtime app is active on soc.

Parameters:

shared_ptr – SiMaBundle

Return values:

bool – true if active else false

bool isAppActive(const shared_ptr<SiMaDevice> simaDevicePtr) noexcept

Check if runtime app is active on soc.

Parameters:

shared_ptr – simaDevicePtr

Return values:

bool – true if active else false

bool isDeviceOpen(const shared_ptr<SiMaDevice> simaDevicePtr) noexcept

Check if device is already open.

Parameters:

shared_ptr – simaDevicePtr

Return values:

bool – true if opened else false

SiMaErrorCode runSynchronous(const shared_ptr<SiMaBundle> bundle, const SiMaTensorList &inputTensors, const SiMaMetaData &metaData, SiMaTensorList &outputTensors) noexcept

Run synchronous inference Transfers data frames synchronously. Check examples/synchronous_example.cpp to know more about API usage.

Parameters:
  • bundle – Shared ptr of class SiMaBundle

  • inputTensors – Vector of class SiMaTensor Holds batch of input tensors

  • metaData – Vector of uint8_t

  • outputTensors – Vector of class SiMaTensor Holds batch of output tensors

Return values:
  • SiMaErrorCode – success

  • SiMaErrorCode – invalid_input

  • SiMaErrorCode – failure

  • SiMaErrorCode – retry

SiMaErrorCode runAsynchronous(const shared_ptr<SiMaBundle> bundle, const SiMaTensorList &inputTensors, const SiMaMetaData &metaData, std::function<void(SiMaTensorList, SiMaMetaData, shared_ptr<SiMaModel>, SiMaErrorCode)> callbackFunc) noexcept

Run asynchronous inference Transfers data frames asynchronously. Check examples/asynchronous_example.cpp to know more about API usage.

Parameters:
  • bundle – Shared ptr of class SiMaBundle

  • inputTensors – Vector of class SiMaTensor Holds batch of input tensors

  • metaData – Vector of uint8_t

  • function – Callback function to be called after receiving the response for the txed frame

Return values:
  • SiMaErrorCode – success

  • SiMaErrorCode – invalid_input

  • SiMaErrorCode – failure

  • SiMaErrorCode – retry

SiMaErrorCode closeDevice(const std::shared_ptr<SiMaDevice> simaDevicePtr) noexcept

Close sima device. If application on SoC is still active, API calls unload API to unload the mpk.

Parameters:

simaDevicePtr – Shared ptr of SiMaDevice class

Return values:
  • SiMaErrorCode – invalid_input

  • SiMaErrorCode – success

SiMaErrorCode resetDevice(const std::shared_ptr<SiMaDevice> simaDevicePtr) noexcept

Reset sima device.

Parameters:

simaDevicePtr – Shared ptr of SiMaDevice class

Return values:
  • SiMaErrorCode – invalid_input

  • SiMaErrorCode – success

void log(const std::shared_ptr<SiMaDevice> simaDevicePtr, const SiMaLogLevel level, const char *file, const int line, const char *function, const char *log, ...) noexcept

Logs the given log string.

Parameters:
  • simaDevicePtr – Shared ptr of SiMaDevice class

  • SiMaLogLevel – Shared ptr of SiMaDevice class

  • file – Name of file of calling function(FILE)

  • line – Line of the calling function(LINE)

  • function – Function name of the calling function(__FUNCTION_)

  • log – Log string that needs to be passed

SiMaErrorCode getLastErrorCode()

Returns last error code.

Return values:
  • SiMaErrorCode – success

  • SiMaErrorCode – invalid_input

  • SiMaErrorCode – failure

  • SiMaErrorCode – retry

  • SiMaErrorCode – overflow

SiMaErrorCode setMaxOutstandingRequests(const shared_ptr<SiMaDevice> simaDevicePtr, uint32_t maxRequests)

Set maximum outstanding i/o requests.

Parameters:
  • simaDevicePtr – Shared ptr of SiMaDevice class

  • maxRequests – Maximum number of outstanding requests. maxRequests will number of queue entries in each data queue.

Return values:
  • SiMaErrorCode – invalid_input

  • SiMaErrorCode – success

SiMaErrorCode getMaxOutstandingRequests(const shared_ptr<SiMaDevice> simaDevicePtr, uint32_t *maxRequests)

Get maximum outstanding i/o requests.

Parameters:
  • simaDevicePtr – Shared ptr of SiMaDevice class

  • maxRequests – Pointer in which maximum number of outstanding requests will stored by the API. maxRequests will number of queue entries in each data queue.

Return values:
  • SiMaErrorCode – invalid_input

  • SiMaErrorCode – success

SiMaErrorCode setRequestTimeout(const shared_ptr<SiMaDevice> simaDevicePtr, uint32_t timeout)

Set i/o request abort timeout.

Parameters:
  • simaDevicePtr – Shared ptr of SiMaDevice class

  • timeout – i/o request abort timeout. Default value for timeout is 40 seconds. Minimum value for timeout is 2 seconds. Maximum value for timeout is 0xFFFFFFFF.

Return values:
  • SiMaErrorCode – invalid_input

  • SiMaErrorCode – success

SiMaErrorCode getRequestTimeout(const shared_ptr<SiMaDevice> simaDevicePtr, uint32_t *timeout)

Get i/o request abort timeout.

Parameters:
  • simaDevicePtr – Shared ptr of SiMaDevice class

  • timeout – Pointer in which i/o request abort timeout will be stored by the API.

Return values:
  • SiMaErrorCode – invalid_input

  • SiMaErrorCode – success

SiMaErrorCode resetQueue(const shared_ptr<SiMaDevice> simaDevicePtr) noexcept

Resets specific data queue.

Parameters:

simaDevicePtr – Shared ptr of SiMaDevice class

Return values:
  • SiMaErrorCode – invalid_input

  • SiMaErrorCode – success

SimaMlsocApi(SimaMlsocApi&) = delete
void operator=(SimaMlsocApi&) = delete
SimaMlsocApi(SimaMlsocApi&&) = delete
void operator=(SimaMlsocApi&&) = delete

Public Static Functions

static shared_ptr<SimaMlsocApi> getInstance()

Get Instance of SimaMlsocApi class.

Parameters:

void

Return values:

Shared_ptr – of SimaMlsocApi class

class SiMaDevice

Contains Device details.

Public Members

unsigned long int slotNumber

Mlsoc device number

SiMaDeviceType deviceType

Sima Device Type

string guid

Mlsoc GUID

class SiMaModel : public SiMaBundle

Derived class of SiMaBundle. TODO: Obsolete this.

template<typename T>
class SiMaTensor

Contains SiMa tensor information.

Public Functions

inline SiMaTensor(std::vector<uint32_t> shape)

constructor: Allocates a shared_ptr to a malloced blob and assigns free as the deleter for the blob

Parameters:

shape – Vector of shapes, for example, if you want a tensor of (224, 224, 3) then you need to pass in a vector<uint32_t> shape{224, 224, 3}

inline void reset(std::vector<uint32_t> shape)

resets memory allocated by simatensor class with help shape vector

Parameters:

shape – vector of shapes

inline SiMaTensor(T *blob, uint32_t blob_size, std::vector<uint32_t> shape)

constructor Allocates a shared_ptr to the input blob and assigns free as the deleter for the blob side_effect: This constructor consumes the give malloced memory and will be automatically deleted when all copies of this SiMaTensor is destroyed.

Parameters:
  • blob – Pointer to a malloced memory which can be freed with free

  • blob_size – Size of the malloced memory in bytes

  • shape – Vector of shapes, for example, if you want a tensor of (224, 224, 3) then you need to pass in a vector<uint32_t> shape{224, 224, 3}

inline void reset(T *blob, uint32_t blob_size, std::vector<uint32_t> shape)

Resets memory allocated by SiMaTensor class with help memory blob, memory blob size and shape vector.

Parameters:
  • blob – Pointer to memeroy blob

  • blob_size – Memory blob size

  • shape – Vector of shapes

inline std::shared_ptr<T> getPtr() const

Get memory blob pointer.

Parameters:

void

Return values:

Shared – pointer to memory blob

inline std::vector<uint32_t> getShape() const

Get shape vector.

Parameters:

void

Return values:

Vector – of shape

inline uint32_t getSizeInBytes() const

Get size of memory blob in bytes.

Parameters:

void

Return values:

Size – of memory blob in bytes

inline uint32_t getSeqId() const

Get sequence ID of tensor.

Parameters:

void

Return values:

Sequence – ID of tensor

inline uint32_t getAppId() const

Get application ID of the tensor.

Parameters:

void

Return values:

Application – ID of the tensor

inline enum SiMaOpcode getOpCode() const

Get OpCode of the tensor.

Parameters:

void

Return values:

Opcode – indicating tensor type

inline void setSeqId(uint32_t seq_id)

Get sequence ID of tensor.

Parameters:

uint32_t – Sequence ID of the tensor

Return values:

void

inline void setAppId(uint32_t app_id)

Set application ID of the tensor.

Parameters:

uint32_t – Application ID of the tensor

Return values:

void

inline void setOpCode(enum SiMaOpcode op_code)

Set Operation code for the tensor.

Parameters:

uint32_t – Opcode of the tensor

Return values:

void