From 5207830e53d454793cebfffa96d366ded79d71da Mon Sep 17 00:00:00 2001 From: Louis Verhaard Date: Wed, 18 Nov 2020 13:35:06 +0100 Subject: 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 --- .../vela/test/extapi/test_extapi_create_payload.py | 42 ++++++++++++++++++++++ ethosu/vela/test/testutil.py | 12 +------ 2 files changed, 43 insertions(+), 11 deletions(-) create mode 100644 ethosu/vela/test/extapi/test_extapi_create_payload.py (limited to 'ethosu/vela/test') diff --git a/ethosu/vela/test/extapi/test_extapi_create_payload.py b/ethosu/vela/test/extapi/test_extapi_create_payload.py new file mode 100644 index 00000000..06dd220d --- /dev/null +++ b/ethosu/vela/test/extapi/test_extapi_create_payload.py @@ -0,0 +1,42 @@ +# Copyright (C) 2020 Arm Limited or its affiliates. All rights reserved. +# +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed under the Apache License, Version 2.0 (the License); you may +# not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an AS IS BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Description: +# Contains unit tests for npu_create_driver_payload API for an external consumer +import random + +import pytest + +from ethosu.vela.api import npu_create_driver_payload +from ethosu.vela.api import NpuAccelerator + + +@pytest.mark.parametrize("accelerator", list(NpuAccelerator)) +def test_create_driver_payload(accelerator: NpuAccelerator): + """Tests npu_create_driver_payload""" + # Generate a random command stream with defined beginning and end + random.seed(0) + num_commands = 793 + register_command_stream = random.choices(range(1 << 32), k=num_commands) + register_command_stream[0] = 0xFEDCBA98 + register_command_stream[-1] = 0xA0B1C2D3 + payload = npu_create_driver_payload(register_command_stream, accelerator) + header_size = 32 # expected driver header size in bytes + assert len(payload) == header_size + 4 * num_commands + # Check that the first register command is located directly after the header + assert list(payload[header_size : header_size + 4]) == [0x98, 0xBA, 0xDC, 0xFE] + # Check that the last register command is present in the payload + assert list(payload[-4:]) == [0xD3, 0xC2, 0xB1, 0xA0] diff --git a/ethosu/vela/test/testutil.py b/ethosu/vela/test/testutil.py index 7cdd4f5e..ee407b6e 100644 --- a/ethosu/vela/test/testutil.py +++ b/ethosu/vela/test/testutil.py @@ -27,17 +27,7 @@ from ethosu.vela.tensor import Tensor def create_arch(): - return architecture_features.ArchitectureFeatures( - vela_config_files=None, - accelerator_config=architecture_features.Accelerator.Ethos_U55_128.value, - system_config=architecture_features.ArchitectureFeatures.DEFAULT_CONFIG, - memory_mode=architecture_features.ArchitectureFeatures.DEFAULT_CONFIG, - override_block_config=None, - block_config_limit=None, - max_blockdep=0, - weight_estimation_scaling=1.0, - verbose_config=False, - ) + return architecture_features.create_default_arch(architecture_features.Accelerator.Ethos_U55_128) def default_quant_params(): -- cgit v1.2.1