Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
8d4f2613
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2310
Star
20933
Fork
5423
代码
文件
提交
分支
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看板
未验证
提交
8d4f2613
编写于
9月 06, 2022
作者:
C
Chen Weihang
提交者:
GitHub
9月 06, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add op count by lib method (#45680)
上级
7a92e74b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
52 addition
and
7 deletion
+52
-7
paddle/fluid/pybind/pybind.cc
paddle/fluid/pybind/pybind.cc
+38
-7
python/paddle/fluid/tests/unittests/test_get_all_op_or_kernel_names.py
.../fluid/tests/unittests/test_get_all_op_or_kernel_names.py
+14
-0
未找到文件。
paddle/fluid/pybind/pybind.cc
浏览文件 @
8d4f2613
...
...
@@ -1049,13 +1049,44 @@ All parameter, weight, gradient are variables in Paddle.
}
return
ret_values
;
});
m
.
def
(
"get_all_op_names"
,
[]()
{
std
::
vector
<
std
::
string
>
op_names
;
for
(
auto
&
iter
:
OpInfoMap
::
Instance
().
map
())
{
op_names
.
emplace_back
(
iter
.
first
);
}
return
op_names
;
});
m
.
def
(
"get_all_op_names"
,
[](
const
std
::
string
&
lib
)
{
std
::
vector
<
std
::
string
>
op_names
;
for
(
auto
&
iter
:
OpInfoMap
::
Instance
().
map
())
{
op_names
.
emplace_back
(
iter
.
first
);
}
if
(
lib
==
"phi"
)
{
std
::
vector
<
std
::
string
>
ops_with_phi_kernel
;
for
(
const
auto
&
op_name
:
op_names
)
{
if
(
phi
::
KernelFactory
::
Instance
().
HasCompatiblePhiKernel
(
op_name
))
{
ops_with_phi_kernel
.
emplace_back
(
op_name
);
}
}
return
ops_with_phi_kernel
;
}
else
if
(
lib
==
"fluid"
)
{
std
::
vector
<
std
::
string
>
ops_with_fluid_kernel
;
auto
all_fluid_op_kernels
=
paddle
::
framework
::
OperatorWithKernel
::
AllOpKernels
();
for
(
const
auto
&
op_name
:
op_names
)
{
if
(
all_fluid_op_kernels
.
find
(
op_name
)
!=
all_fluid_op_kernels
.
end
())
{
ops_with_fluid_kernel
.
emplace_back
(
op_name
);
}
}
return
ops_with_fluid_kernel
;
}
else
{
return
op_names
;
}
},
py
::
arg
(
"lib"
)
=
"all"
,
R"DOC(
Return the operator names in paddle.
Args:
lib[string]: the library contains corresponding OpKernel, could be 'phi', 'fluid' and 'all'. Default value is 'all'.
)DOC"
);
m
.
def
(
"get_op_attrs_default_value"
,
[](
py
::
bytes
byte_name
)
->
paddle
::
framework
::
AttributeMap
{
std
::
string
op_type
=
byte_name
;
...
...
python/paddle/fluid/tests/unittests/test_get_all_
registered_op_kernel
s.py
→
python/paddle/fluid/tests/unittests/test_get_all_
op_or_kernel_name
s.py
浏览文件 @
8d4f2613
...
...
@@ -39,5 +39,19 @@ class TestGetAllRegisteredOpKernels(unittest.TestCase):
self
.
assertTrue
(
core
.
_get_all_register_op_kernels
()[
'sign'
])
class
TestGetAllOpNames
(
unittest
.
TestCase
):
def
test_get_all_op_names
(
self
):
all_op_names
=
core
.
get_all_op_names
()
all_op_with_phi_kernels
=
core
.
get_all_op_names
(
"phi"
)
all_op_with_fluid_kernels
=
core
.
get_all_op_names
(
"fluid"
)
self
.
assertTrue
(
len
(
all_op_names
)
>
len
(
set
(
all_op_with_phi_kernels
)
|
set
(
all_op_with_fluid_kernels
)))
self
.
assertTrue
(
"scale"
in
all_op_with_phi_kernels
)
self
.
assertTrue
(
"scale"
in
all_op_with_phi_kernels
)
if
__name__
==
'__main__'
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录