Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
94ffda57
P
Paddle
项目概览
Crayon鑫
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
94ffda57
编写于
4月 21, 2022
作者:
A
Aurelius84
提交者:
GitHub
4月 21, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Eager]Fix SetDeviceId in eager_final_state_api from python_c_gen.py (#42025)
上级
747ba3f8
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
30 addition
and
4 deletion
+30
-4
paddle/fluid/eager/auto_code_generator/final_state_generator/python_c_gen.py
...auto_code_generator/final_state_generator/python_c_gen.py
+30
-4
未找到文件。
paddle/fluid/eager/auto_code_generator/final_state_generator/python_c_gen.py
浏览文件 @
94ffda57
...
...
@@ -100,6 +100,9 @@ static PyObject * eager_final_state_api_{}(PyObject *self, PyObject *args, PyObj
{}
tstate = PyEval_SaveThread();
// Set Device ID
{}
auto out = {}({});
...
...
@@ -118,6 +121,19 @@ static PyObject * eager_final_state_api_{}(PyObject *self, PyObject *args, PyObj
"""
FUNCTION_SET_DEVICE_TEMPLATE
=
\
"""
{}
if (paddle::platform::is_gpu_place(place)) {{
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
phi::backends::gpu::SetDeviceId(place.device);
VLOG(1) <<"CurrentDeviceId: " << phi::backends::gpu::GetCurrentDeviceId() << " from " << (int)place.device;
#else
PADDLE_THROW(paddle::platform::errors::PreconditionNotMet(
"PaddlePaddle should compile with GPU if use CUDAPlace."));
#endif
}}
"""
FUNCTION_NAME_TEMPLATE
=
\
"{}{}{}"
...
...
@@ -293,14 +309,23 @@ class PythonCSingleFunctionGenerator(FunctionGeneratorBase):
"false"
)
parse_attributes_str
=
""
expected_place_str
=
"auto place = egr::Controller::Instance().GetExpectedPlace();
\n
"
# Generate Python-C Attributes Parsing Logic
for
name
,
atype
,
_
,
pos
in
orig_forward_attrs_list
:
parsing_function_name
=
FindParsingFunctionFromAttributeType
(
atype
)
# Used input argument place if specified from Python frontend.
if
len
(
expected_place_str
)
!=
0
and
parsing_function_name
==
"CastPyArg2Place"
:
expected_place_str
=
""
assert
name
==
"place"
,
"Only support 'place' as template argument name in FUNCTION_SET_DEVICE_TEMPLATE."
parse_attributes_str
+=
PARSE_PYTHON_C_ARGS_TEMPLATE
.
format
(
name
,
pos
,
atype
,
name
,
parsing_function_name
,
name
,
forward_api_name
,
pos
)
set_device_str
=
FUNCTION_SET_DEVICE_TEMPLATE
.
format
(
expected_place_str
)
# Generate Dygraph Function Call Logic
num_args
=
len
(
forward_inputs_position_map
.
keys
())
+
len
(
orig_forward_attrs_list
)
...
...
@@ -326,8 +351,8 @@ class PythonCSingleFunctionGenerator(FunctionGeneratorBase):
"pythonc_record_event"
,
forward_api_name
,
"pybind_imperative_func"
)
self
.
python_c_function_str
=
PYTHON_C_FUNCTION_TEMPLATE
.
format
(
forward_api_name
,
pythonc_record_event_str
,
forward_api_name
,
get_eager_tensor_str
,
parse_attributes_str
,
fwd_function_name
,
dygraph_function_call_str
,
return_str
)
get_eager_tensor_str
,
parse_attributes_str
,
set_device_str
,
fwd_function_name
,
dygraph_function_call_str
,
return_str
)
# Set prefix of forward_api_name to avoid conflicts
prefix
=
self
.
namespace
.
strip
(
"::"
)
...
...
@@ -361,8 +386,9 @@ class PythonCSingleFunctionGenerator(FunctionGeneratorBase):
self
.
python_c_function_str
+=
PYTHON_C_FUNCTION_TEMPLATE
.
format
(
inplaced_forward_api_name
,
pythonc_record_event_str
,
inplaced_forward_api_name
,
get_eager_tensor_str
,
parse_attributes_str
,
inplaced_fwd_function_name
,
dygraph_function_call_str
,
return_str
)
parse_attributes_str
,
set_device_str
,
inplaced_fwd_function_name
,
dygraph_function_call_str
,
return_str
)
# Generate Python-C Function Registration
self
.
python_c_function_reg_str
+=
"
\n
,"
+
PYTHON_C_FUNCTION_REG_TEMPLATE
.
format
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录