Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
PaddleDetection
提交
ae9378f6
P
PaddleDetection
项目概览
s920243400
/
PaddleDetection
与 Fork 源项目一致
Fork自
PaddlePaddle / PaddleDetection
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
ae9378f6
编写于
9月 29, 2018
作者:
Y
Yu Yang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refine PyBind
上级
a1a01899
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
42 addition
and
12 deletion
+42
-12
paddle/fluid/pybind/tensor_py.h
paddle/fluid/pybind/tensor_py.h
+39
-9
python/paddle/fluid/tests/unittests/test_conv2d_op.py
python/paddle/fluid/tests/unittests/test_conv2d_op.py
+3
-3
未找到文件。
paddle/fluid/pybind/tensor_py.h
浏览文件 @
ae9378f6
...
...
@@ -14,6 +14,7 @@ limitations under the License. */
#pragma once
#include <Python.h>
#include <cmake-build-release/third_party/pybind/src/extern_pybind/include/pybind11/common.h>
#include <string>
#include <tuple>
#include <vector>
...
...
@@ -57,7 +58,8 @@ struct CastToPyBufferImpl<true, I, ARGS...> {
prod
*=
dims_outside
[
i
-
1
];
}
framework
::
Tensor
dst_tensor
;
if
(
paddle
::
platform
::
is_gpu_place
(
tensor
.
place
()))
{
bool
is_gpu
=
paddle
::
platform
::
is_gpu_place
(
tensor
.
place
());
if
(
is_gpu
)
{
#ifdef PADDLE_WITH_CUDA
auto
*
src_ptr
=
static_cast
<
const
void
*>
(
tensor
.
data
<
CUR_TYPE
>
());
auto
*
dst_ptr
=
static_cast
<
void
*>
(
dst_tensor
.
mutable_data
<
CUR_TYPE
>
(
...
...
@@ -74,16 +76,44 @@ struct CastToPyBufferImpl<true, I, ARGS...> {
dst_tensor
=
tensor
;
}
if
(
std
::
type_index
(
typeid
(
CUR_TYPE
))
==
std
::
type_index
(
typeid
(
platform
::
float16
)))
{
return
pybind11
::
buffer_info
(
dst_tensor
.
data
<
CUR_TYPE
>
(),
sizeof
(
CUR_TYPE
),
"e"
,
/* np.dtype('e') == np.float16 */
(
size_t
)
framework
::
arity
(
dst_tensor
.
dims
()),
dims_outside
,
strides
);
std
::
string
dtype
=
std
::
type_index
(
typeid
(
CUR_TYPE
))
==
std
::
type_index
(
typeid
(
platform
::
float16
))
?
std
::
string
(
"e"
)
// np.dtype('e') == np.float16
:
pybind11
::
format_descriptor
<
CUR_TYPE
>::
format
();
if
(
is_gpu
)
{
// manually construct a py_buffer if is_gpu since gpu data is copied
// into CPU.
// TODO(yy): Is these following code memleak?
Py_buffer
*
py_buffer
=
reinterpret_cast
<
Py_buffer
*>
(
malloc
(
sizeof
(
Py_buffer
)));
py_buffer
->
format
=
strdup
(
dtype
.
c_str
());
py_buffer
->
itemsize
=
sizeof
(
CUR_TYPE
);
py_buffer
->
ndim
=
framework
::
arity
(
dst_tensor
.
dims
());
py_buffer
->
len
=
tensor
.
numel
();
py_buffer
->
strides
=
reinterpret_cast
<
Py_ssize_t
*>
(
malloc
(
sizeof
(
Py_ssize_t
)
*
strides
.
size
()));
for
(
size_t
i
=
0
;
i
<
strides
.
size
();
++
i
)
{
py_buffer
->
strides
[
i
]
=
strides
[
i
];
}
py_buffer
->
shape
=
reinterpret_cast
<
Py_ssize_t
*>
(
malloc
(
sizeof
(
Py_ssize_t
)
*
tensor
.
dims
().
size
()));
for
(
size_t
i
=
0
;
i
<
tensor
.
dims
().
size
();
++
i
)
{
py_buffer
->
shape
[
i
]
=
tensor
.
dims
()[
i
];
}
py_buffer
->
readonly
=
false
;
py_buffer
->
suboffsets
=
nullptr
;
py_buffer
->
obj
=
nullptr
;
py_buffer
->
buf
=
malloc
(
static_cast
<
size_t
>
(
py_buffer
->
len
*
py_buffer
->
itemsize
));
memcpy
(
py_buffer
->
buf
,
dst_tensor
.
data
<
CUR_TYPE
>
(),
static_cast
<
size_t
>
(
py_buffer
->
len
*
py_buffer
->
itemsize
));
return
pybind11
::
buffer_info
(
py_buffer
,
true
);
}
else
{
return
pybind11
::
buffer_info
(
dst_tensor
.
data
<
CUR_TYPE
>
(),
sizeof
(
CUR_TYPE
),
pybind11
::
format_descriptor
<
CUR_TYPE
>::
format
(),
dst_tensor
.
data
<
CUR_TYPE
>
(),
sizeof
(
CUR_TYPE
),
dtype
,
(
size_t
)
framework
::
arity
(
dst_tensor
.
dims
()),
dims_outside
,
strides
);
}
}
else
{
...
...
python/paddle/fluid/tests/unittests/test_conv2d_op.py
浏览文件 @
ae9378f6
...
...
@@ -289,9 +289,9 @@ class TestFP16CUDNNWithGroup(TestWithGroup):
self
.
check_output_with_place
(
place
,
atol
=
2e-2
)
#
class TestCUDNNWith1x1(TestWith1x1):
#
def init_kernel_type(self):
#
self.use_cudnn = True
class
TestCUDNNWith1x1
(
TestWith1x1
):
def
init_kernel_type
(
self
):
self
.
use_cudnn
=
True
class
TestFP16CUDNNWith1x1
(
TestWith1x1
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录