Exemplo n.º 1
0
    def run(self):
        # Compile network
        compiler = nx.N2Compiler()
        board = compiler.compile(self.net.nxNet)
        logging.info('Network successfully compiled')

        # Add snips and channel
        resetInitSnips = self.net.addResetSnips(board)  # add snips
        resetInitChannels = self.net.createAndConnectResetInitChannels(
            board, resetInitSnips
        )  # create channels for transfering initial values for the reset SNIP

        # Start board
        board.start()
        logging.info('Board successfully started')

        # Write initial data to channels
        for i in range(self.p.numChips):
            resetInitChannels[i].write(
                3,
                [
                    self.p.neuronsPerCore,  # number of neurons per core
                    self.p.totalTrialSteps,  # reset interval
                    self.p.
                    resetSteps  # number of steps to clear voltages/currents
                ])
        logging.info('Initial values transfered to SNIPs via channel')

        # Run and disconnect board
        board.run(self.p.totalSteps)
        board.disconnect()

        # Perform postprocessing
        self.net.postProcessing()
Exemplo n.º 2
0
 def _build_board(self):
     if self.board is not None:
         self.board.disconnect()
     compiler = nx.N2Compiler()
     self.board = compiler.compile(self.net)
     # self.board.sync = True  # TODO Validate
     self._build_snips()
 def setup_snn(self,
               print_axon=False,
               snip_dir='../loihi_network/snip',
               encode_input_num=6,
               decode_output_num=2):
     """
     Setup SNN on Loihi
     """
     self.set_network_output_layer()
     self.set_online_output_decoding()
     self.set_network_input_layer()
     self.set_online_input_encoding()
     self.set_network_bias_layer()
     self.set_online_bias_encoding()
     self.set_network_hidden_layer()
     self.set_network_connections()
     compiler = nx.N2Compiler()
     board = compiler.compile(self.net)
     if print_axon:
         input_axon_id = self.get_online_input_axon_id()
         bias_axon_id = self.get_online_bias_axon_id()
         print("Axon Id For Input Layer: ")
         print(input_axon_id)
         print("Axon Id For Bias Layer: ")
         print(bias_axon_id)
     include_dir = os.path.abspath(snip_dir)
     encoder_snip = board.createSnip(Phase.EMBEDDED_SPIKING,
                                     name='encoder',
                                     includeDir=include_dir,
                                     cFilePath=include_dir + '/encoder.c',
                                     funcName='run_encoder',
                                     guardName='do_encoder')
     decoder_snip = board.createSnip(Phase.EMBEDDED_MGMT,
                                     name='decoder',
                                     includeDir=include_dir,
                                     cFilePath=include_dir + '/decoder.c',
                                     funcName='run_decoder',
                                     guardName='do_decoder')
     encoder_channel = board.createChannel(b'encodeinput', "int",
                                           encode_input_num)
     encoder_channel.connect(None, encoder_snip)
     decoder_channel = board.createChannel(b'decodeoutput', "int",
                                           decode_output_num)
     decoder_channel.connect(decoder_snip, None)
     return board, encoder_channel, decoder_channel
Exemplo n.º 4
0
 def compileAndGetBoard(self):
     """ compiles the network """
     self.board = nx.N2Compiler().compile(self.net)
     return self.board
Exemplo n.º 5
0
 def _compile(self):
     self.compiler = nx.N2Compiler()
     self.board = self.compiler.compile(self.net)
     self.board.sync = True
Exemplo n.º 6
0
 def compileAndGetBoard(self):
     self.board = nx.N2Compiler().compile(self.net)
     return self.board