示例#1
0
minops_list_path = sys.argv[3]
tailored = sys.argv[4]
out_lines = [
    '#pragma once',
    '#include "paddle_lite_factory_helper.h"',
    '',
]

paths = set()
for line in open(ops_list_path):
    paths.add(line.strip())

if tailored == "ON":
    minlines = set()
    with open(minops_list_path) as fd:
        for line in fd:
            minlines.add(line.strip())
for path in paths:
    str_info = open(path.strip()).read()
    op_parser = RegisterLiteOpParser(str_info)
    ops = op_parser.parse()
    for op in ops:
        if tailored == "ON":
            if op not in minlines: continue
        out = "USE_LITE_OP(%s);" % op
        out_lines.append(out)

with open(dest_path, 'w') as f:
    logging.info("write op list to %s" % dest_path)
    f.write('\n'.join(out_lines))
示例#2
0
            for k in kernel_parser.kernels:
                if hasattr(TargetType, k.target):
                    index = getattr(TargetType, k.target)
                    valid_ops[index].append(k.op_type)

# clear the repeated ops
for target in valid_targets:
    index = getattr(TargetType, target)
    valid_ops[index] = list(set(valid_ops[index]))

paths = set()
with open(ops_list_path) as f:
    paths = set([path for path in f])
    for path in paths:
        str_info = open(path.strip()).read()
        op_parser = RegisterLiteOpParser(str_info)
        ops = op_parser.parse(with_extra)
        for op in ops:
            if "_grad" in op:
                continue
            out = '    {"%s", { "' % op
            op_targets = []
            for target in valid_targets:
                if op in valid_ops[getattr(TargetType, target)]:
                    op_targets.append(target)
            if len(op_targets) > 0:
                out = out + '", "'.join(op_targets) + '" }}'
            else:
                # unknow type op:  kUnk = 0
                valid_ops[0].append(op)
                out = out + 'kUnk" }}'