def generateDataSpec(self, processor, subvertex, dao): # Create new DataSpec for this processor: spec = data_spec_gen.DataSpec(processor=processor, dao=dao) spec.initialise(self.core_app_identifier, dao) # User specified identifier spec.comment("\n*** Spec for robot motor control ***\n\n") # Load the expected executable to the list of load targets for this core # and the load addresses: x, y, p = processor.get_coordinates() populationIdentity = packet_conversions.get_key_from_coords(x, y, p+1) #our own key file_path = os.path.join(dao.get_common_binaries_directory(), 'myorobot_motor_control.aplx') executable_target = lib_map.ExecutableTarget(file_path, x, y, p) memory_write_targets = list() simulationTimeInTicks = INFINITE_SIMULATION if dao.run_time is not None: simulationTimeInTicks = int((dao.run_time * 1000.0) / dao.machineTimeStep) user1Addr = 0xe5007000 + 128 * p + 116 # User1 location reserved for core p memory_write_targets.append(lib_map.MemWriteTarget(x, y, p, user1Addr, simulationTimeInTicks)) #reserve regions self.reserve_memory_regions(spec) #write system info spec.switchWriteFocus(region = self.SYSTEM_REGION) spec.write(data = 0xBEEF0000) spec.write(data = 0) spec.write(data = 0) spec.write(data = 0) edge_key = None #locate correct subedge for key for subedge in subvertex.out_subedges: if subedge.edge == self.out_going_edge: edge_key = subedge.key #write params to memory spec.switchWriteFocus(region=self.PARAMS) spec.write(data=edge_key|self.myoID) # spec.write(data=populationIdentity) spec.write(data=spec.doubleToS1615(self.output_scale),sizeof='s1615') spec.write(data=self.sample_time) spec.write(data=spec.doubleToS1615(self.decay_factor), sizeof='s1615') spec.write(data=spec.doubleToS1615(self.kernel_amplitude), sizeof='s1615') spec.write(data=self.threshold) spec.write(data=self.n_neurons) # End-of-Spec: spec.endSpec() spec.closeSpecFile() load_targets = list() # Return list of executables, load files: return executable_target, load_targets, memory_write_targets
def writeDelayParameters(self, spec, processor, subvertex, num_delay_blocks, delay_block): """ Generate Delay Parameter data (region 2): """ # Write spec with commands to construct required delay region: spec.comment("\nWriting Delay Parameters for %d Neurons:\n" % subvertex.n_atoms) # Set the focus to the memory region 2 (delay parameters): spec.switchWriteFocus( region = REGIONS.DELAY_PARAMS ) # Write header info to the memory region: # Write Key info for this core: chipX, chipY, chipP = processor.get_coordinates() populationIdentity = packet_conversions.get_key_from_coords( chipX, chipY, chipP) spec.write(data = populationIdentity) # Write the number of neurons in the block: spec.write(data = subvertex.n_atoms) # Write the number of blocks of delays: spec.write(data = num_delay_blocks) # Write the actual delay blocks for i in range(0, num_delay_blocks): spec.write_array(data = delay_block[i])
def writeBlockIndexRegion(self, spec, subvertex, numNeurons, tableEntries): """ Spike block index table. Gives address of each block of spikes. numNeurons is the total number of spike sources to be modelled. tableEntries is a list of the entries, each of which consists of: struct { uint32 timeStamp # In simulation ticks uint32 addressOfBlockWord # Relative to start of spikeDataRegion } entry """ spec.switchWriteFocus(region = BLOCK_INDEX_REGION) # Word 0 is the key (x, y, p) for this core: chipX, chipY, chipP = subvertex.placement.processor.get_coordinates() populationIdentity = \ packet_conversions.get_key_from_coords(chipX, chipY, chipP) spec.write(data = populationIdentity) # Word 1 is the total number of 'neurons' (i.e. spike sources) in # the population: spec.write(data = numNeurons) # Word 2 is the total number of entries in this table of indices: numEntries = len(tableEntries) spec.write(data = numEntries) # Write individual entries: for entry in tableEntries: timeStamp = entry[0] # Time in ticks when this block is used address = entry[1] # Address into spikeBlock region spec.write(data = timeStamp) spec.write(data = address) return
def generate_routing_info(self, subedge): processor_id = subedge.presubvertex.placement.processor.idx % 16 if self.position == self.RIGHT_RETINA: if self.polarity == ExternalRetinaDevice.UP_POLARITY: part_1 = packet_conversions.get_key_from_coords(0, 6, processor_id) key = part_1 | (1 << 14) return key, 0xffff7800 else: key = packet_conversions.get_key_from_coords(0, 6, processor_id) return key, 0xffff7800 else: if self.polarity == ExternalRetinaDevice.UP_POLARITY: key = packet_conversions.get_key_from_coords(0, 7, processor_id) | (1 << 14) return key, 0xffff7800 else: key = packet_conversions.get_key_from_coords(0, 7, processor_id) return key, 0xffff7800
def generate_routing_info(self, subedge): processor_id = subedge.presubvertex.placement.processor.idx % 16 if self.position == self.RIGHT_RETINA: if self.polarity == ExternalRetinaDevice.UP_POLARITY: part_1 = packet_conversions.get_key_from_coords( 0, 6, processor_id) key = part_1 | (1 << 14) return key, 0xffff7800 else: key = packet_conversions.get_key_from_coords( 0, 6, processor_id) return key, 0xffff7800 else: if self.polarity == ExternalRetinaDevice.UP_POLARITY: key = packet_conversions.get_key_from_coords( 0, 7, processor_id) | (1 << 14) return key, 0xffff7800 else: key = packet_conversions.get_key_from_coords( 0, 7, processor_id) return key, 0xffff7800
def generate_routing_info( self, subedge ): """ For the given subedge generate the key and mask for routing. :param subedge: The subedge for which to generate the key and mask. :returns: A tuple containing the key and mask. """ x, y, p = subedge.presubvertex.placement.processor.get_coordinates() key = packet_conversions.get_key_from_coords(x, y, p) #bodge to deal with external perrifables return key, self._app_mask
def generate_routing_info(self, subedge): """ For the given subedge generate the key and mask for routing. :param subedge: The subedge for which to generate the key and mask. :returns: A tuple containing the key and mask. """ x, y, p = subedge.presubvertex.placement.processor.get_coordinates() key = packet_conversions.get_key_from_coords(x, y, p) #bodge to deal with external perrifables return key, self._app_mask
def writeNeuronParameters(self, spec, machineTimeStep, processor, subvertex, ring_buffer_to_input_left_shift): spec.comment("\nWriting Neuron Parameters for %d " "Neurons:\n"%subvertex.n_atoms) # Set the focus to the memory region 2 (neuron parameters): spec.switchWriteFocus( region = REGIONS.NEURON_PARAMS ) # Write header info to the memory region: # Write Key info for this core: chipX, chipY, chipP = processor.get_coordinates() populationIdentity = \ packet_conversions.get_key_from_coords(chipX, chipY, chipP) spec.write(data = populationIdentity) # Write the number of neurons in the block: spec.write(data = subvertex.n_atoms) # Write the number of parameters per neuron (struct size in words): params = self.get_parameters(machineTimeStep) spec.write(data = len( params )) # Write machine time step: (Integer, expressed in microseconds) spec.write(data = machineTimeStep) # Write ring_buffer_to_input_left_shift spec.write(data = ring_buffer_to_input_left_shift) # TODO: Took this out for now as I need random parameters # Create loop over number of neurons: #spec.loop(countReg = 15, startVal = 0, endVal = subvertex.n_atoms) for atom in range(0, subvertex.n_atoms): # Process the parameters for param in params: value = param.get_value() if (hasattr(value, "__len__")): if len(value) > 1: value = value[atom] else: value = value[0] datatype = param.get_datatype() scale = param.get_scale() value = value * scale if datatype == 's1615': value = spec.doubleToS1615(value) elif datatype == 'uint32': value = ctypes.c_uint32(value).value spec.write(data = value, sizeof=datatype)
def generate_routing_info(self, subedge): x, y, p = subedge.postsubvertex.placement.processor.get_coordinates() key = packet_conversions.get_key_from_coords(x, y, p) return key, 0xfffff800
def writePoissonParameters(self, spec, machineTimeStep, processor, numNeurons): """ Generate Neuron Parameter data for Poisson spike sources (region 2): """ spec.comment("\nWriting Neuron Parameters for %d poisson sources:\n" % numNeurons) # Set the focus to the memory region 2 (neuron parameters): spec.switchWriteFocus(region = POISSON_PARAMS_REGION) # Write header info to the memory region: # Write Key info for this core: chipX, chipY, chipP = processor.get_coordinates() populationIdentity = \ packet_conversions.get_key_from_coords(chipX, chipY, chipP) spec.write(data = populationIdentity) # Write the random seed (4 words), generated randomly! if self.seed == None: spec.write(data = numpy.random.randint(0x7FFFFFFF)) spec.write(data = numpy.random.randint(0x7FFFFFFF)) spec.write(data = numpy.random.randint(0x7FFFFFFF)) spec.write(data = numpy.random.randint(0x7FFFFFFF)) else: spec.write(data = self.seed[0]) spec.write(data = self.seed[1]) spec.write(data = self.seed[2]) spec.write(data = self.seed[3]) # For each neuron, get the rate to work out if it is a slow # or fast source slow_sources = list() fast_sources = list() for i in range(0, numNeurons): # Get the parameter values for source i: rateVal = generateParameter(self.rate, i) startVal = generateParameter(self.start, i) endVal = generateParameter(self.duration, i) + startVal # Decide if it is a fast or slow source and spikesPerTick = (float(rateVal) * (machineTimeStep / 1000000.0)) if spikesPerTick <= SLOW_RATE_PER_TICK_CUTOFF: slow_sources.append([i, rateVal, startVal, endVal]) else: fast_sources.append([i, spikesPerTick, startVal, endVal]) # Write the numbers of each type of source spec.write(data = len(slow_sources)) spec.write(data = len(fast_sources)) # Now write one struct for each slow source as follows # # typedef struct slow_spike_source_t # { # uint32_t neuron_id; # uint32_t start_ticks; # uint32_t end_ticks; # # accum mean_isi_ticks; # accum time_to_spike_ticks; # } slow_spike_source_t; for (neuronId, rateVal, startVal, endVal) in slow_sources: isiValScaled = int(float(1000000.0 / (rateVal * machineTimeStep)) * 32768.0) startScaled = int(startVal * 1000.0 / machineTimeStep) endScaled = int(endVal * 1000.0 / machineTimeStep) spec.write(data = neuronId, sizeof='uint32') spec.write(data = startScaled, sizeof='uint32') spec.write(data = endScaled, sizeof='uint32') spec.write(data = isiValScaled, sizeof='s1615') spec.write(data = 0x0, sizeof='uint32') # Now write # typedef struct fast_spike_source_t # { # uint32_t neuron_id; # uint32_t start_ticks; # uint32_t end_ticks; # # unsigned long fract exp_minus_lambda; # } fast_spike_source_t; for (neuronId, spikesPerTick, startVal, endVal) in fast_sources: exp_minus_lamda = exp(-1.0 * spikesPerTick) exp_minus_lamda_scaled = int(exp_minus_lamda * float(0xFFFFFFFF)) startScaled = int(startVal * 1000.0 / machineTimeStep) endScaled = int(endVal * 1000.0 / machineTimeStep) spec.write(data = neuronId, sizeof='uint32') spec.write(data = startScaled, sizeof='uint32') spec.write(data = endScaled, sizeof='uint32') spec.write(data = exp_minus_lamda_scaled, sizeof='u032') return
def writePoissonParameters(self, spec, machineTimeStep, processor, numNeurons): """ Generate Neuron Parameter data for Poisson spike sources (region 2): """ spec.comment("\nWriting Neuron Parameters for %d poisson sources:\n" % numNeurons) # Set the focus to the memory region 2 (neuron parameters): spec.switchWriteFocus(region=POISSON_PARAMS_REGION) # Write header info to the memory region: # Write Key info for this core: chipX, chipY, chipP = processor.get_coordinates() populationIdentity = \ packet_conversions.get_key_from_coords(chipX, chipY, chipP) spec.write(data=populationIdentity) # Write the random seed (4 words), generated randomly! if self.seed == None: spec.write(data=numpy.random.randint(0x7FFFFFFF)) spec.write(data=numpy.random.randint(0x7FFFFFFF)) spec.write(data=numpy.random.randint(0x7FFFFFFF)) spec.write(data=numpy.random.randint(0x7FFFFFFF)) else: spec.write(data=self.seed[0]) spec.write(data=self.seed[1]) spec.write(data=self.seed[2]) spec.write(data=self.seed[3]) # For each neuron, get the rate to work out if it is a slow # or fast source slow_sources = list() fast_sources = list() for i in range(0, numNeurons): # Get the parameter values for source i: rateVal = generateParameter(self.rate, i) startVal = generateParameter(self.start, i) endVal = generateParameter(self.duration, i) + startVal # Decide if it is a fast or slow source and spikesPerTick = (float(rateVal) * (machineTimeStep / 1000000.0)) if spikesPerTick <= SLOW_RATE_PER_TICK_CUTOFF: slow_sources.append([i, rateVal, startVal, endVal]) else: fast_sources.append([i, spikesPerTick, startVal, endVal]) # Write the numbers of each type of source spec.write(data=len(slow_sources)) spec.write(data=len(fast_sources)) # Now write one struct for each slow source as follows # # typedef struct slow_spike_source_t # { # uint32_t neuron_id; # uint32_t start_ticks; # uint32_t end_ticks; # # accum mean_isi_ticks; # accum time_to_spike_ticks; # } slow_spike_source_t; for (neuronId, rateVal, startVal, endVal) in slow_sources: isiValScaled = int( float(1000000.0 / (rateVal * machineTimeStep)) * 32768.0) startScaled = int(startVal * 1000.0 / machineTimeStep) endScaled = int(endVal * 1000.0 / machineTimeStep) spec.write(data=neuronId, sizeof='uint32') spec.write(data=startScaled, sizeof='uint32') spec.write(data=endScaled, sizeof='uint32') spec.write(data=isiValScaled, sizeof='s1615') spec.write(data=0x0, sizeof='uint32') # Now write # typedef struct fast_spike_source_t # { # uint32_t neuron_id; # uint32_t start_ticks; # uint32_t end_ticks; # # unsigned long fract exp_minus_lambda; # } fast_spike_source_t; for (neuronId, spikesPerTick, startVal, endVal) in fast_sources: exp_minus_lamda = exp(-1.0 * spikesPerTick) exp_minus_lamda_scaled = int(exp_minus_lamda * float(0xFFFFFFFF)) startScaled = int(startVal * 1000.0 / machineTimeStep) endScaled = int(endVal * 1000.0 / machineTimeStep) spec.write(data=neuronId, sizeof='uint32') spec.write(data=startScaled, sizeof='uint32') spec.write(data=endScaled, sizeof='uint32') spec.write(data=exp_minus_lamda_scaled, sizeof='u032') return
def generate_routing_info(self, subedge): x, y, p = subedge.postsubvertex.placement.processor.get_coordinates() key = packet_conversions.get_key_from_coords(x, y, p) return key, 0xfffff800
def generateDataSpec(self, processor, subvertex, dao): # Create new DataSpec for this processor: spec = data_spec_gen.DataSpec(processor=processor, dao=dao) spec.initialise(self.core_app_identifier, dao) # User specified identifier spec.comment("\n*** Spec for robot motor control ***\n\n") # Load the expected executable to the list of load targets for this core # and the load addresses: x, y, p = processor.get_coordinates() populationIdentity = packet_conversions.get_key_from_coords( x, y, p + 1) #our own key file_path = os.path.join(dao.get_common_binaries_directory(), 'myorobot_motor_control.aplx') executable_target = lib_map.ExecutableTarget(file_path, x, y, p) memory_write_targets = list() simulationTimeInTicks = INFINITE_SIMULATION if dao.run_time is not None: simulationTimeInTicks = int( (dao.run_time * 1000.0) / dao.machineTimeStep) user1Addr = 0xe5007000 + 128 * p + 116 # User1 location reserved for core p memory_write_targets.append( lib_map.MemWriteTarget(x, y, p, user1Addr, simulationTimeInTicks)) #reserve regions self.reserve_memory_regions(spec) #write system info spec.switchWriteFocus(region=self.SYSTEM_REGION) spec.write(data=0xBEEF0000) spec.write(data=0) spec.write(data=0) spec.write(data=0) edge_key = None #locate correct subedge for key for subedge in subvertex.out_subedges: if subedge.edge == self.out_going_edge: edge_key = subedge.key #write params to memory spec.switchWriteFocus(region=self.PARAMS) spec.write(data=edge_key | self.myoID) # spec.write(data=populationIdentity) spec.write(data=spec.doubleToS1615(self.output_scale), sizeof='s1615') spec.write(data=self.sample_time) spec.write(data=spec.doubleToS1615(self.decay_factor), sizeof='s1615') spec.write(data=spec.doubleToS1615(self.kernel_amplitude), sizeof='s1615') spec.write(data=self.threshold) spec.write(data=self.n_neurons) # End-of-Spec: spec.endSpec() spec.closeSpecFile() load_targets = list() # Return list of executables, load files: return executable_target, load_targets, memory_write_targets