npu.lib.kernels package#

Submodules#

npu.lib.kernels.addweighted module#

class npu.lib.kernels.addweighted.AddWeighted(*args)#

Bases: object

Vectorized implementation of the cv2.AddWeighted function.

This kernel accepts 2 inputs, each input is weighted by the RTPs alpha and beta, then emits a single output which is the element-wise addition of the weighted inputs.

Read more about this function in the cv2 docs: https://docs.opencv.org/4.x/d2/de8/group__core__array.html#gafafb2513349db3bcff51f54ee5592a19

behavioralfx()#
class npu.lib.kernels.addweighted.AddWeightedScalar(*args)#

Bases: object

Scalar implementation of the cv2.AddWeighted function

npu.lib.kernels.bitwiseand module#

class npu.lib.kernels.bitwiseand.BitwiseAnd(*args)#

Bases: object

Vectorized implementation of the cv2.bitwise_and function.

It accepts 2 buffer inputs and outputs 1 output which is the element-wise logical AND operation applied on each value.

Read more about this function in the cv2 docs: https://docs.opencv.org/4.x/d2/de8/group__core__array.html#ga60b4d04b251ba5eb1392c34425497e14

behavioralfx()#
class npu.lib.kernels.bitwiseand.BitwiseAndScalar(*args)#

Bases: object

Scalar implementation of the cv2.bitwise_and function

npu.lib.kernels.bitwiseor module#

class npu.lib.kernels.bitwiseor.BitwiseOr(*args)#

Bases: object

Vectorized implementation of the cv2.bitwise_or function.

It accepts 2 buffer inputs and outputs 1 output which is the element-wise logical AND operation applied on each value.

Read more about this function in the cv2 docs: https://docs.opencv.org/4.x/d2/de8/group__core__array.html#gab85523db362a4e26ff0c703793a719b4

behavioralfx()#
class npu.lib.kernels.bitwiseor.BitwiseOrScalar(*args)#

Bases: object

Scalar implementation of the cv2.bitwise_or function

npu.lib.kernels.filter2d module#

class npu.lib.kernels.filter2d.Filter2d(*args, linewidth: int = 1280)#

Bases: object

Vectorized implementation of a grayscale filter2d kernel

It supports 720p or 1080p image resolutions.

It accepts a row of the image at a time and uses a circular buffer to keep track of the last three rows. It then applies the filter to the three rows.

Keyword Parameter#

linewidth: optional

Either 1280, 1920

Read more about this function in the cv2 docs: https://docs.opencv.org/4.x/d4/d86/group__imgproc__filter.html#ga27c049795ce870216ddfb366086b5a04

behavioralfx()#
class npu.lib.kernels.filter2d.Filter2dScalar(*args, linewidth: int = 1280)#

Bases: object

Scalar implementation of a filter2d function.

Keyword Parameter#

linewidth: optional

Either 1280, 1920

npu.lib.kernels.gray2rgba module#

class npu.lib.kernels.gray2rgba.Gray2Rgba(*args)#

Bases: object

Vectorized implementation of the cv2.cvtColor RGBA2Gray conversion.

This kernel is used to convert a single channel grayscale image input into a 4 channel RGBA image.

Read more about this function in the cv2 docs: https://docs.opencv.org/4.x/d8/d01/group__imgproc__color__conversions.html#ga397ae87e1288a81d2363b61574eb8cab

behavioralfx()#
class npu.lib.kernels.gray2rgba.Gray2RgbaScalar(*args)#

Bases: object

Scalar implementation of the cv2.cvtColor RGBA2Gray conversion.

npu.lib.kernels.inrange module#

class npu.lib.kernels.inrange.InRange(*args)#

Bases: object

Vectorized implementation of the cv2.inRange function.

This vectorized implementation operates on grayscale image inputs. Read more about this function in the cv2 docs: https://docs.opencv.org/4.x/d2/de8/group__core__array.html#ga48af0ab51e36436c5d04340e036ce981

behavioralfx()#

npu.lib.kernels.inverse module#

class npu.lib.kernels.inverse.Inverse(*args)#

Bases: object

Vectorized implementation of a invert function on grayscale images.

This vectorized implementation operates on grayscale image inputs. It performs the operation 255 - image

behavioralfx()#

npu.lib.kernels.kernelgenerator module#

class npu.lib.kernels.kernelgenerator.KernelObjCall(cpp, bfx, *args)#

Bases: object

Helper function that generates new kernel objects.

