未验证 提交 41e37d4c 编写于 作者: J jiangcheng 提交者: GitHub

[CINN] add python.version.cinn_commit api (#52727)

* [CINN] add python.version.cinn_commit api

* update cinn version get function

* fix cinn_commit in setup.py also need len>0 check bug
上级 523fae59
...@@ -73,5 +73,7 @@ env_dict={ ...@@ -73,5 +73,7 @@ env_dict={
'JIT_RELEASE_WHL':'@JIT_RELEASE_WHL@', 'JIT_RELEASE_WHL':'@JIT_RELEASE_WHL@',
'WITH_PSLIB':'@WITH_PSLIB@', 'WITH_PSLIB':'@WITH_PSLIB@',
'PYBIND_INCLUDE_DIR':'@PYBIND_INCLUDE_DIR@', 'PYBIND_INCLUDE_DIR':'@PYBIND_INCLUDE_DIR@',
'WITH_PYTHON':'@WITH_PYTHON@' 'WITH_PYTHON':'@WITH_PYTHON@',
'WITH_CINN':'@WITH_CINN@',
'CINN_SOURCE_DIR':'@CINN_SOURCE_DIR@'
} }
...@@ -100,6 +100,32 @@ def is_taged(): ...@@ -100,6 +100,32 @@ def is_taged():
else: else:
return False return False
def get_cinn_version():
if '@WITH_CINN@' != 'ON':
return "False"
cinn_git_version = 'Unknown'
try:
cmd = ['git', 'describe', '--exact-match', '--tags', 'HEAD', '2>/dev/null']
cinn_tag = subprocess.Popen(cmd, stdout = subprocess.PIPE, cwd='@CINN_SOURCE_DIR@').communicate()[0].strip()
if len(cinn_tag) > 0:
cinn_git_version = cinn_tag
except:
pass
if cinn_git_version == 'Unknown':
try:
cmd = ['git', 'rev-parse', 'HEAD']
cinn_commit = subprocess.Popen(cmd, stdout = subprocess.PIPE,
cwd='@CINN_SOURCE_DIR@').communicate()[0].strip()
if len(cinn_commit) > 0:
cinn_git_version = cinn_commit
except:
pass
cinn_git_version = cinn_git_version.decode('utf-8')
return str(cinn_git_version)
def write_version_py(filename='paddle/version/__init__.py'): def write_version_py(filename='paddle/version/__init__.py'):
cnt = '''# THIS FILE IS GENERATED FROM PADDLEPADDLE SETUP.PY cnt = '''# THIS FILE IS GENERATED FROM PADDLEPADDLE SETUP.PY
# #
...@@ -115,6 +141,7 @@ xpu_xccl_version = '%(xpu_xccl)s' ...@@ -115,6 +141,7 @@ xpu_xccl_version = '%(xpu_xccl)s'
istaged = %(istaged)s istaged = %(istaged)s
commit = '%(commit)s' commit = '%(commit)s'
with_mkl = '%(with_mkl)s' with_mkl = '%(with_mkl)s'
cinn_version = '%(cinn)s'
__all__ = ['cuda', 'cudnn', 'show', 'xpu', 'xpu_xccl'] __all__ = ['cuda', 'cudnn', 'show', 'xpu', 'xpu_xccl']
...@@ -143,6 +170,8 @@ def show(): ...@@ -143,6 +170,8 @@ def show():
xpu_xccl: the xpu xccl version of package. It will return `False` if non-XPU version paddle package is installed xpu_xccl: the xpu xccl version of package. It will return `False` if non-XPU version paddle package is installed
cinn: the cinn version of package. It will return `False` if paddle package is not compiled with CINN
Examples: Examples:
.. code-block:: python .. code-block:: python
...@@ -159,6 +188,7 @@ def show(): ...@@ -159,6 +188,7 @@ def show():
# cudnn: '7.6.5' # cudnn: '7.6.5'
# xpu: '20230114' # xpu: '20230114'
# xpu_xccl: '1.0.7' # xpu_xccl: '1.0.7'
# cinn: False
# Case 2: paddle is not tagged # Case 2: paddle is not tagged
paddle.version.show() paddle.version.show()
...@@ -167,6 +197,7 @@ def show(): ...@@ -167,6 +197,7 @@ def show():
# cudnn: '7.6.5' # cudnn: '7.6.5'
# xpu: '20230114' # xpu: '20230114'
# xpu_xccl: '1.0.7' # xpu_xccl: '1.0.7'
# cinn: False
""" """
if istaged: if istaged:
print('full_version:', full_version) print('full_version:', full_version)
...@@ -180,6 +211,7 @@ def show(): ...@@ -180,6 +211,7 @@ def show():
print('cudnn:', cudnn_version) print('cudnn:', cudnn_version)
print('xpu:', xpu_version) print('xpu:', xpu_version)
print('xpu_xccl:', xpu_xccl_version) print('xpu_xccl:', xpu_xccl_version)
print('cinn:', cinn_version)
def mkl(): def mkl():
return with_mkl return with_mkl
...@@ -251,6 +283,23 @@ def xpu_xccl(): ...@@ -251,6 +283,23 @@ def xpu_xccl():
""" """
return xpu_xccl_version return xpu_xccl_version
def cinn():
"""Get CINN version of paddle package.
Returns:
string: Return the version information of CINN. If paddle package is not compiled with CINN, it will return False.
Examples:
.. code-block:: python
import paddle
paddle.version.cinn()
# False
"""
return cinn_version
''' '''
commit = git_commit() commit = git_commit()
...@@ -275,7 +324,8 @@ def xpu_xccl(): ...@@ -275,7 +324,8 @@ def xpu_xccl():
'xpu_xccl': get_xpu_xccl_version(), 'xpu_xccl': get_xpu_xccl_version(),
'commit': commit, 'commit': commit,
'istaged': is_taged(), 'istaged': is_taged(),
'with_mkl': '@WITH_MKL@'}) 'with_mkl': '@WITH_MKL@',
'cinn': get_cinn_version()})
write_version_py(filename='@PADDLE_BINARY_DIR@/python/paddle/version/__init__.py') write_version_py(filename='@PADDLE_BINARY_DIR@/python/paddle/version/__init__.py')
......
...@@ -427,6 +427,57 @@ def is_taged(): ...@@ -427,6 +427,57 @@ def is_taged():
return False return False
def get_cinn_version():
if env_dict.get("WITH_CINN") != 'ON':
return "False"
cinn_git_version = 'Unknown'
# try get cinn tag name
try:
cmd = [
'git',
'describe',
'--exact-match',
'--tags',
'HEAD',
'2>/dev/null',
]
cinn_tag = (
subprocess.Popen(
cmd,
stdout=subprocess.PIPE,
cwd=env_dict.get("CINN_SOURCE_DIR"),
)
.communicate()[0]
.strip()
)
if len(cinn_tag) > 0:
cinn_git_version = cinn_tag
except:
pass
if cinn_git_version == 'Unknown':
# try get cinn commit id
try:
cmd = ['git', 'rev-parse', 'HEAD']
cinn_commit = (
subprocess.Popen(
cmd,
stdout=subprocess.PIPE,
cwd=env_dict.get("CINN_SOURCE_DIR"),
)
.communicate()[0]
.strip()
)
if len(cinn_commit) > 0:
cinn_git_version = cinn_commit
except:
pass
cinn_git_version = cinn_git_version.decode('utf-8')
return str(cinn_git_version)
def write_version_py(filename='paddle/version/__init__.py'): def write_version_py(filename='paddle/version/__init__.py'):
cnt = '''# THIS FILE IS GENERATED FROM PADDLEPADDLE SETUP.PY cnt = '''# THIS FILE IS GENERATED FROM PADDLEPADDLE SETUP.PY
# #
...@@ -442,6 +493,7 @@ xpu_xccl_version = '%(xpu_xccl)s' ...@@ -442,6 +493,7 @@ xpu_xccl_version = '%(xpu_xccl)s'
istaged = %(istaged)s istaged = %(istaged)s
commit = '%(commit)s' commit = '%(commit)s'
with_mkl = '%(with_mkl)s' with_mkl = '%(with_mkl)s'
cinn_version = '%(cinn)s'
__all__ = ['cuda', 'cudnn', 'show', 'xpu', 'xpu_xccl'] __all__ = ['cuda', 'cudnn', 'show', 'xpu', 'xpu_xccl']
...@@ -470,6 +522,8 @@ def show(): ...@@ -470,6 +522,8 @@ def show():
xpu_xccl: the xpu xccl version of package. It will return `False` if non-XPU version paddle package is installed xpu_xccl: the xpu xccl version of package. It will return `False` if non-XPU version paddle package is installed
cinn: the cinn version of package. It will return `False` if paddle package is not compiled with CINN
Examples: Examples:
.. code-block:: python .. code-block:: python
...@@ -486,6 +540,7 @@ def show(): ...@@ -486,6 +540,7 @@ def show():
# cudnn: '7.6.5' # cudnn: '7.6.5'
# xpu: '20230114' # xpu: '20230114'
# xpu_xccl: '1.0.7' # xpu_xccl: '1.0.7'
# cinn: False
# Case 2: paddle is not tagged # Case 2: paddle is not tagged
paddle.version.show() paddle.version.show()
...@@ -494,6 +549,7 @@ def show(): ...@@ -494,6 +549,7 @@ def show():
# cudnn: '7.6.5' # cudnn: '7.6.5'
# xpu: '20230114' # xpu: '20230114'
# xpu_xccl: '1.0.7' # xpu_xccl: '1.0.7'
# cinn: False
""" """
if istaged: if istaged:
print('full_version:', full_version) print('full_version:', full_version)
...@@ -507,6 +563,7 @@ def show(): ...@@ -507,6 +563,7 @@ def show():
print('cudnn:', cudnn_version) print('cudnn:', cudnn_version)
print('xpu:', xpu_version) print('xpu:', xpu_version)
print('xpu_xccl:', xpu_xccl_version) print('xpu_xccl:', xpu_xccl_version)
print('cinn:', cinn_version)
def mkl(): def mkl():
return with_mkl return with_mkl
...@@ -578,6 +635,23 @@ def xpu_xccl(): ...@@ -578,6 +635,23 @@ def xpu_xccl():
""" """
return xpu_xccl_version return xpu_xccl_version
def cinn():
"""Get CINN version of paddle package.
Returns:
string: Return the version information of CINN. If paddle package is not compiled with CINN, it will return False.
Examples:
.. code-block:: python
import paddle
paddle.version.cinn()
# False
"""
return cinn_version
''' '''
commit = git_commit() commit = git_commit()
...@@ -605,6 +679,7 @@ def xpu_xccl(): ...@@ -605,6 +679,7 @@ def xpu_xccl():
'commit': commit, 'commit': commit,
'istaged': is_taged(), 'istaged': is_taged(),
'with_mkl': env_dict.get("WITH_MKL"), 'with_mkl': env_dict.get("WITH_MKL"),
'cinn': get_cinn_version(),
} }
) )
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册