Beispiel #1
0
def set_weight_programmable(neu,syn,w):
    '''
        this function set programmable weights (4 values one of [0,1,2,3] )
    '''
    if(w > 3):
        print "error weights!! please enter w in range [0,3]"
        raise Exception
    if w == 0:
        bit0 = 0
        bit1 = 0
    if w == 1:
        bit0 = 1
        bit1 = 0
    if w == 2:
        bit0 = 0
        bit1 = 1
    if w == 3:
        bit0 = 1
        bit1 = 1


    value = 2*2*256*256+bit0*256*256+syn*256+neu+133632
    biasusb_wrap.send_32(int(value))
    #print value
    value = 3*2*256*256+bit1*256*256+syn*256+neu+133632
    biasusb_wrap.send_32(int(value))
 def set_conf(self, address):
     print "Sending Configuration address: " + '{:021b}'.format(
         address) + ' (' + str(address) + ')'
     #conf command has to first two bits "01"
     #self.send_32(address + (1<<30))
     #biasusb_wrap.send_32_1(address+(1<<30))
     biasusb_wrap.send_32(address)
Beispiel #3
0
def load_weight_programmable(neu,syn,w):
    '''
        this function set programmable weights (4 values one of [0,1,2,3] )
    '''
    if(w > 3):
        print "error weights!! please enter w in range [0,3]"
        raise Exception
    if w == 0:
        bit0 = 0
        bit1 = 0
    if w == 1:
        bit0 = 1
        bit1 = 0
    if w == 2:
        bit0 = 0
        bit1 = 1
    if w == 3:
        bit0 = 1
        bit1 = 1


    value = 2*2*256*256+bit0*256*256+syn*256+neu+133632
    biasusb_wrap.send_32(int(value))
    #print value
    value = 3*2*256*256+bit1*256*256+syn*256+neu+133632
    biasusb_wrap.send_32(int(value))
Beispiel #4
0
def load_plastic_weight(neu,syn,value):
    '''
        this function set plastic weight to value (1/0) of row (neu) and column (synapse) 
    '''
    if(value == 1):
        vv = 1*256*256+syn*256+neu+1051136
        biasusb_wrap.send_32(int(vv))
        #print vv
    elif(value == 0):
        vv = syn*256+neu+1051136
        #print vv
        biasusb_wrap.send_32(int(vv))
 def send_32(self, inbits):
     print "inbits", inbits
     programming_bits = np.bitwise_and(inbits,65535) #bits 0 16 
     address_branch = (np.bitwise_and(inbits,8323072)>>16) #bits 17 to 22 
     print "send stuff"
     print "address_branch", np.binary_repr(address_branch)
     print "programming_bits", np.binary_repr(programming_bits)
     print "address_branch", (address_branch)
     print "programming_bits", (programming_bits<<7)
     final_address = (programming_bits<<7) + (address_branch) + 2**31
     print "final address", final_address
     biasusb_wrap.send_32(int(final_address))
Beispiel #6
0
def set_plastic_weight(neu,syn,value):
    '''
        this function set plastic weight to value (1/0) of row (neu) and column (synapse) 
    '''
    if(value == 1):
        vv = 1*256*256+syn*256+neu+1051136
        biasusb_wrap.send_32(int(vv))
        #print vv
    elif(value == 0):
        vv = syn*256+neu+1051136
        #print vv
        biasusb_wrap.send_32(int(vv))
Beispiel #7
0
def load_connections_matrix_plastic(matrix):
    '''
        this function set recurrent matrix 
    '''
    if( np.shape(matrix) != (256,256) ):
        print 'matrix has wrong size.. please input a binary matrix (np.array) with shape = (256,256)'
        return 0
    else:
        #matrix = matrix.astype(int)
        for col in range(256):
            for row in range(256):
                value = matrix[row,col]*256*256+col*256+row+1051136
                biasusb_wrap.send_32(int(value))
Beispiel #8
0
def load_connections_matrix_plastic(matrix):
    '''
        this function set recurrent matrix 
    '''
    if (np.shape(matrix) != (256, 256)):
        print 'matrix has wrong size.. please input a binary matrix (np.array) with shape = (256,256)'
        return 0
    else:
        #matrix = matrix.astype(int)
        for col in range(256):
            for row in range(256):
                value = matrix[row,
                               col] * 256 * 256 + col * 256 + row + 1051136
                biasusb_wrap.send_32(int(value))
