Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
ea42e431
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看板
未验证
提交
ea42e431
编写于
4月 22, 2019
作者:
Q
qingqing01
提交者:
GitHub
4月 22, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Speed unit testing. (#16978)
* Speed affine_channel_op unit testing * Add check in tensor_py * Fix ONLY_CPU Compiling
上级
ae7a2cb8
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
38 addition
and
15 deletion
+38
-15
paddle/fluid/operators/affine_channel_op.cu
paddle/fluid/operators/affine_channel_op.cu
+4
-1
paddle/fluid/pybind/tensor_py.h
paddle/fluid/pybind/tensor_py.h
+19
-11
python/paddle/fluid/tests/unittests/test_affine_channel_op.py
...on/paddle/fluid/tests/unittests/test_affine_channel_op.py
+15
-3
未找到文件。
paddle/fluid/operators/affine_channel_op.cu
浏览文件 @
ea42e431
...
...
@@ -65,6 +65,9 @@ class AffineChannelCUDAKernel : public framework::OpKernel<T> {
int
block
=
1024
;
int
grid
=
(
num
+
block
-
1
)
/
block
;
int
max_threads
=
dev_ctx
.
GetMaxPhysicalThreadCount
();
grid
=
std
::
min
(
std
::
max
(
max_threads
/
block
,
1
),
grid
);
if
(
layout
==
framework
::
DataLayout
::
kNCHW
)
{
KeAffineChannelCUDA
<
T
,
framework
::
DataLayout
::
kNCHW
,
true
><<<
grid
,
block
,
0
,
dev_ctx
.
stream
()
>>>
(
...
...
@@ -162,7 +165,7 @@ class AffineChannelGradCUDAKernel : public framework::OpKernel<T> {
}
}
else
{
if
(
dx
)
{
KeAffineChannelCUDA
<
T
,
framework
::
DataLayout
::
kN
CHW
,
KeAffineChannelCUDA
<
T
,
framework
::
DataLayout
::
kN
HWC
,
false
><<<
grid1
,
block
,
0
,
dev_ctx
.
stream
()
>>>
(
dy_d
,
s_d
,
nullptr
,
C
,
HxW
,
num
,
dx_d
);
}
...
...
paddle/fluid/pybind/tensor_py.h
浏览文件 @
ea42e431
...
...
@@ -138,25 +138,33 @@ inline pybind11::buffer_info CastToPyBuffer(const framework::Tensor &tensor) {
template
<
typename
T
>
T
TensorGetElement
(
const
framework
::
Tensor
&
self
,
size_t
offset
)
{
PADDLE_ENFORCE_LT
(
offset
,
self
.
numel
());
T
b
=
static_cast
<
T
>
(
0
);
if
(
platform
::
is_cpu_place
(
self
.
place
()))
{
return
self
.
data
<
T
>
()[
offset
];
b
=
self
.
data
<
T
>
()[
offset
];
#ifdef PADDLE_WITH_CUDA
}
else
{
std
::
shared_ptr
<
framework
::
Tensor
>
dst
(
new
framework
::
Tensor
);
framework
::
TensorCopySync
(
self
,
platform
::
CPUPlace
(),
dst
.
get
());
return
dst
->
data
<
T
>
()[
offset
];
const
T
*
a
=
self
.
data
<
T
>
();
auto
p
=
boost
::
get
<
platform
::
CUDAPlace
>
(
self
.
place
());
paddle
::
memory
::
Copy
(
platform
::
CPUPlace
(),
&
b
,
p
,
a
+
offset
,
sizeof
(
T
),
nullptr
);
#endif
}
return
b
;
}
// TODO(dzhwinter) : fix the redundant Tensor allocate and free
template
<
typename
T
>
void
TensorSetElement
(
framework
::
Tensor
*
self
,
size_t
offset
,
T
elem
)
{
if
(
platform
::
is_gpu_place
(
self
->
place
()))
{
framework
::
Tensor
dst
;
framework
::
TensorCopySync
(
*
self
,
platform
::
CPUPlace
(),
&
dst
);
dst
.
mutable_data
<
T
>
(
platform
::
CPUPlace
())[
offset
]
=
elem
;
framework
::
TensorCopySync
(
dst
,
self
->
place
(),
self
);
}
else
if
(
platform
::
is_cpu_place
(
self
->
place
()))
{
PADDLE_ENFORCE_LT
(
offset
,
self
->
numel
());
if
(
platform
::
is_cpu_place
(
self
->
place
()))
{
self
->
mutable_data
<
T
>
(
self
->
place
())[
offset
]
=
elem
;
#ifdef PADDLE_WITH_CUDA
}
else
{
auto
p
=
boost
::
get
<
platform
::
CUDAPlace
>
(
self
->
place
());
T
*
a
=
self
->
mutable_data
<
T
>
(
p
);
paddle
::
memory
::
Copy
(
p
,
a
+
offset
,
platform
::
CPUPlace
(),
&
elem
,
sizeof
(
T
),
nullptr
);
#endif
}
}
...
...
python/paddle/fluid/tests/unittests/test_affine_channel_op.py
浏览文件 @
ea42e431
...
...
@@ -70,6 +70,12 @@ class TestAffineChannelNHWC(TestAffineChannelOp):
self
.
C
=
32
self
.
layout
=
'NHWC'
def
test_check_grad_stopgrad_dx
(
self
):
return
def
test_check_grad_stopgrad_dscale_dbias
(
self
):
return
class
TestAffineChannel2D
(
TestAffineChannelOp
):
def
init_test_case
(
self
):
...
...
@@ -77,10 +83,16 @@ class TestAffineChannel2D(TestAffineChannelOp):
self
.
C
=
64
self
.
layout
=
'NCHW'
def
test_check_grad_stopgrad_dx
(
self
):
return
def
test_check_grad_stopgrad_dscale_dbias
(
self
):
return
class
TestAffineChannelNCHWLargeShape
(
TestAffineChannelOp
):
def
init_test_case
(
self
):
self
.
shape
=
[
6
4
,
128
,
112
,
112
]
self
.
shape
=
[
4
,
128
,
112
,
112
]
self
.
C
=
128
self
.
layout
=
'NCHW'
...
...
@@ -95,9 +107,9 @@ class TestAffineChannelNCHWLargeShape(TestAffineChannelOp):
pass
class
TestAffineChannelN
CHW
LargeShape
(
TestAffineChannelNCHWLargeShape
):
class
TestAffineChannelN
HWC
LargeShape
(
TestAffineChannelNCHWLargeShape
):
def
init_test_case
(
self
):
self
.
shape
=
[
64
,
112
,
11
2
,
512
]
self
.
shape
=
[
64
,
32
,
3
2
,
512
]
self
.
C
=
512
self
.
layout
=
'NHWC'
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录