Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
e14a4541
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
e14a4541
编写于
8月 09, 2017
作者:
F
fengjiayi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor registry macro
上级
78c3e1de
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
56 addition
and
46 deletion
+56
-46
paddle/framework/op_registry.h
paddle/framework/op_registry.h
+56
-46
未找到文件。
paddle/framework/op_registry.h
浏览文件 @
e14a4541
...
@@ -307,7 +307,10 @@ class OpRegistry {
...
@@ -307,7 +307,10 @@ class OpRegistry {
}
}
};
};
class
Registrar
{};
class
Registrar
{
public:
void
Touch
()
{}
};
template
<
typename
OpType
,
typename
ProtoMakerType
>
template
<
typename
OpType
,
typename
ProtoMakerType
>
class
OpRegistrar
:
public
Registrar
{
class
OpRegistrar
:
public
Registrar
{
...
@@ -336,8 +339,6 @@ class OpKernelRegistrar : public Registrar {
...
@@ -336,8 +339,6 @@ class OpKernelRegistrar : public Registrar {
}
}
};
};
int
TouchRegistrar
(
const
Registrar
&
registrar
)
{
return
0
;
}
/**
/**
* check if MACRO is used in GLOBAL NAMESPACE.
* check if MACRO is used in GLOBAL NAMESPACE.
*/
*/
...
@@ -354,7 +355,11 @@ int TouchRegistrar(const Registrar& registrar) { return 0; }
...
@@ -354,7 +355,11 @@ int TouchRegistrar(const Registrar& registrar) { return 0; }
STATIC_ASSERT_GLOBAL_NAMESPACE( \
STATIC_ASSERT_GLOBAL_NAMESPACE( \
__reg_op__##op_type, "REGISTER_OP must be called in global namespace"); \
__reg_op__##op_type, "REGISTER_OP must be called in global namespace"); \
static ::paddle::framework::OpRegistrar<op_class, op_maker_class> \
static ::paddle::framework::OpRegistrar<op_class, op_maker_class> \
__op_registrar_##op_type##__(#op_type);
__op_registrar_##op_type##__(#op_type); \
int TouchOpRegistrar_##op_type() { \
__op_registrar_##op_type##__.Touch(); \
return 0; \
}
/**
/**
* Macro to Register Gradient Operator.
* Macro to Register Gradient Operator.
...
@@ -364,18 +369,26 @@ int TouchRegistrar(const Registrar& registrar) { return 0; }
...
@@ -364,18 +369,26 @@ int TouchRegistrar(const Registrar& registrar) { return 0; }
__reg_gradient_op__##op_type##_##grad_op_type, \
__reg_gradient_op__##op_type##_##grad_op_type, \
"REGISTER_GRADIENT_OP must be called in global namespace"); \
"REGISTER_GRADIENT_OP must be called in global namespace"); \
static ::paddle::framework::GradOpRegistrar<grad_op_class> \
static ::paddle::framework::GradOpRegistrar<grad_op_class> \
__op_gradient_register_##op_type##_##grad_op_type##__(#op_type, \
__op_gradient_registrar_##op_type##_##grad_op_type##__(#op_type, \
#grad_op_type);
#grad_op_type); \
int TouchOpGradientRegister_##op_type() { \
__op_gradient_registrar_##op_type##_##grad_op_type##__.Touch(); \
return 0; \
}
/**
/**
* Macro to Register OperatorKernel.
* Macro to Register OperatorKernel.
*/
*/
#define REGISTER_OP_KERNEL(op_type, DEVICE_TYPE, place_class,
kernel_class)
\
#define REGISTER_OP_KERNEL(op_type, DEVICE_TYPE, place_class,
...)
\
STATIC_ASSERT_GLOBAL_NAMESPACE( \
STATIC_ASSERT_GLOBAL_NAMESPACE( \
__reg_op_kernel_##op_type##_##DEVICE_TYPE##__, \
__reg_op_kernel_##op_type##_##DEVICE_TYPE##__, \
"REGISTER_OP_KERNEL must be called in global namespace"); \
"REGISTER_OP_KERNEL must be called in global namespace"); \
static ::paddle::framework::OpKernelRegistrar<place_class, kernel_class> \
static ::paddle::framework::OpKernelRegistrar<place_class, __VA_ARGS__> \
__op_kernel_registrar_##op_type##_##DEVICE_TYPE##__(#op_type);
__op_kernel_registrar_##op_type##_##DEVICE_TYPE##__(#op_type); \
int TouchOpKernelRegistrar_##op_type##_##DEVICE_TYPE() { \
__op_kernel_registrar_##op_type##_##DEVICE_TYPE##__.Touch(); \
return 0; \
}
/**
/**
* Macro to Forbid user register Gradient Operator.
* Macro to Forbid user register Gradient Operator.
...
@@ -385,11 +398,11 @@ int TouchRegistrar(const Registrar& registrar) { return 0; }
...
@@ -385,11 +398,11 @@ int TouchRegistrar(const Registrar& registrar) { return 0; }
__reg_gradient_op__##op_type##_##op_type##_grad, \
__reg_gradient_op__##op_type##_##op_type##_grad, \
"NO_GRADIENT must be called in global namespace")
"NO_GRADIENT must be called in global namespace")
#define REGISTER_OP_GPU_KERNEL(op_type,
kernel_class
) \
#define REGISTER_OP_GPU_KERNEL(op_type,
...
) \
REGISTER_OP_KERNEL(op_type, GPU, ::paddle::platform::GPUPlace,
kernel_class
)
REGISTER_OP_KERNEL(op_type, GPU, ::paddle::platform::GPUPlace,
__VA_ARGS__
)
#define REGISTER_OP_CPU_KERNEL(op_type,
kernel_class
) \
#define REGISTER_OP_CPU_KERNEL(op_type,
...
) \
REGISTER_OP_KERNEL(op_type, CPU, ::paddle::platform::CPUPlace,
kernel_class
)
REGISTER_OP_KERNEL(op_type, CPU, ::paddle::platform::CPUPlace,
__VA_ARGS__
)
/**
/**
* Macro to mark what Operator and Kernel we will use and tell the compiler to
* Macro to mark what Operator and Kernel we will use and tell the compiler to
...
@@ -399,30 +412,27 @@ int TouchRegistrar(const Registrar& registrar) { return 0; }
...
@@ -399,30 +412,27 @@ int TouchRegistrar(const Registrar& registrar) { return 0; }
STATIC_ASSERT_GLOBAL_NAMESPACE( \
STATIC_ASSERT_GLOBAL_NAMESPACE( \
__use_op_itself_##op_type, \
__use_op_itself_##op_type, \
"USE_OP_ITSELF must be called in global namespace"); \
"USE_OP_ITSELF must be called in global namespace"); \
extern ::paddle::framework::OpRegistrar<op_class, op_maker_class> \
extern int TouchOpRegistrar_##op_type(); \
__op_registrar_##op_type##__; \
static int use_op_itself_##op_type##_ __attribute__((unused)) = \
static int __use_op_ptr_##op_type##_without_kernel__ \
TouchOpRegistrar_##op_type##()
__attribute__((unused)) = __op_register_##op_type##_handle__()
#define USE_OP_KERNEL(op_type, DEVICE_TYPE) \
#define USE_OP_KERNEL(op_type, DEVICE_TYPE) \
STATIC_ASSERT_GLOBAL_NAMESPACE( \
STATIC_ASSERT_GLOBAL_NAMESPACE( \
__use_op_kernel_##op_type##_##DEVICE_TYPE##__, \
__use_op_kernel_##op_type##_##DEVICE_TYPE##__, \
"USE_OP_KERNEL must be in global namespace"); \
"USE_OP_KERNEL must be in global namespace"); \
extern int
__op_kernel_register_##op_type##_handle_##DEVICE_TYPE##__
(); \
extern int
TouchOpKernelRegistrar_##op_type##_##DEVICE_TYPE
(); \
static int
__use_op_ptr_##op_type##_##DEVICE_TYPE##_kernel__
\
static int
use_op_kernel_##op_type##_##DEVICE_TYPE##_
\
__attribute__((unused)) = \
__attribute__((unused)) = \
__op_kernel_register_##op_type##_handle_##DEVICE_TYPE##__
()
TouchOpKernelRegistrar_##op_type##_##DEVICE_TYPE##
()
// use Operator with only cpu kernel.
#ifdef PADDLE_ONLY_CPU
#define USE_OP
_CPU(op_type)
\
#define USE_OP
(op_type)
\
USE_OP_ITSELF(op_type); \
USE_OP_ITSELF(op_type); \
USE_OP_KERNEL(op_type, CPU)
USE_OP_KERNEL(op_type, CPU)
#ifdef PADDLE_ONLY_CPU
#define USE_OP(op_type) USE_OP_CPU(op_type)
#else
#else
#define USE_OP(op_type) \
#define USE_OP(op_type) \
USE_OP_CPU(op_type); \
USE_OP_ITSELF(op_type); \
USE_OP_KERNEL(op_type, CPU); \
USE_OP_KERNEL(op_type, GPU)
USE_OP_KERNEL(op_type, GPU)
#endif
#endif
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录