Beispiel #9
0
def load_broadcast_matrix(matrix):
    '''
        this function set broadcast bit (0 / 1) (shape 256,512)
    '''
    if( np.shape(matrix) != (256,512) ):
        print 'matrix has wrong size.. please input a binary matrix (np.array) with shape = (256,512)'
        return 0
    else:
        for row in range(256):
            for col in range(256):
                if(col < 256):
                    value = 1*2*256*256+matrix[row,col]*256*256+col*256+row+788992
                else:
                    value = 4*2*256*256+matrix[row,col]*256*256+col*256+row+133632
                biasusb_wrap.send_32(int(value))
Beispiel #10
0
def set_broadcast_matrix(matrix):
    '''
        this function set broadcast bit (0 / 1) (shape 256,512)
    '''
    if( np.shape(matrix) != (256,512) ):
        print 'matrix has wrong size.. please input a binary matrix (np.array) with shape = (256,512)'
        return 0
    else:
        for row in range(256):
            for col in range(256):
                if(col < 256):
                    value = 1*2*256*256+matrix[row,col]*256*256+col*256+row+788992
                else:
                    value = 4*2*256*256+matrix[row,col]*256*256+col*256+row+133632
                biasusb_wrap.send_32(int(value))
 def send_32(self, inbits):
     #send to fpga
     #self.pcieSeq.put([inbits])
     #if self.pcieMon.get() == inbits:
     #    print "[OK]"
     #else:
     #print "[ERROR]"
     print "inbits", inbits
     programming_bits = np.bitwise_and(inbits,65535) #bits 0 16 
     address_branch = (np.bitwise_and(inbits,8323072)>>16) #bits 17 to 22 
     print "send stuff"
     print "address_branch", np.binary_repr(address_branch)
     print "programming_bits", np.binary_repr(programming_bits)
     print "address_branch", (address_branch)
     print "programming_bits", (programming_bits<<7)
     final_address = (programming_bits<<7) + (address_branch) + 2**31
     print "final address", final_address
     biasusb_wrap.send_32(int(final_address))
 def send_32(self, inbits):
     #send to fpga
     #self.pcieSeq.put([inbits])
     #if self.pcieMon.get() == inbits:
     #    print "[OK]"
     #else:
     #print "[ERROR]"
     print "inbits", inbits
     programming_bits = np.bitwise_and(inbits, 65535)  #bits 0 16
     address_branch = (np.bitwise_and(inbits, 8323072) >> 16
                       )  #bits 17 to 22
     print "send stuff"
     print "address_branch", np.binary_repr(address_branch)
     print "programming_bits", np.binary_repr(programming_bits)
     print "address_branch", (address_branch)
     print "programming_bits", (programming_bits << 7)
     final_address = (programming_bits << 7) + (address_branch) + 2**31
     print "final address", final_address
     biasusb_wrap.send_32(int(final_address))
Beispiel #13
0
def set_recurrent_bit(neu,syn,onoff,recurrent = 0):
    '''
        this function set recurrent bit of row (neu) and col (syn) to on onoff (1 or 0)
    '''
    plastic = False
    programmable = False
    #matrix = matrix.astype(int)
    if (syn < 256):
        plastic = True
    else:
        programmable = True
    if(plastic):
        offset = 788992
        matrix_value = onoff
        value = matrix_value*256*256+syn*256+neu+offset
    if(programmable):
        offset = 133632
        matrix_value = onoff
        value = matrix_value*256*256+(syn-256)*256+neu+offset
    #print value
    biasusb_wrap.send_32(int(value))
Beispiel #14
0
def load_recurrent_bit(neu,syn,onoff,recurrent = 0):
    '''
        this function set recurrent bit of row (neu) and col (syn) to on onoff (1 or 0)
    '''
    plastic = False
    programmable = False
    #matrix = matrix.astype(int)
    if (syn < 256):
        plastic = True
    else:
        programmable = True
    if(plastic):
        offset = 788992
        matrix_value = onoff
        value = matrix_value*256*256+syn*256+neu+offset
    if(programmable):
        offset = 133632
        matrix_value = onoff
        value = matrix_value*256*256+(syn-256)*256+neu+offset
    #print value
    biasusb_wrap.send_32(int(value))
Beispiel #15
0
def set_neuron_tau_1(neurons):
    '''
        set neurons to tau 1 ; neurons is an array 
    '''
    for i in range(len(neurons)):
        biasusb_wrap.send_32(int(neurons[i]+1249026))
        biasusb_wrap.send_32(int(1249283))                     
        biasusb_wrap.send_32(int(neurons[i]+1249026))
