PSOC E8XXGP Device Support Library

| PSOC E8XXGP Device Support Library

Functions
Functions
PDL API Reference » NNLITE HW Accelerator (NNLITE)

## General Description

## Functions
cy_en_nnlite_status_t | Cy_NNLite_Init (NNLITE_Type *nnlite, cy_nnlite_context_t *context)
| nnlite driver init function, validate context structure and set driver to init state More...
cy_en_nnlite_status_t | Cy_NNLite_DeInit (NNLITE_Type *nnlite, cy_nnlite_context_t *context)
| nnlite driver deinit function check's for pending or ongoing operation and set driver state to deinit More...
cy_en_nnlite_status_t | Cy_NNLite_Start (NNLITE_Type *nnlite, cy_nnlite_context_t *context)
| nnlite start operation, streamer should should be configured before calling this function, this function will write to start bit in CMD MEMIO More...
cy_en_nnlite_status_t | Cy_NNLite_Stop (NNLITE_Type *nnlite, cy_nnlite_context_t *context)
| nnlite stop/abort operation, can be used to stop/abort current operation or to reset all configuration, API write abort in CMD MEMIO which will reset all the registers More...
cy_en_nnlite_status_t | Cy_NNLite_ActivationStreamerCfg (NNLITE_Type *nnlite, cy_nnlite_context_t *context, uint32_t filterWidth, uint32_t filterHeight, uint32_t activationRepeats, uint32_t inputWidth, uint32_t inputHeight, uint32_t inputChannel, int16_t padVal, uint8_t padWidth, uint8_t padHeight, uint8_t strideCol, uint8_t strideRow, int32_t inputOffset)
| nnlite activation streamer configuration set, API will configure parameters for activation streamer More...
cy_en_nnlite_status_t | Cy_NNLite_WeightStreamerCfg (NNLITE_Type *nnlite, cy_nnlite_context_t *context, uint32_t weightPerNeuron, int32_t filterOffset)
| nnlite weight streamer configuration set, API will configure offset for weight streamer and weights per neuron parameter* More...
cy_en_nnlite_status_t | Cy_NNLite_OutputStreamerCfg (NNLITE_Type *nnlite, cy_nnlite_context_t *context, cy_nnlite_clipping_t clipping, int32_t outputOffset, uint32_t outputWidth, uint32_t outputHeight, uint32_t outputChannels)
| nnlite out streamer configuration set, API will set clipping mask, offset, width, height and channel for output streamer More...
cy_en_nnlite_status_t | Cy_NNLite_StreamerBaseAddrSet (NNLITE_Type *nnlite, cy_en_nnlite_streamer_id_t strmId, const void *baseAddr)
| set nnlite streamer base address More...
static cy_en_nnlite_status_t | Cy_NNLite_PipelineConfig (NNLITE_Type *nnlite, cy_en_nnlite_op_t opType, cy_en_nnlite_mode_t fetchMode, bool repeatWeights, bool biasEn, bool sparsityEn, cy_en_nnlite_output_rescaling_t outputRescaling, cy_en_nnlite_input_rescaling_t inputRescaling, cy_en_nnlite_fused_activation_t actType, cy_en_nnlite_activation_size_t inputSize, cy_en_nnlite_activation_size_t weightSize, cy_en_nnlite_output_size_t outputSize)
| Set NNLiteV2 pipeline configuration. More...
cy_en_nnlite_status_t | Cy_NNLite_SetPrePostScaling (NNLITE_Type *nnlite, float preScalingFactor, const float *postScalingFactors)
| Set pre/post arithmetic/accumulation scaling. More...
cy_en_nnlite_status_t | Cy_NNLite_SetInterpolationParam (NNLITE_Type *nnlite, uint32_t segment, float gradient)
| set interpolation parameter More...
cy_en_nnlite_status_t | Cy_NNLite_FFTCfg (NNLITE_Type *nnlite, cy_nnlite_context_t *context, void *ppBuf0, void *ppBuf1, unsigned int fftStages)
| Configure NNLite for Q1.15 complex FFT. More...
cy_en_nnlite_status_t | Cy_NNLite_SetInterruptMask (NNLITE_Type *nnlite, uint32_t intrMask)
| nnlite set interrupt mask, available interrupt are operation STATUS Done, MEM Fetch Error different streamers, Output Saturation interrupt More...
cy_en_nnlite_status_t | Cy_NNLite_DatawireTriggerEnable (NNLITE_Type *nnlite, bool trigEn)
| nnlite set datawire trigger control, trigger datawire for next layer when trigger is 1 More...
cy_en_nnlite_status_t | Cy_NNLite_GetOperationStatus (NNLITE_Type *nnlite, uint32_t *opStatus)
| nnlite get nnlite operation status, can be used to poll operation status More...
cy_en_nnlite_status_t | Cy_NNLite_GetInterruptStatus (NNLITE_Type *nnlite, uint32_t *intrStatus)
| get nnlite interrupt status More...
cy_en_nnlite_status_t | Cy_NNLite_GetInterruptMask (NNLITE_Type *nnlite, uint32_t *intrMask)
| get nnlite interrupt mask More...
cy_en_nnlite_status_t | Cy_NNLite_GetDriverState (NNLITE_Type *nnlite, cy_nnlite_context_t *context, cy_en_nnlite_state_t *nnliteState)
| get nnlite driver state More...
cy_en_nnlite_status_t | Cy_NNLite_InterruptClear (NNLITE_Type *nnlite, uint32_t intrMask)
| clear nnlite interrupts More...
void | Cy_NNLite_InterruptHandler (NNLITE_Type *nnlite, cy_nnlite_context_t *context)
| nnlite ISR handler More...
cy_en_nnlite_status_t | Cy_NNLite_WaitForCompletion (NNLITE_Type *nnlite, cy_nnlite_context_t *context)
| wait for completion of operation in busy loop More...

