Ejemplo n.º 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
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
Ejemplo n.º 3
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 {} 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
Ejemplo n.º 5
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,
             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
    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,
                                slevel=2,
                                rlevel=2)
    end = time.time()

    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:")