Beispiel #16
0
def set_neuron_tau_1(neurons):
    '''
        set neurons to tau 1 ; neurons is an array 
    '''
    for i in range(len(neurons)):
        biasusb_wrap.send_32(int(neurons[i]+1249026))
        biasusb_wrap.send_32(int(1249283))                     
        biasusb_wrap.send_32(int(neurons[i]+1249026))
Beispiel #17
0
def setMonitorDPI(name,neuron):
	biasusb_wrap.send_32(int(dpiNames[name])*256+neuron+1247744)
Beispiel #18
0
def set_neurons_tau_2():
    '''
        set all neuron to tau 2
    '''
    biasusb_wrap.send_32(1249282)
    biasusb_wrap.send_32(1249283)
 def set_aer(self, address):
     print "Sending AER address: " + '{:021b}'.format(address) + ' (' + str(address) + ')'
     #aer command has to first two bits "10"
     #self.send_32(address + (2<<30))
     biasusb_wrap.send_32(address)
 def set_conf(self, address):
     print "Sending Configuration address: " + '{:021b}'.format(address) + ' (' + str(address) + ')'
     #conf command has to first two bits "01"
     #self.send_32(address + (1<<30))
     #biasusb_wrap.send_32_1(address+(1<<30))
     biasusb_wrap.send_32(address)
Beispiel #21
0
def set_programmable_exc_inh(neu,syn,ei):
    '''
        this function program the programmable synapse to be exc (ei=1) or inh (ei=0)
    '''
    value = 1*2*256*256+ei*256*256+syn*256+neu+133632
    biasusb_wrap.send_32(int(value)) 
Beispiel #22
0
def load_recurrent_bit_plastic_syn(neu,syn,onoff,recurrent = 0):
    '''
        this function set recurrent bit of row (neu) and col (syn) to on onoff (1 or 0)
    '''
    biasusb_wrap.send_32(recurrent*2*256*256+onoff*256*256+syn*256+neu+788992)
 def set_conf(self, address):
     print "Sending Configuration address: " + '{:021b}'.format(address) + ' (' + str(address) + ')'
     biasusb_wrap.send_32(address)
Beispiel #24
0
def setMonitorNeuron(neuron):
    biasusb_wrap.send_32(1249024)
    biasusb_wrap.send_32(1249025)
    biasusb_wrap.send_32(neuron+1249284) #PLEASE FIX!
    biasusb_wrap.send_32(1249025)
    biasusb_wrap.send_32(neuron+1249284)
 def set_aer(self, address):
     print "Sending AER address: " + '{:021b}'.format(address) + ' (' + str(
         address) + ')'
     #aer command has to first two bits "10"
     #self.send_32(address + (2<<30))
     biasusb_wrap.send_32(address)
Beispiel #26
0
def setMonitorNeuron(neuron):
    biasusb_wrap.send_32(1249024)
    biasusb_wrap.send_32(1249025)
    biasusb_wrap.send_32(neuron+1249284) #PLEASE FIX!
    biasusb_wrap.send_32(1249025)
    biasusb_wrap.send_32(neuron+1249284)
 def set_aer(self, address):
     print "Sending AER address: " + '{:021b}'.format(address) + ' (' + str(address) + ')'
     biasusb_wrap.send_32(address)
Beispiel #28
0
def set_neurons_tau_2():
    '''
        set all neuron to tau 2
    '''
    biasusb_wrap.send_32(1249282)
    biasusb_wrap.send_32(1249283)
Beispiel #29
0
def load_programmable_exc_inh(neu,syn,ei):
    '''
        this function program the programmable synapse to be exc (ei=1) or inh (ei=0)
    '''
    value = 1*2*256*256+ei*256*256+syn*256+neu+133632
    biasusb_wrap.send_32(int(value)) 
Beispiel #30
0
def set_recurrent_bit_plastic_syn(neu,syn,onoff,recurrent = 0):
    '''
        this function set recurrent bit of row (neu) and col (syn) to on onoff (1 or 0)
    '''
    biasusb_wrap.send_32(recurrent*2*256*256+onoff*256*256+syn*256+neu+788992)
Beispiel #31
0
def setMonitorDPI(name,neuron):
	biasusb_wrap.send_32(int(dpiNames[name])*256+neuron+1247744)