## Function Documentation

## ◆ Cy_NNLite_Init()

cy_en_nnlite_status_t Cy_NNLite_Init | ( | NNLITE_Type * | nnlite,
|  | cy_nnlite_context_t * | context
| ) |  |

nnlite driver init function, validate context structure and set driver to init state

Parameters

  [in] | nnlite | base pointer of NNLite Register Map.
  [in] | context | pointer to the driver context structure.

Return values

  Refer | cy_en_nnlite_status_t

[in] context pointer to the driver context structure

## ◆ Cy_NNLite_DeInit()

cy_en_nnlite_status_t Cy_NNLite_DeInit | ( | NNLITE_Type * | nnlite,
|  | cy_nnlite_context_t * | context
| ) |  |

nnlite driver deinit function check's for pending or ongoing operation and set driver state to deinit

Parameters

  [in] | nnlite | base pointer of NNLIte register map.
  [in] | context | pointer to the driver context structure.

Return values

  Refer | cy_en_nnlite_status_t

[in] nnlite base pointer of register map.

[in] context pointer to the driver context structure

## ◆ Cy_NNLite_Start()

cy_en_nnlite_status_t Cy_NNLite_Start | ( | NNLITE_Type * | nnlite,
|  | cy_nnlite_context_t * | context
| ) |  |

nnlite start operation, streamer should should be configured before calling this function, this function will write to start bit in CMD MEMIO

Parameters

  [in] | nnlite | base pointer of NNLIte register map.
  [in] | context | pointer to the driver context structure.

Return values

  Refer | cy_en_nnlite_status_t

[in] nnlite base pointer of register map.

[in] context pointer to the driver context structure

## ◆ Cy_NNLite_Stop()

cy_en_nnlite_status_t Cy_NNLite_Stop | ( | NNLITE_Type * | nnlite,
|  | cy_nnlite_context_t * | context
| ) |  |

nnlite stop/abort operation, can be used to stop/abort current operation or to reset all configuration, API write abort in CMD MEMIO which will reset all the registers

Parameters

  [in] | nnlite | base pointer of NNLIte register map.
  [in] | context | pointer to the driver context structure.

Return values

  Refer | cy_en_nnlite_status_t

[in] nnlite base pointer of register map.

[in] context pointer to the driver context structure

## ◆ Cy_NNLite_ActivationStreamerCfg()

cy_en_nnlite_status_t Cy_NNLite_ActivationStreamerCfg | ( | NNLITE_Type * | nnlite,
|  | cy_nnlite_context_t * | context,
|  | uint32_t | filterWidth,
|  | uint32_t | filterHeight,
|  | uint32_t | activationRepeats,
|  | uint32_t | inputWidth,
|  | uint32_t | inputHeight,
|  | uint32_t | inputChannel,
|  | int16_t | padVal,
|  | uint8_t | padWidth,
|  | uint8_t | padHeight,
|  | uint8_t | strideCol,
|  | uint8_t | strideRow,
|  | int32_t | inputOffset
| ) |  |

nnlite activation streamer configuration set, API will configure parameters for activation streamer

