Hi, I am moving my firsts steps in tvm, and I have this code I am using to optimize a reduction:
@autotvm.template
def reduce(N, M):
# The reduction kernel
A = tvm.placeholder((N, M), name='A', dtype='float32')
k = tvm.reduce_axis((0, M), "k")
B = tvm.compute((N,), lambda i: tvm.sum(A[i, k], axis=k), name="B")
# Optimize the schedule for the GPU
cfg = autotvm.get_config()
cfg.define_knob("factor", [1, 2, 4, 8, 16, 32, 64, 128])
# Parallel reduction
s = tvm.create_schedule(B.op)
ko, ki = s[B].split(B.op.reduce_axis[0], cfg['factor'].val)
BF = s.rfactor(B, ki)
tx = tvm.thread_axis("threadIdx.x")
s[B].bind(s[B].op.reduce_axis[0], tx)
s[BF].compute_at(s[B], s[B].op.reduce_axis[0])
s[B].set_store_predicate(tx.var.equal(0))
return s, [A, B]
task = autotvm.task.create(reduce, args=(N, M), target=target, target_host = target_host)
measure_option = autotvm.measure_option(
builder=autotvm.LocalBuilder(build_func = 'default'),
runner=autotvm.RPCRunner(device_key, host=opencl_device_tracker, port=9190, number=5, timeout=5))
tuner = autotvm.tuner.XGBTuner(task)
tuner.tune(n_trial=10,
measure_option=measure_option,
callbacks=[ autotvm.callback.progress_bar(10, prefix='reduction'),
autotvm.callback.log_to_file('reduction.log')])
remote = autotvm.measure.request_remote(device_key, opencl_device_tracker, opencl_device_port, timeout=10000)
with autotvm.apply_history_best('reduction.log'):
with tvm.target.create(target):
s, arg_bufs = reduce(N, M)
func = tvm.build(s, arg_bufs)
path = 'reduction.tar'
func.export_library(path)
remote.upload(path)
ctx = remote.context(target, 0)
a = tvm.nd.array(np.random.randint(100, size=(N,M)).astype('float32'), ctx)
b = tvm.nd.array(np.zeros(N, dtype='float32'), ctx)
time_f = func.time_evaluator(func.entry_name, ctx, number=10)
cost = time_f(a, b).mean
print('%g secs/op' % cost)
When I run this, I receive the following error:
Traceback (most recent call last):
File "optimize_reduction.py", line 68, in <module>
cost = time_f(a, b).mean
File "/home/giuros01/tvm/python/tvm/module.py", line 178, in evaluator
blob = feval(*args)
File "/home/giuros01/tvm/python/tvm/_ffi/_ctypes/function.py", line 190, in __call__
raise get_last_ffi_error()
tvm._ffi.base.TVMError: Traceback (most recent call last):
[bt] (3) /home/giuros01/tvm/build/libtvm.so(TVMFuncCall+0x61) [0x7fc62e41b361]
[bt] (2) /home/giuros01/tvm/build/libtvm.so(+0x10b0387) [0x7fc62e460387]
[bt] (1) /home/giuros01/tvm/build/libtvm.so(+0x10b003a) [0x7fc62e46003a]
[bt] (0) /home/giuros01/tvm/build/libtvm.so(+0x108161c) [0x7fc62e43161c]
File "/home/giuros01/tvm/src/runtime/module_util.cc", line 54
TVMError: Check failed: ret == 0 (-1 vs. 0) : Assert fail: (dev_type == 4), device_type need to be 4
This is when I try to call time_f(a,b).mean
May I ask for some help?
Thanks,
Giuseppe