Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add paddle.version.cuda and paddle.version.cudnn API #36556

Merged
merged 9 commits into from
Oct 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions python/paddle/fluid/tests/unittests/test_cuda_cudnn_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# 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()
73 changes: 71 additions & 2 deletions python/setup.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand All @@ -67,18 +86,22 @@ 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'
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():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

要不paddle.version.show()命令也公开吧,然后show也可以打印cuda和cudnn的版本信息。
这样只需要告诉用户执行paddle.version.show()命令就可以看到版本和编译相关的信息了。
未来还可以添加其他编译信息,比如nccl版本之类的。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好的,我再提个PR把show公开出来。其它需要公开的编译信息后续跟PM讨论。

Copy link
Contributor Author

@pangyoki pangyoki Oct 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在PR #36800 中把paddle.version.show()公开出来。

if istaged:
print('full_version:', full_version)
Expand All @@ -91,20 +114,65 @@ 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(),
'minor': get_minor(),
'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 = ""
Expand Down Expand Up @@ -247,6 +315,7 @@ packages=['paddle',
'paddle.autograd',
'paddle.device',
'paddle.device.cuda',
'paddle.version',
]

with open('@PADDLE_SOURCE_DIR@/python/requirements.txt') as f:
Expand Down