示例#1
0
    def configDMAFPGA(self, rank_id):
      

        binToSend = bytearray(np.array([self.parameters['neural_net'][rank_id]['rank_info']['ifm_baseaddr']], dtype=np.int64).byteswap().tobytes())
        binToSend.extend(bytearray(np.array([self.parameters['neural_net'][rank_id]['command'][0]['ifm_width'] * self.parameters['neural_net'][rank_id]['command'][0]['ifm_height'] * self.parameters['neural_net'][rank_id]['command'][0]['ifm_depth'] * 2], dtype=np.int64).byteswap().tobytes()))
        binToSend.extend(bytearray(np.array([self.parameters['neural_net'][rank_id]['rank_info']['ofm_baseaddr']], dtype=np.int64).byteswap().tobytes()))
        binToSend.extend(bytearray(np.array([self.parameters['neural_net'][rank_id]['command'][len(self.parameters['neural_net'][rank_id]['command']) - 1]['ofm_height']   * self.parameters['neural_net'][rank_id]['command'][len(self.parameters['neural_net'][rank_id]['command'])-1] ['ofm_width'] * self.parameters['neural_net'][rank_id]['command'][len(self.parameters['neural_net'][rank_id]['command'])-1]['output_channels'] * 2], dtype=np.int64).byteswap().tobytes()))
        GalapagosNet.binToStream(self, binToSend, self.parameters['neural_net'][rank_id]['rank_info']['dst_rank'], 'init' + str(rank_id))
示例#2
0
    def test(self, rank_id):

        binToSend = bytearray(8)  #address
        print binToSend
        print "len of long is " + str(len(binToSend))

        b = bytearray.fromhex("0800 00 00 00 00 00 00")
        binToSend.extend(bytearray(b))  #size

        print "len of long is " + str(len(binToSend))
        GalapagosNet.binToStream(
            self, binToSend,
            self.parameters['neural_net'][rank_id]['rank_info']['dst_rank'])
        binToSend = bytearray(np.array([16]).tobytes())  #dma parameters
        print len(bytearray(np.array([16]).tobytes()))

        GalapagosNet.binToStream(
            self, binToSend,
            self.parameters['neural_net'][rank_id]['rank_info']['dst_rank'])
示例#3
0
    def configParametersFPGA(self, rank_id):

        binToSend = bytearray(
            np.array([
                self.parameters['neural_net'][rank_id]['rank_info']
                ['biases_weights_baseaddr']
            ],
                     dtype=np.int64).byteswap().tobytes())
        print len(binToSend)
        length = 0

        #calculate length of all parameters on fpga
        for cmd_id, cmd in enumerate(
                self.parameters['neural_net'][rank_id]['command']):
            length = length + len(self.parameters['neural_net'][rank_id]
                                  ['command'][cmd_id]['configParameters'])
            print "length of command " + str(cmd_id) + " is " + str(length)

        print "length of command is " + str(length)
        binToSend.extend(
            np.array([length], dtype=np.int64).byteswap().tobytes())

        print len(binToSend)
        #send configuration parameters to all fpga_ranks

        GalapagosNet.binToStream(
            self, binToSend,
            self.parameters['neural_net'][rank_id]['rank_info']['dst_rank'],
            'init' + str(rank_id))
        #send all weights for all commands on fpga
        for cmd_id, cmd in enumerate(
                self.parameters['neural_net'][rank_id]['command']):
            #print binascii.hexlify(self.parameters['neural_net'][rank_id]['command'][cmd_id]['configParameters'])
            GalapagosNet.binToStream(
                self, self.parameters['neural_net'][rank_id]['command'][cmd_id]
                ['configParameters'], self.parameters['neural_net'][rank_id]
                ['rank_info']['dst_rank'], 'init' + str(rank_id))
