Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
fa4ae88a
P
Paddle
项目概览
PaddlePaddle
/
Paddle
接近 2 年 前同步成功
通知
2323
Star
20933
Fork
5424
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
fa4ae88a
编写于
4月 21, 2023
作者:
H
huangjiyi
提交者:
GitHub
4月 21, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update (#53146)
上级
47fa8066
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
22 addition
and
27 deletion
+22
-27
paddle/phi/tools/get_kernel_signatures.py
paddle/phi/tools/get_kernel_signatures.py
+22
-27
未找到文件。
paddle/phi/tools/get_kernel_signatures.py
浏览文件 @
fa4ae88a
...
...
@@ -21,22 +21,6 @@ import warnings
import
pandas
as
pd
def
preprocess_macro
(
file_content
,
processed_file_path
):
if
file_content
is
None
:
return
file_content
# comment out external macro
file_content
=
re
.
sub
(
r
'#(include|pragma)'
,
r
'// \g<0>'
,
file_content
)
with
open
(
processed_file_path
,
"w"
)
as
f
:
f
.
write
(
file_content
)
# expand macro and correct format
subprocess
.
run
(
[
'g++'
,
'-E'
,
processed_file_path
,
'-o'
,
processed_file_path
]
)
subprocess
.
run
([
'clang-format'
,
'-i'
,
processed_file_path
])
file_content
=
open
(
processed_file_path
,
"r"
).
read
()
return
file_content
def
search_pattern
(
pattern
,
file_content
):
if
file_content
is
not
None
:
match_result
=
re
.
search
(
pattern
,
file_content
)
...
...
@@ -100,8 +84,9 @@ class KernelSignatureSearcher:
self
.
func_signature_map
[
match_result
[
1
]]
=
match_result
[
0
]
def
search_kernel_registration
(
self
,
path
):
self
.
processed_file_path
=
osp
.
join
(
self
.
build_path
,
'.processed_file.cc'
self
.
tmp_file_path
=
osp
.
join
(
self
.
build_path
,
'.tmp_file.cc'
)
self
.
processed_file_path
=
self
.
tmp_file_path
.
replace
(
'.tmp_file.cc'
,
'.processed_file.cc'
)
for
file
in
os
.
listdir
(
path
):
file_path
=
osp
.
join
(
path
,
file
)
...
...
@@ -113,6 +98,7 @@ class KernelSignatureSearcher:
if
re
.
match
(
r
'\w+_kernel\.(cc|cu)'
,
file
):
self
.
_search_kernel_registration
(
file_path
,
file
)
if
osp
.
exists
(
self
.
processed_file_path
):
os
.
remove
(
self
.
tmp_file_path
)
os
.
remove
(
self
.
processed_file_path
)
def
_search_kernel_registration
(
self
,
file_path
,
file
):
...
...
@@ -121,9 +107,7 @@ class KernelSignatureSearcher:
# if some kernel registration is in macro, preprocess macro first
self
.
file_preprocessed
=
False
if
re
.
search
(
self
.
macro_kernel_reg_pattern
,
file_content
):
file_content
=
preprocess_macro
(
file_content
,
self
.
processed_file_path
)
file_content
=
self
.
preprocess_macro
(
file_content
)
self
.
file_preprocessed
=
True
# search kernel registration
match_results
=
re
.
findall
(
self
.
kernel_reg_pattern
,
file_content
)
...
...
@@ -161,9 +145,7 @@ class KernelSignatureSearcher:
return
kernel_signature
# expand macro and search again
if
not
self
.
file_preprocessed
:
file_content
=
preprocess_macro
(
file_content
,
self
.
processed_file_path
)
file_content
=
self
.
preprocess_macro
(
file_content
)
kernel_signature
=
search_pattern
(
target_kernel_signature_pattern
,
file_content
)
...
...
@@ -175,9 +157,7 @@ class KernelSignatureSearcher:
if
osp
.
exists
(
header_path
):
self
.
header_content
=
open
(
header_path
,
'r'
).
read
()
if
self
.
header_content
is
not
None
:
self
.
header_content
=
preprocess_macro
(
self
.
header_content
,
self
.
processed_file_path
)
self
.
header_content
=
self
.
preprocess_macro
(
self
.
header_content
)
kernel_signature
=
search_pattern
(
target_kernel_signature_pattern
,
self
.
header_content
)
...
...
@@ -185,6 +165,21 @@ class KernelSignatureSearcher:
return
kernel_signature
return
None
def
preprocess_macro
(
self
,
file_content
):
if
file_content
is
None
:
return
file_content
# comment out external macro
file_content
=
re
.
sub
(
r
'#(include|pragma)'
,
r
'// \g<0>'
,
file_content
)
with
open
(
self
.
tmp_file_path
,
"w"
)
as
f
:
f
.
write
(
file_content
)
# expand macro and correct format
subprocess
.
run
(
[
'g++'
,
'-E'
,
self
.
tmp_file_path
,
'-o'
,
self
.
processed_file_path
]
)
subprocess
.
run
([
'clang-format'
,
'-i'
,
self
.
processed_file_path
])
file_content
=
open
(
self
.
processed_file_path
,
"r"
).
read
()
return
file_content
def
get_kernel_signatures
():
"""
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录