Parameters

  [in] | nnlite | base pointer of NNLIte register map.
  [in] | context | pointer to the driver context structure
  [in] | filterWidth | filter width
  [in] | filterHeight | fFilter height
  [in] | activationRepeats | activation streamer repeat count (how often each "kernel footprint" needs to be fetched)
  [in] | inputWidth | input activation Width
  [in] | inputHeight | input activation Height
  [in] | inputChannel | input activation channels
  [in] | inputChannel | channel depth multiplier (depthwise convolution only)
  [in] | padVal | padding value
  [in] | padHeight | padding Height
  [in] | padWidth | padding Width
  [in] | strideCol | Stride column
  [in] | strideRow | Stride rows
  [in] | inputOffset | input offset value

Return values

  Refer | cy_en_nnlite_status_t

[in] nnlite base pointer of register map.

[in] context pointer to the driver context structure

[in] filterWidth filter width

[in] filterHeight filter height

[in] activationRepeats activation streamer repeat count

[in] inputWidth input activation Width

[in] inputHeight input activation Height

[in] inputChannel input activation channels

[in] padVal padding value

[in] padHeight padding Height

[in] padWidth padding Width

[in] strideCol Stride column

[in] strideRow Stride rows

[in] inputOffset input offset value

## ◆ Cy_NNLite_WeightStreamerCfg()

cy_en_nnlite_status_t Cy_NNLite_WeightStreamerCfg | ( | NNLITE_Type * | nnlite,
|  | cy_nnlite_context_t * | context,
|  | uint32_t | weightPerNeuron,
|  | int32_t | filterOffset
| ) |  |

nnlite weight streamer configuration set, API will configure offset for weight streamer and weights per neuron parameter*

Parameters

  [in] | nnlite | base pointer of NNLIte register map.
  [in] | context | pointer to the driver context structure
  [in] | weightPerNeuron | weight/filter elements count per neuron
  [in] | filterOffset | weight/filter elements offset value

Return values

  Refer | cy_en_nnlite_status_t

nnlite weight streamer configuration set, API will configure offset for weight streamer and weights per neuron parameter*

[in] nnlite base pointer of register map.

[in] context pointer to the driver context structure

[in] weightPerNeuron wight/filter elements count per neuron

[in] filterOffset wight/filter elements offset value

## ◆ Cy_NNLite_OutputStreamerCfg()

cy_en_nnlite_status_t Cy_NNLite_OutputStreamerCfg | ( | NNLITE_Type * | nnlite,
|  | cy_nnlite_context_t * | context,
|  | cy_nnlite_clipping_t | clipping,
|  | int32_t | outputOffset,
|  | uint32_t | outputWidth,
|  | uint32_t | outputHeight,
|  | uint32_t | outputChannels
| ) |  |

nnlite out streamer configuration set, API will set clipping mask, offset, width, height and channel for output streamer

Parameters

  [in] | nnlite | base pointer of NNLIte register map.
  [in] | context | pointer to the driver context structure
  [in] | clipping | output clipping setting
  [in] | outputOffset | output elements offset value
  [in] | outputWidth | output width
  [in] | outputHeight | output height
  [in] | outputChannels | output Channels

Return values

  Refer | cy_en_nnlite_status_t

nnlite out streamer configuration set, API will set clipping mask, offset, width, height and channel for output streamer

[in] nnlite base pointer of register map.

[in] context pointer to the driver context structure

[in] clipping output clipping setting mask or max/min values

[in] outputOffset output elements offset value

[in] outputChannels output Channels

## ◆ Cy_NNLite_StreamerBaseAddrSet()

cy_en_nnlite_status_t Cy_NNLite_StreamerBaseAddrSet | ( | NNLITE_Type * | nnlite,
|  | cy_en_nnlite_streamer_id_t | strmId,
|  | const void * | baseAddr
| ) |  |

set nnlite streamer base address

Parameters

  [in] | nnlite | base pointer of NNLIte register map.
  [in] | strmId | streamer id
  [in] | baseAddr | base address of buffer

Return values

  Refer | cy_en_nnlite_status_t

set nnlite streamer base address

[in] nnlite base pointer of register map.

[in] strmId streamer id

[in] baseAddr base address of buffer

## ◆ Cy_NNLite_PipelineConfig()

static cy_en_nnlite_status_t Cy_NNLite_PipelineConfig | ( | NNLITE_Type * | nnlite,
|  | cy_en_nnlite_op_t | opType,
|  | cy_en_nnlite_mode_t | fetchMode,
|  | bool | repeatWeights,
|  | bool | biasEn,
|  | bool | sparsityEn,
|  | cy_en_nnlite_output_rescaling_t | outputRescaling,
|  | cy_en_nnlite_input_rescaling_t | inputRescaling,
|  | cy_en_nnlite_fused_activation_t | actType,
|  | cy_en_nnlite_activation_size_t | inputSize,
|  | cy_en_nnlite_activation_size_t | weightSize,
|  | cy_en_nnlite_output_size_t | outputSize
| ) |  |
| inlinestatic

