Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
0294a4e2
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
331
Star
4
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
271
列表
看板
标记
里程碑
合并请求
78
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle-Lite
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
271
Issue
271
列表
看板
标记
里程碑
合并请求
78
合并请求
78
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
0294a4e2
编写于
1月 25, 2019
作者:
H
hjchen2
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refine java api, add write_to_array and read_from_array op
上级
195eb11c
变更
31
隐藏空白更改
内联
并排
Showing
31 changed file
with
540 addition
and
97 deletion
+540
-97
src/common/log.h
src/common/log.h
+4
-4
src/common/types.cpp
src/common/types.cpp
+5
-1
src/common/types.h
src/common/types.h
+2
-0
src/framework/attribute.h
src/framework/attribute.h
+4
-0
src/framework/executor.cpp
src/framework/executor.cpp
+1
-0
src/framework/load_ops.h
src/framework/load_ops.h
+9
-0
src/framework/lod_tensor.h
src/framework/lod_tensor.h
+2
-0
src/framework/program/op_desc.cpp
src/framework/program/op_desc.cpp
+1
-3
src/io/jni/paddle_mobile_jni.cpp
src/io/jni/paddle_mobile_jni.cpp
+4
-3
src/operators/controlflow/tensor_array_read_write_op.cpp
src/operators/controlflow/tensor_array_read_write_op.cpp
+43
-0
src/operators/controlflow/tensor_array_read_write_op.h
src/operators/controlflow/tensor_array_read_write_op.h
+34
-0
src/operators/controlflow/while_op.cpp
src/operators/controlflow/while_op.cpp
+36
-0
src/operators/controlflow/while_op.h
src/operators/controlflow/while_op.h
+30
-0
src/operators/kernel/arm/tensor_array_read_write_kernel.cpp
src/operators/kernel/arm/tensor_array_read_write_kernel.cpp
+58
-0
src/operators/kernel/arm/while_kernel.cpp
src/operators/kernel/arm/while_kernel.cpp
+33
-0
src/operators/kernel/tensor_array_read_write_kernel.h
src/operators/kernel/tensor_array_read_write_kernel.h
+32
-0
src/operators/kernel/while_kernel.h
src/operators/kernel/while_kernel.h
+47
-0
src/operators/math/gemm.h
src/operators/math/gemm.h
+1
-0
src/operators/op_param.h
src/operators/op_param.h
+58
-0
src/operators/reshape_op.cpp
src/operators/reshape_op.cpp
+0
-0
test/CMakeLists.txt
test/CMakeLists.txt
+8
-8
test/operators/test_conv_op.cpp
test/operators/test_conv_op.cpp
+17
-21
test/operators/test_log_op.cpp
test/operators/test_log_op.cpp
+0
-1
test/operators/test_quantize_op.cpp
test/operators/test_quantize_op.cpp
+8
-16
test/operators/test_sequence_pool_op.cpp
test/operators/test_sequence_pool_op.cpp
+36
-36
test/operators/test_sigmoid_op.cpp
test/operators/test_sigmoid_op.cpp
+0
-1
test/operators/test_tanh_op.cpp
test/operators/test_tanh_op.cpp
+1
-1
tools/ci_build.sh
tools/ci_build.sh
+10
-2
tools/ci_run_test.sh
tools/ci_run_test.sh
+41
-0
tools/docker_build_fpga.sh
tools/docker_build_fpga.sh
+2
-0
tools/op.cmake
tools/op.cmake
+13
-0
未找到文件。
src/common/log.h
浏览文件 @
0294a4e2
...
@@ -85,18 +85,18 @@ struct Print {
...
@@ -85,18 +85,18 @@ struct Print {
private:
private:
void
print
(
LogLevel
level
)
{
void
print
(
LogLevel
level
)
{
buffer_
<<
std
::
endl
;
//
buffer_ << std::endl;
if
(
level
==
kLOG_ERROR
)
{
if
(
level
==
kLOG_ERROR
)
{
std
::
cerr
<<
buffer_
.
str
();
std
::
cerr
<<
buffer_
.
str
()
<<
std
::
endl
;
}
else
{
}
else
{
std
::
cout
<<
buffer_
.
str
();
std
::
cout
<<
buffer_
.
str
()
<<
std
::
endl
;
}
}
}
}
std
::
ostringstream
buffer_
;
std
::
ostringstream
buffer_
;
};
};
struct
ToLog
{
struct
ToLog
{
ToLog
(
LogLevel
level
=
kLOG_DEBUG
,
const
std
::
string
&
info
=
""
)
explicit
ToLog
(
LogLevel
level
=
kLOG_DEBUG
,
const
std
::
string
&
info
=
""
)
:
level_
(
level
)
{
:
level_
(
level
)
{
unsigned
blanks
=
unsigned
blanks
=
(
unsigned
)(
level
>
kLOG_DEBUG
?
(
level
-
kLOG_DEBUG
)
*
4
:
1
);
(
unsigned
)(
level
>
kLOG_DEBUG
?
(
level
-
kLOG_DEBUG
)
*
4
:
1
);
...
...
src/common/types.cpp
浏览文件 @
0294a4e2
...
@@ -81,6 +81,8 @@ const char *G_OP_TYPE_LOGICAL_AND = "logical_and";
...
@@ -81,6 +81,8 @@ const char *G_OP_TYPE_LOGICAL_AND = "logical_and";
const
char
*
G_OP_TYPE_LOGICAL_OR
=
"logical_or"
;
const
char
*
G_OP_TYPE_LOGICAL_OR
=
"logical_or"
;
const
char
*
G_OP_TYPE_LOGICAL_NOT
=
"logical_not"
;
const
char
*
G_OP_TYPE_LOGICAL_NOT
=
"logical_not"
;
const
char
*
G_OP_TYPE_LOGICAL_XOR
=
"logical_xor"
;
const
char
*
G_OP_TYPE_LOGICAL_XOR
=
"logical_xor"
;
const
char
*
G_OP_TYPE_WRITE_TO_ARRAY
=
"write_to_array"
;
const
char
*
G_OP_TYPE_READ_FROM_ARRAY
=
"read_from_array"
;
const
char
*
G_OP_TYPE_QUANTIZE
=
"quantize"
;
const
char
*
G_OP_TYPE_QUANTIZE
=
"quantize"
;
const
char
*
G_OP_TYPE_DEQUANTIZE
=
"dequantize"
;
const
char
*
G_OP_TYPE_DEQUANTIZE
=
"dequantize"
;
...
@@ -189,5 +191,7 @@ std::unordered_map<
...
@@ -189,5 +191,7 @@ std::unordered_map<
{
G_OP_TYPE_LOGICAL_AND
,
{{
"X"
,
"Y"
},
{
"Out"
}}},
{
G_OP_TYPE_LOGICAL_AND
,
{{
"X"
,
"Y"
},
{
"Out"
}}},
{
G_OP_TYPE_LOGICAL_OR
,
{{
"X"
,
"Y"
},
{
"Out"
}}},
{
G_OP_TYPE_LOGICAL_OR
,
{{
"X"
,
"Y"
},
{
"Out"
}}},
{
G_OP_TYPE_LOGICAL_XOR
,
{{
"X"
,
"Y"
},
{
"Out"
}}},
{
G_OP_TYPE_LOGICAL_XOR
,
{{
"X"
,
"Y"
},
{
"Out"
}}},
{
G_OP_TYPE_LOGICAL_NOT
,
{{
"X"
},
{
"Out"
}}}};
{
G_OP_TYPE_LOGICAL_NOT
,
{{
"X"
},
{
"Out"
}}},
{
G_OP_TYPE_WRITE_TO_ARRAY
,
{{
"X"
,
"I"
},
{
"Out"
}}},
{
G_OP_TYPE_READ_FROM_ARRAY
,
{{
"X"
,
"I"
},
{
"Out"
}}}};
}
// namespace paddle_mobile
}
// namespace paddle_mobile
src/common/types.h
浏览文件 @
0294a4e2
...
@@ -170,6 +170,8 @@ extern const char *G_OP_TYPE_LOGICAL_AND;
...
@@ -170,6 +170,8 @@ extern const char *G_OP_TYPE_LOGICAL_AND;
extern
const
char
*
G_OP_TYPE_LOGICAL_OR
;
extern
const
char
*
G_OP_TYPE_LOGICAL_OR
;
extern
const
char
*
G_OP_TYPE_LOGICAL_NOT
;
extern
const
char
*
G_OP_TYPE_LOGICAL_NOT
;
extern
const
char
*
G_OP_TYPE_LOGICAL_XOR
;
extern
const
char
*
G_OP_TYPE_LOGICAL_XOR
;
extern
const
char
*
G_OP_TYPE_WRITE_TO_ARRAY
;
extern
const
char
*
G_OP_TYPE_READ_FROM_ARRAY
;
extern
const
char
*
G_OP_TYPE_QUANTIZE
;
extern
const
char
*
G_OP_TYPE_QUANTIZE
;
extern
const
char
*
G_OP_TYPE_DEQUANTIZE
;
extern
const
char
*
G_OP_TYPE_DEQUANTIZE
;
...
...
src/framework/attribute.h
浏览文件 @
0294a4e2
...
@@ -90,6 +90,10 @@ class Attribute {
...
@@ -90,6 +90,10 @@ class Attribute {
attr
.
Set
<
int64_t
>
(
attr_desc
->
l
);
attr
.
Set
<
int64_t
>
(
attr_desc
->
l
);
break
;
break
;
}
}
case
PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__BLOCK
:
{
attr
.
Set
<
int
>
(
attr_desc
->
block_idx
);
break
;
}
default:
default:
PADDLE_MOBILE_THROW_EXCEPTION
(
"attr type not support"
);
PADDLE_MOBILE_THROW_EXCEPTION
(
"attr type not support"
);
}
}
...
...
src/framework/executor.cpp
浏览文件 @
0294a4e2
...
@@ -65,6 +65,7 @@ Executor<Device, T>::Executor(const Program<Device> &program,
...
@@ -65,6 +65,7 @@ Executor<Device, T>::Executor(const Program<Device> &program,
for
(
int
j
=
0
;
j
<
ops
.
size
();
++
j
)
{
for
(
int
j
=
0
;
j
<
ops
.
size
();
++
j
)
{
std
::
shared_ptr
<
OpDesc
>
op_desc
=
ops
[
j
];
std
::
shared_ptr
<
OpDesc
>
op_desc
=
ops
[
j
];
DLOG
<<
"create op: "
<<
op_desc
->
Type
();
DLOG
<<
"create op: "
<<
op_desc
->
Type
();
auto
op_handler
=
OpRegistry
<
Device
>::
CreateOp
(
auto
op_handler
=
OpRegistry
<
Device
>::
CreateOp
(
op_desc
->
Type
(),
op_desc
->
GetInputs
(),
op_desc
->
GetOutputs
(),
op_desc
->
Type
(),
op_desc
->
GetInputs
(),
op_desc
->
GetOutputs
(),
op_desc
->
GetAttrMap
(),
program_
.
scope
);
op_desc
->
GetAttrMap
(),
program_
.
scope
);
...
...
src/framework/load_ops.h
浏览文件 @
0294a4e2
...
@@ -297,3 +297,12 @@ LOAD_OP1(logical_not, CPU);
...
@@ -297,3 +297,12 @@ LOAD_OP1(logical_not, CPU);
#ifdef LOGICAL_XOR_OP
#ifdef LOGICAL_XOR_OP
LOAD_OP1
(
logical_xor
,
CPU
);
LOAD_OP1
(
logical_xor
,
CPU
);
#endif
#endif
#ifdef WHILE_OP
LOAD_OP1
(
while
,
CPU
);
#endif
#ifdef WRITE_TO_ARRAY_OP
LOAD_OP1
(
write_to_array
,
CPU
);
#endif
#ifdef READ_FROM_ARRAY_OP
LOAD_OP1
(
read_from_array
,
CPU
);
#endif
src/framework/lod_tensor.h
浏览文件 @
0294a4e2
...
@@ -176,6 +176,8 @@ LoDTensor LodExpand(const LoDTensor &source, const LoD &lod, size_t level) {
...
@@ -176,6 +176,8 @@ LoDTensor LodExpand(const LoDTensor &source, const LoD &lod, size_t level) {
return
tensor
;
return
tensor
;
}
}
using
LoDTensorArray
=
std
::
vector
<
LoDTensor
>
;
// Get the absolute offset of a lod[start_level][start_idx:end_idx] and
// Get the absolute offset of a lod[start_level][start_idx:end_idx] and
// relative length of details for every levels(i.e., [start_level: ]).
// relative length of details for every levels(i.e., [start_level: ]).
//
//
...
...
src/framework/program/op_desc.cpp
浏览文件 @
0294a4e2
...
@@ -41,9 +41,7 @@ OpDesc::OpDesc(PaddleMobile__Framework__Proto__OpDesc *desc) {
...
@@ -41,9 +41,7 @@ OpDesc::OpDesc(PaddleMobile__Framework__Proto__OpDesc *desc) {
for
(
int
k
=
0
;
k
<
desc
->
n_attrs
;
++
k
)
{
for
(
int
k
=
0
;
k
<
desc
->
n_attrs
;
++
k
)
{
PaddleMobile__Framework__Proto__OpDesc__Attr
*
attr
=
desc
->
attrs
[
k
];
PaddleMobile__Framework__Proto__OpDesc__Attr
*
attr
=
desc
->
attrs
[
k
];
std
::
string
attr_name
(
attr
->
name
);
std
::
string
attr_name
(
attr
->
name
);
if
(
attr
->
type
!=
PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__BLOCK
)
{
attrs_
[
attr_name
]
=
Attribute
::
GetAttrValue
(
attr
);
attrs_
[
attr_name
]
=
Attribute
::
GetAttrValue
(
attr
);
}
}
}
}
}
...
...
src/io/jni/paddle_mobile_jni.cpp
浏览文件 @
0294a4e2
...
@@ -90,7 +90,8 @@ JNIEXPORT jboolean JNICALL Java_com_baidu_paddle_PML_loadQualified(
...
@@ -90,7 +90,8 @@ JNIEXPORT jboolean JNICALL Java_com_baidu_paddle_PML_loadQualified(
#ifdef ENABLE_EXCEPTION
#ifdef ENABLE_EXCEPTION
try
{
try
{
isLoadOk
=
getPaddleMobileInstance
()
->
Load
(
isLoadOk
=
getPaddleMobileInstance
()
->
Load
(
jstring2cppstring
(
env
,
modelPath
),
optimize
,
qualified
);
jstring2cppstring
(
env
,
modelPath
),
optimize
,
qualified
,
1
,
static_cast
<
bool
>
(
lodMode
));
}
catch
(
paddle_mobile
::
PaddleMobileException
&
e
)
{
}
catch
(
paddle_mobile
::
PaddleMobileException
&
e
)
{
ANDROIDLOGE
(
"jni got an PaddleMobileException! "
,
e
.
what
());
ANDROIDLOGE
(
"jni got an PaddleMobileException! "
,
e
.
what
());
isLoadOk
=
false
;
isLoadOk
=
false
;
...
@@ -116,7 +117,7 @@ JNIEXPORT jboolean JNICALL Java_com_baidu_paddle_PML_loadCombined(
...
@@ -116,7 +117,7 @@ JNIEXPORT jboolean JNICALL Java_com_baidu_paddle_PML_loadCombined(
try
{
try
{
isLoadOk
=
getPaddleMobileInstance
()
->
Load
(
isLoadOk
=
getPaddleMobileInstance
()
->
Load
(
jstring2cppstring
(
env
,
modelPath
),
jstring2cppstring
(
env
,
paramPath
),
jstring2cppstring
(
env
,
modelPath
),
jstring2cppstring
(
env
,
paramPath
),
optimize
);
optimize
,
false
,
1
,
static_cast
<
bool
>
(
lodMode
)
);
}
catch
(
paddle_mobile
::
PaddleMobileException
&
e
)
{
}
catch
(
paddle_mobile
::
PaddleMobileException
&
e
)
{
ANDROIDLOGE
(
"jni got an PaddleMobileException! "
,
e
.
what
());
ANDROIDLOGE
(
"jni got an PaddleMobileException! "
,
e
.
what
());
isLoadOk
=
false
;
isLoadOk
=
false
;
...
@@ -142,7 +143,7 @@ JNIEXPORT jboolean JNICALL Java_com_baidu_paddle_PML_loadCombinedQualified(
...
@@ -142,7 +143,7 @@ JNIEXPORT jboolean JNICALL Java_com_baidu_paddle_PML_loadCombinedQualified(
try
{
try
{
isLoadOk
=
getPaddleMobileInstance
()
->
Load
(
isLoadOk
=
getPaddleMobileInstance
()
->
Load
(
jstring2cppstring
(
env
,
modelPath
),
jstring2cppstring
(
env
,
paramPath
),
jstring2cppstring
(
env
,
modelPath
),
jstring2cppstring
(
env
,
paramPath
),
optimize
,
qualified
);
optimize
,
qualified
,
1
,
static_cast
<
bool
>
(
lodMode
)
);
}
catch
(
paddle_mobile
::
PaddleMobileException
&
e
)
{
}
catch
(
paddle_mobile
::
PaddleMobileException
&
e
)
{
ANDROIDLOGE
(
"jni got an PaddleMobileException! "
,
e
.
what
());
ANDROIDLOGE
(
"jni got an PaddleMobileException! "
,
e
.
what
());
isLoadOk
=
false
;
isLoadOk
=
false
;
...
...
src/operators/controlflow/tensor_array_read_write_op.cpp
0 → 100644
浏览文件 @
0294a4e2
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
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 "operators/controlflow/tensor_array_read_write_op.h"
namespace
paddle_mobile
{
namespace
operators
{
#ifdef WRITE_TO_ARRAY_OP
template
<
typename
Dtype
,
typename
T
>
void
WriteToArrayOp
<
Dtype
,
T
>::
InferShape
()
const
{}
#endif // WRITE_TO_ARRAY_OP
#ifdef READ_FROM_ARRAY_OP
template
<
typename
Dtype
,
typename
T
>
void
ReadFromArrayOp
<
Dtype
,
T
>::
InferShape
()
const
{}
#endif // READ_FROM_ARRAY_OP
}
// namespace operators
}
// namespace paddle_mobile
namespace
ops
=
paddle_mobile
::
operators
;
#ifdef PADDLE_MOBILE_CPU
#ifdef WRITE_TO_ARRAY_OP
REGISTER_OPERATOR_CPU
(
write_to_array
,
ops
::
WriteToArrayOp
);
#endif // WRITE_TO_ARRAY_OP
#ifdef READ_FROM_ARRAY_OP
REGISTER_OPERATOR_CPU
(
read_from_array
,
ops
::
ReadFromArrayOp
);
#endif // READ_FROM_ARRAY_OP
#endif
src/operators/controlflow/tensor_array_read_write_op.h
0 → 100644
浏览文件 @
0294a4e2
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
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 <string>
#include "framework/operator.h"
#include "operators/kernel/tensor_array_read_write_kernel.h"
#include "operators/op_param.h"
namespace
paddle_mobile
{
namespace
operators
{
#ifdef WRITE_TO_ARRAY_OP
DECLARE_OPERATOR
(
WriteToArray
,
WriteToArrayParam
,
WriteToArrayKernel
);
#endif // WRITE_TO_ARRAY_OP
#ifdef READ_FROM_ARRAY_OP
DECLARE_OPERATOR
(
ReadFromArray
,
ReadFromArrayParam
,
ReadFromArrayKernel
);
#endif // WRITE_TO_ARRAY_OP
}
// namespace operators
}
// namespace paddle_mobile
src/operators/controlflow/while_op.cpp
0 → 100644
浏览文件 @
0294a4e2
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
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 "operators/controlflow/while_op.h"
namespace
paddle_mobile
{
namespace
operators
{
#ifdef WHILE_OP
template
<
typename
Dtype
,
typename
T
>
void
WhileOp
<
Dtype
,
T
>::
InferShape
()
const
{
// TODO(hjchen2)
}
#endif // WHILE_OP
}
// namespace operators
}
// namespace paddle_mobile
namespace
ops
=
paddle_mobile
::
operators
;
#ifdef PADDLE_MOBILE_CPU
#ifdef WHILE_OP
REGISTER_OPERATOR_CPU
(
while
,
ops
::
WhileOp
);
#endif // WHILE_OP
#endif
src/operators/controlflow/while_op.h
0 → 100644
浏览文件 @
0294a4e2
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
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 <string>
#include "framework/operator.h"
#include "operators/kernel/while_kernel.h"
#include "operators/op_param.h"
namespace
paddle_mobile
{
namespace
operators
{
#ifdef WHILE_OP
DECLARE_OPERATOR
(
While
,
WhileParam
,
WhileKernel
);
#endif // WHILE_OP
}
// namespace operators
}
// namespace paddle_mobile
src/operators/kernel/arm/tensor_array_read_write_kernel.cpp
0 → 100644
浏览文件 @
0294a4e2
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
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 "operators/kernel/tensor_array_read_write_kernel.h"
namespace
paddle_mobile
{
namespace
operators
{
#ifdef WRITE_TO_ARRAY_OP
template
<
>
bool
WriteToArrayKernel
<
CPU
,
float
>::
Init
(
WriteToArrayParam
<
CPU
>
*
param
)
{
return
true
;
}
template
<
>
void
WriteToArrayKernel
<
CPU
,
float
>::
Compute
(
const
WriteToArrayParam
<
CPU
>
&
param
)
{
int64_t
offset
=
param
.
index_
->
data
<
int64_t
>
()[
0
];
if
(
offset
>=
param
.
output_
->
size
())
{
param
.
output_
->
resize
(
offset
);
}
framework
::
LoDTensor
*
out_tensor
=
&
(
param
.
output_
->
at
(
offset
));
out_tensor
->
set_lod
(
param
.
input_
->
lod
());
if
(
param
.
input_
->
memory_size
()
>
0
)
{
TensorCopy
(
*
(
param
.
input_
),
out_tensor
);
}
}
#endif // WRITE_TO_ARRAY_OP
#ifdef READ_FROM_ARRAY_OP
template
<
>
bool
ReadFromArrayKernel
<
CPU
,
float
>::
Init
(
ReadFromArrayParam
<
CPU
>
*
param
)
{
return
true
;
}
template
<
>
void
ReadFromArrayKernel
<
CPU
,
float
>::
Compute
(
const
ReadFromArrayParam
<
CPU
>
&
param
)
{
int64_t
offset
=
param
.
index_
->
data
<
int64_t
>
()[
0
];
if
(
offset
<
param
.
input_
->
size
())
{
TensorCopy
(
param
.
input_
->
at
(
offset
),
param
.
output_
);
}
}
#endif // READ_FROM_ARRAY_OP
}
// namespace operators
}
// namespace paddle_mobile
src/operators/kernel/arm/while_kernel.cpp
0 → 100644
浏览文件 @
0294a4e2
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
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 "operators/kernel/while_kernel.h"
namespace
paddle_mobile
{
namespace
operators
{
#ifdef WHILE_OP
template
<
>
bool
WhileKernel
<
CPU
,
float
>::
Init
(
WhileParam
<
CPU
>
*
param
)
{
return
true
;
}
template
<
>
void
WhileKernel
<
CPU
,
float
>::
Compute
(
const
WhileParam
<
CPU
>
&
param
)
{
// TODO(hjchen2)
}
#endif // WHILE_OP
}
// namespace operators
}
// namespace paddle_mobile
src/operators/kernel/tensor_array_read_write_kernel.h
0 → 100644
浏览文件 @
0294a4e2
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
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 "framework/operator.h"
#include "operators/op_param.h"
namespace
paddle_mobile
{
namespace
operators
{
#ifdef WRITE_TO_ARRAY_OP
DECLARE_KERNEL
(
WriteToArray
,
WriteToArrayParam
);
#endif // WRITE_TO_ARRAY_OP
#ifdef READ_FROM_ARRAY_OP
DECLARE_KERNEL
(
ReadFromArray
,
ReadFromArrayParam
);
#endif // READ_FROM_ARRAY_OP
}
// namespace operators
}
// namespace paddle_mobile
src/operators/kernel/while_kernel.h
0 → 100644
浏览文件 @
0294a4e2
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
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 "framework/operator.h"
#include "operators/op_param.h"
namespace
paddle_mobile
{
namespace
operators
{
#ifdef WHILE_OP
template
<
typename
Dtype
>
class
WhileParam
:
public
OpParam
{
public:
WhileParam
(
const
VariableNameMap
&
inputs
,
const
VariableNameMap
&
outputs
,
const
AttributeMap
&
attrs
,
const
Scope
&
scope
)
:
inputs_
(
inputs
),
outputs_
(
outputs
),
scope_
(
scope
)
{
cond_
=
OpParam
::
GetVarValue
<
framework
::
LoDTensor
>
(
"Condition"
,
inputs
,
scope
);
sub_block_
=
OpParam
::
GetAttr
<
int
>
(
"sub_block"
,
attrs
);
}
public:
framework
::
LoDTensor
*
cond_
;
int
sub_block_
;
const
VariableNameMap
inputs_
;
const
VariableNameMap
outputs_
;
const
Scope
scope_
;
};
DECLARE_KERNEL
(
While
,
WhileParam
);
#endif // WHILE_OP
}
// namespace operators
}
// namespace paddle_mobile
src/operators/math/gemm.h
浏览文件 @
0294a4e2
...
@@ -13,6 +13,7 @@ See the License for the specific language governing permissions and
...
@@ -13,6 +13,7 @@ See the License for the specific language governing permissions and
limitations under the License. */
limitations under the License. */
#pragma once
#pragma once
#include <cstring>
#include <string>
#include <string>
#include "common/log.h"
#include "common/log.h"
#include "memory/t_malloc.h"
#include "memory/t_malloc.h"
...
...
src/operators/op_param.h
浏览文件 @
0294a4e2
...
@@ -2991,5 +2991,63 @@ class LogicalUnaryParam : public OpParam {
...
@@ -2991,5 +2991,63 @@ class LogicalUnaryParam : public OpParam {
};
};
#endif // LOGICAL_NOT_OP
#endif // LOGICAL_NOT_OP
// #ifdef WHILE_OP
// template <typename Dtype>
// class WhileParam : public OpParam {
// public:
// WhileParam(const VariableNameMap &inputs,
// const VariableNameMap &outputs, const AttributeMap &attrs,
// const Scope &scope) {
// cond_ = OpParam::GetVarValue<framework::LoDTensor>("Condition", inputs,
// scope); block_desc_ = OpParam::GetAttr<framework::BlockDesc
// *>("sub_block", attrs);
// }
//
// public:
// framework::LoDTensor *cond_;
// const framework::BlockDesc *block_desc_;
// };
// #endif // WHILE_OP
#ifdef WRITE_TO_ARRAY_OP
template
<
typename
Dtype
>
class
WriteToArrayParam
:
public
OpParam
{
public:
WriteToArrayParam
(
const
VariableNameMap
&
inputs
,
const
VariableNameMap
&
outputs
,
const
AttributeMap
&
attrs
,
const
Scope
&
scope
)
{
input_
=
OpParam
::
GetVarValue
<
framework
::
LoDTensor
>
(
"X"
,
inputs
,
scope
);
index_
=
OpParam
::
GetVarValue
<
framework
::
LoDTensor
>
(
"I"
,
inputs
,
scope
);
output_
=
OpParam
::
GetVarValue
<
framework
::
LoDTensorArray
>
(
"Out"
,
outputs
,
scope
);
}
public:
framework
::
LoDTensor
*
input_
;
framework
::
LoDTensor
*
index_
;
framework
::
LoDTensorArray
*
output_
;
};
#endif
#ifdef READ_FROM_ARRAY_OP
template
<
typename
Dtype
>
class
ReadFromArrayParam
:
public
OpParam
{
public:
ReadFromArrayParam
(
const
VariableNameMap
&
inputs
,
const
VariableNameMap
&
outputs
,
const
AttributeMap
&
attrs
,
const
Scope
&
scope
)
{
input_
=
OpParam
::
GetVarValue
<
framework
::
LoDTensorArray
>
(
"X"
,
inputs
,
scope
);
index_
=
OpParam
::
GetVarValue
<
framework
::
LoDTensor
>
(
"I"
,
inputs
,
scope
);
output_
=
OpParam
::
GetVarValue
<
framework
::
LoDTensor
>
(
"Out"
,
outputs
,
scope
);
}
public:
framework
::
LoDTensorArray
*
input_
;
framework
::
LoDTensor
*
index_
;
framework
::
LoDTensor
*
output_
;
};
#endif
}
// namespace operators
}
// namespace operators
}
// namespace paddle_mobile
}
// namespace paddle_mobile
src/operators/reshape_op.cpp
100755 → 100644
浏览文件 @
0294a4e2
文件模式从 100755 更改为 100644
test/CMakeLists.txt
浏览文件 @
0294a4e2
...
@@ -337,8 +337,8 @@ if (NOT FOUND_MATCH)
...
@@ -337,8 +337,8 @@ if (NOT FOUND_MATCH)
target_link_libraries
(
test-genet paddle-mobile
)
target_link_libraries
(
test-genet paddle-mobile
)
# gen test
# gen test
ADD_EXECUTABLE
(
test-sigmoid operators/test_sigmoid_op.cpp test_include.h
)
ADD_EXECUTABLE
(
test-sigmoid
-op
operators/test_sigmoid_op.cpp test_include.h
)
target_link_libraries
(
test-sigmoid paddle-mobile
)
target_link_libraries
(
test-sigmoid
-op
paddle-mobile
)
# gen test
# gen test
ADD_EXECUTABLE
(
test-depthwise-conv-op operators/test_depthwise_conv_op.cpp test_helper.h test_include.h executor_for_test.h
)
ADD_EXECUTABLE
(
test-depthwise-conv-op operators/test_depthwise_conv_op.cpp test_helper.h test_include.h executor_for_test.h
)
...
@@ -408,14 +408,14 @@ if (NOT FOUND_MATCH)
...
@@ -408,14 +408,14 @@ if (NOT FOUND_MATCH)
ADD_EXECUTABLE
(
test-ocr net/test_ocr.cpp test_helper.h test_include.h
)
ADD_EXECUTABLE
(
test-ocr net/test_ocr.cpp test_helper.h test_include.h
)
target_link_libraries
(
test-ocr paddle-mobile
)
target_link_libraries
(
test-ocr paddle-mobile
)
ADD_EXECUTABLE
(
test-sequence-expand operators/test_sequence_expand_op.cpp test_helper.h test_include.h
)
ADD_EXECUTABLE
(
test-sequence-expand
-op
operators/test_sequence_expand_op.cpp test_helper.h test_include.h
)
target_link_libraries
(
test-sequence-expand paddle-mobile
)
target_link_libraries
(
test-sequence-expand
-op
paddle-mobile
)
ADD_EXECUTABLE
(
test-sequence-pool operators/test_sequence_pool_op.cpp test_helper.h test_include.h
)
ADD_EXECUTABLE
(
test-sequence-pool
-op
operators/test_sequence_pool_op.cpp test_helper.h test_include.h
)
target_link_libraries
(
test-sequence-pool paddle-mobile
)
target_link_libraries
(
test-sequence-pool
-op
paddle-mobile
)
ADD_EXECUTABLE
(
test-sequence-softmax operators/test_sequence_softmax_op.cpp test_helper.h test_include.h
)
ADD_EXECUTABLE
(
test-sequence-softmax
-op
operators/test_sequence_softmax_op.cpp test_helper.h test_include.h
)
target_link_libraries
(
test-sequence-softmax paddle-mobile
)
target_link_libraries
(
test-sequence-softmax
-op
paddle-mobile
)
# gen test
# gen test
ADD_EXECUTABLE
(
test-vgg16ssd net/test_vgg16ssd.cpp test_helper.h test_include.h
)
ADD_EXECUTABLE
(
test-vgg16ssd net/test_vgg16ssd.cpp test_helper.h test_include.h
)
...
...
test/operators/test_conv_op.cpp
浏览文件 @
0294a4e2
...
@@ -222,27 +222,8 @@ int TestConvOp(int in_channels, int in_height, int in_width, int out_channels,
...
@@ -222,27 +222,8 @@ int TestConvOp(int in_channels, int in_height, int in_width, int out_channels,
}
// namespace paddle_mobile
}
// namespace paddle_mobile
int
main
(
int
argc
,
char
*
argv
[])
{
int
TestAll
(
const
int
in_channels
,
const
int
in_height
,
const
int
in_width
,
if
(
argc
<
5
)
{
const
int
out_channels
,
const
int
groups
)
{
LOG
(
paddle_mobile
::
kLOG_INFO
)
<<
"Usage:
\n
"
<<
" ./test-int8-conv-op in_channels in_height in_width out_channels "
"[groups]
\n
"
<<
" params:
\n
"
<<
" -in_channels: int, input image's channels
\n
"
<<
" -in_height: int, input image's height
\n
"
<<
" -in_width: int, input image's width
\n
"
<<
" -out_channels: int, conv output channels
\n
"
;
return
1
;
}
int
in_channels
=
atoi
(
argv
[
1
]);
int
in_height
=
atoi
(
argv
[
2
]);
int
in_width
=
atoi
(
argv
[
3
]);
int
out_channels
=
atoi
(
argv
[
4
]);
int
groups
=
1
;
if
(
argc
==
6
)
{
groups
=
atoi
(
argv
[
5
]);
}
// kernel = 3, pad = 0, stride = 1
// kernel = 3, pad = 0, stride = 1
LOG
(
paddle_mobile
::
kLOG_INFO
)
<<
"float, kernel=3, pad=0, stride=1"
;
LOG
(
paddle_mobile
::
kLOG_INFO
)
<<
"float, kernel=3, pad=0, stride=1"
;
paddle_mobile
::
TestConvOp
<
int8_t
,
int32_t
,
3
,
0
,
1
>
(
paddle_mobile
::
TestConvOp
<
int8_t
,
int32_t
,
3
,
0
,
1
>
(
...
@@ -313,3 +294,18 @@ int main(int argc, char *argv[]) {
...
@@ -313,3 +294,18 @@ int main(int argc, char *argv[]) {
return
0
;
return
0
;
}
}
int
main
()
{
TestAll
(
1
,
5
,
5
,
1
,
1
);
TestAll
(
1
,
5
,
5
,
10
,
1
);
TestAll
(
10
,
5
,
5
,
10
,
10
);
TestAll
(
5
,
33
,
33
,
5
,
1
);
TestAll
(
5
,
33
,
33
,
13
,
1
);
TestAll
(
13
,
33
,
33
,
13
,
13
);
TestAll
(
5
,
33
,
13
,
5
,
1
);
TestAll
(
5
,
33
,
13
,
13
,
1
);
TestAll
(
13
,
33
,
13
,
13
,
13
);
return
0
;
}
test/operators/test_log_op.cpp
浏览文件 @
0294a4e2
...
@@ -76,6 +76,5 @@ int main() {
...
@@ -76,6 +76,5 @@ int main() {
paddle_mobile
::
TestLogOp
({
1
,
1
,
2
,
3
});
paddle_mobile
::
TestLogOp
({
1
,
1
,
2
,
3
});
paddle_mobile
::
TestLogOp
({
1
,
3
,
11
,
22
});
paddle_mobile
::
TestLogOp
({
1
,
3
,
11
,
22
});
paddle_mobile
::
TestLogOp
({
1
,
32
,
112
,
112
});
paddle_mobile
::
TestLogOp
({
1
,
32
,
112
,
112
});
std
::
cout
<<
"test log op pass."
<<
std
::
endl
;
return
0
;
return
0
;
}
}
test/operators/test_quantize_op.cpp
浏览文件 @
0294a4e2
...
@@ -92,18 +92,10 @@ static float find_abs_max(const Tensor *input) {
...
@@ -92,18 +92,10 @@ static float find_abs_max(const Tensor *input) {
return
max_abs
;
return
max_abs
;
}
}
int
TestQuqntizeOp
(
int
argc
,
char
*
argv
[])
{
int
TestQuqntizeOp
(
const
int
batch_size
,
const
int
channel
,
const
int
height
,
if
(
argc
<
5
)
{
const
int
width
)
{
std
::
cout
<<
"Usage: ./test-quantize-op batch_size channel height width"
DLOG
<<
"batch_size: "
<<
batch_size
<<
", channel: "
<<
channel
<<
std
::
endl
;
<<
", height: "
<<
height
<<
", width: "
<<
width
;
return
1
;
}
int
batch_size
=
atoi
(
argv
[
1
]);
int
channel
=
atoi
(
argv
[
2
]);
int
height
=
atoi
(
argv
[
3
]);
int
width
=
atoi
(
argv
[
4
]);
std
::
cout
<<
"batch_size: "
<<
batch_size
<<
", channel: "
<<
channel
<<
", height: "
<<
height
<<
", width: "
<<
width
<<
std
::
endl
;
framework
::
DDim
dim
=
framework
::
DDim
dim
=
framework
::
make_ddim
({
batch_size
,
channel
,
height
,
width
});
framework
::
make_ddim
({
batch_size
,
channel
,
height
,
width
});
...
@@ -140,9 +132,7 @@ int TestQuqntizeOp(int argc, char *argv[]) {
...
@@ -140,9 +132,7 @@ int TestQuqntizeOp(int argc, char *argv[]) {
framework
::
Tensor
output_cmp
;
framework
::
Tensor
output_cmp
;
output_cmp
.
Resize
(
output
->
dims
());
output_cmp
.
Resize
(
output
->
dims
());
float
scale
=
127
/
output_scale_cmp
;
float
scale
=
127
/
output_scale_cmp
;
// quantize<round::RoundToEven>(input, scale, &output_cmp);
quantize
<
round
::
RoundAwayZero
>
(
input
,
scale
,
&
output_cmp
);
// quantize<round::RoundAwayZero>(input, scale, &output_cmp);
quantize
<
round
::
RoundTowardsZero
>
(
input
,
scale
,
&
output_cmp
);
int8_t
*
output_cmp_data
=
output_cmp
.
data
<
int8_t
>
();
int8_t
*
output_cmp_data
=
output_cmp
.
data
<
int8_t
>
();
for
(
int
i
=
0
;
i
<
output
->
numel
();
++
i
)
{
for
(
int
i
=
0
;
i
<
output
->
numel
();
++
i
)
{
PADDLE_MOBILE_ENFORCE
(
output_data
[
i
]
==
output_cmp_data
[
i
],
PADDLE_MOBILE_ENFORCE
(
output_data
[
i
]
==
output_cmp_data
[
i
],
...
@@ -157,5 +147,7 @@ int TestQuqntizeOp(int argc, char *argv[]) {
...
@@ -157,5 +147,7 @@ int TestQuqntizeOp(int argc, char *argv[]) {
}
// namespace paddle_mobile
}
// namespace paddle_mobile
int
main
(
int
argc
,
char
*
argv
[])
{
int
main
(
int
argc
,
char
*
argv
[])
{
return
paddle_mobile
::
TestQuqntizeOp
(
argc
,
argv
);
TestQuqntizeOp
(
1
,
10
,
10
,
5
);
TestQuqntizeOp
(
1
,
111
,
111
,
5
);
TestQuqntizeOp
(
5
,
111
,
111
,
5
);
}
}
test/operators/test_sequence_pool_op.cpp
浏览文件 @
0294a4e2
...
@@ -59,7 +59,7 @@ int TestSequencePoolOp(const framework::LoDTensor &input_x,
...
@@ -59,7 +59,7 @@ int TestSequencePoolOp(const framework::LoDTensor &input_x,
int
main
(
int
argc
,
char
*
argv
[])
{
int
main
(
int
argc
,
char
*
argv
[])
{
framework
::
LoDTensor
input_x
,
output
;
framework
::
LoDTensor
input_x
,
output
;
// case 1
// case 1
std
::
cerr
<<
"running max case 1"
<<
std
::
endl
;
DLOG
<<
"running max case 1"
;
{
{
std
::
vector
<
float
>
data
{
1
,
2
,
3
,
4
};
std
::
vector
<
float
>
data
{
1
,
2
,
3
,
4
};
input_x
.
Resize
(
framework
::
make_ddim
({
4
,
1
}));
input_x
.
Resize
(
framework
::
make_ddim
({
4
,
1
}));
...
@@ -71,14 +71,14 @@ int main(int argc, char *argv[]) {
...
@@ -71,14 +71,14 @@ int main(int argc, char *argv[]) {
std
::
vector
<
float
>
expect_data
{
2
,
4
};
std
::
vector
<
float
>
expect_data
{
2
,
4
};
for
(
int
i
=
0
;
i
<
2
;
++
i
)
{
for
(
int
i
=
0
;
i
<
2
;
++
i
)
{
if
(
output
.
data
<
float
>
()[
i
]
!=
expect_data
[
i
])
{
if
(
output
.
data
<
float
>
()[
i
]
!=
expect_data
[
i
])
{
std
::
cerr
<<
"output["
<<
i
<<
"]: "
<<
output
.
data
<
float
>
()[
i
]
DLOG
<<
"output["
<<
i
<<
"]: "
<<
output
.
data
<
float
>
()[
i
]
<<
" != expect["
<<
i
<<
"]: "
<<
expect_data
[
i
]
<<
std
::
endl
;
<<
" != expect["
<<
i
<<
"]: "
<<
expect_data
[
i
]
;
return
1
;
return
1
;
}
}
}
}
}
}
// case 2
// case 2
std
::
cerr
<<
"running max case 2"
<<
std
::
endl
;
DLOG
<<
"running max case 2"
;
{
{
std
::
vector
<
float
>
data
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
};
std
::
vector
<
float
>
data
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
};
input_x
.
Resize
(
framework
::
make_ddim
({
data
.
size
(),
1
}));
input_x
.
Resize
(
framework
::
make_ddim
({
data
.
size
(),
1
}));
...
@@ -90,13 +90,13 @@ int main(int argc, char *argv[]) {
...
@@ -90,13 +90,13 @@ int main(int argc, char *argv[]) {
std
::
vector
<
float
>
expect_data
{
3
,
10
};
std
::
vector
<
float
>
expect_data
{
3
,
10
};
for
(
int
i
=
0
;
i
<
2
;
++
i
)
{
for
(
int
i
=
0
;
i
<
2
;
++
i
)
{
if
(
output
.
data
<
float
>
()[
i
]
!=
expect_data
[
i
])
{
if
(
output
.
data
<
float
>
()[
i
]
!=
expect_data
[
i
])
{
std
::
cerr
<<
"output["
<<
i
<<
"]: "
<<
output
.
data
<
float
>
()[
i
]
DLOG
<<
"output["
<<
i
<<
"]: "
<<
output
.
data
<
float
>
()[
i
]
<<
" != expect["
<<
i
<<
"]: "
<<
expect_data
[
i
]
<<
std
::
endl
;
<<
" != expect["
<<
i
<<
"]: "
<<
expect_data
[
i
]
;
return
1
;
return
1
;
}
}
}
}
}
}
std
::
cerr
<<
"running max case 3"
<<
std
::
endl
;
DLOG
<<
"running max case 3"
;
// case 3
// case 3
{
{
std
::
vector
<
float
>
data
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
};
std
::
vector
<
float
>
data
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
};
...
@@ -109,14 +109,14 @@ int main(int argc, char *argv[]) {
...
@@ -109,14 +109,14 @@ int main(int argc, char *argv[]) {
std
::
vector
<
float
>
expect_data
{
3
,
4
,
7
,
8
};
std
::
vector
<
float
>
expect_data
{
3
,
4
,
7
,
8
};
for
(
int
i
=
0
;
i
<
4
;
++
i
)
{
for
(
int
i
=
0
;
i
<
4
;
++
i
)
{
if
(
output
.
data
<
float
>
()[
i
]
!=
expect_data
[
i
])
{
if
(
output
.
data
<
float
>
()[
i
]
!=
expect_data
[
i
])
{
std
::
cerr
<<
"output["
<<
i
<<
"]: "
<<
output
.
data
<
float
>
()[
i
]
DLOG
<<
"output["
<<
i
<<
"]: "
<<
output
.
data
<
float
>
()[
i
]
<<
" != expect["
<<
i
<<
"]: "
<<
expect_data
[
i
]
<<
std
::
endl
;
<<
" != expect["
<<
i
<<
"]: "
<<
expect_data
[
i
]
;
return
1
;
return
1
;
}
}
}
}
}
}
// case 4
// case 4
std
::
cerr
<<
"running max case 4"
<<
std
::
endl
;
DLOG
<<
"running max case 4"
;
{
{
std
::
vector
<
float
>
data
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
,
std
::
vector
<
float
>
data
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
,
11
,
12
,
13
,
14
,
15
,
16
,
17
,
18
,
19
,
20
};
11
,
12
,
13
,
14
,
15
,
16
,
17
,
18
,
19
,
20
};
...
@@ -129,14 +129,14 @@ int main(int argc, char *argv[]) {
...
@@ -129,14 +129,14 @@ int main(int argc, char *argv[]) {
std
::
vector
<
float
>
expect_data
{
6
,
7
,
8
,
9
,
10
,
16
,
17
,
18
,
19
,
20
};
std
::
vector
<
float
>
expect_data
{
6
,
7
,
8
,
9
,
10
,
16
,
17
,
18
,
19
,
20
};
for
(
int
i
=
0
;
i
<
10
;
++
i
)
{
for
(
int
i
=
0
;
i
<
10
;
++
i
)
{
if
(
output
.
data
<
float
>
()[
i
]
!=
expect_data
[
i
])
{
if
(
output
.
data
<
float
>
()[
i
]
!=
expect_data
[
i
])
{
std
::
cerr
<<
"output["
<<
i
<<
"]: "
<<
output
.
data
<
float
>
()[
i
]
DLOG
<<
"output["
<<
i
<<
"]: "
<<
output
.
data
<
float
>
()[
i
]
<<
" != expect["
<<
i
<<
"]: "
<<
expect_data
[
i
]
<<
std
::
endl
;
<<
" != expect["
<<
i
<<
"]: "
<<
expect_data
[
i
]
;
return
1
;
return
1
;
}
}
}
}
}
}
// case 1
// case 1
std
::
cerr
<<
"running sum case 1"
<<
std
::
endl
;
DLOG
<<
"running sum case 1"
;
{
{
std
::
vector
<
float
>
data
{
1
,
2
,
3
,
4
};
std
::
vector
<
float
>
data
{
1
,
2
,
3
,
4
};
input_x
.
Resize
(
framework
::
make_ddim
({
4
,
1
}));
input_x
.
Resize
(
framework
::
make_ddim
({
4
,
1
}));
...
@@ -148,14 +148,14 @@ int main(int argc, char *argv[]) {
...
@@ -148,14 +148,14 @@ int main(int argc, char *argv[]) {
std
::
vector
<
float
>
expect_data
{
3
,
7
};
std
::
vector
<
float
>
expect_data
{
3
,
7
};
for
(
int
i
=
0
;
i
<
2
;
++
i
)
{
for
(
int
i
=
0
;
i
<
2
;
++
i
)
{
if
(
output
.
data
<
float
>
()[
i
]
!=
expect_data
[
i
])
{
if
(
output
.
data
<
float
>
()[
i
]
!=
expect_data
[
i
])
{
std
::
cerr
<<
"output["
<<
i
<<
"]: "
<<
output
.
data
<
float
>
()[
i
]
DLOG
<<
"output["
<<
i
<<
"]: "
<<
output
.
data
<
float
>
()[
i
]
<<
" != expect["
<<
i
<<
"]: "
<<
expect_data
[
i
]
<<
std
::
endl
;
<<
" != expect["
<<
i
<<
"]: "
<<
expect_data
[
i
]
;
return
1
;
return
1
;
}
}
}
}
}
}
// case 2
// case 2
std
::
cerr
<<
"running sum case 2"
<<
std
::
endl
;
DLOG
<<
"running sum case 2"
;
{
{
std
::
vector
<
float
>
data
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
};
std
::
vector
<
float
>
data
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
};
input_x
.
Resize
(
framework
::
make_ddim
({
data
.
size
(),
1
}));
input_x
.
Resize
(
framework
::
make_ddim
({
data
.
size
(),
1
}));
...
@@ -167,14 +167,14 @@ int main(int argc, char *argv[]) {
...
@@ -167,14 +167,14 @@ int main(int argc, char *argv[]) {
std
::
vector
<
float
>
expect_data
{
6
,
49
};
std
::
vector
<
float
>
expect_data
{
6
,
49
};
for
(
int
i
=
0
;
i
<
2
;
++
i
)
{
for
(
int
i
=
0
;
i
<
2
;
++
i
)
{
if
(
output
.
data
<
float
>
()[
i
]
!=
expect_data
[
i
])
{
if
(
output
.
data
<
float
>
()[
i
]
!=
expect_data
[
i
])
{
std
::
cerr
<<
"output["
<<
i
<<
"]: "
<<
output
.
data
<
float
>
()[
i
]
DLOG
<<
"output["
<<
i
<<
"]: "
<<
output
.
data
<
float
>
()[
i
]
<<
" != expect["
<<
i
<<
"]: "
<<
expect_data
[
i
]
<<
std
::
endl
;
<<
" != expect["
<<
i
<<
"]: "
<<
expect_data
[
i
]
;
return
1
;
return
1
;
}
}
}
}
}
}
// case 3
// case 3
std
::
cerr
<<
"running sum case 3"
<<
std
::
endl
;
DLOG
<<
"running sum case 3"
;
{
{
std
::
vector
<
float
>
data
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
};
std
::
vector
<
float
>
data
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
};
input_x
.
Resize
(
framework
::
make_ddim
({
4
,
2
}));
input_x
.
Resize
(
framework
::
make_ddim
({
4
,
2
}));
...
@@ -186,14 +186,14 @@ int main(int argc, char *argv[]) {
...
@@ -186,14 +186,14 @@ int main(int argc, char *argv[]) {
std
::
vector
<
float
>
expect_data
{
4
,
6
,
12
,
14
};
std
::
vector
<
float
>
expect_data
{
4
,
6
,
12
,
14
};
for
(
int
i
=
0
;
i
<
4
;
++
i
)
{
for
(
int
i
=
0
;
i
<
4
;
++
i
)
{
if
(
output
.
data
<
float
>
()[
i
]
!=
expect_data
[
i
])
{
if
(
output
.
data
<
float
>
()[
i
]
!=
expect_data
[
i
])
{
std
::
cerr
<<
"output["
<<
i
<<
"]: "
<<
output
.
data
<
float
>
()[
i
]
DLOG
<<
"output["
<<
i
<<
"]: "
<<
output
.
data
<
float
>
()[
i
]
<<
" != expect["
<<
i
<<
"]: "
<<
expect_data
[
i
]
<<
std
::
endl
;
<<
" != expect["
<<
i
<<
"]: "
<<
expect_data
[
i
]
;
return
1
;
return
1
;
}
}
}
}
}
}
// case 4
// case 4
std
::
cerr
<<
"running sum case 4"
<<
std
::
endl
;
DLOG
<<
"running sum case 4"
;
{
{
std
::
vector
<
float
>
data
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
,
std
::
vector
<
float
>
data
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
,
11
,
12
,
13
,
14
,
15
,
16
,
17
,
18
,
19
,
20
};
11
,
12
,
13
,
14
,
15
,
16
,
17
,
18
,
19
,
20
};
...
@@ -206,14 +206,14 @@ int main(int argc, char *argv[]) {
...
@@ -206,14 +206,14 @@ int main(int argc, char *argv[]) {
std
::
vector
<
float
>
expect_data
{
7
,
9
,
11
,
13
,
15
,
27
,
29
,
31
,
33
,
35
};
std
::
vector
<
float
>
expect_data
{
7
,
9
,
11
,
13
,
15
,
27
,
29
,
31
,
33
,
35
};
for
(
int
i
=
0
;
i
<
10
;
++
i
)
{
for
(
int
i
=
0
;
i
<
10
;
++
i
)
{
if
(
output
.
data
<
float
>
()[
i
]
!=
expect_data
[
i
])
{
if
(
output
.
data
<
float
>
()[
i
]
!=
expect_data
[
i
])
{
std
::
cerr
<<
"output["
<<
i
<<
"]: "
<<
output
.
data
<
float
>
()[
i
]
DLOG
<<
"output["
<<
i
<<
"]: "
<<
output
.
data
<
float
>
()[
i
]
<<
" != expect["
<<
i
<<
"]: "
<<
expect_data
[
i
]
<<
std
::
endl
;
<<
" != expect["
<<
i
<<
"]: "
<<
expect_data
[
i
]
;
return
1
;
return
1
;
}
}
}
}
}
}
// case 1
// case 1
std
::
cerr
<<
"running first case 1"
<<
std
::
endl
;
DLOG
<<
"running first case 1"
;
{
{
std
::
vector
<
float
>
data
{
1
,
2
,
3
,
4
};
std
::
vector
<
float
>
data
{
1
,
2
,
3
,
4
};
input_x
.
Resize
(
framework
::
make_ddim
({
4
,
1
}));
input_x
.
Resize
(
framework
::
make_ddim
({
4
,
1
}));
...
@@ -225,14 +225,14 @@ int main(int argc, char *argv[]) {
...
@@ -225,14 +225,14 @@ int main(int argc, char *argv[]) {
std
::
vector
<
float
>
expect_data
{
1
,
3
};
std
::
vector
<
float
>
expect_data
{
1
,
3
};
for
(
int
i
=
0
;
i
<
2
;
++
i
)
{
for
(
int
i
=
0
;
i
<
2
;
++
i
)
{
if
(
output
.
data
<
float
>
()[
i
]
!=
expect_data
[
i
])
{
if
(
output
.
data
<
float
>
()[
i
]
!=
expect_data
[
i
])
{
std
::
cerr
<<
"output["
<<
i
<<
"]: "
<<
output
.
data
<
float
>
()[
i
]
DLOG
<<
"output["
<<
i
<<
"]: "
<<
output
.
data
<
float
>
()[
i
]
<<
" != expect["
<<
i
<<
"]: "
<<
expect_data
[
i
]
<<
std
::
endl
;
<<
" != expect["
<<
i
<<
"]: "
<<
expect_data
[
i
]
;
return
1
;
return
1
;
}
}
}
}
}
}
// case 2
// case 2
std
::
cerr
<<
"running first case 2"
<<
std
::
endl
;
DLOG
<<
"running first case 2"
;
{
{
std
::
vector
<
float
>
data
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
};
std
::
vector
<
float
>
data
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
};
input_x
.
Resize
(
framework
::
make_ddim
({
data
.
size
(),
1
}));
input_x
.
Resize
(
framework
::
make_ddim
({
data
.
size
(),
1
}));
...
@@ -244,14 +244,14 @@ int main(int argc, char *argv[]) {
...
@@ -244,14 +244,14 @@ int main(int argc, char *argv[]) {
std
::
vector
<
float
>
expect_data
{
1
,
4
};
std
::
vector
<
float
>
expect_data
{
1
,
4
};
for
(
int
i
=
0
;
i
<
2
;
++
i
)
{
for
(
int
i
=
0
;
i
<
2
;
++
i
)
{
if
(
output
.
data
<
float
>
()[
i
]
!=
expect_data
[
i
])
{
if
(
output
.
data
<
float
>
()[
i
]
!=
expect_data
[
i
])
{
std
::
cerr
<<
"output["
<<
i
<<
"]: "
<<
output
.
data
<
float
>
()[
i
]
DLOG
<<
"output["
<<
i
<<
"]: "
<<
output
.
data
<
float
>
()[
i
]
<<
" != expect["
<<
i
<<
"]: "
<<
expect_data
[
i
]
<<
std
::
endl
;
<<
" != expect["
<<
i
<<
"]: "
<<
expect_data
[
i
]
;
return
1
;
return
1
;
}
}
}
}
}
}
// case 3
// case 3
std
::
cerr
<<
"running first case 3"
<<
std
::
endl
;
DLOG
<<
"running first case 3"
;
{
{
std
::
vector
<
float
>
data
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
};
std
::
vector
<
float
>
data
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
};
input_x
.
Resize
(
framework
::
make_ddim
({
4
,
2
}));
input_x
.
Resize
(
framework
::
make_ddim
({
4
,
2
}));
...
@@ -263,14 +263,14 @@ int main(int argc, char *argv[]) {
...
@@ -263,14 +263,14 @@ int main(int argc, char *argv[]) {
std
::
vector
<
float
>
expect_data
{
1
,
2
,
5
,
6
};
std
::
vector
<
float
>
expect_data
{
1
,
2
,
5
,
6
};
for
(
int
i
=
0
;
i
<
4
;
++
i
)
{
for
(
int
i
=
0
;
i
<
4
;
++
i
)
{
if
(
output
.
data
<
float
>
()[
i
]
!=
expect_data
[
i
])
{
if
(
output
.
data
<
float
>
()[
i
]
!=
expect_data
[
i
])
{
std
::
cerr
<<
"output["
<<
i
<<
"]: "
<<
output
.
data
<
float
>
()[
i
]
DLOG
<<
"output["
<<
i
<<
"]: "
<<
output
.
data
<
float
>
()[
i
]
<<
" != expect["
<<
i
<<
"]: "
<<
expect_data
[
i
]
<<
std
::
endl
;
<<
" != expect["
<<
i
<<
"]: "
<<
expect_data
[
i
]
;
return
1
;
return
1
;
}
}
}
}
}
}
// case 4
// case 4
std
::
cerr
<<
"running first case 4"
<<
std
::
endl
;
DLOG
<<
"running first case 4"
;
{
{
std
::
vector
<
float
>
data
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
,
std
::
vector
<
float
>
data
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
,
11
,
12
,
13
,
14
,
15
,
16
,
17
,
18
,
19
,
20
};
11
,
12
,
13
,
14
,
15
,
16
,
17
,
18
,
19
,
20
};
...
@@ -283,8 +283,8 @@ int main(int argc, char *argv[]) {
...
@@ -283,8 +283,8 @@ int main(int argc, char *argv[]) {
std
::
vector
<
float
>
expect_data
{
1
,
2
,
3
,
4
,
5
,
11
,
12
,
13
,
14
,
15
};
std
::
vector
<
float
>
expect_data
{
1
,
2
,
3
,
4
,
5
,
11
,
12
,
13
,
14
,
15
};
for
(
int
i
=
0
;
i
<
10
;
++
i
)
{
for
(
int
i
=
0
;
i
<
10
;
++
i
)
{
if
(
output
.
data
<
float
>
()[
i
]
!=
expect_data
[
i
])
{
if
(
output
.
data
<
float
>
()[
i
]
!=
expect_data
[
i
])
{
std
::
cerr
<<
"output["
<<
i
<<
"]: "
<<
output
.
data
<
float
>
()[
i
]
DLOG
<<
"output["
<<
i
<<
"]: "
<<
output
.
data
<
float
>
()[
i
]
<<
" != expect["
<<
i
<<
"]: "
<<
expect_data
[
i
]
<<
std
::
endl
;
<<
" != expect["
<<
i
<<
"]: "
<<
expect_data
[
i
]
;
return
1
;
return
1
;
}
}
}
}
...
...
test/operators/test_sigmoid_op.cpp
浏览文件 @
0294a4e2
...
@@ -76,6 +76,5 @@ int main() {
...
@@ -76,6 +76,5 @@ int main() {
paddle_mobile
::
TestSigmoidOp
({
1
,
1
,
2
,
3
});
paddle_mobile
::
TestSigmoidOp
({
1
,
1
,
2
,
3
});
paddle_mobile
::
TestSigmoidOp
({
1
,
3
,
11
,
22
});
paddle_mobile
::
TestSigmoidOp
({
1
,
3
,
11
,
22
});
paddle_mobile
::
TestSigmoidOp
({
1
,
32
,
112
,
112
});
paddle_mobile
::
TestSigmoidOp
({
1
,
32
,
112
,
112
});
std
::
cout
<<
"test sigmoid op pass."
<<
std
::
endl
;
return
0
;
return
0
;
}
}
test/operators/test_tanh_op.cpp
浏览文件 @
0294a4e2
...
@@ -58,7 +58,7 @@ int TestTanhOp(const std::vector<int> input_shape) {
...
@@ -58,7 +58,7 @@ int TestTanhOp(const std::vector<int> input_shape) {
const
float
*
output_data
=
output
->
data
<
float
>
();
const
float
*
output_data
=
output
->
data
<
float
>
();
for
(
int
i
=
0
;
i
<
output
->
numel
();
++
i
)
{
for
(
int
i
=
0
;
i
<
output
->
numel
();
++
i
)
{
float
gap
=
output_data
[
i
]
-
output_cmp_data
[
i
];
float
gap
=
output_data
[
i
]
-
output_cmp_data
[
i
];
if
(
std
::
abs
(
gap
/
(
output_data
[
i
]
+
1e-5
))
>
1e-3
)
{
if
(
gap
>
1e-5
&&
std
::
abs
(
gap
/
(
output_data
[
i
]
+
1e-5
))
>
1e-3
)
{
LOG
(
kLOG_INFO
)
<<
"output_data["
<<
i
<<
"] = "
<<
output_data
[
i
]
LOG
(
kLOG_INFO
)
<<
"output_data["
<<
i
<<
"] = "
<<
output_data
[
i
]
<<
", output_cmp_data["
<<
i
<<
", output_cmp_data["
<<
i
<<
"] = "
<<
output_cmp_data
[
i
];
<<
"] = "
<<
output_cmp_data
[
i
];
...
...
tools/ci_build.sh
浏览文件 @
0294a4e2
...
@@ -15,6 +15,7 @@
...
@@ -15,6 +15,7 @@
# limitations under the License.
# limitations under the License.
set
-e
set
-e
source
./ci_run_test.sh
function
print_usage
()
{
function
print_usage
()
{
echo
"
\n
${
RED
}
Usage
${
NONE
}
:
echo
"
\n
${
RED
}
Usage
${
NONE
}
:
...
@@ -63,7 +64,7 @@ function check_ndk() {
...
@@ -63,7 +64,7 @@ function check_ndk() {
}
}
function
build_android_armv7_cpu_only
()
{
function
build_android_armv7_cpu_only
()
{
rm
-rf
../build/armeabi-v7a
#
rm -rf ../build/armeabi-v7a
cmake ..
\
cmake ..
\
-B
"../build/armeabi-v7a"
\
-B
"../build/armeabi-v7a"
\
-DANDROID_ABI
=
"armeabi-v7a with NEON"
\
-DANDROID_ABI
=
"armeabi-v7a with NEON"
\
...
@@ -82,7 +83,7 @@ function build_android_armv7_cpu_only() {
...
@@ -82,7 +83,7 @@ function build_android_armv7_cpu_only() {
}
}
function
build_android_armv7_gpu
()
{
function
build_android_armv7_gpu
()
{
rm
-rf
../build/armeabi-v7a
#
rm -rf ../build/armeabi-v7a
cmake ..
\
cmake ..
\
-B
"../build/armeabi-v7a"
\
-B
"../build/armeabi-v7a"
\
-DANDROID_ABI
=
"armeabi-v7a with NEON"
\
-DANDROID_ABI
=
"armeabi-v7a with NEON"
\
...
@@ -231,6 +232,11 @@ function build_linux_fpga() {
...
@@ -231,6 +232,11 @@ function build_linux_fpga() {
docker build
-t
paddle-mobile:dev - < Dockerfile
docker build
-t
paddle-mobile:dev - < Dockerfile
fi
fi
docker run
--rm
-v
`
pwd
`
:/workspace paddle-mobile:dev bash /workspace/tools/docker_build_fpga.sh
docker run
--rm
-v
`
pwd
`
:/workspace paddle-mobile:dev bash /workspace/tools/docker_build_fpga.sh
cd
-
}
function
run_android_test
()
{
ExecuteAndroidTest
$1
}
}
function
main
()
{
function
main
()
{
...
@@ -239,9 +245,11 @@ function main() {
...
@@ -239,9 +245,11 @@ function main() {
case
$CMD
in
case
$CMD
in
android_armv7
)
android_armv7
)
build_android_armv7
build_android_armv7
run_android_test armeabi-v7a
;;
;;
android_armv8
)
android_armv8
)
build_android_armv8
build_android_armv8
run_android_test arm64-v8a
;;
;;
ios
)
ios
)
build_ios
build_ios
...
...
tools/ci_run_test.sh
0 → 100644
浏览文件 @
0294a4e2
#!/usr/bin/env bash
operators
=
function
AddTest
()
{
operators
=
"
${
operators
}
$1
"
}
function
ExecuteAndroidTest
()
{
platform
=
$1
adb shell
rm
-rf
/data/local/tmp/
*
adb push ../build/
${
platform
}
/build/libpaddle-mobile.so /data/local/tmp/
for
op
in
${
operators
}
do
adb push ../test/build/test-
${
op
}
-op
/data/local/tmp/
adb shell
"cd /data/local/tmp/; LD_LIBRARY_PATH=. ./test-
${
op
}
-op"
echo
"
${
BLUE
}
run test
${
op
}
pass
${
NONE
}
"
done
}
AddTest batchnorm
AddTest cast
AddTest conv
AddTest dequantize
#AddTest elementwiseadd
AddTest log
AddTest logical-and
AddTest logical-not
AddTest logical-or
AddTest logical-xor
AddTest pool
AddTest quantize
AddTest relu
AddTest relu6
AddTest sequence-expand
AddTest sequence-pool
AddTest sequence-softmax
AddTest sigmoid
AddTest softmax
AddTest tanh
AddTest topk
tools/docker_build_fpga.sh
浏览文件 @
0294a4e2
#!/usr/bin/env bash
apt-get update
apt-get update
apt-get
install
-y
gcc g++ cmake
apt-get
install
-y
gcc g++ cmake
...
...
tools/op.cmake
浏览文件 @
0294a4e2
...
@@ -285,6 +285,9 @@ if(NOT FOUND_MATCH)
...
@@ -285,6 +285,9 @@ if(NOT FOUND_MATCH)
set
(
LOGICAL_OR_OP ON
)
set
(
LOGICAL_OR_OP ON
)
set
(
LOGICAL_NOT_OP ON
)
set
(
LOGICAL_NOT_OP ON
)
set
(
LOGICAL_XOR_OP ON
)
set
(
LOGICAL_XOR_OP ON
)
set
(
WHILE_OP ON
)
set
(
WRITE_TO_ARRAY_OP ON
)
set
(
READ_FROM_ARRAY_OP ON
)
endif
()
endif
()
# option(BATCHNORM_OP "" ON)
# option(BATCHNORM_OP "" ON)
...
@@ -559,3 +562,13 @@ endif()
...
@@ -559,3 +562,13 @@ endif()
if
(
FUSION_DECONVADDRELU_OP
)
if
(
FUSION_DECONVADDRELU_OP
)
add_definitions
(
-DFUSION_DECONVADDRELU_OP
)
add_definitions
(
-DFUSION_DECONVADDRELU_OP
)
endif
()
endif
()
if
(
WHILE_OP
)
add_definitions
(
-DWHILE_OP
)
endif
()
if
(
WRITE_TO_ARRAY_OP
)
add_definitions
(
-DWRITE_TO_ARRAY_OP
)
endif
()
if
(
READ_FROM_ARRAY_OP
)
add_definitions
(
-DREAD_FROM_ARRAY_OP
)
endif
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录