def parse_sppported_kernels_from_path(list_path): with open(list_path) as f: paths = set([path for path in f]) for path in paths: if (sys.version[0] == '3'): with open(path.strip(), encoding='utf-8') as g: c = g.read() kernel_parser = RegisterLiteKernelParser(c) kernel_parser.parse("ON", "ON") for k in kernel_parser.kernels: index = path.rindex('/') filename = path[index + 1:] map_element = ' {"%s,%s,%s,%s,%s", "%s"},' % ( k.op_type, k.target, k.precision, k.data_layout, k.alias, filename.strip()) kernel_src_map_lines.append(map_element) else: with open(path.strip()) as g: c = g.read() kernel_parser = RegisterLiteKernelParser(c) kernel_parser.parse("ON", "ON") for k in kernel_parser.kernels: index = path.rindex('/') filename = path[index + 1:] map_element = ' {"%s,%s,%s,%s,%s", "%s"},' % ( k.op_type, k.target, k.precision, k.data_layout, k.alias, filename.strip()) kernel_src_map_lines.append(map_element)
def parse_fake_kernels_from_path(list_path): with open(list_path) as f: paths = set([path for path in f]) for path in paths: with open(path.strip()) as g: c = g.read() kernel_parser = RegisterLiteKernelParser(c) kernel_parser.parse("ON", "ON") for k in kernel_parser.kernels: out_src_lines = [ '#include "all_kernel_faked.h"', ] out_src_lines.append("") kernel_name = "{op_type}_{target}_{precision}_{data_layout}_{alias}_class".format( op_type=k.op_type, target=k.target, precision=k.precision, data_layout=k.data_layout, alias=k.alias) kernel_define = fake_kernel % (kernel_name, k.target, k.precision, k.data_layout, kernel_name) out_lines.append(kernel_define) out_lines.append("") out_hdr_lines.append(kernel_define) out_hdr_lines.append("") key = "REGISTER_LITE_KERNEL(%s, %s, %s, %s, %s, %s)" % ( k.op_type, k.target, k.precision, k.data_layout, '::paddle::lite::' + kernel_name, k.alias) out_lines.append(key) out_src_lines.append(key) for input in k.inputs: io = ' .BindInput("%s", {%s})' % (input.name, input.type) out_lines.append(io) out_src_lines.append(io) for output in k.outputs: io = ' .BindOutput("%s", {%s})' % (output.name, output.type) out_lines.append(io) out_src_lines.append(io) for op_versions in k.op_versions: io = ' .BindPaddleOpVersion("%s", %s)' % ( op_versions.name, op_versions.version) out_lines.append(io) out_src_lines.append(io) out_lines.append(" .Finalize();") out_lines.append("") out_src_lines.append(" .Finalize();") out_src_lines.append("") with open( os.path.join(src_dest_path, '%s.cc' % (kernel_name)), 'w') as file: file.write('\n'.join(out_src_lines))
def parse_fake_kernels_from_path(list_path): with open(list_path) as f: paths = set([path for path in f]) for path in paths: print('path', path) with open(path.strip()) as g: c = g.read() kernel_parser = RegisterLiteKernelParser(c) kernel_parser.parse("ON") for k in kernel_parser.kernels: kernel_name = "{op_type}_{target}_{precision}_{data_layout}_{alias}_class".format( op_type=k.op_type, target=k.target, precision=k.precision, data_layout=k.data_layout, alias=k.alias) kernel_define = fake_kernel % (kernel_name, k.target, k.precision, k.data_layout, kernel_name) out_lines.append(kernel_define) out_lines.append("") key = "REGISTER_LITE_KERNEL(%s, %s, %s, %s, %s, %s)" % ( k.op_type, k.target, k.precision, k.data_layout, '::paddle::lite::' + kernel_name, k.alias) out_lines.append(key) for input in k.inputs: io = ' .BindInput("%s", {%s})' % (input.name, input.type) out_lines.append(io) for output in k.outputs: io = ' .BindOutput("%s", {%s})' % (output.name, output.type) out_lines.append(io) for op_versions in k.op_versions: io = ' .BindPaddleOpVersion("%s", %s)' % ( op_versions.name, op_versions.version) out_lines.append(io) out_lines.append(" .Finalize();") out_lines.append("") out_lines.append( gen_use_kernel_statement(k.op_type, k.target, k.precision, k.data_layout, k.alias))
kBM = 10 kMLU = 11 kRKNPU = 12 kAPU = 13 kHuaweiAscendNPU = 14 kImaginationNNA = 15 # record op_info of valid kernels into `valid_ops` according to different target type with open(kernels_list_path) as f: paths = set([path for path in f]) for path in paths: with open(path.strip()) as g: c = g.read() kernel_parser = RegisterLiteKernelParser(c) kernel_parser.parse("ON") for k in kernel_parser.kernels: if hasattr(TargetType, k.target): index = getattr(TargetType, k.target) valid_ops[index].append(k.op_type) # record op_info of valid kernels into `valid_ops` according to different target type with open(faked_kernels_list_path) as f: paths = set([path for path in f]) for path in paths: with open(path.strip()) as g: c = g.read() kernel_parser = RegisterLiteKernelParser(c) kernel_parser.parse("ON") for k in kernel_parser.kernels: if hasattr(TargetType, k.target): index = getattr(TargetType, k.target)
'#pragma once', '#include "paddle_lite_factory_helper.h"', '', ] minlines = set() if tailored == "ON": with open(minkernels_list_path) as fd: for line in fd: minlines.add(line.strip()) with open(ops_list_path) as f: paths = set([path for path in f]) for path in paths: with open(path.strip()) as g: c = g.read() kernel_parser = RegisterLiteKernelParser(c) kernel_parser.parse(with_extra, enable_arm_fp16) for k in kernel_parser.kernels: kernel = "%s, %s, %s, %s, %s" % ( k.op_type, k.target, k.precision, k.data_layout, k.alias, ) if tailored == "ON": if kernel not in minlines: continue key = "USE_LITE_KERNEL(%s, %s, %s, %s, %s);" % ( k.op_type, k.target, k.precision,
kARM = 4 kOpenCL = 5 kFPGA = 7 kNPU = 8 kXPU = 9 kAny = 6 # any target # record op_info of valid kernels into `valid_ops` according to different target type with open(kernels_list_path) as f: paths = set([path for path in f]) for path in paths: with open(path.strip()) as g: c = g.read() kernel_parser = RegisterLiteKernelParser(c) kernel_parser.parse() 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()
'#pragma once', '#include "paddle_lite_factory_helper.h"', '', ] minlines = set() if tailored == "ON": with open(minkernels_list_path) as fd: for line in fd: minlines.add(line.strip()) with open(ops_list_path) as f: paths = set([path for path in f]) for path in paths: with open(path.strip()) as g: c = g.read() kernel_parser = RegisterLiteKernelParser(c) kernel_parser.parse(with_extra) for k in kernel_parser.kernels: kernel = "%s, %s, %s, %s, %s" % ( k.op_type, k.target, k.precision, k.data_layout, k.alias, ) if tailored == "ON": if kernel not in minlines: continue key = "USE_LITE_KERNEL(%s, %s, %s, %s, %s);" % ( k.op_type, k.target, k.precision,