def optimize(shapes, slevel=4, rlevel=3, target="llvm", dev_id=0, timeout=4.0, trials=100, parallel=1, method="searching", use_model=False, rpc_info=None, logfile=sys.stdout): ret = dict() for i, shape in enumerate(shapes): print("Optimize depthwise conv2d shape {}".format(shape), flush=True) batch, in_channel, H, W, factor, k, _, stride, padding, dilation = shape # create an empty task but has the correct key we want task = Task( "conv2d", "depthwise", None, (batch, in_channel, H, W, factor, k, stride, padding, dilation), target, dev_id) beg = time.time() s, bufs, configs = schedule( task.key, slevel=slevel, rlevel=rlevel, op_trial=trials, timeout=timeout, op_stop=trials // 2, method=method, use_model=use_model, parallel=parallel, rpc_info=rpc_info, trials=[trials // 10, trials], number=10, ) end = time.time() # print(tvm.lower(s, bufs, simple_mode=True)) print("######################################") print("op schedules:") for config in configs.op_config_lst: print("----------------------------------") for name, value in config.items(): if value: print(name, value) print("graph schedules:") for name, value in configs.graph_config.items(): if value: print(name, value) ret[task.key] = configs string = json.dumps(configs) line = task.key + ":" + string print(line, file=logfile, flush=True) s, bufs = schedule_with_config(task.key, configs) time_cost = evaluate(task.key, s, bufs, target, task.dev_id, 10, rpc_info) print("Use", time_cost, "ms") print("Cost", end - beg, "s") print() return ret
def test(): # create an empty task but has the correct key we want task = Task("yolo1", None, (1, 3, 448, 448, 64, 7, 2, 3, 1, 1), "llvm", 0) beg = time.time() # s, bufs, configs = schedule(task.key) end = time.time() # print(tvm.lower(s, bufs, simple_mode=True)) # print("######################################") # print("op schedules:") # for config in configs.op_config_lst: # print("----------------------------------") # for name, value in config.items(): # if value: # print(name, value) # print("graph schedules:") # for name, value in configs.graph_config.items(): # if value: # print(name, value) op_configs = [{ "spatial": [[1, 1, 1, 1], [1, 1, 1, 3], [454, 1, 1, 1], [1, 227, 2, 1]], "unroll": [[1500, 1]] }, { "spatial": [[1, 1, 1, 1], [2, 4, 2, 4], [8, 1, 4, 7], [7, 1, 16, 2]], "reduce": [[1, 3, 1], [7, 1, 1], [7, 1, 1]], "unroll": [[1500, 1]] }] graph_config = {"inline": [[0, 0]]} configs = Config(op_configs, graph_config) s, bufs = schedule_with_config(task.key, configs) time_cost = _evaluate(s, bufs, "llvm", 0, 10) print("Use", time_cost, "ms") print("Cost", end - beg, "s")
def optimize(prefix, from_, shapes, target="llvm", dev_id=0, trials=100, timeout=4.0, parallel=1, method="searching", use_model=False, logfile=sys.stdout): ret = dict() for i, shape in enumerate(shapes): print("Optimize {} conv_transpose2d layer {} shape {}".format( prefix, i + 1 + from_, shape), flush=True) batch, in_channel, height, width, out_channel, _, k_h, k_w, _, stride, padding, dilation, groups = shape rout_channel = in_channel rin_channel = out_channel rheight = (height + 2 * padding - dilation * (k_h - 1) - 1) // stride + 1 rwidth = (width + 2 * padding - dilation * (k_w - 1) - 1) // stride + 1 # create an empty task but has the correct key we want task = Task("conv_transpose2d", prefix + str(i + from_), None, (batch, rin_channel, rheight, rwidth, rout_channel, k_h, stride, padding, dilation, groups), target, dev_id) beg = time.time() s, bufs, configs = schedule( task.key, op_trial=trials, timeout=timeout, op_stop=30, parallel=parallel, method=method, use_model=use_model, trials=[trials // 10, trials // 10, trials]) end = time.time() # print(tvm.lower(s, bufs, simple_mode=True)) print("######################################") print("op schedules:") for config in configs.op_config_lst: print("----------------------------------") for name, value in config.items(): if value: print(name, value) print("graph schedules:") for name, value in configs.graph_config.items(): if value: print(name, value) ret[task.key] = configs string = json.dumps(configs) line = task.key + ":" + string print(line, file=logfile, flush=True) s, bufs = schedule_with_config(task.key, configs) time_cost = _evaluate(s, bufs, target, task.dev_id, 10) print("Use", time_cost, "ms") print("Cost", end - beg, "s") print() return ret
def optimize(shapes, slevel=4, rlevel=3, target="llvm", dev_id=0, timeout=4.0, trials=100, parallel=1, method="searching", use_model=False, rpc_info=None, logfile=sys.stdout): ret = dict() for i, shape in enumerate(shapes): print("Optimize gemm shape %s [%.6f]" % (str(shape), time.time()), flush=True) N, K, M = shape # create an empty task but has the correct key we want task = Task("gemm", "gemm", None, (N, K, M), target, dev_id) beg = time.time() s, bufs, configs = schedule(task.key, slevel=slevel, rlevel=rlevel, op_trial=trials, timeout=timeout, op_stop=trials // 2, method=method, use_model=use_model, parallel=parallel, rpc_info=rpc_info, number=10) end = time.time() # print(tvm.lower(s, bufs, simple_mode=True)) print("###################################### [%.6f]" % time.time()) print("op schedules:") for config in configs.op_config_lst: print("----------------------------------") for name, value in config.items(): if value: print(name, value) print("graph schedules:") for name, value in configs.graph_config.items(): if value: print(name, value) ret[task.key] = configs string = json.dumps(configs) line = task.key + ":" + string print(line, file=logfile, flush=True) s, bufs = schedule_with_config(task.key, configs) time_cost = evaluate(task.key, s, bufs, target, dev_id, rpc_info=rpc_info) print("Use", time_cost, "ms") print("Cost", end - beg, "s") print() return ret
def optimize(prefix, from_, shapes, target="llvm", dev_id=0, trials=100, timeout=4.0, parallel=1, method="searching", use_model=False, rpc_info=None, force_inline=False, logfile=sys.stdout): ret = dict() for i, shape in enumerate(shapes): print("Optimize {} pixelCNN layer {} shape {}".format( prefix, i + 1 + from_, shape), flush=True) # create an empty task but has the correct key we want task = Task("gatedpixelcnn", "gatedpixelcnn", None, shape, target, dev_id) beg = time.time() s, bufs, configs = schedule( task.key, op_trial=trials, timeout=timeout, op_stop=30, parallel=parallel, method=method, use_model=use_model, # trials=[trials//10, trials], force_inline=force_inline, rpc_info=rpc_info, ) end = time.time() # print(tvm.lower(s, bufs, simple_mode=True)) print("######################################") print("op schedules:") for config in configs.op_config_lst: print("----------------------------------") for name, value in config.items(): if value: print(name, value) print("graph schedules:") for name, value in configs.graph_config.items(): if value: print(name, value) ret[task.key] = configs string = json.dumps(configs) line = task.key + ":" + string print(line, file=logfile, flush=True) s, bufs = schedule_with_config(task.key, configs) time_cost = evaluate(task.key, s, bufs, target, task.dev_id, 10, rpc_info) print("Use", time_cost, "ms") print("Cost", end - beg, "s") print() return ret
def optimize(shapes, slevel=4, rlevel=3, target="llvm", dev_id=0, timeout=4.0, trials=100, parallel=1, method="searching", use_model=False, logfile=sys.stdout): ret = dict() for i, shape in enumerate(shapes): print("Optimize block_circulant_matrix shape {}".format(shape), flush=True) ROW, COL, FFT = shape # create an empty task but has the correct key we want task = Task("block_circulant_matrix", "block_circulant_matrix", None, (ROW, COL, FFT), target, dev_id) beg = time.time() s, bufs, configs = schedule(task.key, slevel=slevel, rlevel=rlevel, op_trial=trials, timeout=timeout, op_stop=30, method=method, use_model=use_model, parallel=parallel) end = time.time() # print(tvm.lower(s, bufs, simple_mode=True)) print("######################################") print("op schedules:") for config in configs.op_config_lst: print("----------------------------------") for name, value in config.items(): if value: print(name, value) print("graph schedules:") for name, value in configs.graph_config.items(): if value: print(name, value) ret[task.key] = configs string = json.dumps(configs) line = task.key + ":" + string print(line, file=logfile, flush=True) s, bufs = schedule_with_config(task.key, configs) time_cost = _evaluate(s, bufs, target, task.dev_id, 10) print("Use", time_cost, "ms") print("Cost", end - beg, "s") print() return ret
vlen = 8 target = "llvm" dev_id = 0 trials = 100 timeout = 10 parallel = 20 method = "searching" force_inline = True use_model = False logfile = open("tmp.log", "w") rpc_info = RpcInfo("0.0.0.0", 9090, target_host="llvm") args = (N, C, H, W, K, k, use_bias, st, pad, dilation, group) task = Task("conv2d_nchwc", "yolo_conv6", conv2d_nchwc_compute_avx2, args, target, dev_id=dev_id) register_task(task, override=False) beg = time.time() s, bufs, configs = schedule(task.key, op_trial=trials, timeout=timeout, op_stop=30, parallel=parallel, method=method, use_model=use_model, trials=[trials // 10, trials], force_inline=force_inline, rpc_info=rpc_info,