Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
4d336d90
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看板
提交
4d336d90
编写于
7月 12, 2017
作者:
Q
qijun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
follow comments
上级
ef5f9deb
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
59 addition
and
97 deletion
+59
-97
paddle/platform/cuda_device_context.h
paddle/platform/cuda_device_context.h
+10
-5
paddle/platform/cuda_device_test.cc
paddle/platform/cuda_device_test.cc
+0
-33
paddle/platform/device.h
paddle/platform/device.h
+0
-41
paddle/platform/device_context.h
paddle/platform/device_context.h
+25
-9
paddle/platform/device_context_test.cc
paddle/platform/device_context_test.cc
+24
-9
未找到文件。
paddle/platform/cuda_device.h
→
paddle/platform/cuda_device
_context
.h
浏览文件 @
4d336d90
...
@@ -20,7 +20,6 @@ limitations under the License. */
...
@@ -20,7 +20,6 @@ limitations under the License. */
#include "paddle/platform/dynload/cudnn.h"
#include "paddle/platform/dynload/cudnn.h"
#include "paddle/platform/dynload/curand.h"
#include "paddle/platform/dynload/curand.h"
#define EIGEN_USE_GPU
#define EIGEN_USE_GPU
#include "paddle/platform/device.h"
#include "paddle/platform/place.h"
#include "paddle/platform/place.h"
#include "unsupported/Eigen/CXX11/Tensor"
#include "unsupported/Eigen/CXX11/Tensor"
...
@@ -29,6 +28,13 @@ using DEVICE_GPU = Eigen::GpuDevice;
...
@@ -29,6 +28,13 @@ using DEVICE_GPU = Eigen::GpuDevice;
namespace
paddle
{
namespace
paddle
{
namespace
platform
{
namespace
platform
{
class
CUDADeviceContext
;
template
<
>
DEVICE_GPU
DeviceContext
::
get_eigen_device
<
DEVICE_GPU
>
()
{
return
static_cast
<
CUDADeviceContext
*>
(
this
)
->
eigen_handle
();
}
class
GPUPlaceGuard
{
class
GPUPlaceGuard
{
public:
public:
explicit
GPUPlaceGuard
(
GPUPlace
new_place
)
:
previous_
(
GetCurrentDeviceId
())
{
explicit
GPUPlaceGuard
(
GPUPlace
new_place
)
:
previous_
(
GetCurrentDeviceId
())
{
...
@@ -43,8 +49,7 @@ class GPUPlaceGuard {
...
@@ -43,8 +49,7 @@ class GPUPlaceGuard {
GPUPlace
previous_
;
GPUPlace
previous_
;
};
};
template
<
>
class
CUDADeviceContext
:
public
DeviceContext
{
class
Device
<
DEVICE_GPU
>
{
public:
public:
explicit
Device
(
const
GPUPlace
gpu_place
)
:
gpu_place_
(
gpu_place
)
{
explicit
Device
(
const
GPUPlace
gpu_place
)
:
gpu_place_
(
gpu_place
)
{
GPUPlaceGuard
guard
(
gpu_place_
);
GPUPlaceGuard
guard
(
gpu_place_
);
...
@@ -61,7 +66,7 @@ class Device<DEVICE_GPU> {
...
@@ -61,7 +66,7 @@ class Device<DEVICE_GPU> {
cudaStream_t
stream
()
{
return
stream_
;
}
cudaStream_t
stream
()
{
return
stream_
;
}
DEVICE_GPU
eigen_device
()
{
return
*
eigen_device_
;
}
Eigen
::
GpuDevice
eigen_device
()
{
return
*
eigen_device_
;
}
cublasHandle_t
cublas_handle
()
{
cublasHandle_t
cublas_handle
()
{
if
(
!
blas_handle_
)
{
if
(
!
blas_handle_
)
{
...
@@ -139,7 +144,7 @@ class Device<DEVICE_GPU> {
...
@@ -139,7 +144,7 @@ class Device<DEVICE_GPU> {
cudaStream_t
stream_
;
cudaStream_t
stream_
;
Eigen
::
CudaStreamDevice
*
eigen_stream_
;
Eigen
::
CudaStreamDevice
*
eigen_stream_
;
DEVICE_GPU
*
eigen_device_
;
Eigen
::
GpuDevice
*
eigen_device_
;
cublasHandle_t
blas_handle_
{
nullptr
};
cublasHandle_t
blas_handle_
{
nullptr
};
...
...
paddle/platform/cuda_device_test.cc
已删除
100644 → 0
浏览文件 @
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
已删除
100644 → 0
浏览文件 @
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
浏览文件 @
4d336d90
...
@@ -13,23 +13,39 @@ See the License for the specific language governing permissions and
...
@@ -13,23 +13,39 @@ See the License for the specific language governing permissions and
limitations under the License. */
limitations under the License. */
#pragma once
#pragma once
#include "paddle/framework/enforce.h"
#include "paddle/platform/device.h"
#include "unsupported/Eigen/CXX11/Tensor"
#include "unsupported/Eigen/CXX11/Tensor"
#ifndef PADDLE_ONLY_CPU
#include "paddle/platform/cuda_device.h"
using
DEVICE_CPU
=
Eigen
::
DefaultDevice
;
#endif
namespace
paddle
{
namespace
paddle
{
namespace
platform
{
namespace
platform
{
struct
DeviceContext
{
class
CPUDeviceContext
;
void
*
device_context
{
nullptr
};
class
DeviceContext
{
public:
virtual
~
DeviceContext
()
{}
template
<
typename
DeviceType
>
template
<
typename
DeviceType
>
inline
paddle
::
platform
::
Device
<
DeviceType
>*
device_context
()
{
DeviceType
get_eigen_device
();
return
static_cast
<
paddle
::
platform
::
Device
<
DeviceType
>*>
(
device_context
);
};
template
<
>
DEVICE_CPU
DeviceContext
::
get_eigen_device
<
DEVICE_CPU
>
()
{
return
static_cast
<
CPUDeviceContext
*>
(
this
)
->
eigen_handle
();
}
class
CPUDeviceContext
:
public
DeviceContext
{
public:
Eigen
::
DefaultDevice
eigen_handle
()
{
if
(
!
eigen_handle_
)
{
eigen_handle_
=
new
Eigen
::
DefaultDevice
();
}
return
*
eigen_handle_
;
}
}
private:
Eigen
::
DefaultDevice
*
eigen_handle_
{
nullptr
};
};
};
}
// namespace platform
}
// namespace platform
...
...
paddle/platform/device_context_test.cc
浏览文件 @
4d336d90
...
@@ -12,19 +12,34 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
...
@@ -12,19 +12,34 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
See the License for the specific language governing permissions and
limitations under the License. */
limitations under the License. */
#include "paddle/platform/device_context.h"
#include "gtest/gtest.h"
#include "gtest/gtest.h"
#include "paddle/platform/cuda_device.h"
TEST
(
Device
Context
,
Init
)
{
TEST
(
Device
,
Init
)
{
int
count
=
paddle
::
platform
::
GetDeviceCount
();
int
count
=
paddle
::
platform
::
GetDeviceCount
();
for
(
int
i
=
0
;
i
<
count
;
i
++
)
{
for
(
int
i
=
0
;
i
<
count
;
i
++
)
{
paddle
::
platform
::
Device
<
DEVICE_GPU
>*
device
=
paddle
::
platform
::
DeviceContext
*
device_context
=
new
paddle
::
platform
::
Device
<
DEVICE_GPU
>
(
i
);
new
paddle
::
platform
::
CUDADeviceContext
(
i
);
paddle
::
platform
::
DeviceContext
context
;
context
.
device_context
=
device
;
Eigen
::
GpuDevice
gpu_device
=
Eigen
::
GpuDevice
gpu_device
=
context
.
device_context
<
DEVICE_GPU
>->
eigen_device
();
device_context
->
get_eigen_device
<
DEVICE_GPU
>
();
ASSERT_NE
(
nullptr
,
gpu_device
.
stream
());
ASSERT_NE
(
nullptr
,
gpu_device
.
stream
());
delete
device
;
delete
device
_context
;
}
}
}
}
\ No newline at end of file
TEST
(
Device
,
CUDADeviceContext
)
{
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
();
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
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录