未验证 提交 05b8630f 编写于 作者: P pangyoki 提交者: GitHub

Cherry-pick-36556: add paddle.version.cuda and paddle.version.cudnn API (#36556) (#36795)

* add paddle.version.cuda and paddle.version.cudnn API

* fix little bug

* fix bug

* add doc string

* fix mkdir error

* fix windows path

* fix new paddle/version path

* fix unittest

* fix format
上级 7647d402
# Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import unittest
import paddle
class TestCPUVersion(unittest.TestCase):
def test_cuda_cudnn_version_in_cpu_package(self):
if not paddle.is_compiled_with_cuda():
self.assertEqual(paddle.version.cuda(), 'False')
self.assertEqual(paddle.version.cudnn(), 'False')
if __name__ == '__main__':
unittest.main()
......@@ -54,6 +54,25 @@ def get_minor():
def get_patch():
return str(_get_version_detail(2))
def get_cuda_version():
if '@WITH_GPU@' == 'ON':
return '@CUDA_VERSION@'
else:
return 'False'
def get_cudnn_version():
if '@WITH_GPU@' == 'ON':
temp_cudnn_version = ''
if '@CUDNN_MAJOR_VERSION@':
temp_cudnn_version += '@CUDNN_MAJOR_VERSION@'
if '@CUDNN_MINOR_VERSION@':
temp_cudnn_version += '.@CUDNN_MINOR_VERSION@'
if '@CUDNN_PATCHLEVEL_VERSION@':
temp_cudnn_version += '.@CUDNN_PATCHLEVEL_VERSION@'
return temp_cudnn_version
else:
return 'False'
def is_taged():
try:
cmd = ['git', 'describe', '--exact-match', '--tags', 'HEAD', '2>/dev/null']
......@@ -67,7 +86,7 @@ def is_taged():
else:
return False
def write_version_py(filename='paddle/version.py'):
def write_version_py(filename='paddle/version/__init__.py'):
cnt = '''# THIS FILE IS GENERATED FROM PADDLEPADDLE SETUP.PY
#
full_version = '%(major)d.%(minor)d.%(patch)s'
......@@ -75,10 +94,14 @@ major = '%(major)d'
minor = '%(minor)d'
patch = '%(patch)s'
rc = '%(rc)d'
cuda_version = '%(cuda)s'
cudnn_version = '%(cudnn)s'
istaged = %(istaged)s
commit = '%(commit)s'
with_mkl = '%(with_mkl)s'
__all__ = ['cuda', 'cudnn']
def show():
if istaged:
print('full_version:', full_version)
......@@ -91,8 +114,51 @@ def show():
def mkl():
return with_mkl
def cuda():
"""Get cuda version of paddle package.
Returns:
string: Return the version information of cuda. If paddle package is CPU version, it will return False.
Examples:
.. code-block:: python
import paddle
paddle.version.cuda()
# '10.2'
"""
return cuda_version
def cudnn():
"""Get cudnn version of paddle package.
Returns:
string: Return the version information of cudnn. If paddle package is CPU version, it will return False.
Examples:
.. code-block:: python
import paddle
paddle.version.cudnn()
# '7.6.5'
"""
return cudnn_version
'''
commit = git_commit()
dirname = os.path.dirname(filename)
try:
os.makedirs(dirname)
except OSError as e:
if e.errno != errno.EEXIST:
raise
with open(filename, 'w') as f:
f.write(cnt % {
'major': get_major(),
......@@ -100,11 +166,13 @@ def mkl():
'patch': get_patch(),
'rc': RC,
'version': '${PADDLE_VERSION}',
'cuda': get_cuda_version(),
'cudnn': get_cudnn_version(),
'commit': commit,
'istaged': is_taged(),
'with_mkl': '@WITH_MKL@'})
write_version_py(filename='@PADDLE_BINARY_DIR@/python/paddle/version.py')
write_version_py(filename='@PADDLE_BINARY_DIR@/python/paddle/version/__init__.py')
def write_cuda_env_config_py(filename='paddle/cuda_env.py'):
cnt = ""
......@@ -251,6 +319,7 @@ packages=['paddle',
'paddle.autograd',
'paddle.device',
'paddle.device.cuda',
'paddle.version',
]
with open('@PADDLE_SOURCE_DIR@/python/requirements.txt') as f:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册