Skip to content

Instantly share code, notes, and snippets.

@zhiqiu
Created June 23, 2020 03:24
Show Gist options
  • Save zhiqiu/ef5c5e5642faaf63bfc7b45495c60772 to your computer and use it in GitHub Desktop.
Save zhiqiu/ef5c5e5642faaf63bfc7b45495c60772 to your computer and use it in GitHub Desktop.
import paddle
# 所有注册op
op_protos = paddle.fluid.framework.get_all_op_protos()
all_registered_ops = [op.type for op in op_protos]
#print('all_registered_ops', len(all_registered_ops), all_registered_ops)
# 无grad的前向op
no_grad_ops = []
# 有grad的前向op
has_grad_ops = []
# # 无dygraph grad的前向op
# no_dygraph_grad_ops = []
# # 有dygraph grad的前向op
# has_dygraph_grad_ops = []
for op in all_registered_ops:
if not paddle.fluid.core.has_grad_op_maker(op):
no_grad_ops.append(op)
else:
has_grad_ops.append(op)
# if not paddle.fluid.core.has_dygraphgrad_op_maker(op):
# no_grad_ops.append(op)
# else:
# has_grad_ops.append(op)
# 无kernel op
# grad_op_desc_list, op_grad_to_var = core.get_grad_op_desc(
# op_desc, set(), [])
# 无kernel的前向op
no_kernel_ops = []
# 有kernel的前向op
has_kernel_ops = []
op_kernels = paddle.fluid.core._get_all_register_op_kernels()
for op in all_registered_ops:
if op in op_kernels:
has_kernel_ops.append(op)
else:
no_kernel_ops.append(op)
print('no_kernel_ops', len(no_kernel_ops), no_kernel_ops)
print('has_kernel_ops', len(has_kernel_ops), has_kernel_ops)
# 无cuda kernel的op
no_cuda_kernel_ops = []
# 有cuda kernel的op
has_cuda_kernel_ops = []
# 所有注册kernel的op,包括反向
op_types = []
for k,v in op_kernels.items():
has_cuda_kernel = 0
for kernel in v:
if 'CUDAPlace' in kernel:
has_cuda_kernel = 1
break
if has_cuda_kernel:
has_cuda_kernel_ops.append(k)
else:
no_cuda_kernel_ops.append(k)
print('no_cuda_kernel_ops', len(no_cuda_kernel_ops), no_cuda_kernel_ops)
# print('op_types', len(op_types), op_types)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment