Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
7e0b51f2
P
Paddle
项目概览
机器未来
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
7e0b51f2
编写于
10月 24, 2016
作者:
H
hedaoyuan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
some bugs fix
上级
a7855d3e
变更
11
显示空白变更内容
内联
并排
Showing
11 changed file
with
161 addition
and
215 deletion
+161
-215
paddle/cuda/include/hl_tensor_ops.h
paddle/cuda/include/hl_tensor_ops.h
+13
-9
paddle/math/TensorApply.h
paddle/math/TensorApply.h
+13
-9
paddle/math/TensorEvaluate.h
paddle/math/TensorEvaluate.h
+13
-9
paddle/math/TensorExpression.h
paddle/math/TensorExpression.h
+13
-9
paddle/math/TrainingAlgorithmOp.cu
paddle/math/TrainingAlgorithmOp.cu
+13
-9
paddle/math/TrainingAlgorithmOp.h
paddle/math/TrainingAlgorithmOp.h
+13
-9
paddle/math/tests/OriginalOptimizerApi.h
paddle/math/tests/OriginalOptimizerApi.h
+13
-8
paddle/math/tests/TensorCheck.h
paddle/math/tests/TensorCheck.h
+1
-43
paddle/math/tests/test_Tensor.cu
paddle/math/tests/test_Tensor.cu
+15
-101
paddle/math/tests/test_TrainingAlgorithm.cpp
paddle/math/tests/test_TrainingAlgorithm.cpp
+44
-8
paddle/math/tests/test_lazyAssign.cu
paddle/math/tests/test_lazyAssign.cu
+10
-1
未找到文件。
paddle/cuda/include/hl_tensor_ops.h
浏览文件 @
7e0b51f2
/**
* hl_tensor_ops.h
*
* Author: hedaoyuan (hedaoyuan@baidu.com)
* Created on: 2016-06-06
*
* Copyright (c) Baidu.com, Inc. All Rights Reserved
*
*/
/* Copyright (c) 2016 Baidu, Inc. All Rights Reserve.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#ifndef HL_TENSOR_OPS_H_
#define HL_TENSOR_OPS_H_
...
...
paddle/math/TensorApply.h
浏览文件 @
7e0b51f2
/**
* TensorApply.h
*
* Author: hedaoyuan (hedaoyuan@baidu.com)
* Created on: 2016-06-06
*
* Copyright (c) Baidu.com, Inc. All Rights Reserved
*
*/
/* Copyright (c) 2016 Baidu, Inc. All Rights Reserve.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#pragma once
...
...
paddle/math/TensorEvaluate.h
浏览文件 @
7e0b51f2
/**
* TensorEvaluate.h
*
* Author: hedaoyuan (hedaoyuan@baidu.com)
* Created on: 2016-06-06
*
* Copyright (c) Baidu.com, Inc. All Rights Reserved
*
*/
/* Copyright (c) 2016 Baidu, Inc. All Rights Reserve.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#pragma once
...
...
paddle/math/TensorExpression.h
浏览文件 @
7e0b51f2
/**
* TensorExpression.h
*
* Author: hedaoyuan (hedaoyuan@baidu.com)
* Created on: 2016-06-06
*
* Copyright (c) Baidu.com, Inc. All Rights Reserved
*
*/
/* Copyright (c) 2016 Baidu, Inc. All Rights Reserve.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#pragma once
#include <cstddef>
...
...
paddle/math/TrainingAlgorithmOp.cu
浏览文件 @
7e0b51f2
/**
* TrainingAlgorithmOp.cu
*
* Author: hedaoyuan (hedaoyuan@baidu.com)
* Created on: 2016-06-29
*
* Copyright (c) Baidu.com, Inc. All Rights Reserved
*
*/
/* Copyright (c) 2016 Baidu, Inc. All Rights Reserve.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#include "paddle/utils/Logging.h"
#include "BaseMatrix.h"
...
...
paddle/math/TrainingAlgorithmOp.h
浏览文件 @
7e0b51f2
/**
* TrainingAlgorithmOp.h
*
* Author: hedaoyuan (hedaoyuan@baidu.com)
* Created on: 2016-06-29
*
* Copyright (c) Baidu.com, Inc. All Rights Reserved
*
*/
/* Copyright (c) 2016 Baidu, Inc. All Rights Reserve.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#pragma once
...
...
paddle/math/tests/OriginalOptimizerApi.h
浏览文件 @
7e0b51f2
/**
* OriginalOptimizerApi.h
*
* Author: hedaoyuan (hedaoyuan@baidu.com)
* Created on: 2016-06-29
*
* Copyright (c) Baidu.com, Inc. All Rights Reserved
*/
/* Copyright (c) 2016 Baidu, Inc. All Rights Reserve.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#pragma once
...
...
paddle/math/tests/TensorCheck.h
浏览文件 @
7e0b51f2
...
...
@@ -9,6 +9,7 @@
#include <gtest/gtest.h>
#include "paddle/math/Matrix.h"
using
namespace
paddle
;
// NOLINT
using
namespace
std
;
// NOLINT
...
...
@@ -105,50 +106,9 @@ void TensorCheckEqual(const GpuVectorT<T>& vector1,
TensorCheckEqual
(
cpu1
,
cpu2
);
}
int
VectorCheckErr
(
const
Vector
&
vector1
,
const
Vector
&
vector2
)
{
CHECK
(
vector1
.
getSize
()
==
vector2
.
getSize
());
const
real
*
data1
=
vector1
.
getData
();
const
real
*
data2
=
vector2
.
getData
();
size_t
size
=
vector1
.
getSize
();
int
count
=
0
;
for
(
size_t
i
=
0
;
i
<
size
;
i
++
)
{
real
a
=
data1
[
i
];
real
b
=
data2
[
i
];
if
(
fabs
(
a
-
b
)
>
FLAGS_max_diff
)
{
if
((
fabsf
(
a
-
b
)
/
fabsf
(
a
))
>
(
FLAGS_max_diff
/
10.0
f
))
{
count
++
;
}
}
}
return
count
;
}
#define INIT_UNARY(A1, A2) \
Tensor A1(height, width); \
Tensor A2(height, width); \
A1.randomizeUniform(); \
A2.copyFrom(A1)
#define INIT_BINARY(A1, A2, B) \
INIT_UNARY(A1, A2); \
Tensor B(height, width); \
B.randomizeUniform()
#define INIT_TERNARY(A1, A2, B, C) \
INIT_BINARY(A1, A2, B); \
Tensor C(height, width); \
C.randomizeUniform()
#define INIT_QUATERNARY(A1, A2, B, C, D) \
INIT_TERNARY(A1, A2, B, C); \
Tensor D(height, width); \
D.randomizeUniform()
// Performance Check
#ifdef PADDLE_DISABLE_TIMER
#define CHECK_VECTORPTR(vector1, vector2) \
EXPECT_EQ(VectorCheckErr(vector1, vector2), 0)
#define EXPRESSION_PERFORMANCE(expression) \
expression;
...
...
@@ -156,8 +116,6 @@ int VectorCheckErr(const Vector& vector1, const Vector& vector2) {
#include "paddle/utils/Stat.h"
#define CHECK_VECTORPTR(vector1, vector2)
#define EXPRESSION_PERFORMANCE(expression) \
do {\
char expr[30];\
...
...
paddle/math/tests/test_Tensor.cu
浏览文件 @
7e0b51f2
/**
* test_Tensor.cpp
*
* Author: hedaoyuan (hedaoyuan@baidu.com)
* Created on: 2016-06-06
*
* Copyright (c) Baidu.com, Inc. All Rights Reserved
*/
#include <gtest/gtest.h>
#include "paddle/math/Matrix.h"
using
namespace
paddle
;
// NOLINT
using
namespace
std
;
// NOLINT
template
<
typename
Tensor
>
extern
void
TensorCheckEqual
(
const
Tensor
&
tensor1
,
const
Tensor
&
tensor2
);
void
TensorCheckEqual
(
const
CpuMatrix
&
matrix1
,
const
CpuMatrix
&
matrix2
)
{
CHECK
(
matrix1
.
getHeight
()
==
matrix2
.
getHeight
());
CHECK
(
matrix1
.
getWidth
()
==
matrix2
.
getWidth
());
int
height
=
matrix1
.
getHeight
();
int
width
=
matrix1
.
getWidth
();
const
real
*
data1
=
matrix1
.
getData
();
const
real
*
data2
=
matrix2
.
getData
();
int
count
=
0
;
for
(
int
i
=
0
;
i
<
height
;
i
++
)
{
for
(
int
j
=
0
;
j
<
width
;
j
++
)
{
if
(
data1
[
i
*
width
+
j
]
!=
data2
[
i
*
width
+
j
])
{
count
++
;
}
}
}
EXPECT_EQ
(
count
,
0
)
<<
"There are "
<<
count
<<
" different element."
;
}
void
TensorCheckEqual
(
const
GpuMatrix
&
matrix1
,
const
GpuMatrix
&
matrix2
)
{
CpuMatrix
cpu1
(
matrix1
.
getHeight
(),
matrix1
.
getWidth
());
CpuMatrix
cpu2
(
matrix2
.
getHeight
(),
matrix2
.
getWidth
());
cpu1
.
copyFrom
(
matrix1
);
cpu2
.
copyFrom
(
matrix2
);
TensorCheckEqual
(
cpu1
,
cpu2
);
}
void
TensorCheckErr
(
const
CpuMatrix
&
matrix1
,
const
CpuMatrix
&
matrix2
)
{
CHECK
(
matrix1
.
getHeight
()
==
matrix2
.
getHeight
());
CHECK
(
matrix1
.
getWidth
()
==
matrix2
.
getWidth
());
#ifndef PADDLE_TYPE_DOUBLE
real
err
=
1e-5
;
#else
real
err
=
1e-10
;
#endif
/* Copyright (c) 2016 Baidu, Inc. All Rights Reserve.
int
height
=
matrix1
.
getHeight
();
int
width
=
matrix1
.
getWidth
();
const
real
*
data1
=
matrix1
.
getData
();
const
real
*
data2
=
matrix2
.
getData
();
int
count
=
0
;
for
(
int
i
=
0
;
i
<
height
;
i
++
)
{
for
(
int
j
=
0
;
j
<
width
;
j
++
)
{
real
a
=
data1
[
i
*
width
+
j
];
real
b
=
data2
[
i
*
width
+
j
];
if
(
fabs
(
a
-
b
)
>
err
)
{
if
((
fabsf
(
a
-
b
)
/
fabsf
(
a
))
>
(
err
/
10.0
f
))
{
count
++
;
}
}
}
}
EXPECT_EQ
(
count
,
0
)
<<
"There are "
<<
count
<<
" different element."
;
}
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
void
TensorCheckErr
(
const
GpuMatrix
&
matrix1
,
const
GpuMatrix
&
matrix2
)
{
CpuMatrix
cpu1
(
matrix1
.
getHeight
(),
matrix1
.
getWidth
());
CpuMatrix
cpu2
(
matrix2
.
getHeight
(),
matrix2
.
getWidth
());
cpu1
.
copyFrom
(
matrix1
);
cpu2
.
copyFrom
(
matrix2
);
TensorCheckErr
(
cpu1
,
cpu2
);
}
http://www.apache.org/licenses/LICENSE-2.0
template
<
class
T
>
void
TensorCheckEqual
(
const
CpuVectorT
<
T
>&
vector1
,
const
CpuVectorT
<
T
>&
vector2
)
{
CHECK
(
vector1
.
getSize
()
==
vector2
.
getSize
());
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
const
T
*
data1
=
vector1
.
getData
();
const
T
*
data2
=
vector2
.
getData
();
size_t
size
=
vector1
.
getSize
();
int
count
=
0
;
for
(
size_t
i
=
0
;
i
<
size
;
i
++
)
{
if
(
data1
[
i
]
!=
data2
[
i
])
{
count
++
;
}
}
EXPECT_EQ
(
count
,
0
)
<<
"There are "
<<
count
<<
" different element."
;
}
#include <gtest/gtest.h>
#include "paddle/math/Matrix.h"
#include "TensorCheck.h"
template
<
class
T
>
void
TensorCheckEqual
(
const
GpuVectorT
<
T
>&
vector1
,
const
GpuVectorT
<
T
>&
vector2
)
{
CpuVectorT
<
T
>
cpu1
(
vector1
.
getSize
());
CpuVectorT
<
T
>
cpu2
(
vector2
.
getSize
());
cpu1
.
copyFrom
(
vector1
);
cpu2
.
copyFrom
(
vector2
);
TensorCheckEqual
(
cpu1
,
cpu2
);
}
using
namespace
paddle
;
// NOLINT
using
namespace
std
;
// NOLINT
#define INIT_UNARY(A1, A2) \
Tensor A1(height, width); \
...
...
paddle/math/tests/test_TrainingAlgorithm.cpp
浏览文件 @
7e0b51f2
/**
* test_TrainingAlgorithm.cpp
*
* Author: hedaoyuan (hedaoyuan@baidu.com)
* Created on: 2016-06-29
*
* Copyright (c) Baidu.com, Inc. All Rights Reserved
*/
/* Copyright (c) 2016 Baidu, Inc. All Rights Reserve.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#include <gtest/gtest.h>
#include "paddle/utils/Util.h"
...
...
@@ -44,6 +49,26 @@ private:
}\
} while (0)
int
VectorCheckErr
(
const
Vector
&
vector1
,
const
Vector
&
vector2
)
{
CHECK
(
vector1
.
getSize
()
==
vector2
.
getSize
());
const
real
*
data1
=
vector1
.
getData
();
const
real
*
data2
=
vector2
.
getData
();
size_t
size
=
vector1
.
getSize
();
int
count
=
0
;
for
(
size_t
i
=
0
;
i
<
size
;
i
++
)
{
real
a
=
data1
[
i
];
real
b
=
data2
[
i
];
if
(
fabs
(
a
-
b
)
>
FLAGS_max_diff
)
{
if
((
fabsf
(
a
-
b
)
/
fabsf
(
a
))
>
(
FLAGS_max_diff
/
10.0
f
))
{
count
++
;
}
}
}
return
count
;
}
int
VectorCheckErr
(
const
VectorPtr
&
vector1
,
const
VectorPtr
&
vector2
)
{
VectorPtr
tmp1
;
VectorPtr
tmp2
;
...
...
@@ -52,6 +77,17 @@ int VectorCheckErr(const VectorPtr& vector1, const VectorPtr& vector2) {
return
VectorCheckErr
(
*
tmp1
,
*
tmp2
);
}
#ifdef PADDLE_DISABLE_TIMER
#define CHECK_VECTORPTR(vector1, vector2) \
EXPECT_EQ(VectorCheckErr(vector1, vector2), 0)
#else
#define CHECK_VECTORPTR(vector1, vector2)
#endif
typedef
std
::
function
<
void
(
size_t
size
,
bool
useGpu
)
>
testMatrixFunc
;
void
testCase
(
testMatrixFunc
matrixFunc
)
{
...
...
paddle/math/tests/test_lazyAssign.cu
浏览文件 @
7e0b51f2
...
...
@@ -27,7 +27,16 @@ void testMatrixCase(testMatrixFunc matrixFunc) {
template
<
typename
Tensor
>
void
testLazyAssign
(
int
height
,
int
width
)
{
INIT_QUATERNARY
(
A1
,
A2
,
B
,
C
,
D
);
Tensor
A1
(
height
,
width
);
Tensor
A2
(
height
,
width
);
Tensor
B
(
height
,
width
);
Tensor
C
(
height
,
width
);
Tensor
D
(
height
,
width
);
A1
.
randomizeUniform
();
B
.
randomizeUniform
();
C
.
randomizeUniform
();
D
.
randomizeUniform
();
A2
.
copyFrom
(
A1
);
EXPRESSION_PERFORMANCE
(
A1
=
B
+
C
;
A1
=
A1
*
D
;);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录