Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
5fddd99e
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看板
提交
5fddd99e
编写于
12月 20, 2016
作者:
H
hedaoyuan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
move TEST from test_matrixCompare.cpp to cross_map_normal_op_test.cpp
上级
148bd4d0
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
221 addition
and
154 deletion
+221
-154
cmake/util.cmake
cmake/util.cmake
+1
-0
paddle/function/CMakeLists.txt
paddle/function/CMakeLists.txt
+25
-10
paddle/function/FunctionTest.h
paddle/function/FunctionTest.h
+102
-0
paddle/function/TestMain.cpp
paddle/function/TestMain.cpp
+22
-0
paddle/function/cross_map_normal_op_test.cpp
paddle/function/cross_map_normal_op_test.cpp
+71
-0
paddle/math/tests/test_matrixCompare.cpp
paddle/math/tests/test_matrixCompare.cpp
+0
-144
未找到文件。
cmake/util.cmake
浏览文件 @
5fddd99e
...
@@ -107,6 +107,7 @@ function(link_paddle_exe TARGET_NAME)
...
@@ -107,6 +107,7 @@ function(link_paddle_exe TARGET_NAME)
paddle_parameter
paddle_parameter
paddle_proto
paddle_proto
paddle_cuda
paddle_cuda
paddle_test_main
${
METRIC_LIBS
}
${
METRIC_LIBS
}
${
PROTOBUF_LIBRARY
}
${
PROTOBUF_LIBRARY
}
${
LIBGLOG_LIBRARY
}
${
LIBGLOG_LIBRARY
}
...
...
paddle/function/CMakeLists.txt
浏览文件 @
5fddd99e
file
(
GLOB FUNCTION_HEADERS . *.h
)
file
(
GLOB h_files . *_op.h
)
file
(
GLOB cpp_files . *_op.cpp
)
if
(
NOT WITH_GPU
)
file
(
GLOB FUNCTION_SOURCES . *.cpp
)
list
(
APPEND h_files Function.h
)
add_library
(
paddle_function STATIC
${
FUNCTION_SOURCES
}
)
list
(
APPEND cpp_files Function.cpp
)
else
()
file
(
GLOB FUNCTION_SOURCES . *.cpp *.cu
)
if
(
WITH_GPU
)
cuda_add_library
(
paddle_function
${
FUNCTION_SOURCES
}
)
file
(
GLOB cu_files . *_op_gpu.cu
)
cuda_compile
(
cu_objs
${
cu_files
}
)
endif
()
endif
()
add_style_check_target
(
paddle_function
${
FUNCTION_SOURCES
}
)
add_library
(
paddle_function STATIC
${
cpp_files
}
${
cu_objs
}
)
add_style_check_target
(
paddle_function
${
FUNCTION_HEADERS
}
)
add_library
(
paddle_test_main STATIC TestMain.cpp
)
if
(
WITH_GPU
)
# TODO:
# file(GLOB test_files . *_op_test.cpp)
# add_executable(${test_bin} EXCLUDE_FROM_ALL ${test_files})
add_simple_unittest
(
cross_map_normal_op_test
)
endif
()
add_style_check_target
(
paddle_function
${
h_files
}
)
add_style_check_target
(
paddle_function
${
cpp_files
}
)
if
(
WITH_GPU
)
add_style_check_target
(
paddle_function
${
cu_files
}
)
endif
()
paddle/function/FunctionTest.h
0 → 100644
浏览文件 @
5fddd99e
/* Copyright (c) 2016 PaddlePaddle Authors. 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 "Function.h"
#include "paddle/math/Vector.h"
#include "paddle/math/tests/TensorCheck.h"
namespace
paddle
{
class
FunctionCompare
{
public:
FunctionCompare
(
const
std
::
string
&
name
,
const
FuncConfig
&
config
)
:
cpu
(
FunctionBase
::
funcRegistrar_
.
createByType
(
name
+
"-CPU"
)),
gpu
(
FunctionBase
::
funcRegistrar_
.
createByType
(
name
+
"-GPU"
))
{
cpu
->
init
(
config
);
gpu
->
init
(
config
);
}
void
cmpWithArg
(
const
Arguments
&
inputs
,
const
Arguments
&
outputs
,
const
Arguments
&
inouts
)
{
// init cpu and gpu arguments
auto
initArgs
=
[
=
](
Arguments
&
cpuArgs
,
Arguments
&
gpuArgs
,
const
Arguments
&
inArgs
)
{
for
(
auto
arg
:
inArgs
)
{
size_t
size
=
sizeof
(
real
);
for
(
auto
dim
:
arg
.
dims_
)
{
size
*=
dim
;
}
cpuMemory
.
emplace_back
(
std
::
make_shared
<
CpuMemoryHandle
>
(
size
));
gpuMemory
.
emplace_back
(
std
::
make_shared
<
GpuMemoryHandle
>
(
size
));
cpuArgs
.
emplace_back
(
Tensor
((
real
*
)
cpuMemory
.
back
()
->
getBuf
(),
arg
.
dims_
));
gpuArgs
.
emplace_back
(
Tensor
((
real
*
)
gpuMemory
.
back
()
->
getBuf
(),
arg
.
dims_
));
// will use an api to refactor this code.
CpuVector
cpuVector
(
size
/
sizeof
(
real
),
(
real
*
)
cpuArgs
.
back
().
getData
());
GpuVector
gpuVector
(
size
/
sizeof
(
real
),
(
real
*
)
gpuArgs
.
back
().
getData
());
cpuVector
.
uniform
(
0.001
,
1
);
gpuVector
.
copyFrom
(
cpuVector
);
}
};
initArgs
(
cpuInputs
,
gpuInputs
,
inputs
);
initArgs
(
cpuOutputs
,
gpuOutputs
,
outputs
);
initArgs
(
cpuInouts
,
gpuInouts
,
inouts
);
// function calculate
cpu
->
calc
(
cpuInputs
,
cpuOutputs
,
cpuInouts
);
gpu
->
calc
(
gpuInputs
,
gpuOutputs
,
gpuInouts
);
// check outputs and inouts
auto
checkArgs
=
[
=
](
const
Arguments
&
cpuArgs
,
const
Arguments
&
gpuArgs
)
{
for
(
size_t
i
=
0
;
i
<
cpuArgs
.
size
();
i
++
)
{
auto
cpu
=
cpuArgs
[
i
];
auto
gpu
=
gpuArgs
[
i
];
size_t
size
=
1
;
for
(
auto
dim
:
cpu
.
dims_
)
{
size
*=
dim
;
}
CpuVector
cpuVector
(
size
,
(
real
*
)
cpu
.
getData
());
GpuVector
gpuVector
(
size
,
(
real
*
)
gpu
.
getData
());
autotest
::
TensorCheckErr
(
cpuVector
,
gpuVector
);
}
};
checkArgs
(
cpuOutputs
,
gpuOutputs
);
checkArgs
(
cpuInouts
,
gpuInouts
);
}
protected:
std
::
shared_ptr
<
FunctionBase
>
cpu
;
std
::
shared_ptr
<
FunctionBase
>
gpu
;
std
::
vector
<
CpuMemHandlePtr
>
cpuMemory
;
std
::
vector
<
GpuMemHandlePtr
>
gpuMemory
;
Arguments
cpuInputs
;
Arguments
cpuOutputs
;
Arguments
cpuInouts
;
Arguments
gpuInputs
;
Arguments
gpuOutputs
;
Arguments
gpuInouts
;
};
}
// namespace paddle
using
paddle
::
FunctionCompare
;
using
paddle
::
FuncConfig
;
using
paddle
::
Dims
;
using
paddle
::
Tensor
;
paddle/function/TestMain.cpp
0 → 100644
浏览文件 @
5fddd99e
/* Copyright (c) 2016 PaddlePaddle Authors. 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"
int
main
(
int
argc
,
char
**
argv
)
{
testing
::
InitGoogleTest
(
&
argc
,
argv
);
paddle
::
initMain
(
argc
,
argv
);
return
RUN_ALL_TESTS
();
}
paddle/function/cross_map_normal_op_test.cpp
0 → 100644
浏览文件 @
5fddd99e
/* Copyright (c) 2016 PaddlePaddle Authors. 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 "FunctionTest.h"
TEST
(
CrossMapNormal
,
real
)
{
for
(
size_t
numSamples
:
{
5
,
32
})
{
for
(
size_t
channels
:
{
1
,
5
,
32
})
{
for
(
size_t
imgSizeH
:
{
5
,
33
,
100
})
{
for
(
size_t
imgSizeW
:
{
5
,
32
,
96
})
{
for
(
size_t
size
:
{
1
,
2
,
3
,
5
,
7
})
{
VLOG
(
3
)
<<
" numSamples="
<<
numSamples
<<
" channels="
<<
channels
<<
" imgSizeH="
<<
imgSizeH
<<
" imgSizeW="
<<
imgSizeW
<<
" size="
<<
size
;
FunctionCompare
compare
(
"CrossMapNormal"
,
FuncConfig
()
.
set
(
"size"
,
size
)
.
set
(
"scale"
,
(
real
)
1.5
)
.
set
(
"pow"
,
(
real
)
0.5
));
Dims
dims
{
numSamples
,
channels
,
imgSizeH
,
imgSizeW
};
compare
.
cmpWithArg
({
Tensor
(
nullptr
,
dims
)},
{
Tensor
(
nullptr
,
dims
),
Tensor
(
nullptr
,
dims
)},
{});
}
}
}
}
}
}
TEST
(
CrossMapNormalGrad
,
real
)
{
for
(
size_t
numSamples
:
{
5
,
32
})
{
for
(
size_t
channels
:
{
1
,
5
,
32
})
{
for
(
size_t
imgSizeH
:
{
5
,
33
,
100
})
{
for
(
size_t
imgSizeW
:
{
5
,
32
,
96
})
{
for
(
size_t
size
:
{
1
,
2
,
3
,
5
,
7
})
{
VLOG
(
3
)
<<
" numSamples="
<<
numSamples
<<
" channels="
<<
channels
<<
" imgSizeH="
<<
imgSizeH
<<
" imgSizeW="
<<
imgSizeW
<<
" size="
<<
size
;
FunctionCompare
compare
(
"CrossMapNormalGrad"
,
FuncConfig
()
.
set
(
"size"
,
size
)
.
set
(
"scale"
,
(
real
)
1.5
)
.
set
(
"pow"
,
(
real
)
0.5
));
Dims
dims
{
numSamples
,
channels
,
imgSizeH
,
imgSizeW
};
compare
.
cmpWithArg
({
Tensor
(
nullptr
,
dims
),
Tensor
(
nullptr
,
dims
),
Tensor
(
nullptr
,
dims
),
Tensor
(
nullptr
,
dims
)},
{
Tensor
(
nullptr
,
dims
)},
{});
}
}
}
}
}
}
paddle/math/tests/test_matrixCompare.cpp
浏览文件 @
5fddd99e
...
@@ -1263,150 +1263,6 @@ TEST(Matrix, MaxOutFwdBwd) {
...
@@ -1263,150 +1263,6 @@ TEST(Matrix, MaxOutFwdBwd) {
}
}
}
}
void
testCrossMapNormalFwd
(
int
numSamples
,
int
channels
,
int
imgSizeH
,
int
imgSizeW
,
int
sizeX
)
{
float
scale
=
1.5
;
float
pow
=
0.5
;
int
width
=
imgSizeH
*
imgSizeW
*
channels
;
CpuMatrix
inputs
(
numSamples
,
width
);
CpuMatrix
denoms
(
numSamples
,
width
);
CpuMatrix
outputs
(
numSamples
,
width
);
GpuMatrix
inputsGpu
(
numSamples
,
width
);
GpuMatrix
denomsGpu
(
numSamples
,
width
);
GpuMatrix
outputsGpu
(
numSamples
,
width
);
inputs
.
randomizeUniform
();
outputs
.
randomizeUniform
();
inputsGpu
.
copyFrom
(
inputs
);
outputsGpu
.
copyFrom
(
outputs
);
FunctionBase
*
cpu
=
FunctionBase
::
funcRegistrar_
.
createByType
(
FUNC_NAME
(
CrossMapNormal
,
CPU
));
FunctionBase
*
gpu
=
FunctionBase
::
funcRegistrar_
.
createByType
(
FUNC_NAME
(
CrossMapNormal
,
GPU
));
cpu
->
init
(
FuncConfig
()
.
set
(
"size"
,
(
size_t
)
sizeX
)
.
set
(
"scale"
,
scale
)
.
set
(
"pow"
,
pow
));
gpu
->
init
(
FuncConfig
()
.
set
(
"size"
,
(
size_t
)
sizeX
)
.
set
(
"scale"
,
scale
)
.
set
(
"pow"
,
pow
));
Dims
dims
{
(
size_t
)
numSamples
,
(
size_t
)
channels
,
(
size_t
)
imgSizeH
,
(
size_t
)
imgSizeW
};
cpu
->
calc
({
Tensor
(
inputs
.
getData
(),
dims
)},
{
Tensor
(
outputs
.
getData
(),
dims
),
Tensor
(
denoms
.
getData
(),
dims
)},
{});
gpu
->
calc
(
{
Tensor
(
inputsGpu
.
getData
(),
dims
)},
{
Tensor
(
outputsGpu
.
getData
(),
dims
),
Tensor
(
denomsGpu
.
getData
(),
dims
)},
{});
TensorCheckErr
(
outputs
,
outputsGpu
);
TensorCheckErr
(
denoms
,
denomsGpu
);
}
TEST
(
Matrix
,
crossMapNormalFwd
)
{
for
(
auto
numSamples
:
{
5
,
32
})
{
for
(
auto
channels
:
{
1
,
5
,
32
})
{
for
(
auto
imgSizeH
:
{
5
,
33
,
100
})
{
for
(
auto
imgSizeW
:
{
5
,
32
,
96
})
{
for
(
auto
sizeX
:
{
1
,
2
,
3
,
5
,
7
})
{
VLOG
(
3
)
<<
" numSamples="
<<
numSamples
<<
" channels="
<<
channels
<<
" imgSizeH="
<<
imgSizeH
<<
" imgSizeW="
<<
imgSizeW
<<
" sizeX="
<<
sizeX
;
testCrossMapNormalFwd
(
numSamples
,
channels
,
imgSizeH
,
imgSizeW
,
sizeX
);
}
}
}
}
}
}
void
testCrossMapNormalBwd
(
int
numSamples
,
int
channels
,
int
imgSizeH
,
int
imgSizeW
,
int
sizeX
)
{
float
scale
=
1.5
;
float
pow
=
0.5
;
size_t
width
=
imgSizeH
*
imgSizeW
*
channels
;
CpuMatrix
inputsGrad
(
numSamples
,
width
);
CpuMatrix
inputsValue
(
numSamples
,
width
);
CpuMatrix
outputsGrad
(
numSamples
,
width
);
CpuMatrix
outputsValue
(
numSamples
,
width
);
CpuMatrix
denoms
(
numSamples
,
width
);
outputsGrad
.
randomizeUniform
();
denoms
.
randomizeUniform
();
inputsValue
.
randomizeUniform
();
outputsValue
.
randomizeUniform
();
inputsGrad
.
randomizeUniform
();
denoms
.
add
(
0.01
);
GpuMatrix
inputsGradGpu
(
numSamples
,
width
);
GpuMatrix
inputsValueGpu
(
numSamples
,
width
);
GpuMatrix
outputsGradGpu
(
numSamples
,
width
);
GpuMatrix
outputsValueGpu
(
numSamples
,
width
);
GpuMatrix
denomsGpu
(
numSamples
,
width
);
outputsGradGpu
.
copyFrom
(
outputsGrad
);
denomsGpu
.
copyFrom
(
denoms
);
inputsValueGpu
.
copyFrom
(
inputsValue
);
outputsValueGpu
.
copyFrom
(
outputsValue
);
inputsGradGpu
.
copyFrom
(
inputsGrad
);
FunctionBase
*
cpu
=
FunctionBase
::
funcRegistrar_
.
createByType
(
FUNC_NAME
(
CrossMapNormalGrad
,
CPU
));
FunctionBase
*
gpu
=
FunctionBase
::
funcRegistrar_
.
createByType
(
FUNC_NAME
(
CrossMapNormalGrad
,
GPU
));
cpu
->
init
(
FuncConfig
()
.
set
(
"size"
,
(
size_t
)
sizeX
)
.
set
(
"scale"
,
scale
)
.
set
(
"pow"
,
pow
));
gpu
->
init
(
FuncConfig
()
.
set
(
"size"
,
(
size_t
)
sizeX
)
.
set
(
"scale"
,
scale
)
.
set
(
"pow"
,
pow
));
Dims
dims
{
(
size_t
)
numSamples
,
(
size_t
)
channels
,
(
size_t
)
imgSizeH
,
(
size_t
)
imgSizeW
};
cpu
->
calc
({
Tensor
(
inputsValue
.
getData
(),
dims
),
Tensor
(
outputsValue
.
getData
(),
dims
),
Tensor
(
outputsGrad
.
getData
(),
dims
),
Tensor
(
denoms
.
getData
(),
dims
)},
{
Tensor
(
inputsGrad
.
getData
(),
dims
)},
{});
gpu
->
calc
({
Tensor
(
inputsValueGpu
.
getData
(),
dims
),
Tensor
(
outputsValueGpu
.
getData
(),
dims
),
Tensor
(
outputsGradGpu
.
getData
(),
dims
),
Tensor
(
denomsGpu
.
getData
(),
dims
)},
{
Tensor
(
inputsGradGpu
.
getData
(),
dims
)},
{});
TensorCheckErr
(
inputsGrad
,
inputsGradGpu
);
}
TEST
(
Matrix
,
crossMapNormalBwd
)
{
for
(
auto
numSamples
:
{
5
,
32
})
{
for
(
auto
channels
:
{
1
,
5
,
32
})
{
for
(
auto
imgSizeH
:
{
5
,
33
,
100
})
{
for
(
auto
imgSizeW
:
{
5
,
32
,
96
})
{
for
(
auto
sizeX
:
{
1
,
2
,
3
,
5
,
7
})
{
VLOG
(
3
)
<<
" numSamples="
<<
numSamples
<<
" channels="
<<
channels
<<
" imgSizeH="
<<
imgSizeH
<<
" imgSizeW="
<<
imgSizeW
<<
" sizeX="
<<
sizeX
;
testCrossMapNormalBwd
(
numSamples
,
channels
,
imgSizeH
,
imgSizeW
,
sizeX
);
}
}
}
}
}
}
int
main
(
int
argc
,
char
**
argv
)
{
int
main
(
int
argc
,
char
**
argv
)
{
testing
::
InitGoogleTest
(
&
argc
,
argv
);
testing
::
InitGoogleTest
(
&
argc
,
argv
);
initMain
(
argc
,
argv
);
initMain
(
argc
,
argv
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录