예제 #1
0
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
예제 #2
0
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 {} convolution 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
        # create an empty task but has the correct key we want
        task = Task(
            "conv2d",
            prefix + str(i + from_),
            None,
            (batch, in_channel, height, width, out_channel,
             k_h, stride, padding, dilation, groups),
            target,
            dev_id
        )
        beg = time.time()
        s, bufs, configs = schedule(
            task.key,
            op_trial=trials,
            op_stop=trials // 2,
            timeout=timeout,
            parallel=parallel,
            method=method,
            use_model=use_model,
            trials=[trials//10, trials],
            force_inline=force_inline,
            rpc_info=rpc_info,
            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