Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
ef5f9deb
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
大约 1 年 前同步成功
通知
695
Star
11112
Fork
2696
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
184
列表
看板
标记
里程碑
合并请求
40
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
184
Issue
184
列表
看板
标记
里程碑
合并请求
40
合并请求
40
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
ef5f9deb
编写于
7月 12, 2017
作者:
Q
qijun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refine device_context
上级
6bbc2944
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
102 addition
and
32 deletion
+102
-32
paddle/platform/CMakeLists.txt
paddle/platform/CMakeLists.txt
+1
-0
paddle/platform/cuda_device.h
paddle/platform/cuda_device.h
+8
-5
paddle/platform/cuda_device_test.cc
paddle/platform/cuda_device_test.cc
+33
-0
paddle/platform/device.h
paddle/platform/device.h
+41
-0
paddle/platform/device_context.h
paddle/platform/device_context.h
+9
-14
paddle/platform/device_context_test.cc
paddle/platform/device_context_test.cc
+10
-13
未找到文件。
paddle/platform/CMakeLists.txt
浏览文件 @
ef5f9deb
...
...
@@ -5,4 +5,5 @@ nv_test(cuda_test SRCS cuda_test.cu)
cc_library
(
place SRCS place.cc
)
cc_test
(
place_test SRCS place_test.cc DEPS place glog gflags
)
nv_test
(
cuda_device_test SRCS cuda_device_test.cc DEPS dynload_cuda dynamic_loader eigen3 place
)
nv_test
(
device_context_test SRCS device_context_test.cc DEPS dynload_cuda dynamic_loader eigen3 place
)
paddle/platform/cuda_device
_context
.h
→
paddle/platform/cuda_device.h
浏览文件 @
ef5f9deb
...
...
@@ -20,10 +20,12 @@ limitations under the License. */
#include "paddle/platform/dynload/cudnn.h"
#include "paddle/platform/dynload/curand.h"
#define EIGEN_USE_GPU
#include "paddle/platform/device
_context
.h"
#include "paddle/platform/device.h"
#include "paddle/platform/place.h"
#include "unsupported/Eigen/CXX11/Tensor"
using
DEVICE_GPU
=
Eigen
::
GpuDevice
;
namespace
paddle
{
namespace
platform
{
...
...
@@ -41,9 +43,10 @@ class GPUPlaceGuard {
GPUPlace
previous_
;
};
class
CUDADeviceContext
:
public
DeviceContext
{
template
<
>
class
Device
<
DEVICE_GPU
>
{
public:
explicit
CUDADeviceContext
(
const
GPUPlace
gpu_place
)
:
gpu_place_
(
gpu_place
)
{
explicit
Device
(
const
GPUPlace
gpu_place
)
:
gpu_place_
(
gpu_place
)
{
GPUPlaceGuard
guard
(
gpu_place_
);
paddle
::
platform
::
throw_on_error
(
cudaStreamCreate
(
&
stream_
),
"cudaStreamCreate failed"
);
...
...
@@ -58,7 +61,7 @@ class CUDADeviceContext : public DeviceContext {
cudaStream_t
stream
()
{
return
stream_
;
}
Eigen
::
GpuDevice
eigen_device
()
{
return
*
eigen_device_
;
}
DEVICE_GPU
eigen_device
()
{
return
*
eigen_device_
;
}
cublasHandle_t
cublas_handle
()
{
if
(
!
blas_handle_
)
{
...
...
@@ -136,7 +139,7 @@ class CUDADeviceContext : public DeviceContext {
cudaStream_t
stream_
;
Eigen
::
CudaStreamDevice
*
eigen_stream_
;
Eigen
::
GpuDevice
*
eigen_device_
;
DEVICE_GPU
*
eigen_device_
;
cublasHandle_t
blas_handle_
{
nullptr
};
...
...
paddle/platform/cuda_device_test.cc
0 → 100644
浏览文件 @
ef5f9deb
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.
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. */
#include "paddle/platform/cuda_device.h"
#include "gtest/gtest.h"
TEST
(
Device
,
Init
)
{
int
count
=
paddle
::
platform
::
GetDeviceCount
();
for
(
int
i
=
0
;
i
<
count
;
i
++
)
{
paddle
::
platform
::
Device
<
DEVICE_GPU
>*
device
=
new
paddle
::
platform
::
Device
<
DEVICE_GPU
>
(
i
);
Eigen
::
GpuDevice
gpu_device
=
device
->
eigen_device
();
ASSERT_NE
(
nullptr
,
gpu_device
.
stream
());
cudnnHandle_t
cudnn_handle
=
device
->
cudnn_handle
();
ASSERT_NE
(
nullptr
,
cudnn_handle
);
cublasHandle_t
cublas_handle
=
device
->
cublas_handle
();
ASSERT_NE
(
nullptr
,
cublas_handle
);
curandGenerator_t
curand_handle
=
device
->
curand_generator
();
ASSERT_NE
(
nullptr
,
curand_handle
);
delete
device
;
}
}
paddle/platform/device.h
0 → 100644
浏览文件 @
ef5f9deb
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.
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. */
#pragma once
#include "unsupported/Eigen/CXX11/Tensor"
using
DEVICE_CPU
=
Eigen
::
DefaultDevice
;
namespace
paddle
{
namespace
platform
{
template
<
typename
DeviceType
>
class
Device
;
template
<
>
class
Device
<
DEVICE_CPU
>
{
public:
DEVICE_CPU
eigen_handle
()
{
if
(
!
eigen_handle_
)
{
eigen_handle_
=
new
Eigen
::
DefaultDevice
();
}
return
*
eigen_handle_
;
}
private:
DEVICE_CPU
*
eigen_handle_
{
nullptr
};
};
}
// namespace platform
}
// namespace paddle
paddle/platform/device_context.h
浏览文件 @
ef5f9deb
...
...
@@ -14,27 +14,22 @@ limitations under the License. */
#pragma once
#include "paddle/framework/enforce.h"
#include "paddle/platform/device.h"
#include "unsupported/Eigen/CXX11/Tensor"
#ifndef PADDLE_ONLY_CPU
#include "paddle/platform/cuda_device.h"
#endif
namespace
paddle
{
namespace
platform
{
class
DeviceContext
{
public:
virtual
~
DeviceContext
()
{}
};
struct
DeviceContext
{
void
*
device_context
{
nullptr
};
class
CPUDeviceContext
:
public
DeviceContext
{
public:
Eigen
::
DefaultDevice
eigen_handle
()
{
if
(
!
eigen_handle_
)
{
eigen_handle_
=
new
Eigen
::
DefaultDevice
();
}
return
*
eigen_handle_
;
template
<
typename
DeviceType
>
inline
paddle
::
platform
::
Device
<
DeviceType
>*
device_context
()
{
return
static_cast
<
paddle
::
platform
::
Device
<
DeviceType
>*>
(
device_context
);
}
private:
Eigen
::
DefaultDevice
*
eigen_handle_
{
nullptr
};
};
}
// namespace platform
...
...
paddle/platform/device_context_test.cc
浏览文件 @
ef5f9deb
...
...
@@ -12,22 +12,19 @@ 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. */
#include "paddle/platform/device_context.h"
#include "gtest/gtest.h"
#include "paddle/platform/cuda_device_context.h"
TEST
(
CUDA
DeviceContext
,
Init
)
{
TEST
(
DeviceContext
,
Init
)
{
int
count
=
paddle
::
platform
::
GetDeviceCount
();
for
(
int
i
=
0
;
i
<
count
;
i
++
)
{
paddle
::
platform
::
CUDADeviceContext
*
device_context
=
new
paddle
::
platform
::
CUDADeviceContext
(
i
);
Eigen
::
GpuDevice
gpu_device
=
device_context
->
eigen_device
();
paddle
::
platform
::
Device
<
DEVICE_GPU
>*
device
=
new
paddle
::
platform
::
Device
<
DEVICE_GPU
>
(
i
);
paddle
::
platform
::
DeviceContext
context
;
context
.
device_context
=
device
;
Eigen
::
GpuDevice
gpu_device
=
context
.
device_context
<
DEVICE_GPU
>->
eigen_device
();
ASSERT_NE
(
nullptr
,
gpu_device
.
stream
());
cudnnHandle_t
cudnn_handle
=
device_context
->
cudnn_handle
();
ASSERT_NE
(
nullptr
,
cudnn_handle
);
cublasHandle_t
cublas_handle
=
device_context
->
cublas_handle
();
ASSERT_NE
(
nullptr
,
cublas_handle
);
curandGenerator_t
curand_handle
=
device_context
->
curand_generator
();
ASSERT_NE
(
nullptr
,
curand_handle
);
delete
device_context
;
delete
device
;
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录