diff options
author | Louis Verhaard <louis.verhaard@arm.com> | 2020-11-18 13:35:06 +0100 |
---|---|---|
committer | Louis Verhaard <louis.verhaard@arm.com> | 2020-11-23 13:39:56 +0100 |
commit | 5207830e53d454793cebfffa96d366ded79d71da (patch) | |
tree | b99da4124607c6d20ceef9605eccf89e150ba666 /ethosu/vela/driver_actions.py | |
parent | aeae56770f3c19182d32cc63fd32396e061a7648 (diff) | |
download | ethos-u-vela-5207830e53d454793cebfffa96d366ded79d71da.tar.gz |
MLBEDSW-3425: Added external API for driver actions
Added external API to add driver actions to a command stream.
Change-Id: Ie4779c1c745defc5769fa694358470cd6aea191c
Signed-off-by: Louis Verhaard <louis.verhaard@arm.com>
Diffstat (limited to 'ethosu/vela/driver_actions.py')
-rw-r--r-- | ethosu/vela/driver_actions.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/ethosu/vela/driver_actions.py b/ethosu/vela/driver_actions.py index 29c2b181..86bed110 100644 --- a/ethosu/vela/driver_actions.py +++ b/ethosu/vela/driver_actions.py @@ -15,10 +15,15 @@ # limitations under the License. # Description: # Creates driver actions that are embedded in the custom operator payload. +import struct from typing import List import numpy as np +from .api import NpuAccelerator +from .architecture_features import Accelerator +from .architecture_features import ArchitectureFeatures +from .architecture_features import create_default_arch from .ethos_u55_regs.ethos_u55_regs import ARCH_VER from .ethos_u55_regs.ethos_u55_regs import config_r from .ethos_u55_regs.ethos_u55_regs import id_r @@ -106,3 +111,24 @@ def emit_reg_read(data: List[int], reg_index: int, reg_count: int = 1): def emit_dump_shram(data: List[int]): assert data is not None data.append(make_da_tag(DACommands.DumpSHRAM, 0, 0)) + + +def create_driver_payload(register_command_stream: List[int], arch: ArchitectureFeatures) -> bytes: + """Creates driver header and includes the given command + """ + # Prepare driver actions for this command tensor + da_list = [] + emit_fourcc(da_list, "COP1") + emit_config(da_list, 0, 1, arch) + emit_cmd_stream_header(da_list, len(register_command_stream)) + + # Append command stream words + da_list.extend(register_command_stream) + # Convert to bytes, in little endian format + return struct.pack("<{0}I".format(len(da_list)), *da_list) + + +def npu_create_driver_payload(register_command_stream: List[int], accelerator: NpuAccelerator) -> bytes: + """Internal implementation of the public facing API to create driver payload""" + arch = create_default_arch(Accelerator.from_npu_accelerator(accelerator)) + return create_driver_payload(register_command_stream, arch) |