blob: 812991a952e53090d8f4975e5670423ef8d6a32f [file] [log] [blame]
Louis Verhaarde8a5a782020-11-02 18:04:27 +01001# Copyright (C) 2020 Arm Limited or its affiliates. All rights reserved.
2#
3# SPDX-License-Identifier: Apache-2.0
4#
5# Licensed under the Apache License, Version 2.0 (the License); you may
6# not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an AS IS BASIS, WITHOUT
13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17# Description:
Louis Verhaardaeae5672020-11-02 18:04:27 +010018# Contains unit tests for npu_generate_register_command_stream API for an external consumer
Louis Verhaard933f55e2020-11-25 14:10:30 +010019from ethosu.vela.api import npu_find_block_configs
Louis Verhaardaeae5672020-11-02 18:04:27 +010020from ethosu.vela.api import npu_generate_register_command_stream
21from ethosu.vela.api import NpuAccelerator
Louis Verhaarde8a5a782020-11-02 18:04:27 +010022from ethosu.vela.api import NpuActivation
23from ethosu.vela.api import NpuActivationOp
24from ethosu.vela.api import NpuAddressRange
25from ethosu.vela.api import NpuBlockTraversal
26from ethosu.vela.api import NpuConv2DOperation
27from ethosu.vela.api import NpuConvDepthWiseOperation
28from ethosu.vela.api import NpuDataType
29from ethosu.vela.api import NpuDmaOperation
30from ethosu.vela.api import NpuElementWiseOp
31from ethosu.vela.api import NpuElementWiseOperation
32from ethosu.vela.api import NpuFeatureMap
33from ethosu.vela.api import NpuKernel
34from ethosu.vela.api import NpuLayout
35from ethosu.vela.api import NpuPadding
36from ethosu.vela.api import NpuPoolingOp
37from ethosu.vela.api import NpuPoolingOperation
38from ethosu.vela.api import NpuQuantization
39from ethosu.vela.api import NpuShape3D
40from ethosu.vela.api import NpuTileBox
Louis Verhaarde8a5a782020-11-02 18:04:27 +010041from ethosu.vela.ethos_u55_regs.ethos_u55_regs import cmd0
42from ethosu.vela.ethos_u55_regs.ethos_u55_regs import cmd1
43from ethosu.vela.register_command_stream_generator import CmdMode
Louis Verhaarde8a5a782020-11-02 18:04:27 +010044from ethosu.vela.register_command_stream_generator import get_address_ranges
45
46
47def check_cmd0(cmd_stream, cmd, param):
48 """Checks that the command stream contains the given command + parameter"""
49 param = int(param) & 0xFFFF
50 command = cmd.value | (param << 16)
51 assert command in cmd_stream, f"Not in command stream: {cmd} {param}"
52
53
54def check_cmd1(cmd_stream, cmd, offset, param=0x0):
55 """Checks that the command stream contains the given command + parameter"""
56 offset = int(offset) & 0xFFFFFFFFF
57 command = cmd.value | CmdMode.Payload32.value | (param << 16)
58 for i in range(len(cmd_stream) - 1):
59 if cmd_stream[i] == command and cmd_stream[i + 1] == offset:
60 return # found
61 assert False, f"Not in command stream: {cmd} {offset} {param}"
62
63
64def find_cmd0(cmd_stream, cmd) -> int:
65 """Returns parameter of the first command in the stream that matches the given command"""
66 for command in cmd_stream:
67 if (command & 0xFFFF) == cmd.value:
68 return (command >> 16) & 0xFFFF
69 assert False, f"Not in command stream: {cmd}"
70
71
72def create_feature_map(
73 shape: NpuShape3D,
74 region: int,
75 address: int,
76 dtype: NpuDataType = NpuDataType.UINT8,
77 layout: NpuLayout = NpuLayout.NHWC,
78 quant=NpuQuantization(scale_f32=1, zero_point=0),
79) -> NpuFeatureMap:
80 """Creates feature map using 1 tile"""
81 fm = NpuFeatureMap()
82 fm.data_type = dtype
83 fm.shape = shape
84 fm.tiles = NpuTileBox(
85 width_0=shape.width, height_0=shape.height, height_1=shape.height, addresses=[address, 0, 0, 0]
86 )
87 fm.region = region
88 fm.layout = layout
89 fm.quantization = quant
90 return fm
91
92
93def test_conv2d():
94 """Tests command stream generation for a conv2d operation"""
95 op = NpuConv2DOperation()
96 op.ifm = create_feature_map(
97 NpuShape3D(height=30, width=62, depth=46), 1, 512, quant=NpuQuantization(scale_f32=0.007843138, zero_point=128)
98 )
99 op.ofm = create_feature_map(
100 NpuShape3D(height=30, width=31, depth=46),
101 1,
102 0x14E40,
103 quant=NpuQuantization(scale_f32=0.20392157, zero_point=128),
104 )
105 op.kernel = NpuKernel(3, 2, 2, 1)
106 op.weights = [NpuAddressRange(region=0, address=0, length=7696)]
107 op.biases = [NpuAddressRange(region=0, address=32000, length=464)]
108 op.padding = NpuPadding(top=0, left=0, right=1, bottom=1)
109 op.block_traversal = NpuBlockTraversal.PART_KERNEL_FIRST
Louis Verhaard933f55e2020-11-25 14:10:30 +0100110 op.block_config = NpuShape3D(height=16, width=4, depth=16)
Louis Verhaardaeae5672020-11-02 18:04:27 +0100111 cmds = npu_generate_register_command_stream([op], NpuAccelerator.Ethos_U55_128)
Louis Verhaarde8a5a782020-11-02 18:04:27 +0100112 check_cmd0(cmds, cmd0.NPU_SET_IFM_REGION, 1)
113 check_cmd1(cmds, cmd1.NPU_SET_IFM_BASE0, 512)
114 check_cmd1(cmds, cmd1.NPU_SET_IFM_BASE1, 0)
115 check_cmd1(cmds, cmd1.NPU_SET_IFM_BASE2, 0)
116 check_cmd1(cmds, cmd1.NPU_SET_IFM_BASE3, 0)
117 check_cmd0(cmds, cmd0.NPU_SET_IFM_HEIGHT0_M1, 29)
118 check_cmd0(cmds, cmd0.NPU_SET_IFM_HEIGHT1_M1, 29)
119 check_cmd0(cmds, cmd0.NPU_SET_IFM_WIDTH0_M1, 61)
120 check_cmd0(cmds, cmd0.NPU_SET_IFM_DEPTH_M1, 45)
121 check_cmd1(cmds, cmd1.NPU_SET_IFM_STRIDE_C, 1)
122 check_cmd1(cmds, cmd1.NPU_SET_IFM_STRIDE_Y, 2852)
123 check_cmd1(cmds, cmd1.NPU_SET_IFM_STRIDE_X, 46)
124 check_cmd0(cmds, cmd0.NPU_SET_IFM_ZERO_POINT, 128)
125 check_cmd0(cmds, cmd0.NPU_SET_IFM_PRECISION, 0)
126 check_cmd0(cmds, cmd0.NPU_SET_IFM_UPSCALE, 0)
127 check_cmd0(cmds, cmd0.NPU_SET_IFM_PAD_TOP, 0)
128 check_cmd0(cmds, cmd0.NPU_SET_IFM_PAD_LEFT, 0)
129 check_cmd0(cmds, cmd0.NPU_SET_IFM_PAD_BOTTOM, 1)
130 check_cmd0(cmds, cmd0.NPU_SET_IFM_PAD_RIGHT, 1)
131 check_cmd0(cmds, cmd0.NPU_SET_OFM_REGION, 1)
132 check_cmd1(cmds, cmd1.NPU_SET_OFM_BASE0, 85568)
133 check_cmd1(cmds, cmd1.NPU_SET_OFM_BASE1, 0)
134 check_cmd1(cmds, cmd1.NPU_SET_OFM_BASE2, 0)
135 check_cmd1(cmds, cmd1.NPU_SET_OFM_BASE3, 0)
136 check_cmd0(cmds, cmd0.NPU_SET_OFM_HEIGHT0_M1, 29)
137 check_cmd0(cmds, cmd0.NPU_SET_OFM_HEIGHT1_M1, 29)
138 check_cmd0(cmds, cmd0.NPU_SET_OFM_WIDTH0_M1, 30)
139 check_cmd0(cmds, cmd0.NPU_SET_OFM_HEIGHT_M1, 29)
140 check_cmd0(cmds, cmd0.NPU_SET_OFM_WIDTH_M1, 30)
141 check_cmd0(cmds, cmd0.NPU_SET_OFM_DEPTH_M1, 45)
142 check_cmd1(cmds, cmd1.NPU_SET_OFM_STRIDE_C, 1)
143 check_cmd1(cmds, cmd1.NPU_SET_OFM_STRIDE_Y, 1426)
144 check_cmd1(cmds, cmd1.NPU_SET_OFM_STRIDE_X, 46)
145 check_cmd0(cmds, cmd0.NPU_SET_OFM_ZERO_POINT, 128)
146 check_cmd0(cmds, cmd0.NPU_SET_OFM_PRECISION, 0)
147 check_cmd0(cmds, cmd0.NPU_SET_KERNEL_HEIGHT_M1, 1)
148 check_cmd0(cmds, cmd0.NPU_SET_KERNEL_WIDTH_M1, 2)
149 check_cmd0(cmds, cmd0.NPU_SET_KERNEL_STRIDE, 5)
150 check_cmd0(cmds, cmd0.NPU_SET_WEIGHT_REGION, 0)
151 check_cmd1(cmds, cmd1.NPU_SET_WEIGHT_BASE, 0)
152 check_cmd1(cmds, cmd1.NPU_SET_WEIGHT_LENGTH, 7696)
153 check_cmd0(cmds, cmd0.NPU_SET_SCALE_REGION, 0)
154 check_cmd1(cmds, cmd1.NPU_SET_SCALE_BASE, 32000)
155 check_cmd1(cmds, cmd1.NPU_SET_SCALE_LENGTH, 464)
156 check_cmd0(cmds, cmd0.NPU_SET_ACTIVATION, 0)
157 check_cmd0(cmds, cmd0.NPU_SET_ACTIVATION_MIN, 0)
158 check_cmd0(cmds, cmd0.NPU_SET_ACTIVATION_MAX, 255)
159 check_cmd0(cmds, cmd0.NPU_SET_OFM_BLK_HEIGHT_M1, 15)
160 check_cmd0(cmds, cmd0.NPU_SET_OFM_BLK_WIDTH_M1, 3)
161 check_cmd0(cmds, cmd0.NPU_SET_OFM_BLK_DEPTH_M1, 15)
162 check_cmd0(cmds, cmd0.NPU_SET_IFM_IB_END, 14)
163 check_cmd0(cmds, cmd0.NPU_SET_AB_START, 14)
164 check_cmd0(cmds, cmd0.NPU_SET_ACC_FORMAT, 0)
165 check_cmd0(cmds, cmd0.NPU_SET_BLOCKDEP, 0)
166 check_cmd0(cmds, cmd0.NPU_OP_CONV, 0)
Louis Verhaarde8a5a782020-11-02 18:04:27 +0100167
168
169def create_fully_connected_op() -> NpuConv2DOperation:
170 op = NpuConv2DOperation()
171 op.ifm = create_feature_map(
172 NpuShape3D(height=1, width=1, depth=114),
173 1,
174 0,
175 quant=NpuQuantization(scale_f32=0.007843138, zero_point=128),
176 layout=NpuLayout.NHCWB16,
177 )
178 op.ofm = create_feature_map(
179 NpuShape3D(height=1, width=1, depth=96),
180 1,
181 0x6A0,
182 quant=NpuQuantization(scale_f32=0.20392157, zero_point=128),
183 layout=NpuLayout.NHCWB16,
184 )
185 op.kernel = NpuKernel(1, 1)
186 op.weights = [NpuAddressRange(region=0, address=0x16880, length=13120)]
187 op.biases = [NpuAddressRange(region=0, address=0x19BC0, length=960)]
188 op.padding = NpuPadding(top=0, left=0, right=0, bottom=0)
189 op.block_traversal = NpuBlockTraversal.DEPTH_FIRST
Louis Verhaard933f55e2020-11-25 14:10:30 +0100190 op.block_config = NpuShape3D(height=2, width=4, depth=96)
Louis Verhaarde8a5a782020-11-02 18:04:27 +0100191 return op
192
193
194def test_fully_connected():
195 """Tests command stream generation for a fully connected operation"""
196 op = create_fully_connected_op()
Louis Verhaardaeae5672020-11-02 18:04:27 +0100197 cmds = npu_generate_register_command_stream([op], NpuAccelerator.Ethos_U55_128)
Louis Verhaarde8a5a782020-11-02 18:04:27 +0100198 check_cmd0(cmds, cmd0.NPU_OP_CONV, 0)
199 assert len(cmds) > 20
200
201
202def test_depthwise():
203 """Test depthwise operation, preceeded by DMA operation"""
204 weights_src = NpuAddressRange(region=0, address=0x40, length=96)
205 weights_dest = NpuAddressRange(region=1, address=0x10000, length=96)
206 dma_op = NpuDmaOperation(weights_src, weights_dest)
207 op = NpuConvDepthWiseOperation()
208 ifm_quant = NpuQuantization(scale_f32=0.007843138, zero_point=128)
209 op.ifm = create_feature_map(NpuShape3D(height=64, width=64, depth=8), 1, 0x0, quant=ifm_quant)
210 ofm_quant = NpuQuantization(scale_f32=0.062745101749897, zero_point=128)
211 op.ofm = create_feature_map(NpuShape3D(height=64, width=64, depth=8), 1, 0x8000, quant=ofm_quant)
212 op.kernel = NpuKernel(3, 3)
213 op.padding = NpuPadding(top=1, left=1, right=1, bottom=1)
214 op.weights = [weights_dest]
215 op.biases = [NpuAddressRange(region=0, address=0, length=80)]
Louis Verhaard933f55e2020-11-25 14:10:30 +0100216 op.block_config = NpuShape3D(height=8, width=12, depth=8)
Louis Verhaardaeae5672020-11-02 18:04:27 +0100217 cmds = npu_generate_register_command_stream([dma_op, op], NpuAccelerator.Ethos_U55_128)
Louis Verhaarde8a5a782020-11-02 18:04:27 +0100218 check_cmd0(cmds, cmd0.NPU_SET_DMA0_SRC_REGION, 0)
219 check_cmd1(cmds, cmd1.NPU_SET_DMA0_SRC, 0x40)
220 check_cmd0(cmds, cmd0.NPU_SET_DMA0_DST_REGION, 1)
221 check_cmd1(cmds, cmd1.NPU_SET_DMA0_DST, 0x10000)
222 check_cmd1(cmds, cmd1.NPU_SET_DMA0_LEN, 96)
223 check_cmd0(cmds, cmd0.NPU_OP_DMA_START, 0)
224 # A DMA WAIT should have been inserted
225 check_cmd0(cmds, cmd0.NPU_OP_DMA_WAIT, 0)
226 check_cmd0(cmds, cmd0.NPU_OP_DEPTHWISE, 0)
Louis Verhaarde8a5a782020-11-02 18:04:27 +0100227
228
229def test_mul_with_broadcast_and_relu():
230 """Test multiplication with broadcasted IFM2"""
231 op = NpuElementWiseOperation(NpuElementWiseOp.MUL)
232 op.ifm = create_feature_map(NpuShape3D(height=31, width=22, depth=31), 1, 0x20)
233 op.ifm2 = create_feature_map(NpuShape3D(height=1, width=22, depth=1), 1, 0)
234 op.ofm = create_feature_map(NpuShape3D(height=31, width=22, depth=31), 1, 0x52C0)
235 op.activation = NpuActivation(NpuActivationOp.NONE_OR_RELU)
236 op.activation.min = 0 # RELU
Louis Verhaard933f55e2020-11-25 14:10:30 +0100237 accelerator = NpuAccelerator.Ethos_U55_32
238 # Select a block config using npu_find_block_configs
239 op.block_config = npu_find_block_configs(op, accelerator)[0]
240 cmds = npu_generate_register_command_stream([op], accelerator)
Louis Verhaarde8a5a782020-11-02 18:04:27 +0100241 check_cmd1(cmds, cmd1.NPU_SET_OFM_SCALE, 1073741824, 30)
242 check_cmd0(cmds, cmd0.NPU_SET_IFM_REGION, 1)
243 check_cmd1(cmds, cmd1.NPU_SET_IFM_BASE0, 32)
244 check_cmd1(cmds, cmd1.NPU_SET_IFM_BASE1, 0)
245 check_cmd1(cmds, cmd1.NPU_SET_IFM_BASE2, 0)
246 check_cmd1(cmds, cmd1.NPU_SET_IFM_BASE3, 0)
247 check_cmd0(cmds, cmd0.NPU_SET_IFM_HEIGHT0_M1, 30)
248 check_cmd0(cmds, cmd0.NPU_SET_IFM_HEIGHT1_M1, 30)
249 check_cmd0(cmds, cmd0.NPU_SET_IFM_WIDTH0_M1, 21)
250 check_cmd0(cmds, cmd0.NPU_SET_IFM_DEPTH_M1, 30)
251 check_cmd1(cmds, cmd1.NPU_SET_IFM_STRIDE_C, 1)
252 check_cmd1(cmds, cmd1.NPU_SET_IFM_STRIDE_Y, 682)
253 check_cmd1(cmds, cmd1.NPU_SET_IFM_STRIDE_X, 31)
254 check_cmd0(cmds, cmd0.NPU_SET_IFM_ZERO_POINT, 0)
255 check_cmd0(cmds, cmd0.NPU_SET_IFM_PRECISION, 0)
256 check_cmd0(cmds, cmd0.NPU_SET_IFM_UPSCALE, 0)
257 check_cmd0(cmds, cmd0.NPU_SET_OFM_REGION, 1)
258 check_cmd1(cmds, cmd1.NPU_SET_OFM_BASE0, 21184)
259 check_cmd1(cmds, cmd1.NPU_SET_OFM_BASE1, 0)
260 check_cmd1(cmds, cmd1.NPU_SET_OFM_BASE2, 0)
261 check_cmd1(cmds, cmd1.NPU_SET_OFM_BASE3, 0)
262 check_cmd0(cmds, cmd0.NPU_SET_OFM_HEIGHT0_M1, 30)
263 check_cmd0(cmds, cmd0.NPU_SET_OFM_HEIGHT1_M1, 30)
264 check_cmd0(cmds, cmd0.NPU_SET_OFM_WIDTH0_M1, 21)
265 check_cmd0(cmds, cmd0.NPU_SET_OFM_HEIGHT_M1, 30)
266 check_cmd0(cmds, cmd0.NPU_SET_OFM_WIDTH_M1, 21)
267 check_cmd0(cmds, cmd0.NPU_SET_OFM_DEPTH_M1, 30)
268 check_cmd1(cmds, cmd1.NPU_SET_OFM_STRIDE_C, 1)
269 check_cmd1(cmds, cmd1.NPU_SET_OFM_STRIDE_Y, 682)
270 check_cmd1(cmds, cmd1.NPU_SET_OFM_STRIDE_X, 31)
271 check_cmd0(cmds, cmd0.NPU_SET_OFM_ZERO_POINT, 0)
272 check_cmd0(cmds, cmd0.NPU_SET_OFM_PRECISION, 256)
273 check_cmd0(cmds, cmd0.NPU_SET_ACTIVATION, 0)
274 check_cmd0(cmds, cmd0.NPU_SET_ACTIVATION_MIN, 0)
275 check_cmd0(cmds, cmd0.NPU_SET_ACTIVATION_MAX, 255)
276 check_cmd0(cmds, cmd0.NPU_SET_IFM2_REGION, 1)
277 check_cmd1(cmds, cmd1.NPU_SET_IFM2_BASE0, 0)
278 check_cmd1(cmds, cmd1.NPU_SET_IFM2_BASE1, 0)
279 check_cmd1(cmds, cmd1.NPU_SET_IFM2_BASE2, 0)
280 check_cmd1(cmds, cmd1.NPU_SET_IFM2_BASE3, 0)
281 check_cmd0(cmds, cmd0.NPU_SET_IFM2_HEIGHT0_M1, 0)
282 check_cmd0(cmds, cmd0.NPU_SET_IFM2_HEIGHT1_M1, 0)
283 check_cmd0(cmds, cmd0.NPU_SET_IFM2_WIDTH0_M1, 21)
284 check_cmd1(cmds, cmd1.NPU_SET_IFM2_STRIDE_C, 1)
285 check_cmd1(cmds, cmd1.NPU_SET_IFM2_STRIDE_Y, 22)
286 check_cmd1(cmds, cmd1.NPU_SET_IFM2_STRIDE_X, 1)
287 check_cmd0(cmds, cmd0.NPU_SET_IFM2_ZERO_POINT, 0)
288 check_cmd0(cmds, cmd0.NPU_SET_IFM2_PRECISION, 0)
289 check_cmd0(cmds, cmd0.NPU_SET_IFM2_BROADCAST, 5)
Louis Verhaarde8a5a782020-11-02 18:04:27 +0100290 check_cmd0(cmds, cmd0.NPU_SET_IFM_IB_END, 16)
291 check_cmd0(cmds, cmd0.NPU_SET_AB_START, 16)
292 check_cmd0(cmds, cmd0.NPU_SET_IFM2_IB_START, 9)
293 check_cmd0(cmds, cmd0.NPU_SET_ACC_FORMAT, 0)
294 check_cmd0(cmds, cmd0.NPU_SET_BLOCKDEP, 0)
295 check_cmd0(cmds, cmd0.NPU_OP_ELEMENTWISE, 0)
296 # Check that block width/height were generated that fit
297 blk_height = find_cmd0(cmds, cmd0.NPU_SET_OFM_BLK_HEIGHT_M1)
298 blk_width = find_cmd0(cmds, cmd0.NPU_SET_OFM_BLK_WIDTH_M1)
299 blk_depth = find_cmd0(cmds, cmd0.NPU_SET_OFM_BLK_DEPTH_M1)
300 assert blk_height >= 0
301 assert blk_width >= 0
302 assert blk_depth >= 0
303 assert (blk_height + 1) * (blk_width + 1) + (blk_depth + 1) <= 3072
304
305
306def create_avg_pool_op() -> NpuPoolingOperation:
307 op = NpuPoolingOperation(NpuPoolingOp.AVERAGE)
308 op.ifm = create_feature_map(
309 NpuShape3D(height=29, width=30, depth=27), 2, 0, quant=NpuQuantization(scale_f32=0.007843138, zero_point=128)
310 )
311 op.ofm = create_feature_map(
312 NpuShape3D(height=10, width=10, depth=27),
313 2,
314 0x5BD0,
315 quant=NpuQuantization(scale_f32=0.20392157, zero_point=128),
316 )
317 op.kernel = NpuKernel(8, 2, 3, 3)
318 op.padding = NpuPadding(top=0, left=2, right=3, bottom=0)
Louis Verhaard933f55e2020-11-25 14:10:30 +0100319 # Select a block config
320 op.block_config = NpuShape3D(height=4, width=4, depth=16)
Louis Verhaarde8a5a782020-11-02 18:04:27 +0100321 return op
322
323
324def test_avg_pool():
325 """Tests average pool operation"""
326 op = create_avg_pool_op()
Louis Verhaardaeae5672020-11-02 18:04:27 +0100327 cmds = npu_generate_register_command_stream([op], NpuAccelerator.Ethos_U55_128)
Louis Verhaarde8a5a782020-11-02 18:04:27 +0100328 check_cmd0(cmds, cmd0.NPU_OP_POOL, 1)
329 assert len(cmds) > 10
330
331
332def test_two_operations():
333 """Tests code generation with 2 operations"""
334 op1 = create_fully_connected_op()
335 op2 = create_avg_pool_op()
Louis Verhaardaeae5672020-11-02 18:04:27 +0100336 cmds = npu_generate_register_command_stream([op1, op2], NpuAccelerator.Ethos_U55_64)
Louis Verhaarde8a5a782020-11-02 18:04:27 +0100337 check_cmd0(cmds, cmd0.NPU_OP_POOL, 1)
338 check_cmd0(cmds, cmd0.NPU_OP_CONV, 0)
339 check_cmd0(cmds, cmd0.NPU_SET_BLOCKDEP, 0)
340 # The operations are not dependent, so expect a blockdep 3
341 check_cmd0(cmds, cmd0.NPU_SET_BLOCKDEP, 3)
342 assert len(cmds) > 10
343
344
345def test_dma_op():
346 """Tests DMA operation followed by average pool. The DMA provides the contents of the average pool's IFM."""
347 pool_op = create_avg_pool_op()
348 assert pool_op.ofm is not None
349 dest = get_address_ranges(pool_op.ofm)[0]
350 assert dest is not None
351 src = NpuAddressRange(0, 0x24000, dest.length)
352 dma_op = NpuDmaOperation(src, dest)
Louis Verhaardaeae5672020-11-02 18:04:27 +0100353 cmds = npu_generate_register_command_stream([dma_op, pool_op], NpuAccelerator.Ethos_U55_64)
Louis Verhaarde8a5a782020-11-02 18:04:27 +0100354 check_cmd0(cmds, cmd0.NPU_OP_DMA_START, 0)
355 # A DMA WAIT should have been inserted
356 check_cmd0(cmds, cmd0.NPU_OP_DMA_WAIT, 0)
357 check_cmd0(cmds, cmd0.NPU_OP_POOL, 1)