def __init__(self, name: str, packetSize: int = 256, numSnipsPerChip: int = 1, queueSize: int = 64): """ SpikeInputGenerator is layer which can encode and inject spikes into neurocore. Spike Input Generator performs following tasks: 1. Input encoding to compress data in most suitable form for channel communication 2. Writing input to channel 3. Input decoding on host or embedded CPU 4. Input injection to neuro core on host or embedded CPU via SNIP code :param name: Name of the Input Encoder :param packetSize: Size of one packet :param numSnipsPerChip: Number of snips per chip on which input layer is present :param queueSize: Number of inputs that can be queued without blocking): """ super().__init__() self.name = name self.packetSize = packetSize self.numLmts = numSnipsPerChip self.queueSize = queueSize self._logger = get_logger("NET.INE") self._dataChannels = [] self.axonMap = None self.decoderSnip = os.path.join(os.path.dirname(__file__), 'templates', 'inject_spike.c.template') self._portName = "output" self._addSnipPlaceholder() self._createOutputPort()
def load(path: str, board: Graph = None) -> 'AbstractComposable': """Loads the Input Generator""" with open(os.path.join(path, "ig"), "rb") as ig_file: result = pickle.load(ig_file) result.deserialize(path) with open(os.path.join(path, "ig_metadata"), "r") as m_file: metadata = json.load(m_file) result.logger = get_logger("NET.INE") result.dataChannels = [ board.channels[idx] for idx in metadata["dataChannelsIndices"] ] result.infoChannels = [ board.channels[idx] for idx in metadata["infoChannelsIndices"] ] result.dataSizeChannels = [ board.channels[idx] for idx in metadata["dataSizeChannelsIndices"] ] result.metaDataChannels = [ board.channels[idx] for idx in metadata["metaDataChannelsIndices"] ] return result
def _build(self, *args, **kwargs): """Builds the input encoder using the parameters passed in""" self.shape = kwargs["shape"] self.encoderType = kwargs["encoderType"] self.queueSize = kwargs["queueSize"] self.numSnipsPerChip = kwargs["numSnipsPerChip"] self.startRunning = kwargs["startRunning"] self.interval = kwargs["interval"] self.packetSize = kwargs["packetSize"] self.dataSize = reduce(operator.mul, self.shape, 1) self._logger = get_logger("NET.INE") # Holds the partition and map information # injectionPointsPerChip is the dictionary mapping chipId to # number of injection points for that chip self._injectionPointsPerChip = {} # List of size ( numChips * numSnipsPerChip) consisting of injection points for all individual snips self._injectionPointsPerSnip = [] # List to store tuple consisting chipId, numData to be send self._dataOrder = [] # Dictionary to store snip id to chip mapping self._chipIdForSnip = {} # List of chips being used self._chips = [] # Flag to indicate if input generator is compiled and ready self._compiled = False # List of compressed representation of resource map of cxs self._rangeAddress = [] # List of list of compressed reprsentation of resource maps of cxs per snip # Size of this list will be ( numChips * numSnipsPerChip) # Ultimately gets shipped to the snip via metaDataChannel self._metaData = [] # List consisting of number of packets per snip self._packetPerSnip = [] # List of Channels # dataChannel : Used to send injection data # infoChannel : Used to send packetSize info ToDo: Use jinja2 # dataSizeChannel : Used to send the numPackets info ToDo: Use jinja2 # metaDataChannel : Used to send range based address self._dataChannels = [] self._infoChannels = [] self._dataSizeChannels = [] self._metaDataChannels = [] # Portname self._portName = "output" # Bias Exp ( should be same for all Cxs) self.biasExp = 0 if bool(kwargs["encoderFunction"]) != bool(kwargs["decoderSnip"]): raise ValueError( "Either both encoderFunction and decoderSnip should be specified" "or both should be specified. Just one among them cannot be specified" ) if kwargs["encoderFunction"] and kwargs["decoderSnip"]: self.encoderFunction = kwargs["encoderFunction"] if not isinstance(kwargs["decoderSnip"], str): raise ValueError( "Decoder Snip should be of type str as it is path to template c file" ) self.decoderSnip = kwargs["decoderSnip"] else: self.encoderFunction = self._defaultEncoder if self.encoderType: self.decoderSnip = os.path.join(os.path.dirname(__file__), 'templates', 'inject_state.c.template') else: self.decoderSnip = os.path.join(os.path.dirname(__file__), 'templates', 'inject_spike.c.template') self._createOutputPort() self._addSnipPlaceholder()