Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
c4103821
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c4103821
编写于
11月 30, 2016
作者:
H
hedaoyuan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add some comments
上级
1df826e7
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
29 addition
and
54 deletion
+29
-54
paddle/math/tests/TensorCheck.h
paddle/math/tests/TensorCheck.h
+9
-2
paddle/math/tests/TestUtils.h
paddle/math/tests/TestUtils.h
+15
-48
paddle/math/tests/test_Matrix.cpp
paddle/math/tests/test_Matrix.cpp
+5
-4
未找到文件。
paddle/math/tests/TensorCheck.h
浏览文件 @
c4103821
...
@@ -12,9 +12,18 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
...
@@ -12,9 +12,18 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
See the License for the specific language governing permissions and
limitations under the License. */
limitations under the License. */
#pragma once
/**
* This file provides a TensorCheck template function, which can be used to
* compare CpuMatrix and GpuMatrix, CpuVector and GpuVector, and so on.
*/
#include <cmath>
#include <cmath>
#include "paddle/math/Matrix.h"
#include "paddle/math/Matrix.h"
namespace
autotest
{
using
paddle
::
Matrix
;
using
paddle
::
Matrix
;
using
paddle
::
CpuMatrix
;
using
paddle
::
CpuMatrix
;
using
paddle
::
GpuMatrix
;
using
paddle
::
GpuMatrix
;
...
@@ -22,8 +31,6 @@ using paddle::VectorT;
...
@@ -22,8 +31,6 @@ using paddle::VectorT;
using
paddle
::
CpuVectorT
;
using
paddle
::
CpuVectorT
;
using
paddle
::
GpuVectorT
;
using
paddle
::
GpuVectorT
;
namespace
autotest
{
class
AssertEqual
{
class
AssertEqual
{
public:
public:
AssertEqual
(
real
err
=
0
)
:
err_
(
err
)
{}
AssertEqual
(
real
err
=
0
)
:
err_
(
err
)
{}
...
...
paddle/math/tests/TestUtils.h
浏览文件 @
c4103821
...
@@ -12,8 +12,13 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
...
@@ -12,8 +12,13 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
See the License for the specific language governing permissions and
limitations under the License. */
limitations under the License. */
#pragma once
/**
/**
* TestUtils.h is used to automatically compare CPU and GPU code is consistent.
* TestUtils.h is used to automatically compare CPU and GPU code is consistent.
* This file provides a class(AutoCompare) and a template
* function(BaseMatrixCompare) to simplify the comparison
* of CPU and GPU member functions.
* Refer test_Matrix.cpp and test_BaseMatrix.cpp for how to use autotest.
* Refer test_Matrix.cpp and test_BaseMatrix.cpp for how to use autotest.
*/
*/
...
@@ -22,14 +27,14 @@ limitations under the License. */
...
@@ -22,14 +27,14 @@ limitations under the License. */
#include "paddle/math/SparseMatrix.h"
#include "paddle/math/SparseMatrix.h"
#include "TensorCheck.h"
#include "TensorCheck.h"
namespace
autotest
{
using
paddle
::
BaseMatrix
;
using
paddle
::
BaseMatrix
;
using
paddle
::
CpuIVector
;
using
paddle
::
CpuIVector
;
using
paddle
::
GpuIVector
;
using
paddle
::
GpuIVector
;
using
paddle
::
CpuSparseMatrix
;
using
paddle
::
CpuSparseMatrix
;
using
paddle
::
GpuSparseMatrix
;
using
paddle
::
GpuSparseMatrix
;
namespace
autotest
{
template
<
typename
T1
,
typename
T2
>
template
<
typename
T1
,
typename
T2
>
class
ReplaceType
{
class
ReplaceType
{
public:
public:
...
@@ -66,7 +71,7 @@ T construct(int height, int width);
...
@@ -66,7 +71,7 @@ T construct(int height, int width);
template
<
>
template
<
>
float
construct
(
int
height
,
int
width
)
{
float
construct
(
int
height
,
int
width
)
{
return
0.
0
;
return
0.
5
;
}
}
template
<
>
template
<
>
...
@@ -89,15 +94,7 @@ GpuMatrix construct(int height, int width) {
...
@@ -89,15 +94,7 @@ GpuMatrix construct(int height, int width) {
// init a argument
// init a argument
template
<
typename
T
>
template
<
typename
T
>
void
init
(
T
&
v
);
void
init
(
T
&
v
)
{
template
<
>
void
init
(
float
&
v
)
{
v
=
0.5
;
}
template
<
>
void
init
(
size_t
&
v
)
{
return
;
return
;
}
}
...
@@ -125,15 +122,7 @@ template <std::size_t I = 0, typename... Args>
...
@@ -125,15 +122,7 @@ template <std::size_t I = 0, typename... Args>
// copy a argument, copy src to dest
// copy a argument, copy src to dest
template
<
typename
T1
,
typename
T2
>
template
<
typename
T1
,
typename
T2
>
void
copy
(
T1
&
dest
,
T2
&
src
);
void
copy
(
T1
&
dest
,
T2
&
src
)
{
template
<
>
void
copy
(
float
&
dest
,
float
&
src
)
{
dest
=
src
;
}
template
<
>
void
copy
(
size_t
&
dest
,
size_t
&
src
)
{
dest
=
src
;
dest
=
src
;
}
}
...
@@ -155,28 +144,6 @@ template <std::size_t I = 0, typename... Args1, typename... Args2>
...
@@ -155,28 +144,6 @@ template <std::size_t I = 0, typename... Args1, typename... Args2>
copyTuple
<
I
+
1
>
(
dest
,
src
);
copyTuple
<
I
+
1
>
(
dest
,
src
);
}
}
// Compare output
template
<
std
::
size_t
I
=
0
,
typename
...
Args1
,
typename
...
Args2
,
typename
AssertEq
>
inline
typename
std
::
enable_if
<
I
==
sizeof
...(
Args1
),
void
>::
type
checkTuple
(
std
::
tuple
<
Args1
...
>&
args1
,
std
::
tuple
<
Args2
...
>&
args2
,
AssertEq
compare
)
{}
template
<
std
::
size_t
I
=
0
,
typename
...
Args1
,
typename
...
Args2
,
typename
AssertEq
>
inline
typename
std
::
enable_if
<
I
<
sizeof
...(
Args1
),
void
>::
type
checkTuple
(
std
::
tuple
<
Args1
...
>&
args1
,
std
::
tuple
<
Args2
...
>&
args2
,
AssertEq
compare
)
{
TensorCheck
(
compare
,
std
::
get
<
I
>
(
args1
),
std
::
get
<
I
>
(
args2
));
checkTuple
<
I
+
1
>
(
args1
,
args2
,
compare
);
}
// call member function
// call member function
template
<
typename
C
,
template
<
typename
C
,
typename
FC
,
typename
FC
,
...
@@ -227,6 +194,7 @@ void BaseMatrixCompare(R (C::*f)(Args...), AssertEq compare) {
...
@@ -227,6 +194,7 @@ void BaseMatrixCompare(R (C::*f)(Args...), AssertEq compare) {
}
}
}
}
// AutoCompare
template
<
typename
T
>
template
<
typename
T
>
class
ReturnType
{
class
ReturnType
{
public:
public:
...
@@ -252,32 +220,31 @@ public:
...
@@ -252,32 +220,31 @@ public:
};
};
template
<
typename
T
>
template
<
typename
T
>
typename
ReturnType
<
T
>::
type
autoArgs
(
T
v
)
{
typename
ReturnType
<
T
>::
type
autoArgs
(
T
&
v
)
{
return
v
;
return
v
;
}
}
template
<
>
template
<
>
GpuMatrix
autoArgs
(
CpuMatrix
v
)
{
GpuMatrix
autoArgs
(
CpuMatrix
&
v
)
{
GpuMatrix
a
(
v
.
getHeight
(),
v
.
getWidth
());
GpuMatrix
a
(
v
.
getHeight
(),
v
.
getWidth
());
a
.
copyFrom
(
v
);
a
.
copyFrom
(
v
);
return
a
;
return
a
;
}
}
template
<
>
template
<
>
GpuIVector
autoArgs
(
CpuIVector
v
)
{
GpuIVector
autoArgs
(
CpuIVector
&
v
)
{
GpuIVector
a
(
v
.
getSize
());
GpuIVector
a
(
v
.
getSize
());
a
.
copyFrom
(
v
);
a
.
copyFrom
(
v
);
return
a
;
return
a
;
}
}
template
<
>
template
<
>
GpuSparseMatrix
autoArgs
(
CpuSparseMatrix
v
)
{
GpuSparseMatrix
autoArgs
(
CpuSparseMatrix
&
v
)
{
GpuSparseMatrix
a
(
v
.
getHeight
(),
GpuSparseMatrix
a
(
v
.
getHeight
(),
v
.
getWidth
(),
v
.
getWidth
(),
v
.
getElementCnt
(),
v
.
getElementCnt
(),
v
.
getValueType
(),
v
.
getValueType
(),
v
.
getFormat
());
v
.
getFormat
());
a
.
copyFrom
(
v
,
HPPL_STREAM_DEFAULT
);
a
.
copyFrom
(
v
,
HPPL_STREAM_DEFAULT
);
hl_stream_synchronize
(
HPPL_STREAM_DEFAULT
);
hl_stream_synchronize
(
HPPL_STREAM_DEFAULT
);
return
a
;
return
a
;
...
...
paddle/math/tests/test_Matrix.cpp
浏览文件 @
c4103821
...
@@ -14,7 +14,7 @@ limitations under the License. */
...
@@ -14,7 +14,7 @@ limitations under the License. */
#ifndef PADDLE_ONLY_CPU
#ifndef PADDLE_ONLY_CPU
/**
/**
* This test file use AutoCompare to compares the implementation
* This test file use
autotest::
AutoCompare to compares the implementation
* of CPU and GPU member function in Matrix.cpp.
* of CPU and GPU member function in Matrix.cpp.
*
*
* 1. Constructs an AutoCompare object, a AutoCompare object contains
* 1. Constructs an AutoCompare object, a AutoCompare object contains
...
@@ -28,20 +28,21 @@ limitations under the License. */
...
@@ -28,20 +28,21 @@ limitations under the License. */
* AutoCompare test(...);
* AutoCompare test(...);
* Init Argument arg1,arg2...
* Init Argument arg1,arg2...
* test(function, arg1, arg2....)
* test(function, arg1, arg2....)
*
*/
*/
#include <gtest/gtest.h>
#include <gtest/gtest.h>
#include "TestUtils.h"
#include "TestUtils.h"
using
paddle
::
BaseMatrix
;
using
paddle
::
Matrix
;
using
paddle
::
CpuMatrix
;
using
paddle
::
CpuMatrix
;
using
paddle
::
CpuIVector
;
using
paddle
::
CpuSparseMatrix
;
using
paddle
::
SparseValueType
;
using
paddle
::
SparseValueType
;
using
paddle
::
SparseFormat
;
using
paddle
::
SparseFormat
;
using
paddle
::
NO_VALUE
;
using
paddle
::
NO_VALUE
;
using
paddle
::
SPARSE_CSR
;
using
paddle
::
SPARSE_CSR
;
using
paddle
::
initMain
;
using
paddle
::
initMain
;
using
autotest
::
TensorCheckEqual
;
using
autotest
::
TensorCheckErr
;
using
autotest
::
AutoCompare
;
using
autotest
::
AutoCompare
;
void
testBilinearFwdBwd
(
int
numSamples
,
void
testBilinearFwdBwd
(
int
numSamples
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录