Set NNLiteV2 pipeline configuration.

Parameters

  [in] | nnlite | base pointer of NNLIte register map.
  [in] | opType | ALU (Arithmetic accumulation) stage operation
  [in] | fetchMode | Activation fetch mode (depthwise, tensorwise)
  [in] | repeatWeights | Enable weight repetition
  [in] | biasEn | Enable bias
  [in] | sparsityEn | Enable packed sparse weights
  [in] | outputRescaling | ALU stage scaling mode
  [in] | inputRescaling | ALU prescaling mode
  [in] | actType | Activation stage activation function
  [in] | inputSize | Activation.rhs input bit width
  [in] | weightSize | Weight/lhs input bit width
  [in] | outputSize | Output bit width.

Returns
  cy_en_nnlite_status_t

Note
  inline as typical most parameters are constants

## ◆ Cy_NNLite_SetPrePostScaling()

cy_en_nnlite_status_t Cy_NNLite_SetPrePostScaling | ( | NNLITE_Type * | nnlite,
|  | float | preScalingFactor,
|  | const float * | postScalingFactors
| ) |  |

Set pre/post arithmetic/accumulation scaling.

Parameters

  [in] | nnlite | base pointer of NNLIte register map.
  [in] | preScalingFactor | Pre-scaling factor to input prior to arithmetic/accumulation operation
  [in] | postScalingFactors | Post-scaling factor(s) to be applied after arithmetic/accumulation

Return values

  Refer | cy_en_nnlite_status_t

Note
  Scale factors are restricted IEEE754 float values. For NNLite V2.0 supported exponents [8,-24] are supported. Mantissa is rounded to 16-bits. Non Nan etc.

## ◆ Cy_NNLite_SetInterpolationParam()

cy_en_nnlite_status_t Cy_NNLite_SetInterpolationParam | ( | NNLITE_Type * | nnlite,
|  | uint32_t | segment,
|  | float | gradient
| ) |  |

set interpolation parameter

Parameters

  [in] | nnlite | base pointer of NNLIte register map.
  [in] | segment | lookup segment table addr (0: [-inf..0], 1: [0..inf] )
  [in] | gradient | slope value for interpolation (IEEE 32-bit float mantissa will be rounded to 7 bits)

Return values

  Refer | cy_en_nnlite_status_t

set interpolation parameter

Parameters

  [in] | nnlite | base pointer of NNLIte register map.
  [in] | segment | lookup segment table addr (0: [-inf..0], 1: [0..inf] )
  [in] | gradient | slope value for interpolation (IEEE 32-bit float mantissa will be rounded to 7 bits)

Return values

  Refer | cy_en_nnlite_status_t

## ◆ Cy_NNLite_FFTCfg()

cy_en_nnlite_status_t Cy_NNLite_FFTCfg | ( | NNLITE_Type * | nnlite,
|  | cy_nnlite_context_t * | context,
|  | void * | ppBuf0,
|  | void * | ppBuf1,
|  | unsigned int | fftStages
| ) |  |

Configure NNLite for Q1.15 complex FFT.

NNLite implements Decimation-in-Time Radix-2 FFT

Note
  FFT length =^= Number complex input values *2 = #

