コード例 #1
0
ファイル: spu_psmap.py プロジェクト: KapilRijhwani/corepy
  r_lsa = prgm.acquire_register()

  spu.il(r_lsa, 0x1000)

  lbl_incloop = prgm.get_label("incloop")
  code.add(lbl_incloop)

  spu.lqx(r_data, r_cnt, r_lsa)
  spu.ai(r_data, r_data, 2)
  spu.stqx(r_data, r_cnt, r_lsa)

  spu.ai(r_cnt, r_cnt, 16)
  spu.ceq(r_cmp, r_cnt, r_sum)
  spu.brz(r_cmp, lbl_incloop)

  dma.spu_write_out_mbox(code, code.r_zero)

  prgm += code

  t3 = time.time()
  id = proc.execute(prgm, async = True, mode = 'int')


  t1 = time.time()
  for i in xrange(0, ITERS):
    #env.spu_exec.write_in_mbox(id, 1)
    #env.spu_exec.write_in_mbox(id, 1)
    env.spu_exec.write_in_mbox(id, i)
    #cnt = env.spu_exec.stat_in_mbox(id)
    #print "cnt %x" % cnt
コード例 #2
0
    r_lsa = prgm.acquire_register()

    spu.il(r_lsa, 0x1000)

    lbl_incloop = prgm.get_label("incloop")
    code.add(lbl_incloop)

    spu.lqx(r_data, r_cnt, r_lsa)
    spu.ai(r_data, r_data, 2)
    spu.stqx(r_data, r_cnt, r_lsa)

    spu.ai(r_cnt, r_cnt, 16)
    spu.ceq(r_cmp, r_cnt, r_sum)
    spu.brz(r_cmp, lbl_incloop)

    dma.spu_write_out_mbox(code, code.r_zero)

    prgm += code

    t3 = time.time()
    id = proc.execute(prgm, async=True, mode='int')

    t1 = time.time()
    for i in xrange(0, ITERS):
        #env.spu_exec.write_in_mbox(id, 1)
        #env.spu_exec.write_in_mbox(id, 1)
        env.spu_exec.write_in_mbox(id, i)
        #cnt = env.spu_exec.stat_in_mbox(id)
        #print "cnt %x" % cnt

        #cnt = env.spu_exec.stat_out_mbox(id)
コード例 #3
0
ファイル: spu_write_mbox.py プロジェクト: tmaone/efi
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import corepy.arch.spu.isa as spu
import corepy.arch.spu.platform as env
import corepy.arch.spu.lib.dma as dma
from corepy.arch.spu.lib.util import load_word

code = env.InstructionStream()
proc = env.Processor()

# Grab a register and initialize it
reg = code.acquire_register()
load_word(code, reg, 0xCAFEBABE)

# Write the value to the outbound mailbox
dma.spu_write_out_mbox(code, reg)

# Wait for a signal
sig = dma.spu_read_signal1(code)

code.release_register(sig)
code.release_register(reg)

# Start the synthesized SPU program
id = proc.execute(code, async=True)

# Spin until the mailbox can be read
while env.spu_exec.stat_out_mbox(id) == 0:
    pass
value = env.spu_exec.read_out_mbox(id)
コード例 #4
0
import corepy.arch.spu.isa as spu
import corepy.arch.spu.platform as env
import corepy.arch.spu.lib.dma as dma
from corepy.arch.spu.lib.util import load_word


prgm = env.Program()
code = prgm.get_stream()
proc = env.Processor()

# Grab a register and initialize it
reg = prgm.acquire_register()
load_word(code, reg, 0xCAFEBABE)

# Write the value to the outbound mailbox
dma.spu_write_out_mbox(code, reg)

# Wait for a signal
sig = dma.spu_read_signal1(code)

prgm.release_register(sig)
prgm.release_register(reg)


prgm.add(code)

# Start the synthesized SPU program
id = proc.execute(prgm, async = True)

