Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
0b81d763
P
Paddle
项目概览
Crayon鑫
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
0b81d763
编写于
8月 16, 2020
作者:
W
wangchaochaohu
提交者:
GitHub
8月 16, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[API2.0] add op for cudnn version query test=develop (#26180)
上级
e87436a5
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
86 addition
and
5 deletion
+86
-5
paddle/fluid/platform/CMakeLists.txt
paddle/fluid/platform/CMakeLists.txt
+1
-1
paddle/fluid/platform/gpu_info.cc
paddle/fluid/platform/gpu_info.cc
+9
-4
paddle/fluid/platform/gpu_info.h
paddle/fluid/platform/gpu_info.h
+2
-0
paddle/fluid/pybind/pybind.cc
paddle/fluid/pybind/pybind.cc
+4
-0
python/paddle/__init__.py
python/paddle/__init__.py
+1
-0
python/paddle/device.py
python/paddle/device.py
+37
-0
python/paddle/fluid/tests/unittests/test_query_op.py
python/paddle/fluid/tests/unittests/test_query_op.py
+32
-0
未找到文件。
paddle/fluid/platform/CMakeLists.txt
浏览文件 @
0b81d763
...
...
@@ -45,7 +45,7 @@ ENDIF()
cc_library
(
cpu_info SRCS cpu_info.cc DEPS
${
CPU_INFO_DEPS
}
)
cc_test
(
cpu_info_test SRCS cpu_info_test.cc DEPS cpu_info
)
nv_library
(
gpu_info SRCS gpu_info.cc DEPS gflags glog enforce monitor
)
nv_library
(
gpu_info SRCS gpu_info.cc DEPS gflags glog enforce monitor
dynload_cuda
)
cc_library
(
place SRCS place.cc DEPS enforce boost
)
cc_test
(
place_test SRCS place_test.cc DEPS place glog gflags
)
...
...
paddle/fluid/platform/gpu_info.cc
浏览文件 @
0b81d763
...
...
@@ -19,6 +19,7 @@ limitations under the License. */
#include "gflags/gflags.h"
#include "paddle/fluid/platform/cuda_device_guard.h"
#include "paddle/fluid/platform/dynload/cudnn.h"
#include "paddle/fluid/platform/enforce.h"
#include "paddle/fluid/platform/lock_guard_ptr.h"
#include "paddle/fluid/platform/macros.h"
...
...
@@ -38,11 +39,11 @@ USE_GPU_MEM_STAT;
namespace
paddle
{
namespace
platform
{
/* Here is a very simple CUDA “pro tip”: cudaDeviceGetAttribute() is a much
faster way to query device properties. You can see details in
https://devblogs.nvidia.com/cuda-pro-tip-the-fast-way-to-query-device-properties/
*/
int
CudnnVersion
()
{
if
(
!
dynload
::
HasCUDNN
())
return
-
1
;
return
dynload
::
cudnnGetVersion
();
}
static
int
GetCUDADeviceCountImpl
()
{
int
driverVersion
=
0
;
cudaError_t
status
=
cudaDriverGetVersion
(
&
driverVersion
);
...
...
@@ -73,6 +74,10 @@ int GetCUDADeviceCount() {
return
dev_cnt
;
}
/* Here is a very simple CUDA “pro tip”: cudaDeviceGetAttribute() is a much
faster way to query device properties. You can see details in
https://devblogs.nvidia.com/cuda-pro-tip-the-fast-way-to-query-device-properties/
*/
int
GetCUDAComputeCapability
(
int
id
)
{
PADDLE_ENFORCE_LT
(
id
,
GetCUDADeviceCount
(),
platform
::
errors
::
InvalidArgument
(
...
...
paddle/fluid/platform/gpu_info.h
浏览文件 @
0b81d763
...
...
@@ -23,6 +23,8 @@ limitations under the License. */
namespace
paddle
{
namespace
platform
{
//! Get the version of cudnn
int
CudnnVersion
();
//! Get the total number of GPU devices in system.
int
GetCUDADeviceCount
();
...
...
paddle/fluid/pybind/pybind.cc
浏览文件 @
0b81d763
...
...
@@ -341,6 +341,10 @@ PYBIND11_MODULE(core_noavx, m) {
m
.
def
(
"set_num_threads"
,
&
platform
::
SetNumThreads
);
#ifdef PADDLE_WITH_CUDA
m
.
def
(
"cudnn_version"
,
&
platform
::
CudnnVersion
);
#endif
m
.
def
(
"from_dlpack"
,
[](
py
::
capsule
*
dltensor
)
{
DLManagedTensor
*
dmt
=
reinterpret_cast
<
DLManagedTensor
*>
(
PyCapsule_GetPointer
(
dltensor
->
ptr
(),
"dltensor"
));
...
...
python/paddle/__init__.py
浏览文件 @
0b81d763
...
...
@@ -232,6 +232,7 @@ from .tensor.stat import reduce_mean #DEFINE_ALIAS
from
.tensor.stat
import
std
#DEFINE_ALIAS
from
.tensor.stat
import
var
#DEFINE_ALIAS
from
.fluid.data
import
data
from
.device
import
get_cudnn_version
from
.device
import
set_device
from
.device
import
get_device
# from .tensor.tensor import Tensor #DEFINE_ALIAS
...
...
python/paddle/device.py
浏览文件 @
0b81d763
...
...
@@ -12,10 +12,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# TODO: define the functions to manipulate devices
from
paddle.fluid
import
core
from
paddle.fluid
import
framework
import
re
__all__
=
[
'get_cudnn_version'
,
'set_device'
,
'get_device'
# 'cpu_places',
...
...
@@ -27,6 +30,40 @@ __all__ = [
# 'is_compiled_with_cuda'
]
_cudnn_version
=
None
def
get_cudnn_version
():
"""
This funciton return the version of cudnn. the retuen value is int which represents the
cudnn version. For example, if it return 7600, it represents the version of cudnn is 7.6.
Returns:
int: A int value which represents the cudnn version. If cudnn version is not installed, it return None.
Examples:
.. code-block:: python
import paddle
cudnn_version = get_cudnn_version()
"""
global
_cudnn_version
if
not
core
.
is_compiled_with_cuda
():
return
None
if
_cudnn_version
is
None
:
cudnn_version
=
int
(
core
.
cudnn_version
())
_cudnn_version
=
cudnn_version
if
_cudnn_version
<
0
:
return
None
else
:
return
cudnn_version
else
:
return
_cudnn_version
def
set_device
(
device
):
"""
...
...
python/paddle/fluid/tests/unittests/test_query_op.py
0 → 100644
浏览文件 @
0b81d763
# Copyright (c) 2020 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.
from
__future__
import
print_function
import
unittest
import
paddle
from
paddle.fluid
import
core
class
TestCudnnVersion
(
unittest
.
TestCase
):
def
test_no_cudnn
(
self
):
cudnn_version
=
paddle
.
get_cudnn_version
()
if
not
core
.
is_compiled_with_cuda
():
self
.
assertEqual
((
cudnn_version
is
None
),
True
)
else
:
self
.
assertEqual
((
isinstance
(
cudnn_version
,
int
)),
True
)
if
__name__
==
'__main__'
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录