aboutsummaryrefslogtreecommitdiff
path: root/ethosu/vela/test
diff options
context:
space:
mode:
authorLouis Verhaard <louis.verhaard@arm.com>2020-11-02 18:04:27 +0100
committerLouis Verhaard <louis.verhaard@arm.com>2020-11-23 13:39:35 +0100
commitaeae56770f3c19182d32cc63fd32396e061a7648 (patch)
tree95ca2e6c90d81ba8910c8ca9ced68ffa132b7dab /ethosu/vela/test
parent27d36f003d35413beb51c1de8f33259ddeca7543 (diff)
downloadethos-u-vela-aeae56770f3c19182d32cc63fd32396e061a7648.tar.gz
MLBEDSW-3424: Expose API through separate file
All external APIs are now exposed by api.py. Signed-off-by: Louis Verhaard <louis.verhaard@arm.com> Change-Id: I33f480e424692ac30e9c7d791f583199f31164a7
Diffstat (limited to 'ethosu/vela/test')
-rw-r--r--ethosu/vela/test/extapi/test_extapi_encode_bias.py6
-rw-r--r--ethosu/vela/test/extapi/test_extapi_encode_weights.py18
-rw-r--r--ethosu/vela/test/extapi/test_extapi_generate_commands.py20
3 files changed, 18 insertions, 26 deletions
diff --git a/ethosu/vela/test/extapi/test_extapi_encode_bias.py b/ethosu/vela/test/extapi/test_extapi_encode_bias.py
index ffdd3b0c..c0a4a9ab 100644
--- a/ethosu/vela/test/extapi/test_extapi_encode_bias.py
+++ b/ethosu/vela/test/extapi/test_extapi_encode_bias.py
@@ -14,12 +14,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# Description:
-# Contains unit tests for encode_biases API for an external consumer
+# Contains unit tests for npu_encode_bias API for an external consumer
import random
import numpy as np
-from ethosu.vela.weight_compressor import encode_bias
+from ethosu.vela.api import npu_encode_bias
def test_encode_bias():
@@ -34,6 +34,6 @@ def test_encode_bias():
bias = np.int64(random.randint(bias_lower_limit, bias_upper_limit))
scale = int(random.randint(scale_lower_limit, scale_upper_limit))
shift = int(random.randint(shift_lower_limit, shift_upper_limit))
- biases_enc = encode_bias(bias, scale, shift)
+ biases_enc = npu_encode_bias(bias, scale, shift)
assert isinstance(biases_enc, bytearray)
assert len(biases_enc) == 10
diff --git a/ethosu/vela/test/extapi/test_extapi_encode_weights.py b/ethosu/vela/test/extapi/test_extapi_encode_weights.py
index 854d14c0..6367cb30 100644
--- a/ethosu/vela/test/extapi/test_extapi_encode_weights.py
+++ b/ethosu/vela/test/extapi/test_extapi_encode_weights.py
@@ -14,25 +14,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# Description:
-# Contains unit tests for encode_weights API for an external consumer
+# Contains unit tests for npu_encode_weights API for an external consumer
import numpy as np
import pytest
-from ethosu.vela import weight_compressor
+from ethosu.vela.api import npu_encode_weights
+from ethosu.vela.api import NpuAccelerator
from ethosu.vela.api import NpuBlockTraversal
-from ethosu.vela.architecture_features import Accelerator
@pytest.mark.parametrize(
- "arch",
- [
- Accelerator.Ethos_U55_32,
- Accelerator.Ethos_U55_64,
- Accelerator.Ethos_U55_128,
- Accelerator.Ethos_U55_256,
- Accelerator.Ethos_U65_256,
- Accelerator.Ethos_U65_512,
- ],
+ "arch", list(NpuAccelerator),
)
@pytest.mark.parametrize("dilation_x", [1, 2])
@pytest.mark.parametrize("dilation_y", [1, 2])
@@ -56,7 +48,7 @@ def test_encode_weights(
block_traversal = NpuBlockTraversal.PART_KERNEL_FIRST if depth_control == 3 else NpuBlockTraversal.DEPTH_FIRST
dilation_xy = (dilation_x, dilation_y)
- encoded_stream = weight_compressor.encode_weights(
+ encoded_stream = npu_encode_weights(
accelerator=arch,
weights_volume=weights_ohwi,
dilation_xy=dilation_xy,
diff --git a/ethosu/vela/test/extapi/test_extapi_generate_commands.py b/ethosu/vela/test/extapi/test_extapi_generate_commands.py
index 49b24b2b..86ef804a 100644
--- a/ethosu/vela/test/extapi/test_extapi_generate_commands.py
+++ b/ethosu/vela/test/extapi/test_extapi_generate_commands.py
@@ -15,7 +15,9 @@
# limitations under the License.
#
# Description:
-# Contains unit tests for generate_register_command_stream API for an external consumer
+# Contains unit tests for npu_generate_register_command_stream API for an external consumer
+from ethosu.vela.api import npu_generate_register_command_stream
+from ethosu.vela.api import NpuAccelerator
from ethosu.vela.api import NpuActivation
from ethosu.vela.api import NpuActivationOp
from ethosu.vela.api import NpuAddressRange
@@ -35,11 +37,9 @@ from ethosu.vela.api import NpuPoolingOperation
from ethosu.vela.api import NpuQuantization
from ethosu.vela.api import NpuShape3D
from ethosu.vela.api import NpuTileBox
-from ethosu.vela.architecture_features import Accelerator
from ethosu.vela.ethos_u55_regs.ethos_u55_regs import cmd0
from ethosu.vela.ethos_u55_regs.ethos_u55_regs import cmd1
from ethosu.vela.register_command_stream_generator import CmdMode
-from ethosu.vela.register_command_stream_generator import generate_register_command_stream
from ethosu.vela.register_command_stream_generator import get_address_ranges
@@ -109,7 +109,7 @@ def test_conv2d():
# In this example we assume that the weights were compressed with ofm depth 16;
# let vela choose suitable block width and height by setting these to -1
op.block_config = NpuShape3D(height=-1, width=-1, depth=16)
- cmds = generate_register_command_stream([op], Accelerator.Ethos_U55_128)
+ cmds = npu_generate_register_command_stream([op], NpuAccelerator.Ethos_U55_128)
check_cmd0(cmds, cmd0.NPU_SET_IFM_REGION, 1)
check_cmd1(cmds, cmd1.NPU_SET_IFM_BASE0, 512)
check_cmd1(cmds, cmd1.NPU_SET_IFM_BASE1, 0)
@@ -203,7 +203,7 @@ def create_fully_connected_op() -> NpuConv2DOperation:
def test_fully_connected():
"""Tests command stream generation for a fully connected operation"""
op = create_fully_connected_op()
- cmds = generate_register_command_stream([op], Accelerator.Ethos_U55_128)
+ cmds = npu_generate_register_command_stream([op], NpuAccelerator.Ethos_U55_128)
check_cmd0(cmds, cmd0.NPU_OP_CONV, 0)
assert len(cmds) > 20
@@ -223,7 +223,7 @@ def test_depthwise():
op.weights = [weights_dest]
op.biases = [NpuAddressRange(region=0, address=0, length=80)]
op.block_config = NpuShape3D(height=-1, width=-1, depth=8)
- cmds = generate_register_command_stream([dma_op, op], Accelerator.Ethos_U55_128)
+ cmds = npu_generate_register_command_stream([dma_op, op], NpuAccelerator.Ethos_U55_128)
check_cmd0(cmds, cmd0.NPU_SET_DMA0_SRC_REGION, 0)
check_cmd1(cmds, cmd1.NPU_SET_DMA0_SRC, 0x40)
check_cmd0(cmds, cmd0.NPU_SET_DMA0_DST_REGION, 1)
@@ -248,7 +248,7 @@ def test_mul_with_broadcast_and_relu():
op.activation = NpuActivation(NpuActivationOp.NONE_OR_RELU)
op.activation.min = 0 # RELU
# Do not set a block config, let vela choose one
- cmds = generate_register_command_stream([op], Accelerator.Ethos_U55_32)
+ cmds = npu_generate_register_command_stream([op], NpuAccelerator.Ethos_U55_32)
check_cmd1(cmds, cmd1.NPU_SET_OFM_SCALE, 1073741824, 30)
check_cmd0(cmds, cmd0.NPU_SET_IFM_REGION, 1)
check_cmd1(cmds, cmd1.NPU_SET_IFM_BASE0, 32)
@@ -337,7 +337,7 @@ def create_avg_pool_op() -> NpuPoolingOperation:
def test_avg_pool():
"""Tests average pool operation"""
op = create_avg_pool_op()
- cmds = generate_register_command_stream([op], Accelerator.Ethos_U55_128)
+ cmds = npu_generate_register_command_stream([op], NpuAccelerator.Ethos_U55_128)
check_cmd0(cmds, cmd0.NPU_OP_POOL, 1)
assert len(cmds) > 10
@@ -346,7 +346,7 @@ def test_two_operations():
"""Tests code generation with 2 operations"""
op1 = create_fully_connected_op()
op2 = create_avg_pool_op()
- cmds = generate_register_command_stream([op1, op2], Accelerator.Ethos_U55_64)
+ cmds = npu_generate_register_command_stream([op1, op2], NpuAccelerator.Ethos_U55_64)
check_cmd0(cmds, cmd0.NPU_OP_POOL, 1)
check_cmd0(cmds, cmd0.NPU_OP_CONV, 0)
check_cmd0(cmds, cmd0.NPU_SET_BLOCKDEP, 0)
@@ -363,7 +363,7 @@ def test_dma_op():
assert dest is not None
src = NpuAddressRange(0, 0x24000, dest.length)
dma_op = NpuDmaOperation(src, dest)
- cmds = generate_register_command_stream([dma_op, pool_op], Accelerator.Ethos_U55_64)
+ cmds = npu_generate_register_command_stream([dma_op, pool_op], NpuAccelerator.Ethos_U55_64)
check_cmd0(cmds, cmd0.NPU_OP_DMA_START, 0)
# A DMA WAIT should have been inserted
check_cmd0(cmds, cmd0.NPU_OP_DMA_WAIT, 0)