Parameters

  context | pointer to the driver context structure.
  ppBuf0 | Input / ping-pong buffer 0, Output (even stages/# values)
  ppBuf1 | ping-pong buffer 1, Output (odd stages/# values)
  fftStages | log_2(FFT length)

Returns
  cy_en_nnlite_status_t

NNLite implements Decimation-in-Time Radix-2 FFT

Note
  FFT length =^= Number complex input values *2 = #

Parameters

  [in] | nnlite | base pointer of NNLIte register map.
  [in] | context | pointer to the driver context structure.
  [in] | ppBuf0 | Input / ping-pong buffer 0, Output (even stages/# values)
  [in] | ppBuf1 | ping-pong buffer 1, Output (odd stages/# values)
  [in] | fftStages | log_2(FFT length)

Return values

  Refer | cy_en_nnlite_status_t

## ◆ Cy_NNLite_SetInterruptMask()

cy_en_nnlite_status_t Cy_NNLite_SetInterruptMask | ( | NNLITE_Type * | nnlite,
|  | uint32_t | intrMask
| ) |  |

nnlite set interrupt mask, available interrupt are operation STATUS Done, MEM Fetch Error different streamers, Output Saturation interrupt

Parameters

  [in] | nnlite | base pointer of NNLIte register map.
  [in] | intrMask | nnlite interrupt mask register

Return values

  Refer | cy_en_nnlite_status_t

[in] nnlite base pointer of register map.

[in] intrMask interrupt mask value

## ◆ Cy_NNLite_DatawireTriggerEnable()

cy_en_nnlite_status_t Cy_NNLite_DatawireTriggerEnable | ( | NNLITE_Type * | nnlite,
|  | bool | trigEn
| ) |  |

nnlite set datawire trigger control, trigger datawire for next layer when trigger is 1

Parameters

  [in] | nnlite | base pointer of NNLIte register map.
  [in] | trigEn | datawire trigger mask

Return values

  Refer | cy_en_nnlite_status_t

[in] nnlite base pointer of register map.

[in] trigEn datawire trigger enable

## ◆ Cy_NNLite_GetOperationStatus()

cy_en_nnlite_status_t Cy_NNLite_GetOperationStatus | ( | NNLITE_Type * | nnlite,
|  | uint32_t * | opStatus
| ) |  |

nnlite get nnlite operation status, can be used to poll operation status

Parameters

  [in] | nnlite | base pointer of NNLIte register map.
  [out] | opStatus | nnlite last operation status

Return values

  Refer | cy_en_nnlite_status_t

[in] nnlite base pointer of register map.

[out] opStatus nnlite last operation status

## ◆ Cy_NNLite_GetInterruptStatus()

cy_en_nnlite_status_t Cy_NNLite_GetInterruptStatus | ( | NNLITE_Type * | nnlite,
|  | uint32_t * | intrStatus
| ) |  |

get nnlite interrupt status

Parameters

  [in] | nnlite | base pointer of NNLIte register map.
  [out] | intrStatus | nnlite interrupt status register

Return values

  Refer | cy_en_nnlite_status_t

get nnlite interrupt status

[in] nnlite base pointer of register map.

[out] intrStatus nnlite interrupt status register

## ◆ Cy_NNLite_GetInterruptMask()

cy_en_nnlite_status_t Cy_NNLite_GetInterruptMask | ( | NNLITE_Type * | nnlite,
|  | uint32_t * | intrMask
| ) |  |

get nnlite interrupt mask

Parameters

  [in] | nnlite | base pointer of NNLIte register map.
  [out] | intrMask | interrupt mask value

Return values

  Refer | cy_en_nnlite_status_t

[in] nnlite base pointer of register map.

[out] intrMask nnlite interrupt mask

## ◆ Cy_NNLite_GetDriverState()

cy_en_nnlite_status_t Cy_NNLite_GetDriverState | ( | NNLITE_Type * | nnlite,
|  | cy_nnlite_context_t * | context,
|  | cy_en_nnlite_state_t * | nnliteState
| ) |  |

get nnlite driver state

Parameters

  [in] | nnlite | base pointer of NNLIte register map.
  [in] | context | pointer to the driver context structure
  [out] | nnliteState | driver current state

Return values

  Refer | cy_en_nnlite_status_t

## ◆ Cy_NNLite_InterruptClear()

cy_en_nnlite_status_t Cy_NNLite_InterruptClear | ( | NNLITE_Type * | nnlite,
|  | uint32_t | intrMask
| ) |  |

clear nnlite interrupts

Parameters

  [in] | nnlite | base pointer of NNLIte register map.
  [in] | intrMask | nnlite interrupts to be cleared

Return values

  Refer | cy_en_nnlite_status_t

[in] nnlite base pointer of register map.

[in] intrMask nnlite interrupts to be cleared

## ◆ Cy_NNLite_InterruptHandler()

void Cy_NNLite_InterruptHandler | ( | NNLITE_Type * | nnlite,
|  | cy_nnlite_context_t * | context
| ) |  |

nnlite ISR handler

Parameters

  [in] | nnlite | base pointer of NNLIte register map.
  [in] | context | nnlite context structure pointer

[in] nnlite base pointer of register map.

[in] context nnlite context structure pointer

## ◆ Cy_NNLite_WaitForCompletion()

cy_en_nnlite_status_t Cy_NNLite_WaitForCompletion | ( | NNLITE_Type * | nnlite,
|  | cy_nnlite_context_t * | context
| ) |  |

wait for completion of operation in busy loop

Parameters

  [in] | nnlite | base pointer of NNLIte register map.
  [in] | context | nnlite context structure pointer

wait for completion of operation in busy loop

[in] nnlite base pointer of register map.

[in] context pointer to the driver context structure