已合并
add proto extend #10332
wang-minbo创建于 16 天前
add proto extend #10332
已合并
共 3 个文件变更+35-17
| @@ -108,6 +108,7 @@ if (BUILD_OPEN_PROJECT) | |||
| 108 | ) | 108 | ) |
| 109 | 109 | ||
| 110 | add_subdirectory(src/framework) | 110 | add_subdirectory(src/framework) |
| 111 | + add_subdirectory(include/op_graph) | ||
| 111 | else() | 112 | else() |
| 112 | add_library(${COMMON_NAME}_obj OBJECT) | 113 | add_library(${COMMON_NAME}_obj OBJECT) |
| 113 | 114 | ||
| @@ -130,6 +131,7 @@ else() | |||
| 130 | $<BUILD_INTERFACE:intf_pub_cxx17> | 131 | $<BUILD_INTERFACE:intf_pub_cxx17> |
| 131 | tiling_api | 132 | tiling_api |
| 132 | ) | 133 | ) |
| 134 | + add_subdirectory(include/op_graph) | ||
| 133 | endif() | 135 | endif() |
| 134 | 136 | ||
| 135 | if (ENABLE_TILING_SINK) | 137 | if (ENABLE_TILING_SINK) |
| @@ -0,0 +1,11 @@ | |||
| 1 | +# ----------------------------------------------------------------------------------------------------------- | ||
| 2 | +# Copyright (c) 2025 Huawei Technologies Co., Ltd. | ||
| 3 | +# This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | +# CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | +# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | +# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | +# See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | +# ----------------------------------------------------------------------------------------------------------- | ||
| 10 | + | ||
| 11 | +add_graph_plugin_sources() | ||
| @@ -17,29 +17,34 @@ import argparse | |||
| 17 | 17 | ||
| 18 | 18 | ||
| 19 | def match_op_proto(file_path): | 19 | def match_op_proto(file_path): |
| 20 | - with open(file_path, 'r', encoding='utf-8') as f: | 20 | + with open(file_path, "r", encoding="utf-8") as f: |
| 21 | content = f.read() | 21 | content = f.read() |
| 22 | 22 | ||
| 23 | - op_def_pattern = re.compile(r"REG_OP\((.+)\).*OP_END_FACTORY_REG\(\1\)", re.DOTALL) | 23 | + op_defs = [] |
| 24 | - match = op_def_pattern.search(content) | 24 | + op_def_pattern = re.compile( |
| 25 | - | 25 | + r"REG_OP\((\w+)\).*?OP_END_FACTORY_REG\(\1\)", re.DOTALL |
| 26 | - if match: | 26 | + ) |
| 27 | + for match in op_def_pattern.finditer(content): | ||
| 27 | op_name = match.group(1) | 28 | op_name = match.group(1) |
| 28 | op_def = match.group(0) | 29 | op_def = match.group(0) |
| 29 | - return op_name, op_def | 30 | + op_defs.append((op_name, op_def)) |
| 30 | - else: | 31 | + |
| 31 | - return None, None | 32 | + return op_defs |
| 32 | 33 | ||
| 33 | 34 | ||
| 34 | def merge_op_proto(protos_path, output_file): | 35 | def merge_op_proto(protos_path, output_file): |
| 35 | op_defs = [] | 36 | op_defs = [] |
| 37 | + seen = set() | ||
| 36 | for proto_path in protos_path: | 38 | for proto_path in protos_path: |
| 37 | - if not proto_path.endswith("_proto.h"): | 39 | + if not ( |
| 40 | + proto_path.endswith("_proto.h") or proto_path.endswith("_proto_extend.h") | ||
| 41 | + ): | ||
| 38 | continue | 42 | continue |
| 39 | print(f"proto_path: {proto_path}") | 43 | print(f"proto_path: {proto_path}") |
| 40 | - op_name, op_def = match_op_proto(proto_path) | 44 | + for op_name, op_def in match_op_proto(proto_path): |
| 41 | - if op_def: | 45 | + if op_name not in seen: |
| 42 | - op_defs.append(op_def) | 46 | + seen.add(op_name) |
| 47 | + op_defs.append(op_def) | ||
| 43 | 48 | ||
| 44 | # merge op_proto | 49 | # merge op_proto |
| 45 | merged_content = f"""#ifndef OP_TRANSFORMER_PROTO_H_ | 50 | merged_content = f"""#ifndef OP_TRANSFORMER_PROTO_H_ |
| @@ -50,13 +55,13 @@ def merge_op_proto(protos_path, output_file): | |||
| 50 | 55 | ||
| 51 | namespace ge{{ | 56 | namespace ge{{ |
| 52 | 57 | ||
| 53 | -{os.linesep.join([f'{op_def}{os.linesep}' for op_def in op_defs])} | 58 | +{os.linesep.join([f"{op_def}{os.linesep}" for op_def in op_defs])} |
| 54 | }} // namespace ge | 59 | }} // namespace ge |
| 55 | 60 | ||
| 56 | #endif // OP_TRANSFORMER_PROTO_H_ | 61 | #endif // OP_TRANSFORMER_PROTO_H_ |
| 57 | """ | 62 | """ |
| 58 | 63 | ||
| 59 | - with open(output_file, 'w', encoding='utf-8') as f: | 64 | + with open(output_file, "w", encoding="utf-8") as f: |
| 60 | f.write(merged_content) | 65 | f.write(merged_content) |
| 61 | 66 | ||
| 62 | print(f"merged op transformer proto file: {output_file}") | 67 | print(f"merged op transformer proto file: {output_file}") |
| @@ -64,14 +69,14 @@ namespace ge{{ | |||
| 64 | 69 | ||
| 65 | def parse_args(argv): | 70 | def parse_args(argv): |
| 66 | parser = argparse.ArgumentParser() | 71 | parser = argparse.ArgumentParser() |
| 67 | - parser.add_argument("protos", nargs='+') | 72 | + parser.add_argument("protos", nargs="+") |
| 68 | parser.add_argument("--output-file", nargs=1, default=None) | 73 | parser.add_argument("--output-file", nargs=1, default=None) |
| 69 | return parser.parse_args(argv) | 74 | return parser.parse_args(argv) |
| 70 | 75 | ||
| 71 | 76 | ||
| 72 | if __name__ == "__main__": | 77 | if __name__ == "__main__": |
| 73 | args = parse_args(sys.argv) | 78 | args = parse_args(sys.argv) |
| 74 | - | 79 | + |
| 75 | protos_path = args.protos[1:] | 80 | protos_path = args.protos[1:] |
| 76 | output_file = args.output_file[0] | 81 | output_file = args.output_file[0] |
| 77 | - merge_op_proto(protos_path, output_file) | 82 | + merge_op_proto(protos_path, output_file) |