blob: 4a03d0efe368951d6fc9468d1d69b576c701ae99 [file] [log] [blame]
Tim Hall79d07d22020-04-27 18:20:16 +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
18# Description:
19# Holds a container for Ethos-U55/System architecture parameters.
20
21from .nn_graph import MemArea, TensorPurpose, NpuBlockType, TensorFormat
22from .numeric_util import round_up, round_up_divide
23from collections import namedtuple
24from configparser import ConfigParser
25from .supported_operators import SupportedOperators
26import numpy as np
27import enum
28
29PointXY = namedtuple("PointXY", "x y")
30PointXYZ = namedtuple("PointXYZ", "x y z")
31
32
33class Block:
34 def __init__(self, w, h, d):
35 self.width = w
36 self.height = h
37 self.depth = d
38
39 def __eq__(self, other):
40 if self.width == other.width and self.height == other.height and self.depth == other.depth:
41 return True
42 else:
43 return False
44
45 def __repr__(self):
46 return "<Block: {0},{1},{2}>".format(self.width, self.height, self.depth)
47
48 @classmethod
49 def from_string(cls, s):
50 w, h, c = (int(v) for v in s.split("x"))
51 return cls(w, h, c)
52
53
54class Rect:
55 def __init__(self, x, y, z, x2, y2, z2):
56 self.x = x
57 self.y = y
58 self.z = z
59 self.x2 = x2
60 self.y2 = y2
61 self.z2 = z2
62
63 def start(self):
64 return PointXYZ(self.x, self.y, self.z)
65
66 def end(self):
67 return PointXYZ(self.x2, self.y2, self.z2)
68
69 def size(self):
70 return Block(self.x2 - self.x + 1, self.y2 - self.y + 1, self.z2 - self.z + 1)
71
72 def __repr__(self):
73 return "<Rect: ({0},{1},{2}) ({3},{4},{5})>".format(self.x, self.y, self.z, self.x2, self.y2, self.z2)
74
75
76class Kernel:
77 def __init__(self, w, h, sx=1, sy=1, dx=1, dy=1):
78 assert sx > 0 and sy > 0
79 assert dx > 0 and dy > 0
80 self.width = w
81 self.height = h
82 self.stride = PointXY(sx, sy)
83 self.dilation = PointXY(dx, dy)
84
85
86class SHRAMElements:
87 IFM8 = 0
88 IFM16 = 1
89 IFM8_Elementwise = 2
90 IFM16_Elementwise = 3
91 Acc16 = 4
92 Acc32 = 5
93 Acc40 = 6
94 Last = Acc40
95 BitSizes = np.array([8, 16, 8, 16, 16, 32, 40], np.int32)
96
97
98class SHRAMBlockConfig:
99 def __init__(self, sizes, banks):
100 assert len(banks) == SHRAMElements.Last + 1
101 self.sizes = sizes
102 self.banks = banks
103
104
105# Area indices must match Ethos-U55 SHRAM layout spec
106class SharedBufferArea(enum.IntEnum):
107 OFM = 0
108 Weights = 1
109 IFM = 2
110 Accumulators = 3
111 Size = Accumulators + 1
112
113
114class ArchitectureFeatures:
115 """This class is a container for various parameters of the Ethos-U55 core
116and system configuration that can be tuned, either by command line
117parameters or by the Ethos-U55 architects. The class is often passed
118around to passes that need to do architecture-dependent actions.
119
120Note the difference between ArchitectureFeatures and CompilerOptions
121- ArchitectureFeatures is for changing the Ethos-U55 and system architecture
122- CompilerOptions is for changing the behaviour of the compiler
123
124"""
125
126 ArchitectureConfig = namedtuple(
127 "ArchitectureConfig", "macs cores ofm_ublock ifm_ublock shram_banks shram_granules elem_units"
128 )
129 accelerator_configs = {
130 "ethos-u55-256": ArchitectureConfig(256, 1, Block(2, 2, 8), Block(2, 2, 8), 48, [8, 8, 8, 8, 8, 16, 20], 8),
131 "ethos-u55-128": ArchitectureConfig(128, 1, Block(2, 1, 8), Block(2, 2, 8), 24, [4, 4, 4, 4, 4, 8, 12], 4),
132 "ethos-u55-64": ArchitectureConfig(64, 1, Block(1, 1, 8), Block(1, 1, 8), 16, [2, 2, 2, 2, 4, 4, 8], 2),
133 "ethos-u55-32": ArchitectureConfig(32, 1, Block(1, 1, 4), Block(1, 1, 8), 16, [2, 2, 2, 2, 4, 4, 4], 1),
134 }
135
136 OFMSplitDepth = 16
137
138 def __init__(
139 self,
140 vela_config: ConfigParser,
141 accelerator_config,
142 system_config,
143 permanent_storage,
144 inter_pass_cycle_delay,
145 dram_bandwidth,
146 override_block_config,
147 block_config_limit,
148 global_memory_clock_scale,
149 max_blockdep,
150 ):
151 accelerator_config = accelerator_config.lower()
152 self.vela_config = vela_config
153 self.accelerator_config = accelerator_config
154 if not self.accelerator_config in ArchitectureFeatures.accelerator_configs:
155 raise Exception("Unknown accelerator configuration " + self.accelerator_config)
156 accel_config = ArchitectureFeatures.accelerator_configs[self.accelerator_config]
157 self.config = accel_config
158
159 self.system_config = system_config
160
161 is_yoda_system = "yoda-" in self.accelerator_config
162
163 if is_yoda_system:
164 self.sram_size = 256 * 1024
165 else:
166 self.sram_size = 200 * 1024 * 1024
167
168 self.ncores = accel_config.cores
169 self.ofm_ublock = accel_config.ofm_ublock
170 self.ifm_ublock = accel_config.ifm_ublock
171 self.subkernel_max = Block(8, 8, 65536)
172 self.ofm_block_max = Block(64, 32, 128)
173 self.override_block_config = override_block_config
174 self.block_config_limit = block_config_limit
175
176 self.global_memory_clock_scale = global_memory_clock_scale
177 if self.global_memory_clock_scale <= 0.0 or self.global_memory_clock_scale > 1.0:
178 raise Exception(
179 "Invalid global_memory_clock_scale = "
180 + str(self.global_memory_clock_scale)
181 + " (must be > 0.0 and <= 1.0)"
182 )
183
184 self.max_blockdep = max_blockdep
185
186 dpu_min_height = accel_config.ofm_ublock.height
187 dpu_min_width = accel_config.ofm_ublock.width
188 dpu_dot_product_width = 8
189 dpu_min_ofm_channels = accel_config.ofm_ublock.depth
190
191 self.num_elem_wise_units = accel_config.elem_units
192 self.num_macs_per_cycle = dpu_min_height * dpu_min_width * dpu_dot_product_width * dpu_min_ofm_channels
193
194 self.memory_clock_scales = np.zeros(MemArea.Size)
195 self.memory_port_widths = np.zeros(MemArea.Size)
196
197 # Get system configuration
198 self.__read_sys_config()
199
200 # apply the global memory clock scales to the individual ones from the system config
201 for mem in MemArea.all():
202 self.memory_clock_scales[mem] *= self.global_memory_clock_scale
203
204 self.memory_clocks = self.memory_clock_scales * self.npu_clock
205 self.memory_bandwidths_per_cycle = self.memory_port_widths * self.memory_clock_scales / 8
206
207 if dram_bandwidth != 0:
208 self.memory_bandwidths_per_cycle[MemArea.Dram] = dram_bandwidth * 1e9 / self.npu_clock
209
210 self.memory_bandwidths_per_second = self.memory_bandwidths_per_cycle * self.npu_clock
211
212 # sizes as N x H x W x C. we need to round up to these when allocating storage
213 self.storage_rounding_quantums = {
214 TensorFormat.Unknown: (1, 1, 1, 1),
215 TensorFormat.WeightsCompressed: (1, 1, 1, 1),
216 TensorFormat.NHWC: (1, 1, 1, 1),
217 TensorFormat.NHCWB16: (1, 1, 1, 16),
218 }
219
220 # brick sizes as N x H x W x C. We have to fetch whole bricks at a time
221 self.brick_sizes = {
222 TensorFormat.Unknown: (1, 1, 1, 1),
223 TensorFormat.WeightsCompressed: (1, 1, 1, 1),
224 TensorFormat.NHWC: (1, 1, 1, 1),
225 TensorFormat.NHCWB16: (1, 1, 1, 16),
226 }
227
228 self.inter_pass_cycle_delay = inter_pass_cycle_delay
229
230 self.default_weight_format = TensorFormat.WeightsCompressed
231 self.default_feature_map_format = TensorFormat.NHWC
232
233 if permanent_storage != MemArea.OffChipFlash:
234 self.permanent_storage_mem_area = permanent_storage
235
236 self.tensor_storage_mem_area = {
237 # permanent mem_area
238 TensorPurpose.Weights: self.permanent_storage_mem_area,
239 TensorPurpose.FeatureMap: self.feature_map_storage_mem_area,
240 }
241
242 self.tensor_load_mem_area = dict(self.tensor_storage_mem_area)
243
244 if self.tensor_storage_mem_area[TensorPurpose.Weights] in (MemArea.OffChipFlash,):
245 self.tensor_load_mem_area[TensorPurpose.Weights] = MemArea.Sram
246
247 self.min_block_sizes = {
248 NpuBlockType.Default: (dpu_min_height, dpu_min_width),
249 NpuBlockType.VectorProduct: (1, 1),
250 NpuBlockType.ConvolutionMxN: (dpu_min_height, dpu_min_width),
251 NpuBlockType.Pooling: (dpu_min_height, dpu_min_width),
252 NpuBlockType.ConvolutionDepthWise: (dpu_min_height, dpu_min_width),
253 NpuBlockType.ElementWise: (1, 1),
254 }
255
256 self.sub_kernel_limits = {
257 NpuBlockType.Default: (8, 8),
258 NpuBlockType.VectorProduct: (1, 1),
259 NpuBlockType.ConvolutionMxN: (8, 8),
260 NpuBlockType.Pooling: (8, 8),
261 NpuBlockType.ConvolutionDepthWise: (8, 8),
262 NpuBlockType.ElementWise: (1, 1),
263 }
264
265 # weights for scheduler search
266 from .npu_performance import make_bandwidth_array
267
268 self.bandwidth_weights = make_bandwidth_array()
269 self.bandwidth_weights[MemArea.Sram] = 1.0
270 self.bandwidth_weights[MemArea.Dram] = 10.0
271 self.bandwidth_weights[MemArea.OnChipFlash] = 2.0
272 self.bandwidth_weights[MemArea.OffChipFlash] = 20.0
273 self.cycles_weight = 40
274 self.max_sram_used_weight = 1000
275
276 if is_yoda_system:
277 self.max_sram_used_weight = 0
278
279 # Shared Buffer Block allocations
280 self.shram_bank_size = 1024 # bytes
281 self.shram_size_bytes = accel_config.shram_banks * self.shram_bank_size
282 self.shram_reserved_output_banks = 2
283 self.shram_reserved_weight_banks = 0
284 self.shram_reserved_unused_banks = 2 if accel_config.shram_banks > 16 else 0
285 self.shram_total_banks = accel_config.shram_banks - self.shram_reserved_unused_banks
286 self.shram_bank_granules = np.array(accel_config.shram_granules, np.int32)
287
288 # Build a map of acceptable IFM/OFM block configurations up to the maximum
289 # IFM/OFM block size.
290 ifm_block_max = self.get_ifm_block_size(32, self.ofm_block_max, Kernel(8, 8))
291 self.block_config_map = dict()
292 self.generate_block_config_map(Block(ifm_block_max.width, ifm_block_max.height, 128))
293
294 # Setup supported operators and restriction checkers class
295 self.supported_operators = SupportedOperators()
296
297 # Calculate block configuration for ALL known IFM operations and
298 # accumulator sizes. Consumers will need to select their preferred
299 # operation and bit-width at read-time.
300 def generate_block_config(self, width, height, depth):
301 # Number of bytes required for any SRAM element for a FM of given dimensions
302 size_bytes = (SHRAMElements.BitSizes * (height * width * depth)) // 8
303 # Convert byte size (rounded) to size in banks
304 size_banks = round_up_divide(size_bytes, self.shram_bank_size)
305 size_banks *= 2 # Double buffer the IFM/Acc (need twice as many banks)
306 # Round bank requirement to bank granularity
307 required_banks = round_up(size_banks, self.shram_bank_granules)
308 return SHRAMBlockConfig(size_bytes, required_banks)
309
310 @staticmethod
311 def make_block_config_key(width, height, depth):
312 return (int(height), int(width), int(depth))
313
314 def get_block_config(self, width, height, depth):
315 assert depth <= self.ofm_block_max.depth
316 key = ArchitectureFeatures.make_block_config_key(width, height, depth)
317 config = self.block_config_map.get(key, None)
318 return config
319
320 # Generate a key:value map of possible block configurations, where the
321 # key is compounded from the block dimensions: 0x00HHWWCC
322 def generate_block_config_map(self, block: Block):
323 for h in range(1, block.height + 1):
324 for w in range(1, block.width + 1):
325 # All possible IFM/OFM depth values
326 for c in [4, 8, 12, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, 128]:
327 key = ArchitectureFeatures.make_block_config_key(w, h, c)
328 self.block_config_map[key] = self.generate_block_config(w, h, c)
329
330 def calc_ifm_block_depth(self, ifm_depth, ifm_bits):
331 assert ifm_bits == 8 or ifm_bits == 16
332 assert ifm_depth > 0
333 ifm_depth = round_up(ifm_depth, self.ifm_ublock.depth)
334 max_block_depth = 32 if ifm_bits == 8 else 16
335 return min(max_block_depth, ifm_depth)
336
337 # Calculate the size of the IFM block given a depth, target OFM block and a kernel
338 def get_ifm_block_size(
339 self, ifm_block_depth, ofm_block: Block, kernel: Kernel, subkernel: Block = Block(8, 8, 65536)
340 ):
341 upscaling = 1
342 # Height
343 ifm_odd_2x_height_enable = 0
344 dilated_kernel_height = ((kernel.height - 1) * kernel.dilation.y) + 1
345 ifm_block_height = (
346 (ofm_block.height - 1) * kernel.stride.y
347 + min(subkernel.height, dilated_kernel_height)
348 + ifm_odd_2x_height_enable
349 ) // upscaling
350
351 if kernel.stride.y == 1:
352 ifm_block_height = round_up(ifm_block_height, self.ofm_ublock.height)
353 elif kernel.stride.y == 2:
354 if (self.ofm_ublock.height == 2) and (ifm_block_height % 4 == 2):
355 ifm_block_height = ifm_block_height + 2
356 else:
357 ifm_block_height = round_up(ifm_block_height, self.ofm_ublock.height)
358 else:
359 assert False
360
361 # Width
362 ifm_odd_2x_width_enable = 0
363 dilated_kernel_width = ((kernel.width - 1) * kernel.dilation.x) + 1
364 ifm_block_width = (
365 (ofm_block.width - 1) * kernel.stride.x
366 + min(subkernel.width, dilated_kernel_width)
367 + ifm_odd_2x_width_enable
368 ) // upscaling
369
370 if kernel.stride.x == 1:
371 ifm_block_width = round_up(ifm_block_width, self.ofm_ublock.width)
372 elif kernel.stride.x == 2:
373 if (self.ofm_ublock.width == 2) and (ifm_block_width % 4 == 2):
374 ifm_block_width = ifm_block_width + 2
375 else:
376 ifm_block_width = round_up(ifm_block_width, self.ofm_ublock.width)
377 else:
378 assert False
379
380 return Block(ifm_block_width, ifm_block_height, ifm_block_depth)
381
382 @staticmethod
383 def intersects(start_a, end_a, start_b, end_b):
384 start_x = max(start_a[0], start_b[0])
385 end_x = min(end_a[0], end_b[0])
386 start_y = max(start_a[1], start_b[1])
387 end_y = min(end_a[1], end_b[1])
388 start_z = max(start_a[2], start_b[2])
389 end_z = min(end_a[2], end_b[2])
390 return ((end_x - start_x) > 0) and ((end_y - start_y) > 0) and ((end_z - start_z) > 0)
391
392 # Block job dependency:
393 # Does the VOLUME of IFMs for block job B(0) overlap with VOLUME of OFMs block jobs A(8,9,10)
394 #
395 # A | B
396 # ----------------------+------------------
397 # .... 3,4,5,6,7,8,9,10 | 0,1,2,3,4,5,6,8 10 < JOB NUMBER
398 # |<------->| dependency offset
399 #
400 MAX_BLOCKDEP = 3
401
402 # Get the coordinates of a block offset from either the end (negative)
403 # or the start (zero or positive) of the given 3d area
404 def get_offset_block_coords(self, area: Rect, block: Block, offset):
405 size = area.size()
406 # Dimensions of the region, in blocks
407 width_blocks = round_up_divide(size.width, block.width)
408 height_blocks = round_up_divide(size.height, block.height)
409 depth_blocks = round_up_divide(size.depth, block.depth)
410 total_blocks = width_blocks * height_blocks * depth_blocks
411 if offset < 0:
412 index = total_blocks + offset
413 else:
414 index = offset
415
416 if index >= total_blocks:
417 return None
418
419 # Coordinates of the indexed block
420 coord_z = block.depth * (index % depth_blocks)
421 coord_y = block.height * (index // (depth_blocks * width_blocks))
422 coord_x = block.width * ((index // depth_blocks) % width_blocks)
423
424 return (coord_x + area.x, coord_y + area.y, coord_z + area.z)
425
426 def get_first_job_input_volume(
427 self, ifm: Rect, ofm: Rect, ifm_block_depth, ofm_block: Block, kernel: Kernel, padLT, block_offset
428 ):
429 # Get ifm block size (jobs are invisibly decomposed into subkernels)
430 ifm_block = self.get_ifm_block_size(ifm_block_depth, ofm_block, kernel, self.ofm_block_max)
431 ifm_depth_blocks = round_up_divide(ifm.size().depth, ifm_block_depth)
432
433 # Which OFM block are we calculating
434 ofm_coord = self.get_offset_block_coords(ofm, ofm_block, block_offset // ifm_depth_blocks)
435 if ofm_coord is None:
436 return None
437
438 # Coordinate of the source IFM block
439 ifm_coord_x = max(0, ofm_coord[0] * kernel.stride.x - padLT[0])
440 ifm_coord_y = max(0, ofm_coord[1] * kernel.stride.y - padLT[1])
441 ifm_coord_z = ifm.z + (block_offset % ifm_depth_blocks) * ifm_block.depth
442
443 # IFM block that will be sampled for the FIRST+block_offset job in the next operator's OFM
444 start_coord = (ifm_coord_x, ifm_coord_y, ifm_coord_z)
445 end_coord = (
446 start_coord[0] + ifm_block.width,
447 start_coord[1] + ifm_block.height,
448 start_coord[2] + ifm_block.depth,
449 )
450
451 return (start_coord, end_coord, 1) # start, end, total jobs
452
453 def get_prev_job_output_volume(
454 self, ifm: Block, ofm: Rect, ifm_block_depth, ofm_block: Block, kernel: Kernel, block_offset
455 ):
456 assert block_offset >= 0
457
458 # Get OFM block's volume coordinates
459 start_coord = self.get_offset_block_coords(ofm, ofm_block, -1 - block_offset)
460 if start_coord is None:
461 return None
462 end_coord = (
463 start_coord[0] + ofm_block.width,
464 start_coord[1] + ofm_block.height,
465 start_coord[2] + ofm_block.depth,
466 )
467
468 # Calculate how many IFM blocks this OFM block requires (i.e how many jobs)
469 ifm_block = self.get_ifm_block_size(ifm_block_depth, ofm_block, kernel, self.ofm_block_max)
470 ifm_depth_blocks = round_up_divide(ifm.size().depth, ifm_block_depth)
471 ifm_depth_blocks = 1 # Overwrite with 1 to force OFM block dependency, not IFM
472
473 return (start_coord, end_coord, ifm_depth_blocks) # start, end, total jobs for this OFM block
474
475 def calc_block_dep(
476 self,
477 prev_ifm: Block,
478 prev_ofm: Block,
479 prev_ifm_block_depth,
480 prev_ofm_block: Block,
481 prev_kernel: Kernel,
482 ifm: Block,
483 ofm: Block,
484 ifm_block_depth,
485 ofm_block: Block,
486 kernel: Kernel,
487 padLT,
488 ):
489
490 blockdep = ArchitectureFeatures.MAX_BLOCKDEP
491
492 # Iterate over the next BLOCKDEP inputs, checking to see if a sliding window
493 # of IFM area overlaps with any previous OFM block generation.
494 elapsed_jobs = 0
495 ifm_depth = ifm.size().depth
496 for forward_offset in range(ArchitectureFeatures.MAX_BLOCKDEP):
497 # This is the IFM block we want to sample from
498 in_area = self.get_first_job_input_volume(
499 ifm, ofm, ifm_block_depth, ofm_block, kernel, padLT, forward_offset
500 )
501 if in_area is None:
502 break
503
504 # Try several previous-OFM blocks in the past (they still might comprise multiple IFM jobs)
505 outstanding_jobs = 0
506 for block_offset in range(ArchitectureFeatures.MAX_BLOCKDEP):
507 # This is the OFM block being generated by the previous op
508 out_area = self.get_prev_job_output_volume(
509 prev_ifm, prev_ofm, prev_ifm_block_depth, prev_ofm_block, prev_kernel, block_offset
510 )
511 if out_area is None:
512 break
513
514 # Block dependency is the max number of allowed outstanding jobs
515 # in the pipeline. Selected by determining how many jobs occur
516 # in between two operators' overlapping OFM->IFM block volumes
517 if ArchitectureFeatures.intersects(in_area[0], in_area[1], out_area[0], out_area[1]):
518 break
519 # Early exit if no intersections and we've seen enough jobs in the pipeline
520 elif outstanding_jobs > ArchitectureFeatures.MAX_BLOCKDEP:
521 break
522
523 # This OFM had this many jobs (accumulate over multiple OFM blocks)
524 outstanding_jobs += out_area[2]
525
526 blockdep = min(blockdep, elapsed_jobs + outstanding_jobs)
527 elapsed_jobs += in_area[2]
528 # Early exit if no intersections and we've seen enough jobs in the pipeline
529 if elapsed_jobs > ArchitectureFeatures.MAX_BLOCKDEP:
530 break
531
532 return blockdep
533
534 def cpu_cycle_estimate(self, op):
535 """
536 Gets estimated performance of a CPU operation, based on a linear model of intercept, slope,
537 specified in the vela config file, in ConfigParser file format (.ini file).
538 Example configuration snippet:
539 [CpuPerformance.MyOperationType]
540 Cortex-Mx.intercept=<some float value>
541 Cortex-Mx.slope=<some float value>
542 """
543 section = "CpuPerformance." + op.type
544 if self.vela_config is not None and section in self.vela_config:
545 op_config = self.vela_config[section]
546 try:
547 intercept = float(op_config.get(self.cpu_config + ".intercept", op_config["default.intercept"]))
548 slope = float(op_config.get(self.cpu_config + ".slope", op_config["default.slope"]))
549 n_elements = op.inputs[0].elements()
550 cycles = intercept + n_elements * slope
551 return cycles
552 except:
553 print("Error: Reading CPU cycle estimate in vela configuration file, section {}".format(section))
554 raise
555
556 print("Warning: No configured CPU performance estimate for", op.type)
557 return 0
558
559 def __read_sys_config(self):
560 """
561 Gets the system configuration with the given name from the vela configuration file
562 Example configuration snippet:
563 [SysConfig.MyConfigName]
564 npu_freq=<some float value>
565 cpu=Cortex-Mx
566 ...
567 """
568 # Get system configuration from the vela configuration file
569 if self.vela_config is None:
570 print("Warning: Using default values for system configuration")
571 else:
572 section_key = "SysConfig." + self.system_config
573 if not section_key in self.vela_config:
574 raise Exception("Unknown system configuration " + self.system_config)
575
576 try:
577 self.npu_clock = float(self.__sys_config("npu_freq", "500e6"))
578 self.cpu_config = self.__sys_config("cpu", "Cortex-M7")
579
580 self.memory_clock_scales[MemArea.Sram] = float(self.__sys_config("Sram_clock_scale", "1"))
581 self.memory_port_widths[MemArea.Sram] = int(self.__sys_config("Sram_port_width", "64"))
582
583 self.memory_clock_scales[MemArea.OnChipFlash] = float(self.__sys_config("OnChipFlash_clock_scale", "1"))
584 self.memory_port_widths[MemArea.OnChipFlash] = int(self.__sys_config("OnChipFlash_port_width", "64"))
585
586 self.memory_clock_scales[MemArea.OffChipFlash] = float(
587 self.__sys_config("OffChipFlash_clock_scale", "0.25")
588 )
589 self.memory_port_widths[MemArea.OffChipFlash] = int(self.__sys_config("OffChipFlash_port_width", "32"))
590
591 self.memory_clock_scales[MemArea.Dram] = float(self.__sys_config("Dram_clock_scale", "1"))
592 self.memory_port_widths[MemArea.Dram] = int(self.__sys_config("Dram_port_width", "32"))
593
594 self.fast_storage_mem_area = MemArea[self.__sys_config("fast_storage_mem_area", "Sram")]
595 self.feature_map_storage_mem_area = MemArea[self.__sys_config("feature_map_storage_mem_area", "Sram")]
596 self.permanent_storage_mem_area = MemArea[self.__sys_config("permanent_storage_mem_area", "OffChipFlash")]
597 if self.permanent_storage_mem_area not in set((MemArea.OnChipFlash, MemArea.OffChipFlash)):
598 raise Exception(
599 "Invalid permanent_storage_mem_area = "
600 + str(self.permanent_storage_mem_area)
601 + " (must be 'OnChipFlash' or 'OffChipFlash'). To store the weights and other constant data in SRAM"
602 " select 'OnChipFlash'"
603 )
604 except:
605 print("Error: Reading System Configuration in vela configuration file, section {}".format(section_key))
606 raise
607
608 def __sys_config(self, key, default_value):
609 """
610 Gets the system configuration value with the given key from the vela config file.
611 """
612 if self.vela_config is None:
613 return default_value
614 section = "SysConfig." + self.system_config
615 result = self.vela_config[section].get(key, None)
616 if result is None:
617 raise Exception("Error: System Configuration Missing key {} in section [{}] ".format(key, section))
618 return result