Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
dce2db48
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
Star
20931
Fork
5422
代码
文件
提交
分支
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
dce2db48
编写于
2月 24, 2021
作者:
A
Aurelius84
提交者:
GitHub
2月 24, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[CustomOp] Split build directory for each setup.py (#31124)
* split build directory for each setup.py * fix template string
上级
4b220550
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
53 addition
and
4 deletion
+53
-4
python/paddle/utils/cpp_extension/cpp_extension.py
python/paddle/utils/cpp_extension/cpp_extension.py
+50
-3
python/paddle/utils/cpp_extension/extension_utils.py
python/paddle/utils/cpp_extension/extension_utils.py
+3
-1
未找到文件。
python/paddle/utils/cpp_extension/cpp_extension.py
浏览文件 @
dce2db48
...
...
@@ -22,6 +22,7 @@ import re
import
setuptools
from
setuptools.command.easy_install
import
easy_install
from
setuptools.command.build_ext
import
build_ext
from
distutils.command.build
import
build
from
.extension_utils
import
find_cuda_home
,
normalize_extension_kwargs
,
add_compile_flag
,
bootstrap_context
from
.extension_utils
import
is_cuda_file
,
prepare_unix_cudaflags
,
prepare_win_cudaflags
,
add_std_without_repeat
,
get_build_directory
...
...
@@ -103,6 +104,13 @@ def setup(**attr):
assert
'easy_install'
not
in
cmdclass
cmdclass
[
'easy_install'
]
=
EasyInstallCommand
# Note(Aurelius84): Add rename build_base directory hook in build command.
# To avoid using same build directory that will lead to remove the directory
# by mistake while parallelling execute setup.py, for example on CI.
assert
'build'
not
in
cmdclass
build_base
=
os
.
path
.
join
(
'build'
,
attr
[
'name'
])
cmdclass
[
'build'
]
=
BuildCommand
.
with_options
(
build_base
=
build_base
)
# Always set zip_safe=False to make compatible in PY2 and PY3
# See http://peak.telecommunity.com/DevCenter/setuptools#setting-the-zip-safe-flag
attr
[
'zip_safe'
]
=
False
...
...
@@ -491,6 +499,43 @@ class EasyInstallCommand(easy_install, object):
assert
os
.
path
.
exists
(
new_so_path
)
class
BuildCommand
(
build
,
object
):
"""
Extend build Command to control the behavior of specifying `build_base` root directory.
NOTE(Aurelius84): This is a hook subclass inherited Command used to specify customized
build_base directory.
"""
@
classmethod
def
with_options
(
cls
,
**
options
):
"""
Returns a BuildCommand subclass containing use-defined options.
"""
class
cls_with_options
(
cls
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
kwargs
.
update
(
options
)
cls
.
__init__
(
self
,
*
args
,
**
kwargs
)
return
cls_with_options
def
__init__
(
self
,
*
args
,
**
kwargs
):
# Note: shall put before super()
self
.
_specified_build_base
=
kwargs
.
get
(
'build_base'
,
None
)
super
(
BuildCommand
,
self
).
__init__
(
*
args
,
**
kwargs
)
def
initialize_options
(
self
):
"""
build_base is root directory for all sub-command, such as
build_lib, build_temp. See `distutils.command.build` for details.
"""
super
(
BuildCommand
,
self
).
initialize_options
()
if
self
.
_specified_build_base
is
not
None
:
self
.
build_base
=
self
.
_specified_build_base
def
load
(
name
,
sources
,
extra_cflags
=
None
,
...
...
@@ -569,11 +614,13 @@ def load(name,
verbose
)
# write setup.py file and compile it
_write_setup_file
(
name
,
sources
,
file_path
,
extra_include_paths
,
compile_flags
,
extra_ldflags
,
verbose
)
build_base_dir
=
os
.
path
.
join
(
build_directory
,
name
)
_write_setup_file
(
name
,
sources
,
file_path
,
build_base_dir
,
extra_include_paths
,
compile_flags
,
extra_ldflags
,
verbose
)
_jit_compile
(
file_path
,
interpreter
,
verbose
)
# import as callable python api
custom_op_api
=
_import_module_from_library
(
name
,
build_
directory
,
verbose
)
custom_op_api
=
_import_module_from_library
(
name
,
build_
base_dir
,
verbose
)
return
custom_op_api
python/paddle/utils/cpp_extension/extension_utils.py
浏览文件 @
dce2db48
...
...
@@ -580,6 +580,7 @@ def _get_api_inputs_str(op_name):
def
_write_setup_file
(
name
,
sources
,
file_path
,
build_dir
,
include_dirs
,
compile_flags
,
link_args
,
...
...
@@ -600,7 +601,7 @@ def _write_setup_file(name,
extra_compile_args={extra_compile_args},
extra_link_args={extra_link_args})],
cmdclass={{"build_ext" : BuildExtension.with_options(
output_dir=
get_build_directory()
,
output_dir=
'{build_dir}'
,
no_python_abi_suffix=True,
use_new_method={use_new_method})
}})"""
).
lstrip
()
...
...
@@ -617,6 +618,7 @@ def _write_setup_file(name,
include_dirs
=
list2str
(
include_dirs
),
extra_compile_args
=
list2str
(
compile_flags
),
extra_link_args
=
list2str
(
link_args
),
build_dir
=
build_dir
,
use_new_method
=
use_new_custom_op_load_method
())
log_v
(
'write setup.py into {}'
.
format
(
file_path
),
verbose
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录