Example #1
0
def TestSynIterInc():
  SIZE = 64

  # build and run the kernel
  prgm = env.Program()
  code = prgm.get_stream()

  code.add(cal.dcl_output(reg.o0, USAGE=cal.usage.pos))
  ones = prgm.acquire_register((1, 1, 1, 1))
  counter = prgm.acquire_register()
  code.add(cal.mov(counter, ones))

  for i in syn_iter(code, 4, step=1, mode=INC):
    code.add(cal.iadd(counter, counter, ones))

  code.add(cal.mov(reg.o0, counter.x))

  domain = (0, 0, SIZE, SIZE)
  proc = env.Processor(0)

  ext_output=proc.alloc_remote('i', 1, SIZE)
  prgm.set_binding(reg.o0, ext_output)

  prgm.add(code)
  proc.execute(prgm, domain)

  passed = True
  for i in xrange(0, SIZE):
    if ext_output[i] != 5:
      passed = False
  print "Passed == ", passed

  proc.free(ext_output)

  return
Example #2
0
def TestRelativeAddressing():
    import corepy.arch.cal.platform as env
    import corepy.arch.cal.isa as cal

    proc = env.Processor(0)

    input_mem = proc.alloc_remote('I', 4, 16, 1)
    output_mem = proc.alloc_remote('I', 4, 1, 1)

    for i in range(16 * 1 * 4):
        for j in range(4):
            input_mem[i * 4 + j] = i

    prgm = env.Program()
    code = prgm.get_stream()
    cal.set_active_code(code)

    cal.dcl_output(o0, USAGE=cal.usage.generic)
    cal.dcl_literal(l0, 1, 1, 1, 1)
    cal.dcl_literal(l1, 16, 16, 16, 16)
    cal.mov(r0, r0('0000'))
    cal.mov(r1, r1('0000'))

    cal.whileloop()
    cal.iadd(r1, r1, g[r0.x])
    cal.iadd(r0, r0, l0)
    cal.breakc(cal.relop.ge, r0, l1)
    cal.endloop()

    cal.mov(o0, r1)

    prgm.set_binding('g[]', input_mem)
    prgm.set_binding('o0', output_mem)

    prgm.add(code)
    domain = (0, 0, 128, 128)

    prgm.print_code()
    proc.execute(prgm, domain)

    # code.cache_code()
    # print code.render_string

    if output_mem[0] == 120:
        print "Passed relative addressing test"
    else:
        print "Failed relative addressing test"

    proc.free(input_mem)
    proc.free(output_mem)
Example #3
0
def test_4comp():
    proc = env.Processor(0)
    prgm = env.Program()
    code = prgm.get_stream()

    inp = proc.alloc_remote('i', 1, 4, 1)
    out = proc.alloc_remote('i', 4, 1, 1)

    for i in xrange(0, 4):
        inp[i] = i + 1
        out[i] = 0

    print "inp", inp[0:4]
    print "out", out[0:4]

    cal.set_active_code(code)

    cal.dcl_output(reg.o0, USAGE=cal.usage.generic)
    cal.dcl_resource(0, cal.pixtex_type.oned, cal.fmt.float,
                     UNNORM=True)  # positions

    r_cnt = prgm.acquire_register()
    r = prgm.acquire_registers(4)

    cal.mov(r_cnt, r_cnt('0000'))

    for i in xrange(0, 4):
        cal.sample(0, 0, r[i].x000, r_cnt.x)
        cal.add(r_cnt, r_cnt, r_cnt('1111'))

    cal.iadd(r[0], r[0], r[1]('0x00'))
    cal.iadd(r[0], r[0], r[2]('00x0'))
    cal.iadd(r[0], r[0], r[3]('000x'))
    cal.iadd(r[0], r[0], r[0])
    cal.mov(reg.o0, r[0])

    prgm.set_binding(reg.i0, inp)
    prgm.set_binding(reg.o0, out)

    prgm.add(code)
    prgm.print_code()

    proc.execute(prgm, (0, 0, 1, 1))

    print "inp", inp[0:4]
    print "out", out[0:4]
    for i in xrange(0, 4):
        assert (out[i] == (i + 1) * 2)
    return
Example #4
0
def TestSynIterIncFloatExtStopExtStart():
  SIZE = 64

  # build and run the kernel
  prgm = env.Program()
  code = prgm.get_stream()

  code.add(cal.dcl_output(reg.o0, USAGE=cal.usage.pos))
  ones = prgm.acquire_register((1, 1, 1, 1))
  counter = prgm.acquire_register()
  code.add(cal.mov(counter, ones))

  stop = prgm.acquire_register((4.0, 4.0, 4.0, 4.0))
  start = prgm.acquire_register((2.0, 2.0, 2.0, 2.0))
  step = prgm.acquire_register((1.0, 1.0, 1.0, 1.0))

  fiter = syn_iter_float(code, stop, step=step, mode=INC)
  fiter.set_start_reg(start)
  for i in fiter:
    code.add(cal.iadd(counter, counter, ones))

  code.add(cal.mov(reg.o0, counter.x))

  domain = (0, 0, SIZE, SIZE)
  proc = env.Processor(0)

  ext_output=proc.alloc_remote('i', 1, SIZE, 1)
  prgm.set_binding(reg.o0, ext_output)

  prgm.add(code)
  proc.execute(prgm, domain)

  passed = True
  for i in xrange(0, SIZE):
    if ext_output[i] != 3:
      passed = False
  print "Passed == ", passed

  proc.free(ext_output)

  return
Example #5
0
def test_foo():
    proc = env.Processor(0)
    prgm = env.Program()
    code = prgm.get_stream()

    cal.set_active_code(code)

    cb = proc.alloc_remote('i', 1, 4, 1)
    out = proc.alloc_remote('i', 4, 1, 1)
    gb = proc.alloc_remote('i', 1, 4, 1, True)

    for i in xrange(0, 4):
        cb[i] = i + 1
        out[i] = 42
        gb[i] = 67

    cal.dcl_output(reg.o0, USAGE=cal.usage.generic)
    cal.dcl_cb('cb0[4]')

    cal.mov('r0', 'cb0[0]')
    cal.mov('r1', 'cb0[1]')
    #cal.mov('r2', 'cb0[2]')
    #cal.mov('r3', 'cb0[3]')

    cal.mov('o0', 'r0')
    cal.mov('g[0]', 'r0')

    prgm.set_binding('cb0', cb)
    prgm.set_binding('o0', out)
    prgm.set_binding('g[]', gb)

    prgm.add(code)
    prgm.print_code()

    proc.execute(prgm, (0, 0, 1, 1))

    print "cb ", cb[0:4]
    print "out", out[0:4]
    print "gb ", gb[0:4]
    return
Example #6
0
    cal.breakc(cal.relop.ge, r_count.y, r_limit)

    cal.add(r_sum, r_sum, r_sum('1111'))

    cal.add(r_count, r_count, r_count('0100'))
    cal.endloop()

    cal.add(r_count, r_count, r_count('1000'))
    cal.endloop()

    cal.mov(reg.o0, r_sum)

    return code


if __name__ == '__main__':
    SIZE = 64

    prgm = env.Program()
    prgm.add(generate(prgm))

    proc = env.Processor(0)

    out = proc.alloc_remote('f', 4, SIZE, SIZE)
    prgm.set_binding(reg.o0, out)

    proc.execute(prgm, (0, 0, SIZE, SIZE))

    print out
    prgm.print_code()