Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
b2075351
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看板
提交
b2075351
编写于
11月 11, 2016
作者:
W
wangyang59
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add setUseGpu in PaddleAPI.h and handle UnsupportedError in swig with meaningful message displayed
上级
91e6dcb6
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
46 addition
and
25 deletion
+46
-25
paddle/api/Matrix.cpp
paddle/api/Matrix.cpp
+2
-4
paddle/api/Paddle.swig
paddle/api/Paddle.swig
+14
-0
paddle/api/PaddleAPI.h
paddle/api/PaddleAPI.h
+12
-7
paddle/api/Util.cpp
paddle/api/Util.cpp
+2
-0
paddle/api/Vector.cpp
paddle/api/Vector.cpp
+4
-8
paddle/api/test/testMatrix.py
paddle/api/test/testMatrix.py
+6
-2
paddle/api/test/testVector.py
paddle/api/test/testVector.py
+6
-4
未找到文件。
paddle/api/Matrix.cpp
浏览文件 @
b2075351
...
...
@@ -53,13 +53,11 @@ Matrix* Matrix::createDense(const std::vector<float>& data, size_t height,
}
Matrix
*
Matrix
::
createDenseFromNumpy
(
float
*
data
,
int
dim1
,
int
dim2
,
bool
copy
,
bool
useGpu
)
throw
(
UnsupportError
)
{
bool
copy
,
bool
useGpu
)
{
if
(
useGpu
)
{
/// Gpu mode only supports copy=True
if
(
!
copy
)
{
UnsupportError
e
;
throw
e
;
throw
UnsupportError
(
"Gpu mode only supports copy=True"
);
}
return
Matrix
::
createGpuDenseFromNumpy
(
data
,
dim1
,
dim2
);
}
else
{
...
...
paddle/api/Paddle.swig
浏览文件 @
b2075351
...
...
@@ -4,6 +4,20 @@
#define SWIG_FILE_WITH_INIT
#include "api/PaddleAPI.h"
%}
%include "exception.i"
%exception{
try{
$action
}
catch(UnsupportError &ex ){
SWIG_exception(SWIG_RuntimeError, ex.what());
}
catch( ... ){
SWIG_fail;
}
}
%include "std_vector.i"
%include "std_pair.i"
#ifdef SWIGPYTHON
...
...
paddle/api/PaddleAPI.h
浏览文件 @
b2075351
...
...
@@ -18,6 +18,7 @@ limitations under the License. */
#include <stddef.h>
#include <stdint.h>
#include <string>
#include <stdexcept>
#include <vector>
#include "paddle/utils/GlobalConstants.h"
#include "paddle/utils/TypeDefs.h"
...
...
@@ -45,6 +46,9 @@ void initPaddle(int argc, char** argv);
/// Return FLAGS_use_gpu
bool
isUsingGpu
();
/// Set the Flags_use_gpu to the given parameter
void
setUseGpu
(
bool
useGpu
);
/// Return true if this py_paddle is compiled in GPU Version
bool
isGpuVersion
();
...
...
@@ -55,7 +59,11 @@ class IOError {};
class
RangeError
{};
/// Not support Error, such as access GPU memory directly, etc.
class
UnsupportError
{};
class
UnsupportError
:
public
std
::
runtime_error
{
public:
UnsupportError
()
:
std
::
runtime_error
(
" "
)
{};
UnsupportError
(
const
std
::
string
&
message
)
:
std
::
runtime_error
(
message
)
{};
};
/// This type will map to python's list of float.
struct
FloatArray
{
...
...
@@ -131,8 +139,7 @@ public:
static
Matrix
*
createDenseFromNumpy
(
float
*
data
,
int
dim1
,
int
dim2
,
bool
copy
=
true
,
bool
useGpu
=
isUsingGpu
())
throw
(
UnsupportError
)
;
bool
useGpu
=
isUsingGpu
());
/**
* Create Cpu Dense Matrix from numpy matrix, dtype=float32
...
...
@@ -241,8 +248,7 @@ public:
bool
useGpu
=
isUsingGpu
());
static
Vector
*
createVectorFromNumpy
(
float
*
data
,
int
dim
,
bool
copy
=
true
,
bool
useGpu
=
isUsingGpu
())
throw
(
UnsupportError
)
;
bool
useGpu
=
isUsingGpu
());
/**
* Create Cpu Vector from numpy array, which dtype=float32
*
...
...
@@ -305,8 +311,7 @@ public:
bool
useGpu
=
isUsingGpu
());
static
IVector
*
createVectorFromNumpy
(
int
*
data
,
int
dim
,
bool
copy
=
true
,
bool
useGpu
=
isUsingGpu
())
throw
(
UnsupportError
)
;
bool
useGpu
=
isUsingGpu
());
/**
* Create Cpu IVector from numpy array, which dtype=int32
...
...
paddle/api/Util.cpp
浏览文件 @
b2075351
...
...
@@ -43,6 +43,8 @@ IntWithFloatArray::IntWithFloatArray(const float* v, const int* i, size_t l,
bool
isUsingGpu
()
{
return
FLAGS_use_gpu
;}
void
setUseGpu
(
bool
useGpu
)
{
FLAGS_use_gpu
=
useGpu
;}
bool
isGpuVersion
()
{
#ifdef PADDLE_ONLY_CPU
return
false
;
...
...
paddle/api/Vector.cpp
浏览文件 @
b2075351
...
...
@@ -40,13 +40,11 @@ IVector* IVector::create(const std::vector<int>& data, bool useGpu) {
}
IVector
*
IVector
::
createVectorFromNumpy
(
int
*
data
,
int
dim
,
bool
copy
,
bool
useGpu
)
throw
(
UnsupportError
)
{
bool
useGpu
)
{
if
(
useGpu
)
{
/// if use gpu only copy=true is supported
if
(
!
copy
)
{
UnsupportError
e
;
throw
e
;
throw
UnsupportError
(
"Gpu mode only supports copy=True"
);
}
return
IVector
::
createGpuVectorFromNumpy
(
data
,
dim
);
}
else
{
...
...
@@ -204,13 +202,11 @@ Vector* Vector::createByPaddleVectorPtr(void* ptr) {
}
Vector
*
Vector
::
createVectorFromNumpy
(
float
*
data
,
int
dim
,
bool
copy
,
bool
useGpu
)
throw
(
UnsupportError
)
{
bool
useGpu
)
{
if
(
useGpu
)
{
/// if use gpu only copy=True is supported
if
(
!
copy
)
{
UnsupportError
e
;
throw
e
;
throw
UnsupportError
(
"Gpu mode only supports copy=True"
);
}
return
Vector
::
createGpuVectorFromNumpy
(
data
,
dim
);
}
else
{
...
...
paddle/api/test/testMatrix.py
浏览文件 @
b2075351
...
...
@@ -111,5 +111,9 @@ class TestMatrix(unittest.TestCase):
if
__name__
==
"__main__"
:
swig_paddle
.
initPaddle
(
"--use_gpu=1"
if
swig_paddle
.
isGpuVersion
()
else
"--use_gpu=0"
)
unittest
.
main
()
swig_paddle
.
initPaddle
(
"--use_gpu=0"
)
suite
=
unittest
.
TestLoader
().
loadTestsFromTestCase
(
TestMatrix
)
unittest
.
TextTestRunner
().
run
(
suite
)
if
swig_paddle
.
isGpuVersion
():
swig_paddle
.
setUseGpu
(
True
)
unittest
.
main
()
paddle/api/test/testVector.py
浏览文件 @
b2075351
...
...
@@ -147,7 +147,9 @@ class TestVector(unittest.TestCase):
if
__name__
==
'__main__'
:
swig_paddle
.
initPaddle
(
"--use_gpu=1"
if
swig_paddle
.
isGpuVersion
()
else
"--use_gpu=0"
)
unittest
.
main
()
swig_paddle
.
initPaddle
(
"--use_gpu=0"
)
suite
=
unittest
.
TestLoader
().
loadTestsFromTestCase
(
TestVector
)
unittest
.
TextTestRunner
().
run
(
suite
)
if
swig_paddle
.
isGpuVersion
():
swig_paddle
.
setUseGpu
(
True
)
unittest
.
main
()
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录