def __init__( self, width=None, height=None, with_wrap_arounds=False, version=None, n_cpus_per_chip=18, with_monitors=True, sdram_per_chip=None): """ :param width: the width of the virtual machine in chips :type width: int :param height: the height of the virtual machine in chips :type height: int :param with_wrap_arounds: bool defining if wrap around links exist :type with_wrap_arounds: bool :param version: the version id of a board; if None, a machine is\ created with the correct dimensions, otherwise the machine\ will be a single board of the given version :type version: int :param n_cpus_per_chip: The number of CPUs to put on each chip :type n_cpus_per_chip: int :param with_monitors: True if CPU 0 should be marked as a monitor :type with_monitors: bool :param sdram_per_chip: The amount of SDRAM to give to each chip :type sdram_per_chip: int or None """ Machine.__init__(self, ()) if ((width is not None and width < 0) or (height is not None and height < 0)): raise exceptions.SpinnMachineInvalidParameterException( "width or height", "{} or {}".format(width, height), "Negative dimensions are not supported") if version is None and (width is None or height is None): raise exceptions.SpinnMachineInvalidParameterException( "version, width, height", "{}, {}, {}".format(version, width, height), "Either version must be specified, " "or width and height must both be specified") if version is not None and (version < 2 or version > 5): raise exceptions.SpinnMachineInvalidParameterException( "version", str(version), "Version must be between 2 and 5 inclusive or None") if ((version == 5 or version == 4) and with_wrap_arounds is not None and with_wrap_arounds): raise exceptions.SpinnMachineInvalidParameterException( "version and with_wrap_arounds", "{} and True".format(version), "A version {} board does not have wrap arounds; set " "version to None or with_wrap_arounds to None".format(version)) if (version == 2 or version == 3) and with_wrap_arounds is not None: raise exceptions.SpinnMachineInvalidParameterException( "version and with_wrap_arounds", "{} and {}".format(version, with_wrap_arounds), "A version {} board has complex wrap arounds; set " "version to None or with_wrap_arounds to None".format(version)) if ((version == 5 or version == 4) and ( (width is not None and width != 8) or (height is not None and height != 8))): raise exceptions.SpinnMachineInvalidParameterException( "version, width, height", "{}, {}, {}".format(version, width, height), "A version {} board has a width and height of 8; set " "version to None or width and height to None".format(version)) if ((version == 2 or version == 3) and ( (width is not None and width != 2) or (height is not None and height != 2))): raise exceptions.SpinnMachineInvalidParameterException( "version, width, height", "{}, {}, {}".format(version, width, height), "A version {} board has a width and height of 2; set " "version to None or width and height to None".format(version)) if version == 5 or version == 4: if width is None: width = 8 if height is None: height = 8 with_wrap_arounds = False if version == 2 or version == 3: if width is None: width = 2 if height is None: height = 2 with_wrap_arounds = True # if x and y are none, assume a 48 chip board logger.debug("width = {} and height = {}".format(width, height)) # calculate the chip ids which this machine is going to have chip_ids = list() for i in xrange(width): for j in xrange(height): coords = (i, j) if (version == 5 and width == 8 and height == 8 and coords in _48boardgaps): # a chip doesn't exist in this static position # on these boards, so nullify it pass else: chip_ids.append((i, j)) progress_bar = ProgressBar( width * height, "Generating a virtual machine") # Create the chips and their links for i in xrange(width): for j in xrange(height): coords = (i, j) if (version == 5 and width == 8 and height == 8 and coords in _48boardgaps): # a chip doesn't exist in this static position # on these boards, so nullify it pass else: processors = list() for processor_id in range(0, n_cpus_per_chip): processor = Processor(processor_id, 200000000) if processor_id == 0 and with_monitors: processor.is_monitor = True processors.append(processor) chip_links = self._calculate_links( i, j, width, height, with_wrap_arounds, version, chip_ids) chip_router = Router(chip_links, False) if sdram_per_chip is None: sdram = SDRAM() else: system_base_address = ( SDRAM.DEFAULT_BASE_ADDRESS + sdram_per_chip) sdram = SDRAM(system_base_address=system_base_address) chip = Chip(i, j, processors, chip_router, sdram, 0, 0, "127.0.0.1") self.add_chip(chip) progress_bar.update() progress_bar.end() processor_count = 0 for chip in self.chips: processor_count += len(list(chip.processors)) link_count = 0 for chip in self.chips: link_count += len(list(chip.router.links)) logger.debug( "Static Allocation Complete;" " {} calculated app cores and {} links!".format( processor_count, link_count))