Exemplo n.º 1
0
def run(sched_lambda):
    return run_tvm(0,
                   1, {
                       A: 1 * np.ones(get_shape(A)).astype(np.float32),
                       B: 2 * np.ones(get_shape(B)).astype(np.float32)
                   },
                   C,
                   scheduling=sched_lambda,
                   debug=True)
Exemplo n.º 2
0
def demo_array1():
  with tvm.build_config(instrument_bound_checkers=True):
    a = tvm.placeholder((10,), name='a')
    b = tvm.placeholder((10,), name='b')
    c = tvm.compute((10,), lambda i: a[i+100050000])

    npy = run_tvm(0,1,
            { a:np.ones(get_shape(a)).astype(np.float32)
            , b:np.ones(get_shape(b)).astype(np.float32)
            },c,debug=True)

    print(npy.last_data)
Exemplo n.º 3
0
def test_reduce():
  n = 10
  m = 10
  A = tvm.placeholder((n, m), name='A')

  k = tvm.reduce_axis((0, m), "k")
  k2 = tvm.reduce_axis((0, m), "k")
  B1 = tvm.compute((n,), lambda i: tvm.sum(A[i,k], axis=[k,k2]), name="B")

  # === B1 = tensor_map (\i -> fold1 (+) 0 (map (\k -> A[i,k]) [k_begin..k_end])) A

  r=run_tvm(0,1, { A:2*np.ones(get_shape(A)).astype(np.float32)}, B1, debug=True)
  print(r.last_data)
Exemplo n.º 4
0
def test_compute():
  A = tvm.placeholder((10,), name='A')
  B = tvm.placeholder((30,), name='B')
  C = tvm.compute((30,), lambda i: A[i/3]+B[i], name="C")

  r=run_tvm(0,1,
      { A:1*np.ones(get_shape(A)).astype(np.float32)
      , B:2*np.ones(get_shape(B)).astype(np.float32)
      },
      C,
      debug=True)

  print(r.last_data)
Exemplo n.º 5
0
def demo_broadcast():
    """ Check that broad works as expected """

    num_classes = 10
    batch_size = 1
    img_h = 28
    img_w = 28
    img_c = 1

    f1_c = 1

    x = tvm.placeholder((batch_size, img_h, img_w, img_c), name='x')
    b = tvm.placeholder((img_c, ), name='b')

    # Plus here will perform auto-broadcast
    y = x + topi.broadcast_to(b, (batch_size, 1, 1, img_c))

    npy = run_tvm(
        0, 1, {
            x: np.ones(get_shape(x)).astype(np.float32),
            b: np.ones(get_shape(b)).astype(np.float32)
        }, y)

    print(npy.last_data[0, :, :, 0])