示例#4
0
    def configCmdFPGA(self, rank_id):

        #        cmd_num_commands = np.array([1],dtype=np.int64).byteswap()
        cmd_num_commands = np.array(
            [len(self.parameters['neural_net'][rank_id]['command'])],
            dtype=np.int64).byteswap()

        for cmd_id, cmd in enumerate(
                self.parameters['neural_net'][rank_id]['command']):
            cmd_conv = np.array([
                self.parameters['neural_net'][rank_id]['command'][cmd_id]
                ['ifm_height'], self.parameters['neural_net'][rank_id]
                ['command'][cmd_id]['ifm_width'], self.parameters['neural_net']
                [rank_id]['command'][cmd_id]['kernel_height'],
                self.parameters['neural_net'][rank_id]['command'][cmd_id]
                ['kernel_width'], self.parameters['neural_net'][rank_id]
                ['command'][cmd_id]['stride'], self.parameters['neural_net']
                [rank_id]['command'][cmd_id]['pad'],
                self.parameters['neural_net'][rank_id]['command'][cmd_id]
                ['ofm_height'], self.parameters['neural_net'][rank_id]
                ['command'][cmd_id]['ofm_width'], self.parameters['neural_net']
                [rank_id]['command'][cmd_id]['ifm_slices'],
                self.parameters['neural_net'][rank_id]['command'][cmd_id]
                ['ofm_slices'], self.parameters['neural_net'][rank_id]
                ['command'][cmd_id]['ofm_fragments'],
                self.parameters['neural_net'][rank_id]['command'][cmd_id]
                ['ifm_mem_fragments']
            ],
                                dtype='uint16').byteswap()
            cmd_addr = np.array([
                self.parameters['neural_net'][rank_id]['command'][cmd_id]
                ['ifm_baseaddr'], self.parameters['neural_net'][rank_id]
                ['command'][cmd_id]['ifm_packet_length'],
                self.parameters['neural_net'][rank_id]['command'][cmd_id]
                ['ifm_depth_offset'], self.parameters['neural_net'][rank_id]
                ['command'][cmd_id]['ifm_height_offset'],
                self.parameters['neural_net'][rank_id]['command'][cmd_id]
                ['ofm_baseaddr'], self.parameters['neural_net'][rank_id]
                ['command'][cmd_id]['ofm_packet_length'],
                self.parameters['neural_net'][rank_id]['command'][cmd_id]
                ['weights_baseaddr'], self.parameters['neural_net'][rank_id]
                ['command'][cmd_id]['weights_packet_length'],
                self.parameters['neural_net'][rank_id]['command'][cmd_id]
                ['weight_depth_offset']
            ],
                                dtype='uint32').byteswap()
            cmd_mode = np.array([0, 0], dtype='uint16')
            cmd_pool = np.array([
                0, 1, self.parameters['neural_net'][rank_id]['command'][cmd_id]
                ['pool_input_height'], self.parameters['neural_net'][rank_id]
                ['command'][cmd_id]['pool_input_width'],
                self.parameters['neural_net'][rank_id]['command'][cmd_id]
                ['pool_kernel_height'], self.parameters['neural_net'][rank_id]
                ['command'][cmd_id]['pool_kernel_width'],
                self.parameters['neural_net'][rank_id]['command'][cmd_id]
                ['pool_output_height'], self.parameters['neural_net'][rank_id]
                ['command'][cmd_id]['pool_output_width'],
                self.parameters['neural_net'][rank_id]['command'][cmd_id]
                ['pool_stride'], 0
            ],
                                dtype='uint16').byteswap()
            cmd_relu_bias = np.array([
                self.parameters['neural_net'][rank_id]['command'][cmd_id]
                ['relu'], self.parameters['neural_net'][rank_id]['command']
                [cmd_id]['bias']
            ],
                                     dtype='uint8')
            cmd_bias_addr = np.array([
                self.parameters['neural_net'][rank_id]['command'][cmd_id]
                ['biases_weights_baseaddr']
            ],
                                     dtype='uint32').byteswap()
            cmd_rsvd = np.zeros((11, ), dtype='uint32')
            if (cmd_id == 0):
                #self.cmd = cmd_num_commands.tobytes() + \
                #         cmd_conv.tobytes() + \
                #         cmd_addr.tobytes() + \
                #         cmd_mode.tobytes() + \
                #         cmd_pool.tobytes() + \
                #         cmd_rsvd.tobytes()
                self.cmd = cmd_mode.tobytes() + \
                         cmd_pool.tobytes() + \
                         cmd_rsvd.tobytes()
            else:
                self.cmd.extend(
                    bytearray(cmd_num_commands.tobytes() + cmd_conv.tobytes() +
                              cmd_addr.tobytes() + cmd_mode.tobytes() +
                              cmd_pool.tobytes() + cmd_rsvd.tobytes()))

            self.cmd = bytearray(self.cmd)

        self.cmd.extend(
            bytearray(
                np.array([
                    self.parameters['neural_net'][rank_id]['rank_info']
                    ['batch_size']
                ],
                         dtype=np.int64).byteswap()))
        self.cmd.extend(
            bytearray(
                np.array([
                    self.parameters['neural_net'][rank_id]['rank_info']
                    ['num_ranks']
                ],
                         dtype=np.int64).byteswap()))
        GalapagosNet.binToStream(
            self, self.cmd,
            self.parameters['neural_net'][rank_id]['rank_info']['dst_rank'],
            'init' + str(rank_id))
示例#5
0
#            self.configDMAFPGA(rank_id)
#            self.configCmdFPGA(rank_id)
    def test(self, rank_id):
        
        
        binToSend = bytearray(8) #address
        print binToSend
        print "len of long is " + str(len(binToSend))
        
        
        b = bytearray.fromhex("0800 00 00 00 00 00 00")
        binToSend.extend(bytearray(b)) #size

        print "len of long is " + str(len(binToSend))
<<<<<<< HEAD
        GalapagosNet.binToStream(self, binToSend, self.parameters['neural_net'][rank_id]['dst_rank'])
=======
        GalapagosNet.binToStream(self, binToSend, self.parameters['neural_net'][rank_id]['rank_info']['dst_rank'])
>>>>>>> a83aeb56cba6bb8684d30caa1660636ec0f54f99
        binToSend = bytearray(np.array([16]).tobytes()) #dma parameters
        print len(bytearray(np.array([16]).tobytes()))


<<<<<<< HEAD
        GalapagosNet.binToStream(self, binToSend, self.parameters['neural_net'][rank_id]['dst_rank'])
=======
        GalapagosNet.binToStream(self, binToSend, self.parameters['neural_net'][rank_id]['rank_info']['dst_rank'])
>>>>>>> a83aeb56cba6bb8684d30caa1660636ec0f54f99