npu.utils package#
Submodules#
npu.utils.aiekernels module#
- npu.utils.aiekernels.aiekernels()#
Returns a list of the optimized AIE kernels available
npu.utils.appviz module#
npu.utils.display_widget module#
- class npu.utils.display_widget.DisplayImage#
Bases:
object
Simple class for displaying images/video in Jupyter notebooks.
- _image_widget#
reference to the widgets.Image object.
- Type:
widgets.Image
- _button_widget#
reference to the button widget used to stop the video feed.
- Type:
widgets.Button
- exit#
set by the button widget and read by the display widget to step the video.
- Type:
bool
- frame(value)#
Sets the current image on the widget
- Return type:
None
npu.utils.imgplot module#
- npu.utils.imgplot.image_plot(img_src, img_dst=None, alpha=False)#
Plots the img_src using matplotlib
- Return type:
None
Parameters:#
- img_src: np.ndarray
Primary image to plot.
- img_dst: np.ndarray [Optional]
Secondary image to plot. If provided it will be labeled as Processed Image
- alpha: bool [Optional]
Use alpha channel for visualization.
npu.utils.imgread module#
- class npu.utils.imgread.OpenCVImageReader(filename, grayscale=False, any_resolution=False)#
Bases:
object
Read an image file using OpenCV and return it as a NumPy ndarray
This reader is constrained to images with resolution 720p (720, 1280). You can read images with different resolutions by setting: any_resolution=True
- property img: ndarray#
Returns image in ndarray format
npu.utils.nputop module#
- npu.utils.nputop.nputop()#
Uses XBUtil to display all currently running applications in an ipywidgets form suitable for JupyterLab
npu.utils.svg module#
- class npu.utils.svg.AieTile(col, row, label=False)#
-
- MAX_BUFFERS = 8#
- add_buffer(color, duration=2, start_empty=1, delay=0, color2='')#
- add_kernel(color, duration=2, delay=0)#
- add_mem_animation(up_mem_to_aie=0, up_aie_to_mem=0, down_mem_to_aie=0, down_aie_to_mem=0, right=0, left=0, internal_left=0, internal_right=0, up=0, down=0, color='blue', duration=2, delay=0)#
- add_memory_outlines()#
- add_multiple_kernel(dict_kernels, animate=True)#
Dictionary should follow the format: {‘duration’: int, ‘kernels’: [color0, color1, …, colorn]}
- draw_memory_connections(south_mem_to_aie=0, south_aie_to_mem=0, east=0, south=0, north=0, west=0, color='blue', strokewidth=1)#
- generate_image(filename='aie_tile.svg', show_border=0)#
- get_aie_buffers_svg()#
- get_aie_kernels_svg()#
- get_aie_svg()#
- class npu.utils.svg.Box(id_name, index=0, x=0, y=0, width=0, height=0, color='#000000', stroke_color='black', stroke_width=1, text1='', text2='', font_size=1, text_color='', pulse_text=0, show_label=True)#
Bases:
object
Define a box with
- property append#
- property box#
Return SVG text for a box
- class npu.utils.svg.IfTile(row, col)#
-
- add_dma_animation(south_up=0, south_down=0, color='blue', duration=2, delay=0)#
- add_ic_animation(diagonal_to_tile=0, diagonal_from_tile=0, duration=2, delay=0, color='red')#
- add_single_tile_mem_animation(**kargs)#
- draw_external_memory_connections(south=0, color='black')#
- generate_image(filename='if_tile.svg', show_border=0)#
- get_if_tile_svg()#
- class npu.utils.svg.Image#
Bases:
object
- generate_svg_file(svg_content, filename, show_border=1, show_sysmem=False)#
- hide_key()#
- show_key()#
- class npu.utils.svg.KernelArc(x, y, index, colors, duration, radius=20, animate=True)#
Bases:
Kernel
Generate Sequential Kernels with Arcs
- class npu.utils.svg.MemTile(row, col)#
-
- MAX_BUFFERS = 16#
- add_buffer(color, duration=2, start_empty=1, delay=0, color2='')#
- add_ic_animation(diagonal_to_tile=0, diagonal_from_tile=0, north=0, south=0, duration=2, delay=0, color='red')#
- add_memory_outlines()#
- add_single_tile_ic_animation(north_up=0, north_down=0, duration=2, delay=0, color='red')#
- draw_memory_connections(east=False, west=False, color='red')#
- generate_image(filename='mem_tile.svg', show_border=0)#
- get_buffers_svg()#
- get_mem_tile_svg()#
- class npu.utils.svg.MemoryBox(id_name, index=0, x=0, y=0, width=0, height=0, color='#000000', stroke_color='black', stroke_width=1, text1='', text2='', font_size=1, text_color='', pulse_text=0, show_label=True, max_buffers=8, obj_class='aie_tile_buffers')#
Bases:
Box
- add_buffer(color, duration=2, start_empty=1, delay=0, color2='')#
Add animated buffer in a memory :type color: :param color: Color of the buffer :type color: str :param Optional: :param ——–: :type duration: :param duration: Duration of the animation in seconds :type duration: int :type start_empty: :param start_empty: Buffer starts animation empty :type start_empty: bool :type delay: :param delay: Animation starts after delay seconds :type delay: int :type color2: :param color2: Color used to empty the buffer :type color2: str
- add_memory_outlines(buffers=8)#
Add buffer outline
- class npu.utils.svg.RyzenAiArray(rows=4, cols=5, ns_mem_connections=False, remove_if_tile=True)#
Bases:
Image
A class representing a Ryzen AI Array. Inherits from the Image class.
- Parameters:
rows (int) – Number of rows in the array (default is 4).
cols (int) – Number of columns in the array (default is 5).
ns_mem_connections (bool) – Whether to include memory connections as north south, or more complicated path from memory (North) to AIE (south) (default is False).
remove_if_tile (bool) – Whether to remove first interface tile (for RyzenAI) (default is True).
- draw_app_box(col=1, width=1, text='')#
Add a box around the column to represent an application
- Parameters:
col (index of the column)
width (number of columns)
text (application name)
- draw_system_memory()#
Draw system memory
- generate_svg()#
- generate_svg_image(filename='ryzenai_array.svg', debug=0)#
- hide_aie_tiles(opacity=0.25)#
Hide AIE tiles only.
- hide_if_tiles(opacity=0.25)#
- hide_interconnect(opacity=0.25)#
- hide_mem_tiles(opacity=0.25)#
- hide_memory_connections(opacity=0.25)#
- hide_tiles(opacity=0.25)#
- show_aie_tiles()#
- show_if_tiles()#
- show_interconnect()#
- show_mem_tiles()#
- show_tiles()#
- class npu.utils.svg.RyzenAiColumn(rows=4, cols=1, if_tile=1, mem_label=False)#
Bases:
Image
- draw_system_memory()#
Draw system memory
- generate_column_svg()#
- generate_image(filename='ryzenai_column.svg')#
- generate_key(kernels)#
- hide_compute_tile()#
- hide_interface_tile()#
- hide_memory_tile()#
- show_compute_tile()#
- show_interface_tile()#
- show_memory_tile()#
- class npu.utils.svg.SystemMemory(x=0, y=0, width=50, max_buffers=4)#
Bases:
object
- add_buffer(color, duration=2, start_empty=1, delay=0, color2='')#
- property svg: str#
Return SVG code
- class npu.utils.svg.Tile(row=0, col=0, tile_type='', tile_background_color='#FFFFFF', container_background_color='#FFFFFF')#
Bases:
object
- add_ic_animation(diagonal_to_tile=0, diagonal_from_tile=0, north=0, south=0, east=0, west=0, duration=2, delay=0, color='red')#
- add_single_tile_ic_animation(north_up=0, north_down=0, west_left=0, west_right=0, duration=2, delay=0, color='red')#
- add_single_tile_mem_animation(north_up=0, north_down=0, south_up=0, south_down=0, east_left=0, east_right=0, west_right=0, west_left=0, color='blue', duration=2, delay=0)#
- clear_ic_animation()#
- draw_ic_connections(north, south, east, west)#
- get_hide_tile_svg()#
- get_ic_animations_svg()#
- get_ic_connections_svg()#
- get_memory_animations_svg()#
- get_memory_connections_svg()#
- get_tile_svg()#
- hide_tile(opacity=0.5)#
- show_all()#
- show_tile()#
npu.utils.svg_config module#
- npu.utils.svg_config.get_text_width(text=None, font_size=13)#
Get with of text for a particular font_size
- npu.utils.svg_config.get_tile_x(col)#
Get X coordinate for a AIE tile
- Return type:
int
- npu.utils.svg_config.get_tile_y(row)#
Get Y coordinate for a AIE tile
- Return type:
int
npu.utils.test_device module#
- npu.utils.test_device.get_device_status()#
Returns states of the NPU device, when operating normally should return the string ‘OK’.
- npu.utils.test_device.get_driver_version()#
- npu.utils.test_device.reset_npu()#
This is a utility function that wraps a powershell script to reset the IPU device. Note: this requires admin privileges.
- npu.utils.test_device.test_device_status()#
Checks if device exists, and if the status is expected ‘OK’.
- npu.utils.test_device.test_driver_version(min_driver_version='10.1109.8.100')#
Asserts if the driver version matches a minimum specified version.
- npu.utils.test_device.version_to_tuple(version)#
Convert a version string to a tuple of integers
npu.utils.videoapps module#
- npu.utils.videoapps.videoapps()#
Returns a list of pre-made video processing applications
npu.utils.xbutil module#
- class npu.utils.xbutil.XBUtil#
Bases:
object
- property app_count: int#
The total number of running apps
- app_exists(name)#
Returns true if an app with the given name is present on the NPU device
- Return type:
bool
- property app_table: str#
Returns a table of the apps currently loaded onto the NPU device
- apps()#
Starts a thread displaying all the apps in an ipython widget.
- Return type:
None
- list_apps()#
Lists all the apps running on the NPU device
- Return type:
List
[str
]
- property loaded_functions: List[str]#
Returns a list of loaded functions on the NPU. Applications can have multiple functions.
- property num_riallto_streams: int#
- property num_wse_streams: int#
Returns the current number of active WSE streams
Module contents#
Utilities#
The npu.utils submodule provides useful utility functions to visualize, list available resources, and introspect NPU applications.