Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wmsofts
Paddle
提交
4a1f7bd2
P
Paddle
项目概览
wmsofts
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4a1f7bd2
编写于
7月 31, 2017
作者:
Q
qijun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add gpu python op test
上级
47d8bca8
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
70 addition
and
47 deletion
+70
-47
paddle/framework/detail/tensor-inl.h
paddle/framework/detail/tensor-inl.h
+5
-3
paddle/platform/enforce.h
paddle/platform/enforce.h
+6
-6
paddle/pybind/pybind.cc
paddle/pybind/pybind.cc
+24
-9
python/paddle/v2/framework/tests/op_test_util.py
python/paddle/v2/framework/tests/op_test_util.py
+34
-28
python/paddle/v2/framework/tests/test_fc_op.py
python/paddle/v2/framework/tests/test_fc_op.py
+1
-1
未找到文件。
paddle/framework/detail/tensor-inl.h
浏览文件 @
4a1f7bd2
...
...
@@ -13,7 +13,7 @@ See the License for the specific language governing permissions and
limitations under the License. */
#pragma once
#include <string>
#include "paddle/memory/memcpy.h"
namespace
paddle
{
...
...
@@ -62,9 +62,11 @@ inline T* Tensor::mutable_data(platform::Place place) {
if
(
platform
::
is_cpu_place
(
place
))
{
holder_
.
reset
(
new
PlaceholderImpl
<
T
,
platform
::
CPUPlace
>
(
boost
::
get
<
platform
::
CPUPlace
>
(
place
),
size
));
}
else
if
(
platform
::
is_gpu_place
(
place
))
{
#ifdef PADDLE_ONLY_CPU
PADDLE_THROW
(
"'GPUPlace' is not supported in CPU only device."
);
}
#ifndef PADDLE_ONLY_CPU
else
if
(
platform
::
is_gpu_place
(
place
))
{
#else
holder_
.
reset
(
new
PlaceholderImpl
<
T
,
platform
::
GPUPlace
>
(
boost
::
get
<
platform
::
GPUPlace
>
(
place
),
size
));
}
...
...
paddle/platform/enforce.h
浏览文件 @
4a1f7bd2
...
...
@@ -132,12 +132,12 @@ inline void throw_on_error(T e) {
throw_on_error
(
e
,
""
);
}
#define PADDLE_THROW(...) \
do { \
throw ::paddle::platform::EnforceNotMet( \
std::make_exception_ptr( \
std::runtime_error(string::Sprintf(__VA_ARGS__))), \
__FILE__, __LINE__); \
#define PADDLE_THROW(...)
\
do {
\
throw ::paddle::platform::EnforceNotMet(
\
std::make_exception_ptr(
\
std::runtime_error(
paddle::
string::Sprintf(__VA_ARGS__))), \
__FILE__, __LINE__);
\
} while (0)
#define PADDLE_ENFORCE(...) \
...
...
paddle/pybind/pybind.cc
浏览文件 @
4a1f7bd2
...
...
@@ -56,6 +56,14 @@ static size_t UniqueIntegerGenerator() {
return
generator
.
fetch_add
(
1
);
}
bool
IsCompileGPU
()
{
#ifdef PADDLE_ONLY_CPU
return
false
;
#else
return
true
;
#endif
}
PYBIND11_PLUGIN
(
core
)
{
py
::
module
m
(
"core"
,
"C++ core of PaddlePaddle"
);
...
...
@@ -148,18 +156,23 @@ All parameter, weight, gradient are variables in Paddle.
.
def
(
"temp"
,
pd
::
OperatorBase
::
TMP_VAR_NAME
);
py
::
class_
<
paddle
::
platform
::
DeviceContext
>
(
m
,
"DeviceContext"
)
.
def_static
(
"cpu_context"
,
[]()
->
paddle
::
platform
::
DeviceContext
*
{
return
new
paddle
::
platform
::
CPUDeviceContext
();
})
#ifndef PADDLE_ONLY_CPU
.
def_static
(
"gpu_context"
,
[](
paddle
::
platform
::
GPUPlace
&
place
)
.
def_static
(
"create"
,
[](
paddle
::
platform
::
CPUPlace
&
place
)
->
paddle
::
platform
::
DeviceContext
*
{
return
new
paddle
::
platform
::
C
UDADeviceContext
(
place
);
return
new
paddle
::
platform
::
C
PUDeviceContext
(
);
})
.
def_static
(
"create"
,
[](
paddle
::
platform
::
GPUPlace
&
place
)
->
paddle
::
platform
::
DeviceContext
*
{
#ifdef PADDLE_ONLY_CPU
PADDLE_THROW
(
"'GPUPlace' is not supported in CPU only device."
);
#else
return
new
paddle
::
platform
::
CUDADeviceContext
(
place
);
#endif
;
// NOLINT
});
py
::
class_
<
paddle
::
platform
::
GPUPlace
>
(
m
,
"GPUPlace"
).
def
(
py
::
init
<
int
>
());
py
::
class_
<
paddle
::
platform
::
CPUPlace
>
(
m
,
"CPUPlace"
).
def
(
py
::
init
<>
());
...
...
@@ -198,5 +211,7 @@ All parameter, weight, gradient are variables in Paddle.
m
.
def
(
"unique_integer"
,
UniqueIntegerGenerator
);
m
.
def
(
"is_compile_gpu"
,
IsCompileGPU
);
return
m
.
ptr
();
}
python/paddle/v2/framework/tests/op_test_util.py
浏览文件 @
4a1f7bd2
...
...
@@ -25,42 +25,48 @@ class OpTestMeta(type):
self
.
assertIsNotNone
(
func
)
scope
=
core
.
Scope
(
None
)
place
=
core
.
CPUPlace
()
kwargs
=
dict
()
for
in_name
in
func
.
all_input_args
:
if
hasattr
(
self
,
in_name
):
kwargs
[
in_name
]
=
in_name
var
=
scope
.
create_var
(
in_name
).
get_tensor
()
arr
=
getattr
(
self
,
in_name
)
var
.
set_dims
(
arr
.
shape
)
var
.
set
(
arr
,
place
)
else
:
kwargs
[
in_name
]
=
"@EMPTY@"
places
=
[]
places
.
append
(
core
.
CPUPlace
())
if
core
.
is_compile_gpu
():
places
.
append
(
core
.
GPUPlace
(
0
))
for
place
in
places
:
for
in_name
in
func
.
all_input_args
:
if
hasattr
(
self
,
in_name
):
kwargs
[
in_name
]
=
in_name
var
=
scope
.
create_var
(
in_name
).
get_tensor
()
arr
=
getattr
(
self
,
in_name
)
var
.
set_dims
(
arr
.
shape
)
var
.
set
(
arr
,
place
)
else
:
kwargs
[
in_name
]
=
"@EMPTY@"
for
out_name
in
func
.
all_output_args
:
if
hasattr
(
self
,
out_name
):
kwargs
[
out_name
]
=
out_name
scope
.
create_var
(
out_name
).
get_tensor
()
for
out_name
in
func
.
all_output_args
:
if
hasattr
(
self
,
out_name
):
kwargs
[
out_name
]
=
out_name
scope
.
create_var
(
out_name
).
get_tensor
()
for
attr_name
in
func
.
all_attr_args
:
if
hasattr
(
self
,
attr_name
):
kwargs
[
attr_name
]
=
getattr
(
self
,
attr_name
)
for
attr_name
in
func
.
all_attr_args
:
if
hasattr
(
self
,
attr_name
):
kwargs
[
attr_name
]
=
getattr
(
self
,
attr_name
)
op
=
func
(
**
kwargs
)
op
=
func
(
**
kwargs
)
op
.
infer_shape
(
scope
)
op
.
infer_shape
(
scope
)
ctx
=
core
.
DeviceContext
.
cpu_context
(
)
op
.
run
(
scope
,
ctx
)
ctx
=
core
.
DeviceContext
.
create
(
place
)
op
.
run
(
scope
,
ctx
)
for
out_name
in
func
.
all_output_args
:
actual
=
numpy
.
array
(
scope
.
get_var
(
out_name
).
get_tensor
())
expect
=
getattr
(
self
,
out_name
)
# TODO(qijun) The default decimal is 7, but numpy.dot and eigen.mul
# has some diff, and could not pass unittest. So I set decimal 3 here.
# And I will check this in future.
numpy
.
testing
.
assert_almost_equal
(
actual
,
expect
,
decimal
=
3
)
for
out_name
in
func
.
all_output_args
:
actual
=
numpy
.
array
(
scope
.
get_var
(
out_name
).
get_tensor
())
expect
=
getattr
(
self
,
out_name
)
# TODO(qijun) The default decimal is 7, but numpy.dot and eigen.mul
# has some diff, and could not pass unittest. So I set decimal 3 here.
# And I will check this in future.
numpy
.
testing
.
assert_almost_equal
(
actual
,
expect
,
decimal
=
3
)
obj
.
test_all
=
test_all
return
obj
python/paddle/v2/framework/tests/test_fc_op.py
浏览文件 @
4a1f7bd2
...
...
@@ -33,7 +33,7 @@ class TestFc(unittest.TestCase):
op
.
infer_shape
(
scope
)
self
.
assertEqual
([
1000
,
100
],
tensor
.
shape
())
ctx
=
core
.
DeviceContext
.
c
pu_context
(
)
ctx
=
core
.
DeviceContext
.
c
reate
(
place
)
op
.
run
(
scope
,
ctx
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录