npu.lib.kernels.median module#

class npu.lib.kernels.median.Median(*args)#

Bases: object

Vectorized implementation of a median filter.

behavioralfx()#
class npu.lib.kernels.median.MedianScalar(*args)#

Bases: object

Scalar implementation of a median filter.

npu.lib.kernels.plusn module#

class npu.lib.kernels.plusn.Plus1(*args)#

Bases: object

Vectorized implementation of a plus1 function.

This function simply adds a constant 1 to every element of an input array. This is a useful function to verify that your graph is set up correctly as the input/output relationship is simple to interpret.

behavioralfx()#
class npu.lib.kernels.plusn.PlusN(*args)#

Bases: object

Vectorized implementation of a plusN function.

This function adds a custom value specified by the runtime parameter N to every value of an input array.

behavioralfx()#

npu.lib.kernels.rgba2gray module#

class npu.lib.kernels.rgba2gray.Rgba2Gray(*args)#

Bases: object

Vectorized implementation of the cv2.cvtColor RGBA2Gray conversion.

This kernel is used to convert 4 channel image input into a single channel grayscale image.

Read more about this function in the cv2 docs: https://docs.opencv.org/4.x/d8/d01/group__imgproc__color__conversions.html#ga397ae87e1288a81d2363b61574eb8cab

behavioralfx()#
class npu.lib.kernels.rgba2gray.Rgba2GrayScalar(*args)#

Bases: object

Scalar implementation of of the cv2.cvtColor RGBA2Gray conversion.

npu.lib.kernels.rgba2hue module#

class npu.lib.kernels.rgba2hue.Rgba2Hue(*args)#

Bases: object

Vectorized implementation of the cv2.cvtColor RGBA2HUE conversion.

This kernel is used to convert 4 channel image input into HSV space (hue, saturation, value).

Read more about this function in the cv2 docs: https://docs.opencv.org/4.x/d8/d01/group__imgproc__color__conversions.html#ga397ae87e1288a81d2363b61574eb8cab

behavioralfx()#
class npu.lib.kernels.rgba2hue.Rgba2HueScalar(*args)#

Bases: object

Scalar implementation of the cv2.cvtColor RGBA2HUE conversion

npu.lib.kernels.rgba_inverse module#

class npu.lib.kernels.rgba_inverse.RgbaInverse(*args)#

Bases: object

Vectorized inverse operation for an RGBA image.

For each RGBA 4-Byte pair it subtracts 255 from the R/G/B channel while leaving the alpha channel unchanged. This kernel accepts a single input for the input tile it is processing and returns a buffer for the output tile.

behavioralfx()#

npu.lib.kernels.threshold module#

class npu.lib.kernels.threshold.RgbaRtpThres(*args)#

Bases: object

Vectorized implementation of an RGBA threshold.

For each RGBA 4 byte pair it applies a threshold to the R/G/B channels while leaving the alpha channel unchanged. This kernel accepts one buffer input for the input tile size, a RTP nbytes for the number of bytes that the kernel is expecting to process, r_thresh the threshold value for the red channel, g_thres the threshold value for the green channel, and b_thresh the threshold value for the blue channel. The vectorization factor for the kernel is 64 elements.

behavioralfx()#
class npu.lib.kernels.threshold.ThresholdGrayscale(*args)#

Bases: object

Vectorized implementation of the cv2.threshold function.

This vectorized implementation operates on RGBA image inputs. Read more about this function in the cv2 docs: https://docs.opencv.org/4.x/d7/d1b/group__imgproc__misc.html#gae8a4a146d1ca78c626a53577199e9c57

behavioralfx()#
class npu.lib.kernels.threshold.ThresholdRgba(*args)#

Bases: object

Vectorized implementation of the cv2.threshold function.

This vectorized implementation operates on RGBA image inputs. Read more about this function in the cv2 docs: https://docs.opencv.org/4.x/d7/d1b/group__imgproc__misc.html#gae8a4a146d1ca78c626a53577199e9c57

behavioralfx()#

Module contents#

Kernels#

The npu.lib.kernels submodule includes pre-defined, but not pre-built kernels that can be used in custom application graph definitions. Each kernel also has a behavioral model associated with it allowing validation of data shapes and functionality in Python, before compiling the application binaries.

Example usage of inverse kernel behavioral model

import numpy as np from npu.lib.kernels.inverse import Inverse

kernel = Inverse() x = np.array(np.ones(100,) y = kernel(x, dtype=np.uint8), 100, 1)