diff --git a/python/env_dict.py.in b/python/env_dict.py.in index 5b2078c67510c3f0aadc62c185120a8b1a77bf23..00ca04dc56cded023c32c90556c4c57a75c11ff1 100644 --- a/python/env_dict.py.in +++ b/python/env_dict.py.in @@ -73,5 +73,7 @@ env_dict={ 'JIT_RELEASE_WHL':'@JIT_RELEASE_WHL@', 'WITH_PSLIB':'@WITH_PSLIB@', 'PYBIND_INCLUDE_DIR':'@PYBIND_INCLUDE_DIR@', - 'WITH_PYTHON':'@WITH_PYTHON@' + 'WITH_PYTHON':'@WITH_PYTHON@', + 'WITH_CINN':'@WITH_CINN@', + 'CINN_SOURCE_DIR':'@CINN_SOURCE_DIR@' } diff --git a/python/setup.py.in b/python/setup.py.in index 650a4449b24c619e14ae58d87e3fe32e259e8ca3..fa32dcf13c3d51bbbe9f4573837ee28d37cd90c4 100644 --- a/python/setup.py.in +++ b/python/setup.py.in @@ -100,6 +100,32 @@ def is_taged(): else: 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'): cnt = '''# THIS FILE IS GENERATED FROM PADDLEPADDLE SETUP.PY # @@ -115,6 +141,7 @@ xpu_xccl_version = '%(xpu_xccl)s' istaged = %(istaged)s commit = '%(commit)s' with_mkl = '%(with_mkl)s' +cinn_version = '%(cinn)s' __all__ = ['cuda', 'cudnn', 'show', 'xpu', 'xpu_xccl'] @@ -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 + cinn: the cinn version of package. It will return `False` if paddle package is not compiled with CINN + Examples: .. code-block:: python @@ -159,6 +188,7 @@ def show(): # cudnn: '7.6.5' # xpu: '20230114' # xpu_xccl: '1.0.7' + # cinn: False # Case 2: paddle is not tagged paddle.version.show() @@ -167,6 +197,7 @@ def show(): # cudnn: '7.6.5' # xpu: '20230114' # xpu_xccl: '1.0.7' + # cinn: False """ if istaged: print('full_version:', full_version) @@ -180,6 +211,7 @@ def show(): print('cudnn:', cudnn_version) print('xpu:', xpu_version) print('xpu_xccl:', xpu_xccl_version) + print('cinn:', cinn_version) def mkl(): return with_mkl @@ -251,6 +283,23 @@ def xpu_xccl(): """ 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() @@ -275,7 +324,8 @@ def xpu_xccl(): 'xpu_xccl': get_xpu_xccl_version(), 'commit': commit, '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') diff --git a/setup.py b/setup.py index daa9dbd5cc6e40297ad862adaf06847ff1902bf4..288500feba8548ca58b2c9005f0fba6c06a7d5f5 100644 --- a/setup.py +++ b/setup.py @@ -427,6 +427,57 @@ def is_taged(): 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'): cnt = '''# THIS FILE IS GENERATED FROM PADDLEPADDLE SETUP.PY # @@ -442,6 +493,7 @@ xpu_xccl_version = '%(xpu_xccl)s' istaged = %(istaged)s commit = '%(commit)s' with_mkl = '%(with_mkl)s' +cinn_version = '%(cinn)s' __all__ = ['cuda', 'cudnn', 'show', 'xpu', 'xpu_xccl'] @@ -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 + cinn: the cinn version of package. It will return `False` if paddle package is not compiled with CINN + Examples: .. code-block:: python @@ -486,6 +540,7 @@ def show(): # cudnn: '7.6.5' # xpu: '20230114' # xpu_xccl: '1.0.7' + # cinn: False # Case 2: paddle is not tagged paddle.version.show() @@ -494,6 +549,7 @@ def show(): # cudnn: '7.6.5' # xpu: '20230114' # xpu_xccl: '1.0.7' + # cinn: False """ if istaged: print('full_version:', full_version) @@ -507,6 +563,7 @@ def show(): print('cudnn:', cudnn_version) print('xpu:', xpu_version) print('xpu_xccl:', xpu_xccl_version) + print('cinn:', cinn_version) def mkl(): return with_mkl @@ -578,6 +635,23 @@ def xpu_xccl(): """ 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() @@ -605,6 +679,7 @@ def xpu_xccl(): 'commit': commit, 'istaged': is_taged(), 'with_mkl': env_dict.get("WITH_MKL"), + 'cinn': get_cinn_version(), } )