예제 #1
0
def test_dma_op():
    """Tests DMA operation followed by average pool. The DMA provides the contents of the average pool's IFM."""
    pool_op = create_avg_pool_op()
    assert pool_op.ofm is not None
    dest = get_address_ranges(pool_op.ofm)[0]
    assert dest is not None
    src = NpuAddressRange(0, 0x24000, dest.length)
    dma_op = NpuDmaOperation(src, dest)
    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)
    check_cmd0(cmds, cmd0.NPU_OP_POOL, 1)
def test_get_address_ranges_one_tile():
    """Tests calculation of feature map address ranges, with 1 tile used"""
    fm = NpuFeatureMap()
    fm.region = 4
    fm.layout = NpuLayout.NHWC
    fm.data_type = NpuDataType.INT16
    fm.shape = NpuShape3D(height=50, width=40, depth=3)
    fm.tiles = NpuTileBox(height_0=50,
                          height_1=50,
                          width_0=40,
                          addresses=[8000, 0, 0, 0])
    ranges = get_address_ranges(fm)
    assert ranges == [
        NpuAddressRange(region=4, address=8000, length=12000), None, None, None
    ]
def test_get_address_ranges_horizontal_tiles():
    """Tests calculation of feature map address ranges, with 2 horizontal tiles used"""
    fm = NpuFeatureMap()
    fm.region = 6
    fm.layout = NpuLayout.NHWC
    fm.data_type = NpuDataType.INT16
    fm.shape = NpuShape3D(height=50, width=10, depth=20)
    fm.tiles = NpuTileBox(height_0=20,
                          height_1=30,
                          width_0=10,
                          addresses=[256, 0, 16000, 0])
    ranges = get_address_ranges(fm)
    assert ranges == [
        NpuAddressRange(region=6, address=256, length=8000),
        None,
        NpuAddressRange(region=6, address=16000, length=12000),
        None,
    ]
def test_get_address_ranges_4_tiles():
    """Tests calculation of feature map address ranges, with 4 tiles used"""
    fm = NpuFeatureMap()
    fm.region = 6
    fm.layout = NpuLayout.NHCWB16
    fm.data_type = NpuDataType.INT16
    fm.shape = NpuShape3D(height=50, width=10, depth=20)
    fm.tiles = NpuTileBox(height_0=30,
                          height_1=10,
                          width_0=3,
                          addresses=[16, 32000, 8000, 16000])
    ranges = get_address_ranges(fm)
    assert ranges == [
        NpuAddressRange(region=6, address=16, length=18952),
        NpuAddressRange(region=6, address=32000, length=6280),
        NpuAddressRange(region=6, address=8000, length=12552),
        NpuAddressRange(region=6, address=28800, length=12680),
    ]
def test_get_address_ranges_vertical_tiles():
    """Tests calculation of feature map address ranges, with 2 vertical tiles used"""
    fm = NpuFeatureMap()
    fm.region = 6
    fm.layout = NpuLayout.NHWC
    fm.data_type = NpuDataType.INT8
    # Set strides explicitly
    fm.shape = NpuShape3D(height=50, width=10, depth=20)
    fm.strides = NpuShape3D(height=100, width=20, depth=1)
    fm.tiles = NpuTileBox(height_0=50,
                          height_1=50,
                          width_0=5,
                          addresses=[16, 32000, 0, 0])
    ranges = get_address_ranges(fm)
    assert ranges == [
        NpuAddressRange(region=6, address=16, length=5000),
        NpuAddressRange(region=6, address=32000, length=5000),
        None,
        None,
    ]