Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
a4024a5f
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
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看板
未验证
提交
a4024a5f
编写于
1月 04, 2018
作者:
D
dzhwinter
提交者:
GitHub
1月 04, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
"remove cudnn devicecontext" (#7207)
* "remove cudnndevicecontext" * "remove unused init code" * "fix hash functions"
上级
cd5fad13
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
22 addition
and
71 deletion
+22
-71
doc/design/support_new_device.md
doc/design/support_new_device.md
+2
-12
paddle/framework/library_type.h
paddle/framework/library_type.h
+4
-0
paddle/framework/op_kernel_type.h
paddle/framework/op_kernel_type.h
+6
-7
paddle/platform/device_context.cc
paddle/platform/device_context.cc
+9
-17
paddle/platform/device_context.h
paddle/platform/device_context.h
+1
-13
paddle/platform/device_context_test.cu
paddle/platform/device_context_test.cu
+0
-15
python/paddle/v2/fluid/executor.py
python/paddle/v2/fluid/executor.py
+0
-7
未找到文件。
doc/design/support_new_device.md
浏览文件 @
a4024a5f
...
@@ -48,8 +48,8 @@ Fluid uses class [DeviceContext](https://github.com/PaddlePaddle/Paddle/blob/dev
...
@@ -48,8 +48,8 @@ Fluid uses class [DeviceContext](https://github.com/PaddlePaddle/Paddle/blob/dev
```
```
/-> CPUDeviceContext
--> MKLDeviceContext
/-> CPUDeviceContext
DeviceContext ----> CUDADeviceContext
--> CUDNNDeviceContext
DeviceContext ----> CUDADeviceContext
\-> FPGADeviceContext
\-> FPGADeviceContext
```
```
...
@@ -79,16 +79,6 @@ private:
...
@@ -79,16 +79,6 @@ private:
};
};
```
```
-
CUDNNDeviceContext
```
class CUDNNDeviceContext : public CUDADeviceContext {
private:
cudnnHandle_t cudnn_handle_;
};
```
### Memory and Tensor
### Memory and Tensor
...
...
paddle/framework/library_type.h
浏览文件 @
a4024a5f
...
@@ -13,6 +13,7 @@ See the License for the specific language governing permissions and
...
@@ -13,6 +13,7 @@ See the License for the specific language governing permissions and
limitations under the License. */
limitations under the License. */
#pragma once
#pragma once
#include <cctype>
namespace
paddle
{
namespace
paddle
{
namespace
framework
{
namespace
framework
{
...
@@ -41,6 +42,9 @@ inline std::string LibraryTypeToString(const LibraryType& library_type) {
...
@@ -41,6 +42,9 @@ inline std::string LibraryTypeToString(const LibraryType& library_type) {
inline
LibraryType
StringToLibraryType
(
const
char
*
ctype
)
{
inline
LibraryType
StringToLibraryType
(
const
char
*
ctype
)
{
std
::
string
s
(
ctype
);
std
::
string
s
(
ctype
);
for
(
size_t
i
=
0
;
i
<
s
.
size
();
++
i
)
{
s
[
i
]
=
toupper
(
s
[
i
]);
}
if
(
s
==
std
::
string
(
"PLAIN"
))
{
if
(
s
==
std
::
string
(
"PLAIN"
))
{
return
LibraryType
::
kPlain
;
return
LibraryType
::
kPlain
;
}
else
if
(
s
==
std
::
string
(
"MKLDNN"
))
{
}
else
if
(
s
==
std
::
string
(
"MKLDNN"
))
{
...
...
paddle/framework/op_kernel_type.h
浏览文件 @
a4024a5f
...
@@ -26,13 +26,12 @@ namespace framework {
...
@@ -26,13 +26,12 @@ namespace framework {
struct
OpKernelType
{
struct
OpKernelType
{
struct
Hash
{
struct
Hash
{
size_t
operator
()(
const
OpKernelType
&
key
)
const
{
size_t
operator
()(
const
OpKernelType
&
key
)
const
{
int
place
=
key
.
place_
.
which
()
+
(
1
<<
LEFT_SHIFT
);
int
place
=
key
.
place_
.
which
();
int
data_type
=
int
data_type
=
static_cast
<
int
>
(
key
.
data_type_
)
<<
LEFT_SHIFT
;
static_cast
<
int
>
(
key
.
data_type_
)
+
(
1
<<
(
LEFT_SHIFT
+
1
));
int
data_layout
=
static_cast
<
int
>
(
key
.
data_layout_
)
<<
(
LEFT_SHIFT
*
2
);
int
data_layout
=
int
library_type
=
static_cast
<
int
>
(
key
.
library_type_
)
static_cast
<
int
>
(
key
.
data_layout_
)
+
(
1
<<
(
LEFT_SHIFT
+
2
));
<<
(
LEFT_SHIFT
*
3
);
int
library_type
=
static_cast
<
int
>
(
key
.
library_type_
)
+
(
1
<<
(
LEFT_SHIFT
+
3
));
std
::
hash
<
int
>
hasher
;
std
::
hash
<
int
>
hasher
;
return
hasher
(
place
+
data_type
+
data_layout
+
library_type
);
return
hasher
(
place
+
data_type
+
data_layout
+
library_type
);
}
}
...
...
paddle/platform/device_context.cc
浏览文件 @
a4024a5f
...
@@ -127,15 +127,21 @@ CUDADeviceContext::CUDADeviceContext(CUDAPlace place) : place_(place) {
...
@@ -127,15 +127,21 @@ CUDADeviceContext::CUDADeviceContext(CUDAPlace place) : place_(place) {
eigen_device_
.
reset
(
new
Eigen
::
GpuDevice
(
eigen_stream_
.
get
()));
eigen_device_
.
reset
(
new
Eigen
::
GpuDevice
(
eigen_stream_
.
get
()));
PADDLE_ENFORCE
(
dynload
::
cublasCreate
(
&
cublas_handle_
));
PADDLE_ENFORCE
(
dynload
::
cublasCreate
(
&
cublas_handle_
));
PADDLE_ENFORCE
(
dynload
::
cublasSetStream
(
cublas_handle_
,
stream_
));
PADDLE_ENFORCE
(
dynload
::
cublasSetStream
(
cublas_handle_
,
stream_
));
if
(
dynload
::
HasCUDNN
())
{
PADDLE_ENFORCE
(
dynload
::
cudnnCreate
(
&
cudnn_handle_
));
PADDLE_ENFORCE
(
dynload
::
cudnnCreate
(
&
cudnn_handle_
));
PADDLE_ENFORCE
(
dynload
::
cudnnSetStream
(
cudnn_handle_
,
stream_
));
PADDLE_ENFORCE
(
dynload
::
cudnnSetStream
(
cudnn_handle_
,
stream_
));
}
else
{
cudnn_handle_
=
nullptr
;
}
}
}
CUDADeviceContext
::~
CUDADeviceContext
()
{
CUDADeviceContext
::~
CUDADeviceContext
()
{
SetDeviceId
(
place_
.
device
);
SetDeviceId
(
place_
.
device
);
Wait
();
Wait
();
PADDLE_ENFORCE
(
dynload
::
cublasDestroy
(
cublas_handle_
));
PADDLE_ENFORCE
(
dynload
::
cublasDestroy
(
cublas_handle_
));
if
(
cudnn_handle_
!=
nullptr
)
{
PADDLE_ENFORCE
(
dynload
::
cudnnDestroy
(
cudnn_handle_
));
PADDLE_ENFORCE
(
dynload
::
cudnnDestroy
(
cudnn_handle_
));
}
eigen_stream_
.
reset
();
eigen_stream_
.
reset
();
eigen_device_
.
reset
();
eigen_device_
.
reset
();
PADDLE_ENFORCE
(
cudaStreamDestroy
(
stream_
));
PADDLE_ENFORCE
(
cudaStreamDestroy
(
stream_
));
...
@@ -160,20 +166,6 @@ cudnnHandle_t CUDADeviceContext::cudnn_handle() const { return cudnn_handle_; }
...
@@ -160,20 +166,6 @@ cudnnHandle_t CUDADeviceContext::cudnn_handle() const { return cudnn_handle_; }
cudaStream_t
CUDADeviceContext
::
stream
()
const
{
return
stream_
;
}
cudaStream_t
CUDADeviceContext
::
stream
()
const
{
return
stream_
;
}
CUDNNDeviceContext
::
CUDNNDeviceContext
(
CUDAPlace
place
)
:
CUDADeviceContext
(
place
)
{
PADDLE_ENFORCE
(
dynload
::
cudnnCreate
(
&
cudnn_handle_
));
PADDLE_ENFORCE
(
dynload
::
cudnnSetStream
(
cudnn_handle_
,
stream
()));
}
CUDNNDeviceContext
::~
CUDNNDeviceContext
()
{
SetDeviceId
(
boost
::
get
<
CUDAPlace
>
(
GetPlace
()).
device
);
Wait
();
PADDLE_ENFORCE
(
dynload
::
cudnnDestroy
(
cudnn_handle_
));
}
cudnnHandle_t
CUDNNDeviceContext
::
cudnn_handle
()
const
{
return
cudnn_handle_
;
}
#endif
#endif
}
// namespace platform
}
// namespace platform
...
...
paddle/platform/device_context.h
浏览文件 @
a4024a5f
...
@@ -103,18 +103,6 @@ struct DefaultDeviceContextType<platform::CUDAPlace> {
...
@@ -103,18 +103,6 @@ struct DefaultDeviceContextType<platform::CUDAPlace> {
using
TYPE
=
CUDADeviceContext
;
using
TYPE
=
CUDADeviceContext
;
};
};
class
CUDNNDeviceContext
:
public
CUDADeviceContext
{
public:
explicit
CUDNNDeviceContext
(
CUDAPlace
place
);
virtual
~
CUDNNDeviceContext
();
/*! \brief Return cudnn handle in the device context. */
cudnnHandle_t
cudnn_handle
()
const
;
private:
cudnnHandle_t
cudnn_handle_
;
};
#endif
#endif
/*! \brief device context pool singleton */
/*! \brief device context pool singleton */
...
@@ -151,7 +139,7 @@ class DeviceContextPool {
...
@@ -151,7 +139,7 @@ class DeviceContextPool {
struct
Hash
{
struct
Hash
{
std
::
hash
<
int
>
hash_
;
std
::
hash
<
int
>
hash_
;
size_t
operator
()(
const
platform
::
Place
&
place
)
const
{
size_t
operator
()(
const
platform
::
Place
&
place
)
const
{
int
pre_hash
=
place
.
which
()
+
(
1
<<
LEFT_SHIFT
)
;
int
pre_hash
=
place
.
which
()
<<
LEFT_SHIFT
;
if
(
platform
::
is_gpu_place
(
place
))
{
if
(
platform
::
is_gpu_place
(
place
))
{
pre_hash
+=
boost
::
get
<
platform
::
CUDAPlace
>
(
place
).
GetDeviceId
();
pre_hash
+=
boost
::
get
<
platform
::
CUDAPlace
>
(
place
).
GetDeviceId
();
}
}
...
...
paddle/platform/device_context_test.cu
浏览文件 @
a4024a5f
...
@@ -49,21 +49,6 @@ TEST(Device, CUDADeviceContext) {
...
@@ -49,21 +49,6 @@ TEST(Device, CUDADeviceContext) {
}
}
}
}
TEST
(
Device
,
CUDNNDeviceContext
)
{
using
paddle
::
platform
::
CUDNNDeviceContext
;
using
paddle
::
platform
::
CUDAPlace
;
if
(
paddle
::
platform
::
dynload
::
HasCUDNN
())
{
int
count
=
paddle
::
platform
::
GetCUDADeviceCount
();
for
(
int
i
=
0
;
i
<
count
;
++
i
)
{
CUDNNDeviceContext
*
device_context
=
new
CUDNNDeviceContext
(
CUDAPlace
(
i
));
cudnnHandle_t
cudnn_handle
=
device_context
->
cudnn_handle
();
ASSERT_NE
(
nullptr
,
cudnn_handle
);
ASSERT_NE
(
nullptr
,
device_context
->
stream
());
delete
device_context
;
}
}
}
TEST
(
Device
,
DeviceContextPool
)
{
TEST
(
Device
,
DeviceContextPool
)
{
using
paddle
::
platform
::
DeviceContextPool
;
using
paddle
::
platform
::
DeviceContextPool
;
using
paddle
::
platform
::
CUDADeviceContext
;
using
paddle
::
platform
::
CUDADeviceContext
;
...
...
python/paddle/v2/fluid/executor.py
浏览文件 @
a4024a5f
...
@@ -65,13 +65,6 @@ class Executor(object):
...
@@ -65,13 +65,6 @@ class Executor(object):
p
.
set_place
(
each
)
p
.
set_place
(
each
)
act_places
.
append
(
p
)
act_places
.
append
(
p
)
# TODO(dzhwinter) : consider that our fluid tests all written in
# CUDAPlace(gpu_id), this will be changed in the future
if
core
.
is_compile_gpu
():
core
.
init_devices
([
"CPU"
,
"GPU:0"
])
else
:
core
.
init_devices
([
"CPU"
])
# TODO(dzhwinter) : only use the first place
# TODO(dzhwinter) : only use the first place
self
.
executor
=
core
.
Executor
(
act_places
[
0
])
self
.
executor
=
core
.
Executor
(
act_places
[
0
])
self
.
places
=
places
self
.
places
=
places
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录