Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
8ee50a35
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
8ee50a35
编写于
7月 12, 2017
作者:
Q
qijun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix gpu build error
上级
ca23d861
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
21 addition
and
24 deletion
+21
-24
paddle/platform/CMakeLists.txt
paddle/platform/CMakeLists.txt
+0
-1
paddle/platform/cuda_device_context.h
paddle/platform/cuda_device_context.h
+7
-8
paddle/platform/device_context.h
paddle/platform/device_context.h
+11
-13
paddle/platform/device_context_test.cc
paddle/platform/device_context_test.cc
+3
-2
未找到文件。
paddle/platform/CMakeLists.txt
浏览文件 @
8ee50a35
...
...
@@ -5,5 +5,4 @@ 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
浏览文件 @
8ee50a35
...
...
@@ -20,19 +20,13 @@ 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/place.h"
#include "unsupported/Eigen/CXX11/Tensor"
namespace
paddle
{
namespace
platform
{
class
CUDADeviceContext
;
template
<
>
Eigen
::
GpuDevice
DeviceContext
::
get_eigen_device
<
Eigen
::
GpuDevice
>
()
{
return
static_cast
<
CUDADeviceContext
*>
(
this
)
->
eigen_handle
();
}
class
GPUPlaceGuard
{
public:
explicit
GPUPlaceGuard
(
GPUPlace
new_place
)
:
previous_
(
GetCurrentDeviceId
())
{
...
...
@@ -49,7 +43,7 @@ class GPUPlaceGuard {
class
CUDADeviceContext
:
public
DeviceContext
{
public:
explicit
Device
(
const
GPUPlace
gpu_place
)
:
gpu_place_
(
gpu_place
)
{
explicit
CUDADeviceContext
(
const
GPUPlace
gpu_place
)
:
gpu_place_
(
gpu_place
)
{
GPUPlaceGuard
guard
(
gpu_place_
);
paddle
::
platform
::
throw_on_error
(
cudaStreamCreate
(
&
stream_
),
"cudaStreamCreate failed"
);
...
...
@@ -156,5 +150,10 @@ class CUDADeviceContext : public DeviceContext {
int
random_seed_
;
curandGenerator_t
rand_generator_
{
nullptr
};
};
template
<
>
Eigen
::
GpuDevice
DeviceContext
::
get_eigen_device
<
Eigen
::
GpuDevice
>
()
{
return
dynamic_cast
<
CUDADeviceContext
*>
(
this
)
->
eigen_device
();
}
}
// namespace platform
}
// namespace paddle
paddle/platform/device_context.h
浏览文件 @
8ee50a35
...
...
@@ -20,30 +20,23 @@ limitations under the License. */
namespace
paddle
{
namespace
platform
{
class
CPUDeviceContext
;
class
DeviceContext
{
public:
virtual
~
DeviceContext
()
{}
template
<
typename
DeviceType
>
DeviceType
get_eigen_device
();
inline
DeviceType
get_eigen_device
();
virtual
Place
GetPlace
()
const
=
0
;
};
template
<
>
Eigen
::
DefaultDevice
DeviceContext
::
get_eigen_device
<
Eigen
::
DefaultDevice
>
()
{
return
static_cast
<
CPUDeviceContext
*>
(
this
)
->
eigen_handle
();
}
class
CPUDeviceContext
:
public
DeviceContext
{
public:
Eigen
::
DefaultDevice
eigen_
handl
e
()
{
if
(
!
eigen_
handl
e_
)
{
eigen_
handl
e_
=
new
Eigen
::
DefaultDevice
();
Eigen
::
DefaultDevice
eigen_
devic
e
()
{
if
(
!
eigen_
devic
e_
)
{
eigen_
devic
e_
=
new
Eigen
::
DefaultDevice
();
}
return
*
eigen_
handl
e_
;
return
*
eigen_
devic
e_
;
}
Place
GetPlace
()
const
override
{
...
...
@@ -52,7 +45,12 @@ class CPUDeviceContext : public DeviceContext {
}
private:
Eigen
::
DefaultDevice
*
eigen_
handl
e_
{
nullptr
};
Eigen
::
DefaultDevice
*
eigen_
devic
e_
{
nullptr
};
};
template
<
>
Eigen
::
DefaultDevice
DeviceContext
::
get_eigen_device
<
Eigen
::
DefaultDevice
>
()
{
return
dynamic_cast
<
CPUDeviceContext
*>
(
this
)
->
eigen_device
();
}
}
// namespace platform
}
// namespace paddle
paddle/platform/device_context_test.cc
浏览文件 @
8ee50a35
...
...
@@ -13,15 +13,16 @@ See the License for the specific language governing permissions and
limitations under the License. */
#include "gtest/gtest.h"
#include "paddle/platform/cuda_device.h"
#include "paddle/platform/cuda_device
_context
.h"
using
DEVICE_GPU
=
Eigen
::
GpuDevice
;
TEST
(
Device
,
Init
)
{
int
count
=
paddle
::
platform
::
GetDeviceCount
();
for
(
int
i
=
0
;
i
<
count
;
i
++
)
{
paddle
::
platform
::
DeviceContext
*
device_context
=
new
paddle
::
platform
::
CUDADeviceContext
(
i
);
Eigen
::
GpuDevice
gpu_device
=
device_context
->
get_eigen_device
<
DEVICE_GPU
>
();
device_context
->
template
get_eigen_device
<
DEVICE_GPU
>();
ASSERT_NE
(
nullptr
,
gpu_device
.
stream
());
delete
device_context
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录