diff --git a/paddle/scripts/get_pten_kernel_function.sh b/paddle/scripts/get_pten_kernel_function.sh deleted file mode 100755 index 6ae2f1b679e3eafcef5c20376ecd82784d61d4e0..0000000000000000000000000000000000000000 --- a/paddle/scripts/get_pten_kernel_function.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env bash - -# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -#================================================= -# Utils -#================================================= - -set -e - -EXIT_CODE=0; -tmp_dir=`mktemp -d` - -PADDLE_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}")/../../" && pwd )" - -unset GREP_OPTIONS && find ${PADDLE_ROOT}/paddle/pten/kernels -name "*.c*" | xargs sed -e '/PT_REGISTER_\(GENERAL_\)\?KERNEL(/,/)/!d' | awk 'BEGIN { RS="{" }{ gsub(/\n /,""); print $0 }' | grep PT_REGISTER | awk -F ",|\(" '{gsub(/ /,"");print $2, $3, $4, $5}' | sort -u | awk '{gsub(/pten::/,"");print $0}' | grep -v "_grad" diff --git a/tools/infrt/get_pten_kernel_function.sh b/tools/infrt/get_pten_kernel_function.sh new file mode 100755 index 0000000000000000000000000000000000000000..0d787d9930b2c739733e8431eaccece88519248a --- /dev/null +++ b/tools/infrt/get_pten_kernel_function.sh @@ -0,0 +1,52 @@ +#!/usr/bin/env bash + +# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#================================================= +# Utils +#================================================= + +set -e + +#step 1:get kernel registered info +kernel_register_info_file=`mktemp` +PADDLE_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}")/../../" && pwd )" +unset GREP_OPTIONS && find ${PADDLE_ROOT}/paddle/pten/kernels -name "*.c*" \ + | xargs sed -e '/PT_REGISTER_\(GENERAL_\)\?KERNEL(/,/)/!d' \ + | awk 'BEGIN { RS="{" }{ gsub(/\n /,""); print $0 }' \ + | grep PT_REGISTER \ + | awk -F ",|\(" '{gsub(/ /,"");print $2, $3, $4, $5}' \ + | sort -u | awk '{gsub(/pten::/,"");print $0}' \ + | grep -v "_grad" > $kernel_register_info_file + +#step 2:get simple general inferMeta function wrap info +temp_path=`mktemp -d` +python3 ${PADDLE_ROOT}/python/paddle/utils/code_gen/wrapped_infermeta_gen.py \ + --api_yaml_path ${PADDLE_ROOT}/python/paddle/utils/code_gen/api.yaml \ + --wrapped_infermeta_header_path ${temp_path}/generate.h \ + --wrapped_infermeta_source_path ${temp_path}/generate.cc + +grep PT_REGISTER_INFER_META_FN ${temp_path}/generate.cc \ + | awk -F "\(|,|::|\)" '{print $2, $4}' > ${temp_path}/wrap_info.txt + +#step 3: merge all infos +# @input1 => pten kernel infomation : kernel_name kernel_key(GPU/CPU, precision, layout) +# @input2 => information from api.yaml : kernel_name kernel_function_name inferMeta_function_name +# @input3 => information from wrapped_infermeta_gen : ensure the inferMeta function has +# same signature with kernel function +python3 ${PADDLE_ROOT}/tools/infrt/get_pten_kernel_info.py \ + --paddle_root_path ${PADDLE_ROOT} \ + --kernel_info_file $kernel_register_info_file \ + --infermeta_wrap_file ${temp_path}/wrap_info.txt diff --git a/paddle/scripts/get_pten_kernel_info.py b/tools/infrt/get_pten_kernel_info.py similarity index 73% rename from paddle/scripts/get_pten_kernel_info.py rename to tools/infrt/get_pten_kernel_info.py index 5575fac41fe3d30f7d2119eaece023f5da25fef1..e311464130008e9c7815c028f69b2d29eef3b349 100644 --- a/paddle/scripts/get_pten_kernel_info.py +++ b/tools/infrt/get_pten_kernel_info.py @@ -31,6 +31,11 @@ def parse_args(): type=str, required=True, help="kernel info file generated by get_pten_kernel_function.sh .") + parser.add_argument( + "--infermeta_wrap_file", + type=str, + required=True, + help="inferMeta wrap info file .") args = parser.parse_args() return args @@ -47,17 +52,24 @@ def get_kernel_info(file_path): return [l.strip() for l in cont] -def merge(infer_meta_data, kernel_data): +def merge(infer_meta_data, kernel_data, wrap_data): meta_map = {} for api in infer_meta_data: - if not api.has_key("kernel") or not api.has_key("infer_meta"): + if "kernel" not in api or "infer_meta" not in api: continue meta_map[api["kernel"]["func"]] = api["infer_meta"]["func"] + wrap_map = {} + for l in wrap_data: + wrap_map[l.split()[0]] = l.split()[1] + full_kernel_data = [] for l in kernel_data: key = l.split()[0] - if meta_map.has_key(key): - full_kernel_data.append((l + " " + meta_map[key]).split()) + if key in meta_map: + if key in meta_map: + full_kernel_data.append((l + " " + wrap_map[key]).split()) + else: + full_kernel_data.append((l + " " + meta_map[key]).split()) else: full_kernel_data.append((l + " unknown").split()) @@ -68,5 +80,6 @@ if __name__ == "__main__": args = parse_args() infer_meta_data = get_api_yaml_info(args.paddle_root_path) kernel_data = get_kernel_info(args.kernel_info_file) - out = merge(infer_meta_data, kernel_data) + info_meta_wrap_data = get_kernel_info(args.infermeta_wrap_file) + out = merge(infer_meta_data, kernel_data, info_meta_wrap_data) print(json.dumps(out))