blob: 51c632e0012819f81aa2fb971578b39b6952a32b [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
Dwight Lidman0538a772020-05-06 14:09:17 +0200351 ifm_block_height = round_up(ifm_block_height, self.ofm_ublock.height)
Tim Hall79d07d22020-04-27 18:20:16 +0100352
353 # Width
354 ifm_odd_2x_width_enable = 0
355 dilated_kernel_width = ((kernel.width - 1) * kernel.dilation.x) + 1
356 ifm_block_width = (
357 (ofm_block.width - 1) * kernel.stride.x
358 + min(subkernel.width, dilated_kernel_width)
359 + ifm_odd_2x_width_enable
360 ) // upscaling
361
Dwight Lidman0538a772020-05-06 14:09:17 +0200362 ifm_block_width = round_up(ifm_block_width, self.ofm_ublock.width)
Tim Hall79d07d22020-04-27 18:20:16 +0100363
364 return Block(ifm_block_width, ifm_block_height, ifm_block_depth)
365
366 @staticmethod
367 def intersects(start_a, end_a, start_b, end_b):
368 start_x = max(start_a[0], start_b[0])
369 end_x = min(end_a[0], end_b[0])
370 start_y = max(start_a[1], start_b[1])
371 end_y = min(end_a[1], end_b[1])
372 start_z = max(start_a[2], start_b[2])
373 end_z = min(end_a[2], end_b[2])
374 return ((end_x - start_x) > 0) and ((end_y - start_y) > 0) and ((end_z - start_z) > 0)
375
376 # Block job dependency:
377 # Does the VOLUME of IFMs for block job B(0) overlap with VOLUME of OFMs block jobs A(8,9,10)
378 #
379 # A | B
380 # ----------------------+------------------
381 # .... 3,4,5,6,7,8,9,10 | 0,1,2,3,4,5,6,8 10 < JOB NUMBER
382 # |<------->| dependency offset
383 #
384 MAX_BLOCKDEP = 3
385
386 # Get the coordinates of a block offset from either the end (negative)
387 # or the start (zero or positive) of the given 3d area
388 def get_offset_block_coords(self, area: Rect, block: Block, offset):
389 size = area.size()
390 # Dimensions of the region, in blocks
391 width_blocks = round_up_divide(size.width, block.width)
392 height_blocks = round_up_divide(size.height, block.height)
393 depth_blocks = round_up_divide(size.depth, block.depth)
394 total_blocks = width_blocks * height_blocks * depth_blocks
395 if offset < 0:
396 index = total_blocks + offset
397 else:
398 index = offset
399
400 if index >= total_blocks:
401 return None
402
403 # Coordinates of the indexed block
404 coord_z = block.depth * (index % depth_blocks)
405 coord_y = block.height * (index // (depth_blocks * width_blocks))
406 coord_x = block.width * ((index // depth_blocks) % width_blocks)
407
408 return (coord_x + area.x, coord_y + area.y, coord_z + area.z)
409
410 def get_first_job_input_volume(
411 self, ifm: Rect, ofm: Rect, ifm_block_depth, ofm_block: Block, kernel: Kernel, padLT, block_offset
412 ):
413 # Get ifm block size (jobs are invisibly decomposed into subkernels)
414 ifm_block = self.get_ifm_block_size(ifm_block_depth, ofm_block, kernel, self.ofm_block_max)
415 ifm_depth_blocks = round_up_divide(ifm.size().depth, ifm_block_depth)
416
417 # Which OFM block are we calculating
418 ofm_coord = self.get_offset_block_coords(ofm, ofm_block, block_offset // ifm_depth_blocks)
419 if ofm_coord is None:
420 return None
421
422 # Coordinate of the source IFM block
423 ifm_coord_x = max(0, ofm_coord[0] * kernel.stride.x - padLT[0])
424 ifm_coord_y = max(0, ofm_coord[1] * kernel.stride.y - padLT[1])
425 ifm_coord_z = ifm.z + (block_offset % ifm_depth_blocks) * ifm_block.depth
426
427 # IFM block that will be sampled for the FIRST+block_offset job in the next operator's OFM
428 start_coord = (ifm_coord_x, ifm_coord_y, ifm_coord_z)
429 end_coord = (
430 start_coord[0] + ifm_block.width,
431 start_coord[1] + ifm_block.height,
432 start_coord[2] + ifm_block.depth,
433 )
434
435 return (start_coord, end_coord, 1) # start, end, total jobs
436
437 def get_prev_job_output_volume(
438 self, ifm: Block, ofm: Rect, ifm_block_depth, ofm_block: Block, kernel: Kernel, block_offset
439 ):
440 assert block_offset >= 0
441
442 # Get OFM block's volume coordinates
443 start_coord = self.get_offset_block_coords(ofm, ofm_block, -1 - block_offset)
444 if start_coord is None:
445 return None
446 end_coord = (
447 start_coord[0] + ofm_block.width,
448 start_coord[1] + ofm_block.height,
449 start_coord[2] + ofm_block.depth,
450 )
451
452 # Calculate how many IFM blocks this OFM block requires (i.e how many jobs)
453 ifm_block = self.get_ifm_block_size(ifm_block_depth, ofm_block, kernel, self.ofm_block_max)
454 ifm_depth_blocks = round_up_divide(ifm.size().depth, ifm_block_depth)
455 ifm_depth_blocks = 1 # Overwrite with 1 to force OFM block dependency, not IFM
456
457 return (start_coord, end_coord, ifm_depth_blocks) # start, end, total jobs for this OFM block
458
459 def calc_block_dep(
460 self,
461 prev_ifm: Block,
462 prev_ofm: Block,
463 prev_ifm_block_depth,
464 prev_ofm_block: Block,
465 prev_kernel: Kernel,
466 ifm: Block,
467 ofm: Block,
468 ifm_block_depth,
469 ofm_block: Block,
470 kernel: Kernel,
471 padLT,
472 ):
473
474 blockdep = ArchitectureFeatures.MAX_BLOCKDEP
475
476 # Iterate over the next BLOCKDEP inputs, checking to see if a sliding window
477 # of IFM area overlaps with any previous OFM block generation.
478 elapsed_jobs = 0
479 ifm_depth = ifm.size().depth
480 for forward_offset in range(ArchitectureFeatures.MAX_BLOCKDEP):
481 # This is the IFM block we want to sample from
482 in_area = self.get_first_job_input_volume(
483 ifm, ofm, ifm_block_depth, ofm_block, kernel, padLT, forward_offset
484 )
485 if in_area is None:
486 break
487
488 # Try several previous-OFM blocks in the past (they still might comprise multiple IFM jobs)
489 outstanding_jobs = 0
490 for block_offset in range(ArchitectureFeatures.MAX_BLOCKDEP):
491 # This is the OFM block being generated by the previous op
492 out_area = self.get_prev_job_output_volume(
493 prev_ifm, prev_ofm, prev_ifm_block_depth, prev_ofm_block, prev_kernel, block_offset
494 )
495 if out_area is None:
496 break
497
498 # Block dependency is the max number of allowed outstanding jobs
499 # in the pipeline. Selected by determining how many jobs occur
500 # in between two operators' overlapping OFM->IFM block volumes
501 if ArchitectureFeatures.intersects(in_area[0], in_area[1], out_area[0], out_area[1]):
502 break
503 # Early exit if no intersections and we've seen enough jobs in the pipeline
504 elif outstanding_jobs > ArchitectureFeatures.MAX_BLOCKDEP:
505 break
506
507 # This OFM had this many jobs (accumulate over multiple OFM blocks)
508 outstanding_jobs += out_area[2]
509
510 blockdep = min(blockdep, elapsed_jobs + outstanding_jobs)
511 elapsed_jobs += in_area[2]
512 # Early exit if no intersections and we've seen enough jobs in the pipeline
513 if elapsed_jobs > ArchitectureFeatures.MAX_BLOCKDEP:
514 break
515
516 return blockdep
517
518 def cpu_cycle_estimate(self, op):
519 """
520 Gets estimated performance of a CPU operation, based on a linear model of intercept, slope,
521 specified in the vela config file, in ConfigParser file format (.ini file).
522 Example configuration snippet:
523 [CpuPerformance.MyOperationType]
524 Cortex-Mx.intercept=<some float value>
525 Cortex-Mx.slope=<some float value>
526 """
527 section = "CpuPerformance." + op.type
528 if self.vela_config is not None and section in self.vela_config:
529 op_config = self.vela_config[section]
530 try:
531 intercept = float(op_config.get(self.cpu_config + ".intercept", op_config["default.intercept"]))
532 slope = float(op_config.get(self.cpu_config + ".slope", op_config["default.slope"]))
533 n_elements = op.inputs[0].elements()
534 cycles = intercept + n_elements * slope
535 return cycles
536 except:
537 print("Error: Reading CPU cycle estimate in vela configuration file, section {}".format(section))
538 raise
539
540 print("Warning: No configured CPU performance estimate for", op.type)
541 return 0
542
543 def __read_sys_config(self):
544 """
545 Gets the system configuration with the given name from the vela configuration file
546 Example configuration snippet:
547 [SysConfig.MyConfigName]
548 npu_freq=<some float value>
549 cpu=Cortex-Mx
550 ...
551 """
552 # Get system configuration from the vela configuration file
553 if self.vela_config is None:
554 print("Warning: Using default values for system configuration")
555 else:
556 section_key = "SysConfig." + self.system_config
557 if not section_key in self.vela_config:
558 raise Exception("Unknown system configuration " + self.system_config)
559
560 try:
561 self.npu_clock = float(self.__sys_config("npu_freq", "500e6"))
562 self.cpu_config = self.__sys_config("cpu", "Cortex-M7")
563
564 self.memory_clock_scales[MemArea.Sram] = float(self.__sys_config("Sram_clock_scale", "1"))
565 self.memory_port_widths[MemArea.Sram] = int(self.__sys_config("Sram_port_width", "64"))
566
567 self.memory_clock_scales[MemArea.OnChipFlash] = float(self.__sys_config("OnChipFlash_clock_scale", "1"))
568 self.memory_port_widths[MemArea.OnChipFlash] = int(self.__sys_config("OnChipFlash_port_width", "64"))
569
570 self.memory_clock_scales[MemArea.OffChipFlash] = float(
571 self.__sys_config("OffChipFlash_clock_scale", "0.25")
572 )
573 self.memory_port_widths[MemArea.OffChipFlash] = int(self.__sys_config("OffChipFlash_port_width", "32"))
574
575 self.memory_clock_scales[MemArea.Dram] = float(self.__sys_config("Dram_clock_scale", "1"))
576 self.memory_port_widths[MemArea.Dram] = int(self.__sys_config("Dram_port_width", "32"))
577
578 self.fast_storage_mem_area = MemArea[self.__sys_config("fast_storage_mem_area", "Sram")]
579 self.feature_map_storage_mem_area = MemArea[self.__sys_config("feature_map_storage_mem_area", "Sram")]
580 self.permanent_storage_mem_area = MemArea[self.__sys_config("permanent_storage_mem_area", "OffChipFlash")]
581 if self.permanent_storage_mem_area not in set((MemArea.OnChipFlash, MemArea.OffChipFlash)):
582 raise Exception(
583 "Invalid permanent_storage_mem_area = "
584 + str(self.permanent_storage_mem_area)
585 + " (must be 'OnChipFlash' or 'OffChipFlash'). To store the weights and other constant data in SRAM"
586 " select 'OnChipFlash'"
587 )
588 except:
589 print("Error: Reading System Configuration in vela configuration file, section {}".format(section_key))
590 raise
591
592 def __sys_config(self, key, default_value):
593 """
594 Gets the system configuration value with the given key from the vela config file.
595 """
596 if self.vela_config is None:
597 return default_value
598 section = "SysConfig." + self.system_config
599 result = self.vela_config[section].get(key, None)
600 if result is None:
601 raise Exception("Error: System Configuration Missing key {} in section [{}] ".format(key, section))
602 return result