예제 #1
0
파일: gemm.py 프로젝트: tmaone/efi
  def _init_vars(self):
    # Address variables
    self.r_tA_addr = ppcvar.UnsignedWord()
    self.r_tB_addr = ppcvar.UnsignedWord()
    self.r_C_addr  = ppcvar.UnsignedWord()
    self.r_C_aux_addr  = ppcvar.UnsignedWord()    

    self.p_tA = ppcvar.UnsignedWord()
    self.p_tB = ppcvar.UnsignedWord()
    self.p_C  = [ppcvar.UnsignedWord() for i in range(self.block.mr)]
    self.p_C_aux = [ppcvar.UnsignedWord() for i in range(self.block.mr)]

    self.vC_row_stride = ppcvar.UnsignedWord(self.C_strides.row)

    mr, nr = self.block.mr, self.block.nr
    
    # Inner loop variables
    if mr != nr:
      raise Exception('mr (%d) should equal nr (%d)' % (mr, nr))

    self.a = [ppcvar.DoubleFloat() for i in range(mr)]
    self.b = [ppcvar.DoubleFloat() for j in range(nr)]

    self.a_pre = [ppcvar.DoubleFloat() for i in range(mr)]
    self.b_pre = [ppcvar.DoubleFloat() for j in range(nr)]

    self.c = [[ppcvar.DoubleFloat() for j in range(nr)] for i in range(mr)]

    return
예제 #2
0
파일: iterators.py 프로젝트: unazed/corepy
def TestRange():

  prgm = synppc.Program()
  code = prgm.get_stream()
  prgm.add(code)
  ppc.set_active_code(code)
  
  a = vars.UnsignedWord(0)

  for i in syn_range(code, 7):
    a.v = a + 1

  for i in syn_range(code, 20, 31):
    a.v = a + 1

  for i in syn_range(code, 20, 26, 2):
    a.v = a + 1
  
  util.return_var( a)
  #a.release_register(code)

  proc = synppc.Processor()
  r = proc.execute(prgm)

  # print 'should be 21:', r
  assert(r == 21)

  return
예제 #3
0
def TestRange():

    code = synppc.InstructionStream()
    ppc.set_active_code(code)

    # code.add(ppc.Illegal())

    a = vars.UnsignedWord(0)

    for i in syn_range(code, 7):
        a.v = a + 1

    for i in syn_range(code, 20, 31):
        a.v = a + 1

    for i in syn_range(code, 20, 26, 2):
        a.v = a + 1

    util.return_var(a)
    a.release_register(code)

    proc = synppc.Processor()
    r = proc.execute(code)

    # print 'should be 21:', r
    assert (r == 21)

    return
예제 #4
0
    def _init_vars(self, vb=None, vtB=None):

        self.vN = ppcvar.UnsignedWord(self.dim.N)

        self.vB = ppcvar.UnsignedWord()
        self.vBi = ppcvar.UnsignedWord()

        self.bij = ppcvar.UnsignedWord()
        self.tbji = ppcvar.UnsignedWord()

        self.vb_local = True
        if vb is None:
            self.vb = ppcvar.DoubleFloat()
        else:
            self.vb = vb
            self.vb_local = False

        self.vtB_local = True
        if vtB is None:
            self.vtB = ppcvar.UnsignedWord(array_address(self.tB))
        else:
            self.vtB = vtB
            self.vtB_local = False

        return
예제 #5
0
    def start(self, align=True, branch=True):

        if self.r_count is None:
            self.r_count = self.code.acquire_register()

        if self.mode == CTR and branch:
            if self.step_size() != 1:
                raise Exception(
                    'CTR loops must have step_size of 1, you used ' +
                    str(self.step_size()))

            if self.external_stop:
                self.code.add(ppc.mtctr(self.r_stop))
            else:
                util.load_word(self.code, self.r_count, self.n_steps())
                self.code.add(ppc.mtctr(self.r_count))

            self.code.release_register(self.r_count)
            self.r_count = None

        elif self.mode == DEC:
            util.load_word(self.code, self.r_count, self.get_count())

        elif self.mode == INC:
            if self.r_stop is None and branch:
                self.r_stop = self.code.acquire_register()

            util.load_word(self.code, self.r_count, self.get_start())

            if branch and not self.external_stop:
                util.load_word(self.code, self.r_stop, self.get_count())

        # /end mode if

        if self.r_count is not None:
            # self.current_count = metavar.int_var(self.code, reg = self.r_count)
            self.current_count = vars.UnsignedWord(reg=self.r_count)

        if align and branch:
            # Align the start of the loop on a 16 byte boundary
            while (self.code.size()) % 4 != 0:
                self.code.add(ppc.noop())

        # Label
        self.start_label = self.code.size() + 1

        return
예제 #6
0
파일: gemm.py 프로젝트: tmaone/efi
  def _init_vars2(self, vars, fvar, vtB):
    """
    Use variables in vars instead of allocating new ones.
    """

    # vB cannot change between runs, allocate locally.
    self.vB = ppcvar.UnsignedWord()
    
    self.vN = vars[0]
    self.vN.v = self.dim.N

    self.vBi = vars[1]
    self.bij = vars[2]
    self.tbji = vars[3]

    self.vtB = vtB

    self.vb = fvar
    return
예제 #7
0
def TestZipIter():
    code = synppc.InstructionStream()
    ppc.set_active_code(code)
    # code.add(ppc.Illegal())

    a = array.array('I', range(16, 32))
    b = array.array('I', range(32, 48))
    c = array.array('I', [0 for i in range(16)])

    sum = vars.UnsignedWord(0)

    for i, j, k in zip_iter(code, var_iter(code, a), var_iter(code, b),
                            var_iter(code, c, store_only=True)):
        k.v = i + j
        sum.v = sum + 1

    av = vector_iter(code, array.array('I', range(16)))
    bv = vector_iter(code, array.array('I', range(16, 32)))
    cv = vector_iter(code,
                     array.array('I', [0 for i in range(16)]),
                     store_only=True)

    for i, j, k in zip_iter(code, av, bv, cv):
        k.v = vmx.vadduws.ex(i, j)  # i + j

    util.return_var(sum)

    proc = synppc.Processor()
    r = proc.execute(code)

    assert (r == 16)
    print a
    print b
    print c

    print av.data
    print bv.data
    print cv.data
    print 'TODO: Finish checking TestZipIter values'
    return
예제 #8
0
def TestNestedIter():

    code = synppc.InstructionStream()
    ppc.set_active_code(code)
    # code.add(ppc.Illegal())

    a = vars.UnsignedWord(0)

    for i in syn_iter(code, 5):
        for j in syn_iter(code, 5):
            for k in syn_iter(code, 5):
                a.v = a + i + j + k

    util.return_var(a)
    a.release_register()

    proc = synppc.Processor()
    r = proc.execute(code)

    # print 'should be 750:', r
    assert (r == 750)
    return
예제 #9
0
파일: iterators.py 프로젝트: unazed/corepy
def TestNestedIter():

  prgm = synppc.Program()
  code = prgm.get_stream()
  prgm.add(code)
  ppc.set_active_code(code)

  a = vars.UnsignedWord(0)

  for i in syn_iter(code, 5):
    for j in syn_iter(code, 5):
      for k in syn_iter(code, 5):
        a.v = a + i + j + k
      
  util.return_var(a)
  #a.release_register()

  proc = synppc.Processor()
  r = proc.execute(prgm)

  # print 'should be 750:', r
  assert(r == 750)
  return