# Spin until the mailbox can be read
while env.spu_exec.stat_out_mbox(id) == 0: pass
コード例 #5
0
ファイル: spu_basics.py プロジェクト: tmaone/efi
def MemoryDescExample(data_size=20000):
    """
  This example uses a memory descriptor to move 20k integers back and 
  forth between main memory and the SPU local store. Each value is
  incremented by 1 while on the SPU.
  
  Memory descriptors are a general purpose method for describing a
  region of memory.  Memory is described by a typecode, address, and
  size.  Memory descriptors can be initialized by hand or from an
  array or buffer object.

  For main memory, memory descriptors are useful for transfering data
  between main memory and an SPU's local store.  The get/put methods
  on a memory descriptor generate the SPU code to move data of any
  size between main memory and local store.

  Memory descriptors can also be used with spu_vec_iters to describe
  the region of memory to iterate over.  The typecode in the memory
  descriptor is used to determine the type for the loop induction
  variable.

  Note that there is currently no difference between memory
  descriptors for main memory and local store.  It's up to the user to
  make sure the memory descriptor settings make sense in the current
  context.  (this will probably change in the near future)

  Note: get/put currently use loops rather than display lists for
        transferring data over 16k.
  """

    code = InstructionStream()
    proc = Processor()

    code.debug = True
    spu.set_active_code(code)

    # Create a python array
    data = extarray.extarray('I', range(data_size))

    # Align the data in the array
    #a_data = aligned_memory(data_size, typecode = 'I')
    #a_data.copy_to(data.buffer_info()[0], data_size)

    # Create memory descriptor for the data in main memory
    data_desc = memory_desc('I')
    #data_desc.from_array(a_data)
    data_desc.from_array(data)

    # Transfer the data to 0x0 in the local store
    data_desc.get(code, 0)

    # Create memory descriptor for the data in the local store for use
    # in the iterator
    lsa_data = memory_desc('i', 0, data_size)

    # Add one to each value
    for x in spu_vec_iter(code, lsa_data):
        x.v = x + 1

    # Transfer the data back to main memory
    data_desc.put(code, 0)

    dma.spu_write_out_mbox(code, 0xCAFE)

    # Execute the synthetic program
    # code.print_code()

    spe_id = proc.execute(code, async=True)
    proc.join(spe_id)

    # Copy it back to the Python array
    #a_data.copy_from(data.buffer_info()[0], data_size)

    for i in xrange(data_size):
        assert (data[i] == i + 1)
    return
コード例 #6
0
ファイル: spu_basics.py プロジェクト: KapilRijhwani/corepy
def MemoryDescExample(data_size = 20000):
  """
  This example uses a memory descriptor to move 20k integers back and 
  forth between main memory and the SPU local store. Each value is
  incremented by 1 while on the SPU.
  
  Memory descriptors are a general purpose method for describing a
  region of memory.  Memory is described by a typecode, address, and
  size.  Memory descriptors can be initialized by hand or from an
  array or buffer object.

  For main memory, memory descriptors are useful for transfering data
  between main memory and an SPU's local store.  The get/put methods
  on a memory descriptor generate the SPU code to move data of any
  size between main memory and local store.

  Memory descriptors can also be used with spu_vec_iters to describe
  the region of memory to iterate over.  The typecode in the memory
  descriptor is used to determine the type for the loop induction
  variable.

  Note that there is currently no difference between memory
  descriptors for main memory and local store.  It's up to the user to
  make sure the memory descriptor settings make sense in the current
  context.  (this will probably change in the near future)

  Note: get/put currently use loops rather than display lists for
        transferring data over 16k.
  """
  
  code = env.InstructionStream()
  proc = env.Processor()

  code.debug = True
  spu.set_active_code(code)

  # Create a python array
  data = extarray.extarray('I', range(data_size))

  # Align the data in the array
  #a_data = aligned_memory(data_size, typecode = 'I')
  #a_data.copy_to(data.buffer_info()[0], data_size)
  
  # Create memory descriptor for the data in main memory
  data_desc = memory_desc('I')
  #data_desc.from_array(a_data)
  data_desc.from_array(data)

  # Transfer the data to 0x0 in the local store
  data_desc.get(code, 0)

  # Create memory descriptor for the data in the local store for use
  # in the iterator  
  lsa_data = memory_desc('i', 0, data_size)

  # Add one to each value
  for x in spu_vec_iter(code, lsa_data):
    x.v = x + 1

  # Transfer the data back to main memory
  data_desc.put(code, 0)

  dma.spu_write_out_mbox(code, 0xCAFE)
  
  # Execute the synthetic program
  # code.print_code()
  
  spe_id = proc.execute(code, async=True)
  proc.join(spe_id)

  # Copy it back to the Python array
  #a_data.copy_from(data.buffer_info()[0], data_size)

  for i in xrange(data_size):
    assert(data[i] == i + 1)
  return