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 op paddle.device.cuda.get_device_name and paddle.device.cuda.get_device_capability. #35672

Merged
merged 28 commits into from
Sep 29, 2021
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
9dc07e1
add op paddle.device.cuda.get_device_name
liyagit21 Sep 12, 2021
064720e
fix some bugs
liyagit21 Sep 13, 2021
84a827f
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
liyagit21 Sep 13, 2021
0fe7eef
fix some bugs
liyagit21 Sep 13, 2021
7941886
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
liyagit21 Sep 13, 2021
abf8f28
fix error message bugs
liyagit21 Sep 13, 2021
7a3a999
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
liyagit21 Sep 13, 2021
6ae8e4b
fix en docs
liyagit21 Sep 14, 2021
baa026a
fix en docs
liyagit21 Sep 14, 2021
d22a0a6
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
liyagit21 Sep 14, 2021
c632559
fix bugs
liyagit21 Sep 14, 2021
7da37f1
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
liyagit21 Sep 14, 2021
36b9c06
fix bugs
liyagit21 Sep 14, 2021
1b51973
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
liyagit21 Sep 14, 2021
e75dd03
fix bugs
liyagit21 Sep 14, 2021
3aa62ce
add error message test case
liyagit21 Sep 15, 2021
e16672e
add error message test case
liyagit21 Sep 15, 2021
be8f04b
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
liyagit21 Sep 15, 2021
db15650
add get_device_name and get_device_capability
liyagit21 Sep 27, 2021
15d81e1
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
liyagit21 Sep 27, 2021
c7fc82e
fix review
liyagit21 Sep 27, 2021
799e861
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
liyagit21 Sep 27, 2021
90375b8
fix docs bug
liyagit21 Sep 27, 2021
df1e9f0
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
liyagit21 Sep 27, 2021
8c9f282
fix docs
liyagit21 Sep 27, 2021
c6268fc
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
liyagit21 Sep 28, 2021
3bc69d4
fix docs
liyagit21 Sep 28, 2021
f38ea9a
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
liyagit21 Sep 28, 2021
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
69 changes: 62 additions & 7 deletions python/paddle/device/cuda/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,8 @@
from .streams import Event # noqa: F401

__all__ = [
'Stream',
'Event',
'current_stream',
'synchronize',
'device_count',
'empty_cache',
'stream_guard',
'Stream', 'Event', 'current_stream', 'synchronize', 'device_count',
'empty_cache', 'stream_guard', 'get_device_name', 'get_device_capability'
liyagit21 marked this conversation as resolved.
Show resolved Hide resolved
]


Expand Down Expand Up @@ -204,3 +199,63 @@ def stream_guard(stream):
yield
finally:
stream = _set_current_stream(pre_stream)


def get_device_name(device=None):
'''
Return the name of the device which is get from CUDA function `cudaDeviceProp<https://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART__DEVICE.html#group__CUDART__DEVICE_1g1bf9d625a931d657e08db2b4391170f0>`_..
liyagit21 marked this conversation as resolved.
Show resolved Hide resolved

Parameters:
device(paddle.CUDAPlace()|int, optional): The device or the ID of the device.
sneaxiy marked this conversation as resolved.
Show resolved Hide resolved
If device is None, the device is the current device. Default: None.

Returns:
str: the name of the device.

Examples:
.. code-block:: python

# required: gpu

import paddle

paddle.device.cuda.get_device_name()

paddle.device.cuda.get_device_name(0)

paddle.device.cuda.get_device_name(paddle.CUDAPlace(0))

'''

return get_device_properties(device).name


def get_device_capability(device=None):
'''
Return the major and minor revision numbers defining the device's compute capability which are get from CUDA function `cudaDeviceProp<https://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART__DEVICE.html#group__CUDART__DEVICE_1g1bf9d625a931d657e08db2b4391170f0>`_..

Parameters:
device(paddle.CUDAPlace()|int, optional): The device or the ID of the device.
If device is None, the device is the current device. Default: None.

Returns:
tuple(int,int): the major and minor revision numbers defining the device's compute capability.

Examples:

.. code-block:: python

# required: gpu

import paddle

paddle.device.cuda.get_device_capability()

paddle.device.cuda.get_device_capability(0)

paddle.device.cuda.get_device_capability(paddle.CUDAPlace(0))

'''

return get_device_properties(device).major, get_device_properties(
device).minor
liyagit21 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# 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 paddle
import unittest


class TestDeviceName(unittest.TestCase):
def test_device_name_default(self):
if paddle.is_compiled_with_cuda():
name = paddle.device.cuda.get_device_name()
self.assertIsNotNone(name)

def test_device_name_int(self):
if paddle.is_compiled_with_cuda():
name = paddle.device.cuda.get_device_name(0)
self.assertIsNotNone(name)

def test_device_name_CUDAPlace(self):
if paddle.is_compiled_with_cuda():
name = paddle.device.cuda.get_device_name(paddle.CUDAPlace(0))
self.assertIsNotNone(name)


class TestDeviceCapability(unittest.TestCase):
def test_device_capability_default(self):
if paddle.is_compiled_with_cuda():
capability = paddle.device.cuda.get_device_capability()
self.assertIsNotNone(capability)

def test_device_capability_int(self):
if paddle.is_compiled_with_cuda():
capability = paddle.device.cuda.get_device_capability(0)
self.assertIsNotNone(capability)

def test_device_capability_CUDAPlace(self):
if paddle.is_compiled_with_cuda():
capability = paddle.device.cuda.get_device_capability(
paddle.CUDAPlace(0))
self.assertIsNotNone(capability)


if __name__ == "__main__":
unittest.main()