def test_resource_container(self): """ tests that creating multiple resoruce containers doesnt cause issues. """ sdram = SDRAMResource(128 * (2**20)) dtcm = DTCMResource(128 * (2**20) + 1) cpu = CPUCyclesPerTickResource(128 * (2**20) + 2) container = ResourceContainer(dtcm, sdram, cpu) self.assertEqual(container.sdram.get_value(), 128 * (2**20)) self.assertEqual(container.dtcm.get_value(), 128 * (2**20) + 1) self.assertEqual(container.cpu_cycles.get_value(), 128 * (2**20) + 2) sdram = SDRAMResource(128 * (2**19)) dtcm = DTCMResource(128 * (2**19) + 1) cpu = CPUCyclesPerTickResource(128 * (2**19) + 2) container = ResourceContainer(dtcm, sdram, cpu) self.assertEqual(container.sdram.get_value(), 128 * (2**19)) self.assertEqual(container.dtcm.get_value(), 128 * (2**19) + 1) self.assertEqual(container.cpu_cycles.get_value(), 128 * (2**19) + 2) sdram = SDRAMResource(128 * (2**21)) dtcm = DTCMResource(128 * (2**21) + 1) cpu = CPUCyclesPerTickResource(128 * (2**21) + 2) container = ResourceContainer(dtcm, sdram, cpu) self.assertEqual(container.sdram.get_value(), 128 * (2**21)) self.assertEqual(container.dtcm.get_value(), 128 * (2**21) + 1) self.assertEqual(container.cpu_cycles.get_value(), 128 * (2**21) + 2)
def test_sdram(self): """ test that adding a sdram resource to a resoruce container works correctly """ sdram = SDRAMResource(128 * (2**20)) self.assertEqual(sdram.get_value(), 128 * (2**20)) sdram = SDRAMResource(128 * (2**19)) self.assertEqual(sdram.get_value(), 128 * (2**19)) sdram = SDRAMResource(128 * (2**21)) self.assertEqual(sdram.get_value(), 128 * (2**21))
def get_resources_used_by_atoms(self, vertex_slice, n_machine_time_steps, machine_time_step): # build resources as i currently know container = ResourceContainer( sdram=SDRAMResource(self.get_sdram_usage_for_atoms(vertex_slice)), dtcm=DTCMResource(self.get_dtcm_usage_for_atoms()), cpu_cycles=CPUCyclesPerTickResource( self.get_cpu_usage_for_atoms())) recording_sizes = recording_utilities.get_recording_region_sizes( [ self._spike_recorder.get_sdram_usage_in_bytes( vertex_slice.n_atoms, self._max_spikes_per_ts(vertex_slice, n_machine_time_steps, machine_time_step), self._N_POPULATION_RECORDING_REGIONS) ], n_machine_time_steps, self._minimum_buffer_sdram, self._maximum_sdram_for_buffering, self._using_auto_pause_and_resume) container.extend( recording_utilities.get_recording_resources( recording_sizes, self._receive_buffer_host, self._receive_buffer_port)) return container
def get_static_resources(input_filters, n_routing_keys, hostname, n_provenance_items): """ generates resource calculation so that it can eb called from outside and not instantiated :param input_filters: the input filters going into this vertex :param n_routing_keys: the n keys from the input filters :param hostname: The hostname of the host machine we're running on :param n_provenance_items: n provenance data items :return: A resource container containing the resources used by this vertex for those inputs. """ iptags = list() iptags.append( IPtagResource( ip_address=hostname, port=None, strip_sdp=False, tag=None, traffic_identifier=( SDPTransmitterMachineVertex.IPTAG_TRAFFIC_IDENTIFIER))) return ResourceContainer(sdram=SDRAMResource( fec_constants.SYSTEM_BYTES_REQUIREMENT + helpful_functions.sdram_size_in_bytes_for_filter_region( input_filters) + helpful_functions.sdram_size_in_bytes_for_routing_region( n_routing_keys) + ProvidesProvenanceDataFromMachineImpl.get_provenance_data_size( n_provenance_items) + SDPTransmitterMachineVertex._transmitter_region()), iptags=iptags)
def get_resources_used_by_atoms(self, vertex_slice, graph): out_edges = graph.get_edges_starting_at_vertex(self) return ResourceContainer( sdram=SDRAMResource(self.get_sdram_usage_for_atoms(out_edges)), dtcm=DTCMResource(self.get_dtcm_usage_for_atoms(vertex_slice)), cpu_cycles=CPUCyclesPerTickResource( self.get_cpu_usage_for_atoms(vertex_slice)))
def get_recording_resources( region_sizes, buffering_ip_address=None, buffering_port=None, notification_tag=None): """ Get the resources for recording :param region_sizes:\ A list of the sizes of each region. A size of 0 is acceptable to\ indicate an empty region :type region_sizes: list(int) :param buffering_ip_address:\ The IP address to receive buffering messages on, or None if buffering\ is not in use :type buffering_ip_address: str :param buffering_port:\ The port to receive buffering messages on, or None if a port is to be\ assigned :type buffering_port: int :param notification_tag:\ The tag to send buffering messages with, or None to use a default tag :type notification_tag: int :rtype: :py:class:`pacman.model.resources.ResourceContainer` """ ip_tags = list() if buffering_ip_address is not None: ip_tags.append(IPtagResource( buffering_ip_address, buffering_port, True, notification_tag, TRAFFIC_IDENTIFIER)) # return the resources including the SDRAM requirements return ResourceContainer( iptags=ip_tags, sdram=SDRAMResource( get_recording_header_size(len(region_sizes)) + get_recording_data_size(region_sizes)))
def get_resources_used_by_atoms(self, vertex_slice): return ResourceContainer( sdram=SDRAMResource( self.get_sdram_usage_for_atoms()), dtcm=DTCMResource(self.get_dtcm_usage_for_atoms(vertex_slice)), cpu_cycles=CPUCyclesPerTickResource( self.get_cpu_usage_for_atoms(vertex_slice)))
def static_resources_required(): return ResourceContainer( sdram=SDRAMResource(sdram=ExtraMonitorSupportMachineVertex. _CONFIG_REGION_REINEJCTOR_SIZE_IN_BYTES + ExtraMonitorSupportMachineVertex. _CONFIG_DATA_SPEED_UP_SIZE_IN_BYTES + ExtraMonitorSupportMachineVertex. _CONFIG_MAX_EXTRA_SEQ_NUM_SIZE_IN_BYTES))
def resources_required(self): sdram_required = (constants.SYSTEM_BYTES_REQUIREMENT + self.TRANSMISSION_DATA_SIZE + self.CONFIG_REGION_SIZE) resources = ResourceContainer(cpu_cycles=CPUCyclesPerTickResource(45), dtcm=DTCMResource(100), sdram=SDRAMResource(sdram_required)) return resources
def resources_required(self): return ResourceContainer( sdram=SDRAMResource(constants.SYSTEM_BYTES_REQUIREMENT + 4), iptags=[ IPtagResource(port=self.PORT, strip_sdp=True, ip_address="localhost") ])
def resources_required(self): return ResourceContainer( sdram=SDRAMResource(constants.SYSTEM_BYTES_REQUIREMENT + self.CONFIG_SIZE), iptags=[ IPtagResource(port=self._connection.local_port, strip_sdp=True, ip_address="localhost") ])
def get_resources_used_by_atoms(lo_atom, hi_atom, vertex_in_edges): vertex = Vertex(1, None) cpu_cycles = vertex.get_cpu_usage_for_atoms(lo_atom, hi_atom) dtcm_requirement = vertex.get_dtcm_usage_for_atoms(lo_atom, hi_atom) sdram_requirement = vertex.get_sdram_usage_for_atoms( lo_atom, hi_atom, vertex_in_edges) return ResourceContainer(cpu_cycles=CPUCyclesPerTickResource(cpu_cycles), dtcm=DTCMResource(dtcm_requirement), sdram=SDRAMResource(sdram_requirement))
def resources_required(self): resources = ResourceContainer(sdram=SDRAMResource( self._calculate_sdram_requirement()), dtcm=DTCMResource(0), cpu_cycles=CPUCyclesPerTickResource(0)) resources.extend( recording_utilities.get_recording_resources( [MAX_SIZE_OF_BUFFERED_REGION_ON_CHIP], self._receive_buffer_host, self._receive_buffer_port)) return resources
def get_resources_used_by_atoms(self, vertex_slice): return ResourceContainer( sdram=SDRAMResource( LivePacketGatherMachineVertex.get_sdram_usage()), dtcm=DTCMResource(LivePacketGatherMachineVertex.get_dtcm_usage()), cpu_cycles=CPUCyclesPerTickResource( LivePacketGatherMachineVertex.get_cpu_usage()), iptags=[IPtagResource( ip_address=self._ip_address, port=self._port, strip_sdp=self._strip_sdp, tag=self._tag, traffic_identifier="LPG_EVENT_STREAM")])
def resources_required(self): sdram = (self.get_timed_commands_bytes() + self.get_n_command_bytes(self._commands_at_start_resume) + self.get_n_command_bytes(self._commands_at_pause_stop) + constants.SYSTEM_BYTES_REQUIREMENT + self.get_provenance_data_size(0) + (self.get_number_of_mallocs_used_by_dsg() * constants.SARK_PER_MALLOC_SDRAM_USAGE)) # Return the SDRAM and 1 core return ResourceContainer(sdram=SDRAMResource(sdram))
def resources_required(self): resources = ResourceContainer( cpu_cycles=CPUCyclesPerTickResource(45), dtcm=DTCMResource(100), sdram=SDRAMResource(constants.SYSTEM_BYTES_REQUIREMENT + self.TRANSMISSION_REGION_N_BYTES)) resources.extend( recording_utilities.get_recording_resources( [self._recording_size], self._receive_buffer_host, self._receive_buffer_port)) return resources
def resources_required(self): resources = ResourceContainer(cpu_cycles=CPUCyclesPerTickResource(45), dtcm=DTCMResource(100), sdram=SDRAMResource(100)) resources.extend( recording_utilities.get_recording_resources( [self._string_data_size], self._receive_buffer_host, self._receive_buffer_port)) return resources
def static_resources_required(): return ResourceContainer(sdram=SDRAMResource( SYSTEM_BYTES_REQUIREMENT + DataSpeedUpPacketGatherMachineVertex.CONFIG_SIZE), iptags=[ IPtagResource( port=None, strip_sdp=True, ip_address="localhost", traffic_identifier="DATA_SPEED_UP") ])
def test_deallocation_of_resources(self): machine = VirtualMachine(width=2, height=2, n_cpus_per_chip=18, with_monitors=True, sdram_per_chip=12346) tracker = ResourceTracker(machine, preallocated_resources=None) sdram_res = SDRAMResource(12345) resources = ResourceContainer(sdram=sdram_res) chip_0 = machine.get_chip_at(0, 0) # verify core tracker is empty if (0, 0) in tracker._core_tracker: raise Exception("shouldnt exist") # verify sdram tracker if tracker._sdram_tracker[0, 0] != -12346: raise Exception("incorrect sdram of {}".format( tracker._sdram_tracker[0, 0])) # allocate some res chip_x, chip_y, processor_id, ip_tags, reverse_ip_tags = \ tracker.allocate_resources(resources, [(0, 0)]) # verify chips used is updated cores = list(tracker._core_tracker[(0, 0)]) self.assertEqual(len(cores), chip_0.n_user_processors - 1) # verify sdram used is updated sdram = tracker._sdram_tracker[(0, 0)] self.assertEqual(sdram, -1) if (0, 0) not in tracker._chips_used: raise Exception("should exist") # deallocate res tracker.unallocate_resources(chip_x, chip_y, processor_id, resources, ip_tags, reverse_ip_tags) # verify chips used is updated if ((0, 0) in tracker._core_tracker and len( tracker._core_tracker[(0, 0)]) != chip_0.n_user_processors): raise Exception("shouldn't exist or should be right size") if (0, 0) in tracker._chips_used: raise Exception("shouldnt exist") # verify sdram tracker if tracker._sdram_tracker[0, 0] != -12346: raise Exception("incorrect sdram of {}".format( tracker._sdram_tracker[0, 0]))
def get_resources(n_machine_time_steps, time_step, time_scale_factor, n_samples_per_recording, sampling_frequency): """ Get the resources used by this vertex :return: Resource container """ # pylint: disable=too-many-locals # get config config = globals_variables.get_simulator().config # get recording params minimum_buffer_sdram = config.getint("Buffers", "minimum_buffer_sdram") using_auto_pause_and_resume = config.getboolean( "Buffers", "use_auto_pause_and_resume") receive_buffer_host = config.get("Buffers", "receive_buffer_host") receive_buffer_port = read_config_int(config, "Buffers", "receive_buffer_port") # figure recording size for max run if not using_auto_pause_and_resume and n_machine_time_steps is None: raise Exception( "You cannot use the chip power montiors without auto pause " "and resume and not allocating a n_machine_time_steps") # figure max buffer size max_buffer_size = 0 if config.getboolean("Buffers", "enable_buffered_recording"): max_buffer_size = config.getint("Buffers", "chip_power_monitor_buffer") maximum_sdram_for_buffering = [max_buffer_size] n_recording_entries = (math.ceil( (sampling_frequency / (time_step * time_scale_factor))) / n_samples_per_recording) recording_size = ( ChipPowerMonitorMachineVertex.RECORDING_SIZE_PER_ENTRY * n_recording_entries) container = ResourceContainer(sdram=SDRAMResource( ChipPowerMonitorMachineVertex.sdram_calculation()), cpu_cycles=CPUCyclesPerTickResource(100), dtcm=DTCMResource(100)) recording_sizes = recording_utilities.get_recording_region_sizes( [int(recording_size) * n_machine_time_steps], minimum_buffer_sdram, maximum_sdram_for_buffering, using_auto_pause_and_resume) container.extend( recording_utilities.get_recording_resources( recording_sizes, receive_buffer_host, receive_buffer_port)) return container
def generate_static_resources(transform_data, n_keys, filters, local_provenance_items): sdram = ( ProvidesProvenanceDataFromMachineImpl.get_provenance_data_size( local_provenance_items) + fec_constants.SYSTEM_BYTES_REQUIREMENT + (InterposerMachineVertex.SLICE_DATA_ITEMS * constants.BYTE_TO_WORD_MULTIPLIER) + (InterposerMachineVertex.MC_TRANSMISSION_REGION_ITEMS * constants.BYTE_TO_WORD_MULTIPLIER) + transform_data.nbytes + (constants.BYTES_PER_KEY * n_keys) + helpful_functions.sdram_size_in_bytes_for_filter_region(filters) + helpful_functions.sdram_size_in_bytes_for_routing_region(n_keys)) return ResourceContainer(sdram=SDRAMResource(sdram))
def get_resources_used_by_atoms(self, vertex_slice): """ standard method call to get the sdram, cpu and dtcm usage of a collection of atoms :param vertex_slice: the collection of atoms """ return ResourceContainer( sdram=SDRAMResource( self.get_sdram_usage_for_atoms(vertex_slice, None)), cpu_cycles=CPUCyclesPerTickResource( self.get_cpu_usage_for_atoms(vertex_slice, None)), dtcm=DTCMResource(self.get_dtcm_usage_for_atoms( vertex_slice, None)))
def __init__(self, label, use_prefix=False, key_prefix=None, prefix_type=None, message_type=EIEIOType.KEY_32_BIT, right_shift=0, payload_as_time_stamps=True, use_payload_prefix=True, payload_prefix=None, payload_right_shift=0, number_of_packets_sent_per_time_step=0, hostname=None, port=None, strip_sdp=None, board_address=None, tag=None, constraints=None): # pylint: disable=too-many-arguments, too-many-locals # inheritance super(LivePacketGatherMachineVertex, self).__init__(label, constraints=constraints) self._resources_required = ResourceContainer( cpu_cycles=CPUCyclesPerTickResource(self.get_cpu_usage()), dtcm=DTCMResource(self.get_dtcm_usage()), sdram=SDRAMResource(self.get_sdram_usage()), iptags=[ IPtagResource(ip_address=hostname, port=port, strip_sdp=strip_sdp, tag=tag, traffic_identifier=self.TRAFFIC_IDENTIFIER) ]) # app specific data items self._use_prefix = use_prefix self._key_prefix = key_prefix self._prefix_type = prefix_type self._message_type = message_type self._right_shift = right_shift self._payload_as_time_stamps = payload_as_time_stamps self._use_payload_prefix = use_payload_prefix self._payload_prefix = payload_prefix self._payload_right_shift = payload_right_shift self._number_of_packets_sent_per_time_step = \ number_of_packets_sent_per_time_step
def resources_required(self): sdram_required = (constants.SYSTEM_BYTES_REQUIREMENT + self.TRANSMISSION_DATA_SIZE + self.CONFIG_PARAM_SIZE) sdram_required += \ app_constants.MACHINE_STEPS * self.RECORD_BYTES_PER_STEP resources = ResourceContainer(cpu_cycles=CPUCyclesPerTickResource(45), dtcm=DTCMResource(100), sdram=SDRAMResource(sdram_required)) # resources.extend(recording_utilities.get_recording_resources( # [app_constants.MACHINE_STEPS * self.RECORD_BYTES_PER_STEP], # self._receive_buffer_host, self._receive_buffer_port)) return resources
def get_resources_used_by_atoms(self, vertex_slice): sdram = ( CommandSenderMachineVertex.get_timed_commands_bytes( self._timed_commands) + CommandSenderMachineVertex.get_n_command_bytes( self._commands_at_start_resume) + CommandSenderMachineVertex.get_n_command_bytes( self._commands_at_pause_stop) + constants.SYSTEM_BYTES_REQUIREMENT + CommandSenderMachineVertex.get_provenance_data_size(0) + (CommandSenderMachineVertex.get_number_of_mallocs_used_by_dsg() * constants.SARK_PER_MALLOC_SDRAM_USAGE)) # Return the SDRAM and 1 core return ResourceContainer(sdram=SDRAMResource(sdram))
def test_allocate_resources_when_chip_used(self): router = Router([]) sdram = SDRAM() empty_chip = Chip(0, 0, [], router, sdram, 0, 0, "127.0.0.1", virtual=False, tag_ids=[1]) machine = Machine([empty_chip], 0, 0) resource_tracker = ResourceTracker(machine) with self.assertRaises(PacmanValueError): resource_tracker.allocate_resources( ResourceContainer(sdram=SDRAMResource(1024)))
def get_static_resources(keys, local_provenance_items): if SDPReceiverMachineVertex.USE_REVERSE_IPTAGS: reverse_ip_tags = [ReverseIPtagResource()] else: reverse_ip_tags = None return ResourceContainer(sdram=SDRAMResource( fec_constants.SYSTEM_BYTES_REQUIREMENT + (SDPReceiverMachineVertex.SDP_PORT_SIZE * constants.BYTE_TO_WORD_MULTIPLIER) + (SDPReceiverMachineVertex.MC_TRANSMISSION_REGION_ITEMS * constants.BYTE_TO_WORD_MULTIPLIER) + ProvidesProvenanceDataFromMachineImpl.get_provenance_data_size( local_provenance_items) + SDPReceiverMachineVertex._calculate_sdram_for_keys(keys)), dtcm=DTCMResource(0), cpu_cycles=CPUCyclesPerTickResource(0), reverse_iptags=reverse_ip_tags)
def get_resources(n_machine_time_steps, time_step, time_scale_factor, n_samples_per_recording, sampling_frequency): """ get resources used by this vertex :return:Resource container """ # get config config = globals_variables.get_simulator().config # get recording params minimum_buffer_sdram = config.getint("Buffers", "minimum_buffer_sdram") using_auto_pause_and_resume = config.getboolean( "Buffers", "use_auto_pause_and_resume") receive_buffer_host = config.get("Buffers", "receive_buffer_host") receive_buffer_port = helpful_functions.read_config_int( config, "Buffers", "receive_buffer_port") # figure max buffer size max_buffer_size = 0 if config.getboolean("Buffers", "enable_buffered_recording"): max_buffer_size = config.getint("Buffers", "spike_buffer_size") maximum_sdram_for_buffering = [max_buffer_size] # figure recording size for max run if n_machine_time_steps is None: n_machine_time_steps = 1. n_recording_entries = math.ceil( (sampling_frequency / (n_machine_time_steps * time_step * time_scale_factor)) / n_samples_per_recording) recording_size = ( ChipPowerMonitorMachineVertex.RECORDING_SIZE_PER_ENTRY * n_recording_entries) container = ResourceContainer(sdram=SDRAMResource( ChipPowerMonitorMachineVertex.sdram_calculation()), cpu_cycles=CPUCyclesPerTickResource(100), dtcm=DTCMResource(100)) recording_sizes = recording_utilities.get_recording_region_sizes( [int(recording_size)], n_machine_time_steps, minimum_buffer_sdram, maximum_sdram_for_buffering, using_auto_pause_and_resume) container.extend( recording_utilities.get_recording_resources( recording_sizes, receive_buffer_host, receive_buffer_port)) return container
def resources_required(self): resources = ResourceContainer( dtcm=DTCMResource(self.get_dtcm_usage()), sdram=SDRAMResource(self.get_sdram_usage( self._send_buffer_times, self._send_buffer_max_space, self._record_buffer_size > 0)), cpu_cycles=CPUCyclesPerTickResource(self.get_cpu_usage()), iptags=self._iptags, reverse_iptags=self._reverse_iptags) if self._iptags is None: resources.extend(recording_utilities.get_recording_resources( [self._record_buffer_size], self._buffer_notification_ip_address, self._buffer_notification_port, self._buffer_notification_tag)) else: resources.extend(recording_utilities.get_recording_resources( [self._record_buffer_size])) return resources
def __init__(self, label, machine_time_step, time_scale_factor, heat_temperature=0, constraints=None): config = globals_variables.get_simulator().config # resources used by a heat element vertex sdram = SDRAMResource(23 + config.getint("Buffers", "minimum_buffer_sdram")) self._resources = \ ResourceContainer(cpu_cycles=CPUCyclesPerTickResource(45), dtcm=DTCMResource(34), sdram=sdram) MachineVertex.__init__(self, label=label, constraints=constraints) # app specific data items self._heat_temperature = heat_temperature self._time_between_requests = config.getint("Buffers", "time_between_requests")